How define a vector valued Body force

207
views
2
5 months ago by
Hi everyone,

I am trying to define exact solution u_D and famous F (on the right-hand side of my bilinear form a(u,v) = f). As follow:

from dolfin import *

# Create mesh
mesh = UnitSquareMesh(32, 32)

# Define function spaces

NED = FiniteElement("N1curl", mesh.ufl_cell(), 1)
CG  = FiniteElement("CG", mesh.ufl_cell(), 1)
W = NED * CG
V = FunctionSpace(mesh,W)

# Define trial and test functions

(sigma, u) = TrialFunctions(V)
(tau, v) = TestFunctions(V)

# Define Exact Solution

u_D = Expression('pow(x[0],2)',('pow(x[0],2)*x[1]'))

# Define Body Force

f = Expression("2","2*x[1]")

# Define variational form
L = f*v*dx

# Define Dirichlet BC
# It has been defined in weak formulation

# Compute solution
w = Function(V)
solve(a == L, w)
(sigma, u) = w.split()

​

As you see they are vector-valued, so I don't know is that possible to define them with Expression or not.

$ud=\left(x^2,y\cdot x^2\right)$ud=(x2,y·x2)
$f=\left(2,2\cdot y\right)$ƒ =(2,2·y)

Thanks,
Ali

Community: FEniCS Project

3
5 months ago by
Yes, it is possible to define vector-valued expressions.

You can check section 3.5.3 (https://fenicsproject.org/pub/tutorial/html/._ftut1010.html#___sec83) of the FEniCS Tutorial, which provides an example of vector-valued Expression:
u_0 = Expression(('sin(x[0])', 'cos(x[0]*x[1])', 'exp(x[1])'), degree=1)​

From that it straightforward for you to define the expressions. For example:

u_D = Expression(('pow(x[0],2)','pow(x[0],2)*x[1]'),degree = 2)