Tensor determinant in nonlinear variational problem

Asked by Stav Gold on 2013-08-13

Here's my code, which seeks to calculate the velocity which will produce a given second invariant of the strain rate tensor:

from dolfin import *
n = 6.
i,j = indices(2)
def eta(u):
        # Calculate strain rate tensor
        epsij = (u[i].dx(j) + u[j].dx(i))
        #epsij = (Dx(u[i],j) + Dx(u[j],i))
        eps = as_matrix(epsij, (i,j))
        # Second invariant of 2x2 matrix is its determinant
        #return det(eps)**((1-n)/n)
        return det(eps)

m = UnitSquareMesh(40,40)
V = VectorFunctionSpace(m,"CG",2)
P = FunctionSpace(m,"CG",1)
S0 = MixedFunctionSpace([V,P])
u_a = Function(S0)
v,p = split(u_a)
v_t, p_t = TestFunctions(S0)

F = eta(v)*p_t*dx
u = Function(S0)
solve(F == 0,u)

And here's what happens when I try to run it.

No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.
All terms in form must have same rank.
Traceback (most recent call last):
  File "StrainRateTest.py", line 23, in <module>
    solve(F == 0,u)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 268, in solve
    _solve_varproblem(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 311, in _solve_varproblem
    form_compiler_parameters=form_compiler_parameters)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/solving.py", line 118, in __init__
    J = Form(J, form_compiler_parameters=form_compiler_parameters)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/form.py", line 56, in __init__
    common_cell)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 66, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 154, in jit
    return jit_compile(form, parameters=p, common_cell=common_cell)
  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 77, in jit
    return jit_form(ufl_object, parameters, common_cell)
  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 159, in jit_form
    element_mapping=element_mapping)
  File "/usr/lib/python2.7/dist-packages/ufl/form.py", line 123, in compute_form_data
    element_mapping=element_mapping)
  File "/usr/lib/python2.7/dist-packages/ufl/algorithms/preprocess.py", line 210, in preprocess
    ufl_assert(len(compute_form_arities(form)) == 1, "All terms in form must have same rank.")
  File "/usr/lib/python2.7/dist-packages/ufl/assertions.py", line 37, in ufl_assert
    if not condition: error(*message)
  File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 154, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: All terms in form must have same rank.

1. Why does UFL see more than one term in the form?
2. What am I doing wrong?

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2013-08-13
Last reply:
2013-08-13
Anders Logg (logg) said : #1

FEniCS no longer uses Launchpad for Questions & Answers. Please consult the documentation on the FEniCS web page for where and how to (re)post your question: http://fenicsproject.org/support/

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.