Grad, Nabla_grad and other operators

Asked by Marcos Samudio

Hello everyone,

I am trying to formulate some variational forms, and I have doubts concerning the operators grad(), nabla_grad() and their use.
What is the exact difference among them? I am working with both scalars and vectors.

Another concern is about the inner product of them, is it commutative? Because I have seen, for instance, inner(grad(u), v) and inner(v, grad(u)) being used in similar circumstances.

I have checked the Python API and found nothing concerning these functions. Is there some resource I can access to somewhere else?

Thanks,

Marcos

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Jack Hale
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Anders Logg (logg) said :
#1

On Mon, Feb 27, 2012 at 09:30:58PM -0000, Marcos Samudio wrote:
> New question #189030 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/189030
>
> Hello everyone,
>
> I am trying to formulate some variational forms, and I have doubts concerning the operators grad(), nabla_grad() and their use.
> What is the exact difference among them? I am working with both scalars and vectors.

No difference for scalars.

For vectors:

  (grad v)_ij = dv_i / dx_j
  (nabla_grad v)_ij = dv_j / dx_i

For matrices:

  (div v)_i = dv_ij / dx_j
  (nabla_div v)_j = dv_ij / dx_i

> Another concern is about the inner product of them, is it
> commutative?

The inner product is always symmetric, yes.

> Because I have seen, for instance, inner(grad(u), v) and inner(v,
> grad(u)) being used in similar circumstances.

Both are the same.

But notice that for the convective term of Navier-Stokes, you must
write it either

  dot(u, nabla_grad(u))

or

  dot(grad(u), u)

> I have checked the Python API and found nothing concerning these functions. Is there some resource I can access to somewhere else?

It's documented in the FEniCS book:

  http://www.fenicsproject.org/book/

--
Anders

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#2

> I have checked the Python API and found nothing concerning these functions.
> Is there some resource I can access to somewhere else?

May I suggest looking at the docstrings of the functions in question? Anders also gave some useful links.

In [1]: import ufl

In [2]: ufl.grad?
Type: function
Base Class: <type 'function'>
String Form: <function grad at 0x21ca6e0>
Namespace: Interactive
File: /home/martinal/opt/fenics/dorsal-stable/lib/python2.7/site-packages/ufl/operators.py
Definition: ufl.grad(f)
Docstring:
    UFL operator: Take the gradient of f.

    This operator follows the grad convention where

      grad(s)[i] = s.dx(j)

      grad(v)[i,j] = v[i].dx(j)

      grad(T)[:,i] = T[:].dx(i)

    for scalar expressions s, vector expressions v,
    and arbitrary rank tensor expressions T.

In [3]: ufl.nabla_grad?
Type: function
Base Class: <type 'function'>
String Form: <function nabla_grad at 0x21ca7d0>
Namespace: Interactive
File: /home/martinal/opt/fenics/dorsal-stable/lib/python2.7/site-packages/ufl/operators.py
Definition: ufl.nabla_grad(f)
Docstring:
    UFL operator: Take the gradient of f.

    This operator follows the grad convention where

      nabla_grad(s)[i] = s.dx(j)

      nabla_grad(v)[i,j] = v[j].dx(i)

      nabla_grad(T)[i,:] = T[:].dx(i)

    for scalar expressions s, vector expressions v,
    and arbitrary rank tensor expressions T.

Revision history for this message
Marcos Samudio (marcossamudio) said :
#3

Thank you both Anders and Martin, that is just what I was looking for.

Marcos

Revision history for this message
Marcos Samudio (marcossamudio) said :
#4

I've imported the ufl module but the command Martin suggested is not working. Typing ufl.grad? yields a syntax error in my python console. I can still access the docstring by __doc__, but this is much less extensive.

Is there something I'm missing??

Thanks again,

Marcos

Revision history for this message
Best Jack Hale (jack-hale) said :
#5

Use ipython for a nice interactive python shell, much better than the
standard python shell. Just type ipython at the prompt.

On 28 February 2012 15:00, Marcos Samudio <
<email address hidden>> wrote:

> Question #189030 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/189030
>
> Status: Solved => Open
>
> Marcos Samudio is still having a problem:
> I've imported the ufl module but the command Martin suggested is not
> working. Typing ufl.grad? yields a syntax error in my python console. I
> can still access the docstring by __doc__, but this is much less
> extensive.
>
> Is there something I'm missing??
>
> Thanks again,
>
> Marcos
>
> --
> 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
Marcos Samudio (marcossamudio) said :
#6

Thanks Jack Hale, that solved my question.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#7

Which version of ufl do you have?

Martin
Den 28. feb. 2012 16.00 skrev "Marcos Samudio" <
<email address hidden>> følgende:

> Question #189030 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/189030
>
> Status: Solved => Open
>
> Marcos Samudio is still having a problem:
> I've imported the ufl module but the command Martin suggested is not
> working. Typing ufl.grad? yields a syntax error in my python console. I
> can still access the docstring by __doc__, but this is much less
> extensive.
>
> Is there something I'm missing??
>
> Thanks again,
>
> Marcos
>
> --
> 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
Marcos Samudio (marcossamudio) said :
#8

My ufl version is 1.0.0.