| 1 |
"Demonstrating function evaluation at arbitrary points." |
| 2 |
|
| 3 |
# Copyright (C) 2008 Anders Logg |
| 4 |
# |
| 5 |
# This file is part of DOLFIN. |
| 6 |
# |
| 7 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU Lesser General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# DOLFIN is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU Lesser General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU Lesser General Public License |
| 18 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
# Modified by Johan Hake, 2009 |
| 21 |
|
| 22 |
|
| 23 |
from dolfin import * |
| 24 |
from numpy import array |
| 25 |
|
| 26 |
# Create mesh and a point in the mesh |
| 27 |
mesh = UnitCubeMesh(8, 8, 8); |
| 28 |
x = (0.31, 0.32, 0.33) |
| 29 |
|
| 30 |
# A user-defined function |
| 31 |
Vs = FunctionSpace(mesh, "CG", 2) |
| 32 |
Vv = VectorFunctionSpace(mesh, "CG", 2) |
| 33 |
fs = Expression("sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2])", degree=2) |
| 34 |
fv = Expression(("sin(3.0*x[0])*sin(3.0*x[1])*sin(3.0*x[2])", |
| 35 |
"1.0 + 3.0*x[0] + 4.0*x[1] + 0.5*x[2]","2"), element = Vv.ufl_element()) |
| 36 |
|
| 37 |
# Project to a discrete function |
| 38 |
g = project(fs, V=Vs) |
| 39 |
|
| 40 |
print(""" |
| 41 |
Evaluate user-defined scalar function fs |
| 42 |
fs(x) = %f |
| 43 |
Evaluate discrete function g (projection of fs) |
| 44 |
g(x) = %f |
| 45 |
Evaluate user-defined vector valued function fv |
| 46 |
fs(x) = %s""" % (fs(x), g(x), str(fv(x))) ) |