determining pressure in a Stokes problem uniquely

Asked by shriram

Hi,
I am a beginner with Fenics and am shifting from Matlab. I have got a small program working to solve the linear Stokes equations with a Taylor-Hood element. As it is known that pressure is determined only upto a constant if only velocities are specified on the boundary, I used to set the pressure at a reference node (say the origin) to the desired value and obtain a unique solution when I worked with my own code.

In FEnics, I tried to do:
----------------------------
def Pressure_level(x, on_boundary):
    return on_boundary and abs(x[0]) < tol and abs(x[1]) < tol

bc = DirichletBC(W.sub(1), p0, Pressure_level ) # p0 is the value
-----------------------------
which of course didnt work.
1.Could you please help me figure out how to do this is Fenics ?

2. In the demo program using Taylor-Hood, there are a couple of commands which I do not understand:
---------------------------------------------------
print "Norm of velocity coefficient vector: %.15g" % v.vector().norm("l2")
print "Norm of pressure coefficient vector: %.15g" % p.vector().norm("l2")
-------------------------------------------------------------------
Could anyone tell me what exactly is the "coefficient vector" here ?
Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
FEniCS Project Edit question
Assignee:
No assignee Edit question
Solved by:
Kristian B. Ølgaard
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

On Thursday September 15 2011 07:30:53 shriram wrote:
> New question #171238 on FEniCS Project:
> https://answers.launchpad.net/fenics/+question/171238
>
> Hi,
> I am a beginner with Fenics and am shifting from Matlab. I have got a small
> program working to solve the linear Stokes equations with a Taylor-Hood
> element. As it is known that pressure is determined only upto a constant
> if only velocities are specified on the boundary, I used to set the
> pressure at a reference node (say the origin) to the desired value and
> obtain a unique solution when I worked with my own code.
>
> In FEnics, I tried to do:
> ----------------------------
> def Pressure_level(x, on_boundary):
> return on_boundary and abs(x[0]) < tol and abs(x[1]) < tol
>
> bc = DirichletBC(W.sub(1), p0, Pressure_level ) # p0 is the value
> -----------------------------
> which of course didnt work.

You need to tell us what did not work and where you would like your BC to be
applied. What mesh do you have? It is always best to provide a minimal
runnable example.

> 1.Could you please help me figure out how to do this is Fenics ?
>
>
> 2. In the demo program using Taylor-Hood, there are a couple of commands
> which I do not understand:
> ---------------------------------------------------
> print "Norm of velocity coefficient vector: %.15g" % v.vector().norm("l2")
> print "Norm of pressure coefficient vector: %.15g" % p.vector().norm("l2")

The coefficient vector holds the solution vector for the unknown degrees of
freedoms, for each finite element Function. Read more about FEM and DOLFIN in
the soon to be released book:

  http://launchpad.net/fenics-book/trunk/rc-1/+download/fenics-
book-2011-06-24.pdf

Johan

Revision history for this message
Best Kristian B. Ølgaard (k.b.oelgaard) said :
#2

On 15 September 2011 17:40, Johan Hake
<email address hidden> wrote:
> Question #171238 on FEniCS Project changed:
> https://answers.launchpad.net/fenics/+question/171238
>
>    Status: Open => Answered
>
> Johan Hake proposed the following answer:
> On Thursday September 15 2011 07:30:53 shriram wrote:
>> New question #171238 on FEniCS Project:
>> https://answers.launchpad.net/fenics/+question/171238
>>
>> Hi,
>> I am a beginner with Fenics and am shifting from Matlab. I have got a small
>> program working to solve the linear Stokes equations with a Taylor-Hood
>> element. As it is known that pressure is determined only upto a constant
>> if only velocities are specified on the boundary, I used to set the
>> pressure at a reference node (say the origin) to the desired value and
>> obtain a unique solution when I worked with my own code.
>>
>> In FEnics, I tried to do:
>> ----------------------------
>> def Pressure_level(x, on_boundary):
>>     return on_boundary and abs(x[0]) < tol and abs(x[1]) < tol
>>
>> bc = DirichletBC(W.sub(1), p0, Pressure_level ) # p0 is the value

When you only want to apply bc to one node based, use "pointwise":

bc = DirichletBC(W.sub(1), p0, Pressure_level, "pointwise" )

not 100% sure if this is the correct order of arguments, but you can
read the manual or do:

>>> help(DirichletBC) in Python.

If you use "pointwise", you can probably not use 'on_boundary' in your
function, it used to have the value False when using "pointwise",
don't know if this has changed.

Kristian

>> -----------------------------
>> which of course didnt work.
>
> You need to tell us what did not work and where you would like your BC to be
> applied. What mesh do you have? It is always best to provide a minimal
> runnable example.
>
>> 1.Could  you please help me figure out how to do this is Fenics ?
>>
>>
>> 2.  In the demo program using Taylor-Hood, there are a couple of commands
>> which I do not understand:
>> ---------------------------------------------------
>> print "Norm of velocity coefficient vector: %.15g" % v.vector().norm("l2")
>> print "Norm of pressure coefficient vector: %.15g" % p.vector().norm("l2")
>
> The coefficient vector holds the solution vector for the unknown degrees of
> freedoms, for each finite element Function. Read more about FEM and DOLFIN in
> the soon to be released book:
>
>  http://launchpad.net/fenics-book/trunk/rc-1/+download/fenics-
> book-2011-06-24.pdf
>
> Johan
>
> --
> You received this question notification because you are a member of
> FEniCS Team, which is an answer contact for FEniCS Project.
>

Revision history for this message
shriram (me-shriram) said :
#3

Thanks Kristian B. Ølgaard, that solved my question.