dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #23506
Re: [Question #159021]: Assigning initial values to a mixed function space for a nonlinear problem.
On Thursday May 26 2011 07:25:55 Douglas Brinkerhoff wrote:
> Question #159021 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/159021
>
> Douglas Brinkerhoff posted a new comment:
> How would one create an expression out of some already known data? It
> seems as though the Expression class is very good for building a
> spatially dependent combination of parameters and elementary functions,
> but I'm not sure how I could turn some list or array of data into an
> expression.
Try this:
from dolfin import *
mesh = UnitCube(10,10,10)
V = FunctionSpace(mesh,"Lagrange",1)
W = MixedFunctionSpace([V,V])
u0 = Function(V)
v0 = Function(V)
# Fill u0, v0
u0.vector()[:] = 1.0
v0.vector()[:] = 2.0
class InitConditions(Expression):
def __init__(self, u0, v0):
self.u0 = u0
self.v0 = v0
def eval(self, value, x):
value[0] = self.u0(x)
value[1] = self.v0(x)
def value_shape(self):
return (2,)
init_cond = InitConditions(u0, v0)
U0 = project(init_cond, W)
############
This can be done as a compiled expression for better speed up. But I guess a
Python Expression is enough for this case.
Johan
> Stated another way:
>
> In my particular application, I'm solving for vertically averaged
> velocities within glacial ice (Basically shallow water equations, with
> some extra stuff). There is a 0-order solution which is solely a
> function of local geometry, e.g. Surface slope and ice thickness, which
> are currently parameterized as coefficients. This is just a simple
> calculation, not a PDE, and it is also stored as coefficients, called u0
> and v0. I want to use this zero order solution as an initial guess for
> a non-linear system of equations which yields a first order solution.
> Is there a way to package u0 and v0 as an expression, or something like
> it, such that it is available to be projected, assigned, or
> interpolated?
References