How to solve ArityMismatch: Adding expressions with non-matching form arguments ('v_0',) vs ()

Dear all,

I want to solver the stokes-cahn-hilliard problem. but, I got the error message is “Adding expressions with non-matching form arguments (‘v_0’,) vs ().”. Can you help me figure out how to solve the arity mismatch?
Thank you so much in advance.

**
import random
from dolfin import *

parameters[“form_compiler”][“optimize”] = True
parameters[“form_compiler”][“cpp_optimize”] = True

radius = 0.1

Class representing the intial conditions

class InitialConditions(UserExpression):
def init(self, **kwargs):
random.seed(2 + MPI.rank(MPI.comm_world))
super().init(**kwargs)
def eval(self, values, x):
if sqrt((x[0]-0.5)(x[0]-0.5) + (x[1]-0.5)(x[1]-0.5)) < radius:
values[0] = 0.0
values[1] = 0.0
values[2] = 0.0
values[3] = 1.0
values[4] = 0.0
else:
values[0] = 0.0
values[1] = 0.0
values[2] = 0.0
values[3] = 0.0
values[4] = 0.0

def value_shape(self):
    return (5,)

Class for interfacing with the Newtonsolver

class StokesCahnHilliardEquation(NonlinearProblem):
def init(self, a, L, bcs):
NonlinearProblem.init(self)
self.L = L
self.a = a
self.bcs = bcs
def F(self, b, x):
assemble(self.L, tensor=b)
for condition in self.bcs: condition.apply(b,x)
def J(self, A, x):
assemble(self.a, tensor=A)
for condition in self.bcs: condition.apply(A)

Creat mesh and build function space

mesh = UnitSquareMesh(50, 50)

Model parameters

lmbda = 1.0e-02 # surface parameter
dt = 5.0e-06 # time step
theta = 1 # time stepping family, e.g. theta=1 -> backward Euler, theta=0.5 -> Crank-Nicolson
rho = 1
eta = 1

FunctionSpace

CGV = VectorElement(“Lagrange”, mesh.ufl_cell(), 2)
CGF = FiniteElement(“Lagrange”, mesh.ufl_cell(), 1)

W = FunctionSpace(mesh, MixedElement(CGV, CGF, CGF, CGF))

Boundary

def inflow(x, on_boundary): return near(x[0], 0)
def top(x, on_boundary): return near(x[1], 0)
def bottom(x, on_boundary): return near(x[1], 1)
def outlet(x, on_boundary): return near(x[0], 1)

bcp0 = DirichletBC(W.sub(1), Constant(0), inflow)
bcu0 = DirichletBC(W.sub(0), Constant((1, 0)), top)
bcu1 = DirichletBC(W.sub(0), Constant((-1, 0)), bottom)
bcp1 = DirichletBC(W.sub(1), Constant(0), outlet)
bcs = [bcu0, bcu1, bcp0, bcp1]

Define trial and test functions

dw = TrialFunction(W)
v, q, r, s = TestFunctions(W)

Define functions

w = Function(W) # current solution
w0 = Function(W) # solution from previous converged step

Split mixed functions

u, g, c, mu = split(w)
u0, g0, c0, mu0 = split(w0)

mu_(n+theta)

mu_mid = (1.0-theta)mu0 + thetamu

Compute the chemical potential df/dc

c = variable©
f = 100c**2(1-c)**2
dfdc = diff(f,c)

Create intial conditions and interpolate

w_init = InitialConditions(degree=1)
w.interpolate(w_init)
w0.interpolate(w_init)

def D(u):
return (grad(u) + grad(u).T)/2

Weak statement of the equations

L0 = 2 * eta * inner(grad(v), D(u)) * dx - rho * div(v) * g * dx - rho * mu * inner(v, grad(c0)) * dx
L1 = q * div(u) * dx
L2 = rho * c * r * dx - rho * c0 * r * dx + dt * inner(grad(mu_mid), grad( r)) * dx + rho * inner(u0,grad(c )) * dx
L3 = mu * s * dx - dfdc * s * dx - lmbda * dot(grad( c), grad(s)) * dx

L = L0 + L1 + L2 + L3

Compute directional derivative about u in the direction of u (Jacobian)

a = derivative(L, w, dw)

Create nonlinear problem and Newton solver

