The next step is to construct a function space over the mesh.
-
We start by loading a Mesh in 2D.
link:{examplesdir}/04-myexpression.cpp[role=include]
-
then we define some expression through the command line of config file:
g
is a scalar field andf
is a vector field, here is an example how to enter them :
./feelpp_tut_myexpression --a=3 --functions.g="a*x*y:x:y:a" --functions.f="{sin(pi*x),cos(pi*y)}:x:y"
You can print back the expression to the screen to check that
everything is ok. You want to use as expression a*x+b*y
, you have to
define a
and b
as option (either in your code, either in the
library).
-
then we compute the gradient of
g
andf
.
link:{examplesdir}/04-myexpression.cpp[role=include]
Note
|
template argument are given to grad to specify the
shape of the gradient: in the case of \$\nabla g\$, it is \$1\times2\$
and \$2\times 2\$ for \$\nabla f\$ since we are in 2D.
|
-
then we compute the laplacian of
g
andf
.
link:{examplesdir}/04-myexpression.cpp[role=include]
-
then we compute the divergence of
f
.
link:{examplesdir}/04-myexpression.cpp[role=include]
-
and the curl of
f
link:{examplesdir}/04-myexpression.cpp[role=include]
-
Finally we evaluate these expressions at one point given by the option
x
andy
.
An implementation reads as follows:
link:{examplesdir}/04-myexpression.cpp[role=include]
and the associated config file
link:{examplesdir}/04-myexpression.cfg[role=include]
$ ./feelpp_tut_myexpression
or
$ ./feelpp_tut_myexpression --a=3 --functions.g="<your_function>" --functions.f="<your_function>"
We start with the following function g=1 and f=(1,1).
$./feelpp_tut_myexpression --functions.g=1:x:y --functions.f="{1,1}:x:y"
and get something like this
g=1
f={1,1}
i=(x-aVal)*y
grad(g)=[[0,0]]
grad(f)=[[0,0],[0,0]]
laplacian(g)=[[0]]
laplacian(f)=[[0],[0]]
div(f)=[[0]]
curl(f)=[[0]]
Evaluation at (0,0):
g(x,y)=1
f(x,y)=1
1
i(x,y)=-0
Gradient:
grad(g)(x,y)=0 0
grad(f)(x,y)=0 0
0 0
Divergence:
div(f)(x,y)=0
Curl:
curl(f)(x,y)=0
Laplacian:
laplacian(g)(x,y)=0
laplacian(f)(x,y)=0
0
The symbolic calculus system worked as expected.