← Back to team overview

dolfin team mailing list archive

Re: [Question #159021]: Assigning initial values to a mixed function space for a nonlinear problem.

 

Question #159021 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/159021

    Status: Open => Answered

Johan Hake proposed the following answer:
You can do something like:

from dolfin import *

mesh = UnitCube(10,10,10)
V = FunctionSpace(mesh,"Lagrange",1)
W = MixedFunctionSpace([V,V])

U = Function(W)

u0 = Function(V)
v0 = Function(V)

# Fill u0, v0
u0.vector()[:] = 1.0
v0.vector()[:] = 2.0

offset = V.dim()
U.vector()[:offset] = u0.vector()
U.vector()[offset:] = v0.vector()

This will only work on this particular MixedFunctionSpace, and it will not 
work in parallel.

Johan

On Wednesday May 25 2011 14:16:06 Douglas Brinkerhoff wrote:
> New question #159021 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/159021
> 
> I would like to assign an initial guess to two solution variables in the
> following way, given two functions u0 and v0:
> 
> 
> V = FunctionSpace(mesh,"Lagrange",1)
> W = MixedFunctionSpace([V,V])
> 
> phi,psi = TestFunctions(W)
> dU = TrialFunctions(W)
> U = Function(W)
> 
> du,dv = split(dU)
> u,v = split(U)
> 
> #Here is where I would like to assign initial values u0 and v0 for my
> non-linear problem u.assign(u0)
> v.assign(v0)
> 
> u0 and v0 are already defined as functions on the appropriate function
> space.
> 
> When I use this particular syntax, I receive an error message stating that
> indexed objects don't have an assign method.  Fair enough, but how do I
> bypass this so that I can assign an initial guess.  This problem cannot
> converge from a zero starting solution.

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.