This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

jacobian of nonlinear problem in mixed formulation

0 votes

I am trying to use FENICS to solve a non-linear mixed problem.
Basically its a non-linear Stokes equation, where the non-linear viscosity mu(p, D) depends on the pressure and the symmetric part of the velocity gradient D.

So, I have

V = VectorFunctionSpace(mesh, "CG", 2)
 Q = FunctionSpace(mesh, "CG", 1)
 W = V*Q
 (w,q) = TestFunctions(W)
 (v, p) = TrialFunctions(W)    
  F = (inner(sym(grad(w)), 2*mu(p,D)*sym(grad(v))) - div(w)*p - q*div(v))*dx - inner(w, rho*b)*dx

In this case how do I calculate the Jacobian ? Does FENICS have the capability to handle such a problem ?

asked Jun 9, 2014 by shriram FEniCS User (1,540 points)
edited Jun 10, 2014 by shriram

1 Answer

+3 votes
 
Best answer

I managed to find the answer by mimicking the non-liner Poisson demo. Adding it here in case someone else has a similar problem.

The following lines work fine ( of course I have ommited, the mesh, bcs, etc here)

(w,q) = TestFunctions(W)
 (v, p) = TrialFunctions(W)    
     def mu(p):
    return  1 + p*p
  F = (inner(sym(grad(w)), 2*mu(p,D)*sym(grad(v))) - div(w)*p - q*div(v))*dx - inner(w, rho*b)*dx

u_p = Function(W)     # the most recently computed solution
     R  = action(F, u_p)
     DR  = derivative(R,  u_p)   # Gateaux derivative 
    problem = NonlinearVariationalProblem(R, u_p, bcs, DR)
    solver  = NonlinearVariationalSolver(problem)
answered Jun 11, 2014 by shriram FEniCS User (1,540 points)
selected Aug 27, 2014 by shriram

Thanks for sharing your solution. It solved a problem I was having, so I'll write a few details in case anybody else runs into it.

Previously, I wasn't using any TrialFunctions, and directly defined R with u_p instead of using the trial functions and action().

This seems to work for irreducible formulations, but when I tried it in a mixed formulation, I got PETSc error 63 (input argument, out of range) when calling solver.solve().

*** -------------------------------------------------------------------------
*** Error:   Unable to successfully call PETSc function 'MatSetValuesLocal'.
*** Reason:  PETSc error code is: 63.
*** Where:   This error was encountered inside /build/dolfin-i8W3lr/dolfin-2016.1.0/dolfin/la/PETScMatrix.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2016.1.0
*** Git changeset:  unknown
*** -------------------------------------------------------------------------

After redefining R and DR as you have, it runs properly.

I'm also having some trouble with the details of my nonlinear vector-valued problem (with a mixed FE space).

Where is the nonlinear Poisson demo? I've only found this one, which doesn't appear to be related to this question: https://fenicsproject.org/olddocs/dolfin/2016.1.0/python/demo/documented/nonlinear-poisson/python/documentation.html

Specifically I don't understand why R and fenics.action are necessary. Related question: Where is the documentation for fenics.action? This is the first I've heard the term "action" in such a context.

Thanks.

...