How to compute $f<g$ amost everywhere for trialfunctions?

4 months ago by
I am working with finite elements for Maxwell's Equations (i.e. with Nedelec's edge elements) and for computation I'm using the <a href="">FEniCS-project</a>. While implementing the Augmented Lagragian Method, I need to solve a PDE with a non-linearity of the form:

f(v) := \begin{cases}
v, \quad &\text{ on } A=\lbrace x : |v(x)| \leq g(x)\rbrace\\
\frac{v}{|v|}g, &\text{ on } \Omega \backslash A

I wanted to implement this by defining a function:
import dolfin

#Define initial values and data
f = dolfin.Constant((1.0,1.0,1.0))
bound = dolfin.Constant(1.0)

#Create mesh and define function spaces
nx = ny = nz = 10
mesh = dolfin.UnitCubeMesh(nx, ny, nz)
V = dolfin.FunctionSpace(mesh, 'N1curl', 1)

E = dolfin.TrialFunction(V)
v = dolfin.TestFunction(V)

#Define linear and bilinear forms
a =, v)*dolfin.dx +, dolfin.curl(v))*dolfin.dx
F =, v)*dolfin.dx

#Define non-linearity
def non_lin(func, bound):
    if func < bound:#somehow almost everywhere
        return func
        return func / abs(func) * bound
a_new = a + non_lin(E, bound)

u = dolfin.Function(V)
dolfin.solve(a_new == F,u)

Thats an example which is not working yet... The problem lies in the function non_lin. Can someone help me?

Community: FEniCS Project
There are more problems with your code.
I don't even understand the first lines..
f = dolfin.Constant((1.0,1.0,1.0))
bound = f = dolfin.Constant(1.0)
what is f now?

Are you sure you want to put "E" into your non_lin function?
written 4 months ago by Lukas O.  
Thanks for your answer. Actually, this was a typo. The function $f$ in my question was somehow not correct, as well. I edited it.
written 4 months ago by FFoDWindow  

1 Answer

4 months ago by
Restate your problem to solve with NewtonSolver --- see the FEniCS tutorial for more info --- then use "conditional"

to form the non-linearity.
I've updated my function $f$ in the question. I guess with this it's not possible to use "conditional", is it? Is there any other possibility? Thanks.
written 4 months ago by FFoDWindow  
Like I said, you have to restate your problem as a nonlinear problem; in this case the trial function is the direction of decent of the residual. Refer to the FEniCS tutorial regarding nonlinear problems.
written 4 months ago by pf4d  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »