Directional derivative

Asked by Mo on 2013-02-07

Hi folks,

Just a quick question:

I have a 2D domain and I need to have \partial (\partial u / \partial x) / \partial x. In other words, div(grad(u)) in x direction only.

Can (u.dx(0)).dx(0) do the job?

I have also tried u[0].dx(0), but I got the following error:

Invalid number of indices (1) for tensor expression of rank 0:
 Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2, None), -1)

Traceback (most recent call last):
  File "adv_diff_2D_opt2.py", line 103, in <module>
    r = u.dx(0) - nu*(u[0].dx(0)) # L(u)
  File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 310, in _getitem
    a = Indexed(self, indices)
  File "/usr/lib/python2.7/dist-packages/ufl/indexed.py", line 45, in __init__
    % (len(indices), expression.rank(), expression))
  File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 148, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Invalid number of indices (1) for tensor expression of rank 0:
 Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2, None), -1)

Any help is deeply appreciated.

Best,
Mo

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
2013-02-07
Last query:
2013-02-07
Last reply:
2013-02-07

Yes :)

Or shorter just u.dx(0,0) if I recall correctly.

Martin
Den 7. feb. 2013 01:30 skrev "Mo" <email address hidden>
følgende:

> New question #221239 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/221239
>
> Hi folks,
>
> Just a quick question:
>
> I have a 2D domain and I need to have \partial (\partial u / \partial x) /
> \partial x. In other words, div(grad(u)) in x direction only.
>
> Can (u.dx(0)).dx(0) do the job?
>
> I have also tried u[0].dx(0), but I got the following error:
>
>
> Invalid number of indices (1) for tensor expression of rank 0:
> Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2,
> None), -1)
>
> Traceback (most recent call last):
> File "adv_diff_2D_opt2.py", line 103, in <module>
> r = u.dx(0) - nu*(u[0].dx(0)) # L(u)
> File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 310,
> in _getitem
> a = Indexed(self, indices)
> File "/usr/lib/python2.7/dist-packages/ufl/indexed.py", line 45, in
> __init__
> % (len(indices), expression.rank(), expression))
> File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 148, in error
> raise self._exception_type(self._format_raw(*message))
> ufl.log.UFLException: Invalid number of indices (1) for tensor expression
> of rank 0:
> Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2,
> None), -1)
>
>
> Any help is deeply appreciated.
>
> Best,
> Mo
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Kent-Andre Mardal (kent-and) said : #2

On 7 February 2013 01:30, Mo <email address hidden> wrote:

> New question #221239 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/221239
>
> Hi folks,
>
> Just a quick question:
>
> I have a 2D domain and I need to have \partial (\partial u / \partial x) /
> \partial x. In other words, div(grad(u)) in x direction only.
>
> Can (u.dx(0)).dx(0) do the job?
>

yes

Kent

>
> I have also tried u[0].dx(0), but I got the following error:
>
>
> Invalid number of indices (1) for tensor expression of rank 0:
> Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2,
> None), -1)
>
> Traceback (most recent call last):
> File "adv_diff_2D_opt2.py", line 103, in <module>
> r = u.dx(0) - nu*(u[0].dx(0)) # L(u)
> File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 310,
> in _getitem
> a = Indexed(self, indices)
> File "/usr/lib/python2.7/dist-packages/ufl/indexed.py", line 45, in
> __init__
> % (len(indices), expression.rank(), expression))
> File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 148, in error
> raise self._exception_type(self._format_raw(*message))
> ufl.log.UFLException: Invalid number of indices (1) for tensor expression
> of rank 0:
> Argument(FiniteElement('Lagrange', Cell('triangle', Space(2)), 2,
> None), -1)
>
>
> Any help is deeply appreciated.
>
> Best,
> Mo
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Mo (mo-h) said : #3

Thanks Martin Sandve Alnæs, that solved my question.

Mo (mo-h) said : #4

Martin and Kent, thank you both.

Mo