I am trying to solve a version of 1D PNP model using mixed space formulation but I obtain an error which I cannot recognise and fix. Model contain 3 nonlinear equations and is set for 1D.
Bests
Bart
from dolfin import *
# Sub domain for Dirichlet boundary condition
class DirichletBoundary(SubDomain):
def inside(self, x, on_boundary):
return (abs(x[0] - 1.0) or abs (x[0])) < DOLFIN_EPS and on_boundary
# Create mesh and define function space
mesh = UnitIntervalMesh(60)
V = FunctionSpace(mesh, "CG", 2) # V space
R = FunctionSpace(mesh, "CG", 2) # c space
VR = MixedFunctionSpace([V, R,R]) # mixed space
w = Function(VR)
(u,c1,c2)= TrialFunctions(VR)
(v,r1,r2)= TestFunction(VR)
# Define boundary condition
u_b = Expression("x[0]*1+20")
bcu = DirichletBC(V, u_b, DirichletBoundary())
c1_b =Expression("x[0]*1+20")
bc1 = DirichletBC(R, c1_b, DirichletBoundary())
c2_b =Expression("x[0]*1+20")
bc2 = DirichletBC(R, c2_b, DirichletBoundary())
bc =[bcu,bc1,bc2]
# Define variational problem
f = Constant(0) # rhs for one of the eq
a=Expression("pi*(pow((x[0]-0.5),2)+0.2)*(pow((x[0]-0.5),2)+0.2)") # are function - radius is equal to (x-0.5)^2 + 0.02
F1 = inner(a*grad(u),grad(v))*dx
F2= - c1*exp(-u)*v*dx - c2*exp(-u)*v*dx
F3=inner(a*exp(-u)*grad(c1), grad(r1))*dx - f*r1*dx
F4=inner(a*exp(-u)*grad(c2), grad(r2))*dx - f*r1*dx
F=F1+F2+F3+F4
# Compute solution
solve(F == 0, w, bc,solver_parameters={"newton_solver":{"relative_tolerance": 1e-6}}
And the error message
No Jacobian form specified for nonlinear variational problem.
Differentiating residual form F to obtain Jacobian J = F'.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File "demo_nonlinear-poisson.py", line 44, in <module>
solve(F == 0, w, bc, solver_parameters={"newton_solver":{"relative_tolerance": 1e-6}})
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/fem/solving.py", line 269, in solve
_solve_varproblem(*args, **kwargs)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/fem/solving.py", line 312, in _solve_varproblem
form_compiler_parameters=form_compiler_parameters)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/fem/solving.py", line 117, in __init__
F = Form(F, form_compiler_parameters=form_compiler_parameters)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/fem/form.py", line 70, in __init__
mpi_comm=mesh.mpi_comm())
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/compilemodules/jit.py", line 64, in mpi_jit
return local_jit(*args, **kwargs)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/compilemodules/jit.py", line 128, in jit
return form_compiler.jit(form, parameters=p)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/jitcompiler.py", line 74, in jit
return jit_form(ufl_object, parameters)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/jitcompiler.py", line 130, in jit_form
parameters=parameters)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/compiler.py", line 151, in compile_form
analysis = analyze_forms(forms, parameters)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/analysis.py", line 59, in analyze_forms
parameters) for form in forms)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/analysis.py", line 59, in <genexpr>
parameters) for form in forms)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ffc/analysis.py", line 132, in _analyze_form
form_data = compute_form_data(form)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/algorithms/compute_form_data.py", line 304, in compute_form_data
check_form_arity(preprocessed_form, form.arguments()) # Currently testing how fast this is
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/algorithms/check_arities.py", line 123, in check_form_arity
check_integrand_arity(itg.integrand(), arguments)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/algorithms/check_arities.py", line 117, in check_integrand_arity
args = map_expr_dag(rules, expr, compress=False)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/corealg/map_dag.py", line 64, in map_expr_dag
r = function(v)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/corealg/multifunction.py", line 72, in __call__
return self._handlers[o._ufl_typecode_](o, *args)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/ufl/algorithms/check_arities.py", line 33, in nonlinear_operator
raise ArityMismatch("Applying nonlinear operator to expression depending on form argument {0}.".format(t))
ufl.algorithms.check_arities.ArityMismatch: Applying nonlinear operator to expression depending on form argument v_1.