making a nodal vector field

Asked by Sungick Kim

Let 'u' be a scalar nodal value.
Now I want to construct a nodal vector field as below.

velocity = Expression(('u', '0.0', '0.0'))

There comes no error related this.
However, it seems that velocity = (0,0,0) all throughout domain.
Can anyone help me to know the right way to do this?

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Sungick Kim
Solved:
Last query:
Last reply:
Revision history for this message
Anders Logg (logg) said :
#1

On Thu, Oct 07, 2010 at 08:01:27PM -0000, Sungick Kim wrote:
> New question #128351 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/128351
>
> Let 'u' be a scalar nodal value.
> Now I want to construct a nodal vector field as below.
>
> velocity = Expression(('u', '0.0', '0.0'))
>
> There comes no error related this.
> However, it seems that velocity = (0,0,0) all throughout domain.
> Can anyone help me to know the right way to do this?

Have you set the value of u?

--
Anders

Revision history for this message
Johan Hake (johan-hake) said :
#2

On Friday October 8 2010 00:12:26 Anders Logg wrote:
> Question #128351 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/128351
>
> Status: Open => Answered
>
> Anders Logg proposed the following answer:
>
> On Thu, Oct 07, 2010 at 08:01:27PM -0000, Sungick Kim wrote:
> > New question #128351 on DOLFIN:
> > https://answers.launchpad.net/dolfin/+question/128351
> >
> > Let 'u' be a scalar nodal value.
> > Now I want to construct a nodal vector field as below.
> >
> > velocity = Expression(('u', '0.0', '0.0'))
> >
> > There comes no error related this.
> > However, it seems that velocity = (0,0,0) all throughout domain.
> > Can anyone help me to know the right way to do this?
>
> Have you set the value of u?

I am not exactly sure what you want to do, but if you just have a scalar
value, you need to initilize u in your Expression.

This can be done in two ways:

  velocity = Expression(('u', '0.0', '0.0'), {'u':value})

or

  velocity = Expression(('u', '0.0', '0.0'))
  velocity.u = value

There are no errors because u is initialized to Zero. Take a look in the
docstring of Expression.

Johan

Revision history for this message
Sungick Kim (sungick) said :
#3

Thank you very much for your replies, Anders and Johan.

Q = FunctionSpace(mesh, "DG", 1)
u1 = Function(Q)
u = u1('-')
velocity = Expression(('u','0','0'))

As you can see above, 'u' is not a scalar but a scalar field. In this case, how can I create an expression for the velocity vector? I intend to use 'grad(velocity)' for later formulation.

Revision history for this message
Johan Hake (johan-hake) said :
#4

On Friday October 8 2010 08:39:14 Sungick Kim wrote:
> Question #128351 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/128351
>
> Status: Answered => Open
>
> Sungick Kim is still having a problem:
> Thank you very much for your replies, Anders and Johan.
>
> Q = FunctionSpace(mesh, "DG", 1)
> u1 = Function(Q)
> u = u1('-')
> velocity = Expression(('u','0','0'))
>
> As you can see above, 'u' is not a scalar but a scalar field. In this
> case, how can I create an expression for the velocity vector? I intend
> to use 'grad(velocity)' for later formulation.

If I am not totaly off you should be able to do:

  velocity = as_vector(u, 0, 0)

Btw you can take a look in

  demo/undocumented/tensor-weighted-poisson/python

to get a better feeling for the as_vector/as_matrix funtion.

Johan

Revision history for this message
Sungick Kim (sungick) said :
#5

Thank you, Johan!
As you suggested, using 'as_vector((u,0,0))' solved my problem.