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?