problem = StokesCahnHilliardEquation(a, L, bcs)
solver = NewtonSolver()
solver.parameters[“linear_solver”] = “lu”
solver.parameters[“convergence_criterion”] = “incremental”
solver.parameters[“relative_tolerance”] = 1e-6
solver.parameters[“maximum_iterations”] = 100

Output file

ufile = File(“Stokes_cahn_Hilliard/u.pvd”, “compressed”)
gfile = File(“Stokes_cahn_Hilliard/g.pvd”, “compressed”)
cfile = File(“Stokes_cahn_Hilliard/c.pvd”, “compressed”)
mufile = File(“Stokes_cahn_Hilliard/mu.pvd”, “compressed”)

Step in time

t = 0.0
T = 50*dt
while (t < T):
t += dt
w0.vector()[:] = w.vector()
solver.solve(problem, w.vector())

(u, g, c, mu)=w.split()
ufile << (u, t)
gfile << (g, t)
cfile << (c, t)
mufile << (mu, t)

**

The error:

Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File “stokes_cahn_test.py”, line 137, in
solver.solve(problem, w.vector())
File “stokes_cahn_test.py”, line 41, in F
assemble(self.L, tensor=b)
File “/usr/lib/python3/dist-packages/dolfin/fem/assembling.py”, line 198, in assemble
dolfin_form = _create_dolfin_form(form, form_compiler_parameters)
File “/usr/lib/python3/dist-packages/dolfin/fem/assembling.py”, line 58, in _create_dolfin_form
function_spaces=function_spaces)
File “/usr/lib/python3/dist-packages/dolfin/fem/form.py”, line 44, in init
mpi_comm=mesh.mpi_comm())
File “/usr/lib/python3/dist-packages/dolfin/jit/jit.py”, line 47, in mpi_jit
return local_jit(*args, **kwargs)
File “/usr/lib/python3/dist-packages/dolfin/jit/jit.py”, line 97, in ffc_jit
return ffc.jit(ufl_form, parameters=p)
File “/usr/lib/python3/dist-packages/ffc/jitcompiler.py”, line 217, in jit
module = jit_build(ufl_object, module_name, parameters)
File “/usr/lib/python3/dist-packages/ffc/jitcompiler.py”, line 133, in jit_build
generate=jit_generate)
File “/usr/lib/python3/dist-packages/dijitso/jit.py”, line 165, in jit
header, source, dependencies = generate(jitable, name, signature, params[“generator”])
File “/usr/lib/python3/dist-packages/ffc/jitcompiler.py”, line 66, in jit_generate
prefix=module_name, parameters=parameters, jit=True)
File “/usr/lib/python3/dist-packages/ffc/compiler.py”, line 143, in compile_form
prefix, parameters, jit)
File “/usr/lib/python3/dist-packages/ffc/compiler.py”, line 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File “/usr/lib/python3/dist-packages/ffc/analysis.py”, line 90, in analyze_ufl_objects
for form in forms)
File “/usr/lib/python3/dist-packages/ffc/analysis.py”, line 90, in
for form in forms)
File “/usr/lib/python3/dist-packages/ffc/analysis.py”, line 174, in _analyze_form
do_apply_restrictions=True)
File “/usr/lib/python3/dist-packages/ufl/algorithms/compute_form_data.py”, line 418, in compute_form_data
check_form_arity(preprocessed_form, self.original_form.arguments(), complex_mode) # Currently testing how fast this is
File “/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py”, line 177, in check_form_arity
check_integrand_arity(itg.integrand(), arguments, complex_mode)
File “/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py”, line 159, in check_integrand_arity
arg_tuples = map_expr_dag(rules, expr, compress=False)
File “/usr/lib/python3/dist-packages/ufl/corealg/map_dag.py”, line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File “/usr/lib/python3/dist-packages/ufl/corealg/map_dag.py”, line 86, in map_expr_dags
r = handlers[v.ufl_typecode](v, *[vcache[u] for u in v.ufl_operands])
File “/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py”, line 48, in sum
raise ArityMismatch(“Adding expressions with non-matching form arguments {0} vs {1}.”.format(_afmt(a), _afmt(b)))
ufl.algorithms.check_arities.ArityMismatch: Adding expressions with non-matching form arguments (‘v_0’,) vs ().