Mixed Function Space: I Know One, I Want the Other

Asked by Stav Gold

I have, through nefarious means, obtained the pressure of a particular system. Now, I want to know the velocity of that system by relating the two through a variational form and solving over a mixed function space.

I know that assigning the pressure function to a shallow copy of the scalar component of a function on the mixed space is the first step, but solving this system produces NaN's in the velocity field. Minimal code follows--anyone have an idea what's going on?

Space = FunctionSpace(mesh, "CG", 2)
VSpace = VectorFunctionSpace(mesh, "CG", 2)
W = VSpace*Space

v = TestFunction(Space)
P = TrialFunction(Space)

(r,q) = TestFunctions(W)
(u,Pv) = TrialFunctions(W)
PNext = Function(Space)
PhiNext = TrialFunction(Space)
Phi = Function(Space)
Phi.interpolate(Phi_init)

pLeft = -inner(grad(P),grad(v))*(Phi**n)*dx-h2*(Phi**m)*P*v*dx
pRight = Dx(Phi**n,1)*v*dx

P = Function(Space)

# Phi time-dependence problem set-up
a = PhiNext*v*dx
L = (Phi+dt*P*h2*Phi**m)*v*dx
A = assemble(a)

vv = div(u)*q*dx-Pv*q*dx
f = Constant(0.0)
vRight = f*q*dx
bigu= Function(W)

while t <= T:
                # Phi, Pressure step
                pl = assemble(pLeft)
                pr = assemble(pRight)
                solver.solve(pl,P.vector(),pr)
                b = assemble(L)
                solver.solve(A,PhiNext.vector(),b)
                Phi.assign(PhiNext)

                # Velocity step
                VL = assemble(vv)
                VR = assemble(vRight)
                uv, us = bigu.split(deepcopy=False)
                us.assign(P)
                solve(VL,bigu.vector(),VR)

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On 29 May 2012 23:31, Stav Gold <email address hidden> wrote:
> New question #198825 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/198825
>
> I have, through nefarious means, obtained the pressure of a particular system. Now, I want to know the velocity of that system by relating the two through a variational form and solving over a mixed function space.
>

If you already know the pressure, why do you need a mixed element?
Could you just feed the pressure in as a Function?

Garth

> I know that assigning the pressure function to a shallow copy of the scalar component of a function on the mixed space is the first step, but solving this system produces NaN's in the velocity field. Minimal code follows--anyone have an idea what's going on?
>
> Space = FunctionSpace(mesh, "CG", 2)
> VSpace = VectorFunctionSpace(mesh, "CG", 2)
> W = VSpace*Space
>
> v = TestFunction(Space)
> P = TrialFunction(Space)
>
> (r,q)      = TestFunctions(W)
> (u,Pv)     = TrialFunctions(W)
> PNext = Function(Space)
> PhiNext = TrialFunction(Space)
> Phi = Function(Space)
> Phi.interpolate(Phi_init)
>
> pLeft = -inner(grad(P),grad(v))*(Phi**n)*dx-h2*(Phi**m)*P*v*dx
> pRight = Dx(Phi**n,1)*v*dx
>
> P = Function(Space)
>
> # Phi time-dependence problem set-up
> a = PhiNext*v*dx
> L = (Phi+dt*P*h2*Phi**m)*v*dx
> A = assemble(a)
>
> vv = div(u)*q*dx-Pv*q*dx
> f = Constant(0.0)
> vRight = f*q*dx
> bigu= Function(W)
>
> while t <= T:
>                # Phi, Pressure step
>                pl = assemble(pLeft)
>                pr = assemble(pRight)
>                solver.solve(pl,P.vector(),pr)
>                b = assemble(L)
>                solver.solve(A,PhiNext.vector(),b)
>                Phi.assign(PhiNext)
>
>                # Velocity step
>                VL = assemble(vv)
>                VR = assemble(vRight)
>                uv, us = bigu.split(deepcopy=False)
>                us.assign(P)
>                solve(VL,bigu.vector(),VR)
>
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Stav Gold (ragaxus) said :
#2

> If you already know the pressure, why do you need a mixed element?
> Could you just feed the pressure in as a Function?

Can I do that without using a mixed function space? The pressure is defined on a scalar function space, and the velocity (which I'm wanting to solve for) is defined on a vector function space...

Revision history for this message
Garth Wells (garth-wells) said :
#3

On 25 June 2012 17:45, Stav Gold <email address hidden> wrote:
> Question #198825 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/198825
>
>    Status: Answered => Open
>
> Stav Gold is still having a problem:
>> If you already know the pressure, why do you need a mixed element?
>> Could you just feed the pressure in as a Function?
>
> Can I do that without using a mixed function space? The pressure is
> defined on a scalar function space, and the velocity (which I'm wanting
> to solve for) is defined on a vector function space...
>

Yes. You need to make sure that the integrands in your form are scalars.

Garth

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

Can you help with this problem?

Provide an answer of your own, or ask Stav Gold for more information if necessary.

To post a message you must log in.