Incompatible Dirichlet boundary condition

6 months ago by

I'm trying to implement a Dirichlet boundary condition in a scalar function space (3d mesh), but then I run into an error saying that "*** Reason: Expecting a vector-valued boundary value but given function is scalar." I wonder how to solve this issue.

To be more precise, I'm working in a 3d mesh, where some functions are vector (such as velocity vector), but others are scalars (like a electric potential). This electric potential is defined as:
$\text{potential= FunctionSpace(mesh,element, constrained_domain=PeriodicBoundary())}$potential= FunctionSpace(mesh,element, constrained_domain=PeriodicBoundary())

Where, I'm applying Periodic boundary conditions defined as  class elsewhere. Then, on the walls of my geometry I should apply Dirichlet Boundary condition, but the condition varies along the geometry, so I created a class to define such subdomains.

Finally, I try to implement it via:
$\text{bc_walls = DirichletBC(potential,external_p,walls) }$bc_walls = DirichletBC(potential,external_p,walls)

Where external_p is an object from the class described above and walls represents the boundary region. The code fails at this line. Notice that if I try to replace external_p for a scalar constant (such as Constant(0)) I still face the same error, however it would run if I replaced it by a vector constant, such as Constant((0,0,0)).

I appreciate your attention and help.
Community: FEniCS Project
What is "element" in the definition of the FunctionSpace potential?  Is it by any chance a VectorElement?
written 6 months ago by David Kamensky  
It is a mixedElement of 3 Finite elements. I'm following the footsteps of the derived for the system of concentrations, for the system of advection–diffusion–reaction equations in the Fenics tutorial by Hans Petter Langtangen and Anders Logg.
written 6 months ago by George  
You can apply a BC to just one scalar component (say, the n-th component) of the mixed element by using DirichletBC(potential.sub(n),external_p,walls)
written 6 months ago by David Kamensky  
Thank you for your response. One more thing, given that all elements in this mixed element are equivalent (i.e. same type) does it matter which component I choose to apply the BC?
written 6 months ago by George  
Do you only want one scalar field?  If so, you might try just creating a FunctionSpace from a scalar FiniteElement instead of a MixedElement, to avoid the extra degrees of freedom.  If you need the other fields for other things, the I guess you just need to decide on a convention for which variable means what in your problem (which will determine which one requires a BC).
written 6 months ago by David Kamensky  
Yes, I need the 2 other fields. That's why I created the mixed Element. Thank you for your response.
written 6 months ago by George  
# Space
V = VectorFunctionSpace(mesh,'CG',1)
Q = FunctionSpace(mesh,'CG',1)
# mix space...
W = V*Q
# v is vector and Q scalar...
# method to extract vector.. V
lc =  DirichletBC((W.sub(0).sub(0)),Constant(0.0),left)
# method to extract scalar second component...Q
CC = DirichletBC(W.sub(1),Constant(1.0),left)

Hope this helps you..... :)

written 6 months ago by hirshikesh  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »