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

MixedFunctionSpace - update a subfunction

+7 votes

Hey, I need help with this:

class InitialConditions(Expression): 
      def eval(self, values, x):
           values[0] = 0.38*((x[0]-203)**2+(x[1]-291)**2+(x[2]-27.8)**2<=225) + 0.0*((x[0]-203)**2+(x[1]-291)**2+(x[2]-27.8)**2>=225)        
           values[1] = 0.0
           values[2] = 1.0
       def value_shape(self):
           return (3,)   
mesh = Mesh("brain.xml")
V=FunctionSpace(mesh,"Lagrange",1)
ME   = MixedFunctionSpace([V,V,V])

du       = TrialFunction(ME)
q, v, w  = TestFunctions(ME)
u  = Function(ME)
u0 = Function(ME)

dc,dmu,dn = split(du)
c,mu,n    = split(u)
c0,mu0,n0 = split(u0)
u_init = InitialConditions()
u.interpolate(u_init)
u0.interpolate(u_init)

Once I've created initial condition, I use c0 to solve a poisson like equation:

def Boundary(x, on_boundary):
  return on_boundary
bc = DirichletBC(V, Constant("1.0"), Boundary)
m  = TrialFunction(V)
t  = TestFunction(V)
beta=1.6
a = inner(grad(m), grad(t))*dx + c0*m*t*dx + beta*m*t*dx
L = beta*t*dx 
m = Function(V)
solve(a == L, m, bc)

Now I have to assign m to n0 in order to have the right initial condition for my cahn hilliard like problem!
Can anyone help??

asked Jul 9, 2014 by MCri FEniCS User (1,120 points)

2 Answers

+7 votes
 
Best answer

Hi, assign does work with subspaces and can be used in your application

from dolfin import *

mesh = UnitIntervalMesh(20)

V = FunctionSpace(mesh, 'CG', 1)
M = MixedFunctionSpace([V, V])

# Some function in M to illustrate that components
# will change by assign
m = interpolate(Expression(('x[0]', '1-x[0]')), M)
m0, m1 = split(m)

# Plot for comparison
plot(m0, title='m0 before')
plot(m1, title='m1 before')

# Functions for components
v0 = interpolate(Expression('cos(pi*x[0])'), V)
v1 = interpolate(Expression('sin(pi*x[0])'), V)

# Assign the components
assign(m.sub(0), v0)
assign(m.sub(1), v1)

# See if it worked
plot(m0, title='m0 after')
plot(m1, title='m1 after')
interactive() 
answered Jul 9, 2014 by MiroK FEniCS Expert (80,920 points)
selected Jul 11, 2014 by MCri

Thanks a lot!!!!

mixed space assignment
0 votes
answered Jul 9, 2014 by V_L FEniCS User (4,440 points)

I've checked this before asking, but I wasn't able to use it for my problem

...