How define a vector valued Body force

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
a = (dot(sigma, tau) - dot(u, grad(tau))+ dot(grad(sigma),v) + dot(curl(u),curl(v)))*dx
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)


Community: FEniCS Project

1 Answer

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

You can check section 3.5.3 ( 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)

Please login to add an answer/comment or follow this question.

Similar posts:
Search »