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

Solving a nonlinear problem with PETScSNESS Solver. Discretization Problem

0 votes

I want to solve the Problem

$$ \min_\phi \int_\Omega \nabla \phi \cdot \nabla \phi + \int_\Omega f \cdot \phi $$

which I would usually do like this: (code snippet)

u = Function(V)
du = TrialFunction(V)
v = TestFunction(V)
e_n = interpolate(Constant(1), V)
F =  inner(grad(u) , grad(v)) * dx + f * v * dx
problem = Subproblem(derivative(F, u, du), F)

solver = PETScSNESSolver()
# vector for the lower and upper bound. 
lb = interpolate(Constant(0), V)
ub = interpolate(Constant(1), V)

solver.solve(problem, u.vector(), lb.vector(), ub.vector())  # Bounded solve

using a Solver (I tried PETScSNESS)

now what happens when $$ \phi $$ is a two dim phase field - means I want to solve

$$ \min_\phi \int_\Omega \nabla \phi \cdot \nabla \phi dx + \int_\Omega \nabla (1-\phi) \cdot \nabla (1-\phi) dx + \int_\Omega f \cdot \phi dx + \int_\Omega f \cdot (1-\phi) dx $$

e_n = interpolate(Constant(1), V)
u = Trialfunction(V)
v = Testfunction(V)
a = inner(grad(u) , grad(v)) * dx + inner(grad(e_n - u) , grad(e_n - v)) * dx + f * v * dx+ f *(e_n -  v) * dx

is throwing a syntax error.

Is it just my code that is wrong - or am I wrong on the mathematical side?

closed with the note: solved due to answer below
asked Apr 20, 2016 by Whistler FEniCS Novice (460 points)
closed May 25, 2016 by Whistler

1 Answer

0 votes

I solved the problem using another translation of the phase field

instead of "phi" and "(1-phi)" I am now using (1+phi)/2 and (1-phi)/2 where phi is now in [-1,1] instead of [0,1].

answered May 25, 2016 by Whistler FEniCS Novice (460 points)
...