This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Assign values to component of W.sub(0)

0 votes

if mixed function space W = V*Q, where V is a vector function space, and I want to set the value of second component of V to zero, can we access it as (W.sub(0)).sub(1) ?

Is it possible to set the value using V and then create W ?

asked Aug 31, 2014 by shriram FEniCS User (1,540 points)

1 Answer

0 votes
 
Best answer

Should be straight forward. Something like this should do it:

# Get the scalar FunctionSpace corresponding to V 
S = FunctionSpace(mesh, V.ufl_element().family(), V.ufl_element().degree())    
u0 = interpolate(Expression("x[0]"), S)

# Get Function on W and assign u0 to second component of V
u = Function(W)
assign(u.sub(0).sub(1), u0)
answered Aug 31, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Aug 31, 2014 by shriram
Setting boundary condition of vector component using DirichletBC

Thank you for the answer. That is very useful to know. However, I realized I had completely misrepresented my question. I have submitted a new question for it.

...