Hi,
I would like to define three initial conditions p0=1bar, θs0=100K and θg0=40K. I am working on a Taylor-Hood mixed function space, and I have tried to apply to Cahn-hilliard demo, but I get an error.
mesh = Mesh("bonmesh.xml")
V1 = VectorFunctionSpace(mesh, 'CG', 2)
V2 = FunctionSpace(mesh, 'CG', 1)
V3 = FunctionSpace(mesh, 'CG', 1)
V4 = FunctionSpace(mesh, 'CG', 1)
W = MixedFunctionSpace([V1, V2, V3, V4])
# Class representing the intial conditions
class InitialConditions(Expression):
def eval(self, values, x):
values[0] = 1.0
values[1] = 100.0
values[2] = 40.0
def value_shape(self):
return (3,)
# Class for interfacing with the Newton solver
class ECRTCEquation(NonlinearProblem):
def __init__(self, a, L):
NonlinearProblem.__init__(self)
self.L = L
self.a = a
self.reset_sparsity = True
def F(self, b, x):
assemble(self.L, tensor=b)
def J(self, A, x):
assemble(self.a, tensor=A, reset_sparsity=self.reset_sparsity)
self.reset_sparsity = False
# Define trial and test functions
du = TrialFunction(W)
v, q, tS, tG = TestFunctions(W)
# Define functions
u = Function(W) # current solution
u0 = Function(W) # solution from previous converged step
# Split mixed functions
duS, dpGR, dthetaS, dthetaG = split(du)
uS, pGR, thetaS, thetaG = split(u)
uS0, pGR0, thetaS0, thetaG0 = split(u0)
# Create intial conditions and interpolate
u_init = InitialConditions()
u.interpolate(u_init)
u0.interpolate(u_init)
And the error:
File "mesh.py", line 161, in <module>
u.interpolate(u_init)
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** https://answers.launchpad.net/dolfin
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to interpolate function into function space.
*** Reason: Dimension 0 of function (3) does not match dimension 0 of function space (5).
*** Where: This error was encountered inside FunctionSpace.cpp.
*** Process: 0
Is there another way to define and interpolate initial conditions?
Thanks in advance,
Remi