I am doing elasticity assisted phase field calculations in FEniCS. The system is an anisotropic (single domain) sphere compressed uniaxially. I am using a mixed function space (a vector element for displacement and a scalar element for field variable. The variable can assume any value but only between 0 and 1 (inclusive).
Here is the minimal code of my problem
## TETRAGONAL
t11 = 361.0
t12 = 100.0
t13 = 62.0
t33 = 264.0
t44 = 59.0
t66 = 64.0
## MONOCLINIC
m11 = 327
m22 = 408
m33 = 258
m44 = 100
m55 = 81
m66 = 126
m12 = 142
m13 = 55
m16 = -21
m23 = 196
m26 = 31
m36 = -18
m45 = -23
Compliance_tetragonal = [
[t11, t12, t13, 0.0, 0.0, 0.0],
[t12, 0.0, 0.0, 0.0, 0.0, 0.0],
[t13, 0.0, t33, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, t44, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, t66]
]
Compliance_tetragonal = as_tensor(Compliance_tetragonal)
Compliance_monoclinic = [
[m11, m12, m13, 0.0, 0.0, m16],
[m12, m22, 0.0, 0.0, 0.0, m26],
[m13, 0.0, m33, 0.0, 0.0, m36],
[0.0, 0.0, 0.0, m44, m45, 0.0],
[0.0, 0.0, 0.0, m45, m55, 0.0],
[m16, m26, m36, 0.0, 0.0, m66]
]
Compliance_monoclinic = as_tensor(Compliance_monoclinic)
N = 20
R = 1.0
sphr = Sphere(Point(0,0,0), R)
cb1 = Box(Point(0, 2*R, 2*R), Point(2*R, -2*R, -2*R))
cb2 = Box(Point(0, 2*R, -2*R), Point(-2*R, -2*R, 0))
cb3 = Box(Point(2*R, 0, 0), Point(-2*R, -2*R, 2*R))
domain = sphr-cb1-cb2-cb3
# nucleation volume
tol = 1E-14
nucleus = '(x[0] - 0.5)*(x[0] - 0.5) + (x[1] - 0.5)*(x[1] - 0.5) + (x[2] - 0.5)*(x[2] - 0.5) <= 0.1 + tol'
mesh = generate_mesh(domain, N)
X = SpatialCoordinate(mesh)
h = CellDiameter(mesh)
subdomain_0 = CompiledSubDomain(nucleus, tol=tol)
P1 = VectorElement("Lagrange", mesh.ufl_cell(), 2)
P2 = FiniteElement("Lagrange", mesh.ufl_cell(), 2)
element = MixedElement([P1, P2])#, Re])
W = FunctionSpace(mesh, element)
w = Function(W)
v, p0 = TestFunctions(W)
u, c0 = split(w)
bdry_disp = Constant(0.1)
bcs = [DirichletBC(W.sub(0).sub(0), Constant(0), "x[0]<DOLFIN_EPS"),
DirichletBC(W.sub(0).sub(1), Constant(0), "x[1]<DOLFIN_EPS"),
DirichletBC(W.sub(0).sub(2), bdry_disp, "x[2]<DOLFIN_EPS"),
DirichletBC(W.sub(1), Constant(1.0), subdomain_0)
]
'''
VOIGT FORMAT DEFINITIONS:
'''
def strain3voigt(e):
return as_vector(
[e[0, 0],
e[1, 1],
e[2, 2],
e[1, 2] * 2,
e[0, 2] * 2,
e[0, 1] * 2]
)
def voigt3stress(s):
return as_tensor(
[[s[0], s[5], s[4]],
[s[5], s[1], s[3]],
[s[4], s[3], s[2]]]
)
'''
CONSTITUTIVE LAW: FUNCTIONS AND DEFINITIONS
'''
# 3*3 matrix
def epsilon(v):
return sym(grad(v))
def trans_strain(c0, e_v1):
return (1-c0)*e_v1
def epsilon_elastic(v, c0):
return epsilon(v)- trans_strain(c0, e_v1)
def Vstrain_elastic(v, c0):
return strain3voigt(epsilon_elastic(v, c0))
def mixture_compliance(c0):
global Compliance_monoclinic, Compliance_tetragonal
return (c0 * Compliance_tetragonal) + ((1 - c0) * Compliance_monoclinic)
def sigma(v, c0):
return voigt3stress(dot(mixture_compliance(c0), Vstrain_elastic(v, c0)))
'''
PENALTY FORCE:
'''
x = X + u
R = Constant(R)
k = Constant(1.0)
G = Constant(1.0)
E = 9*k*G/(3*k+G)
C_pen = Constant(1e3) # (Dimensionless constant)
k_pen = C_pen*E/h # (Typical choice of contact penalty)
chi_pen = conditional(gt(x[2], R), 1, Constant(0))
t_pen = k_pen*chi_pen*as_vector([Constant(0), Constant(0), R-x[2]])
'''
RESIDUAL OF THE VARIATIONAL PROBLEM:
'''
res = 0.5*inner(sigma(v, p0), epsilon_elastic(v, p0))*dx + 13.0*p0*(1 - p0)*dx + 18.0*(1 - p0)*dx - dot(t_pen, v)*ds
dw = Function(W)
J = derivative(res, w, dw)
'''
SOLUTION:
'''
w = Function(W)
problem = NonlinearVariationalProblem(res, w, bcs, J)
solver = NonlinearVariationalSolver(problem)
u_, c0_ = w.split()
I am getting the following error consistently and I am not able to figure out how to proceed from here. I see that there is some issue with the solver function as it raises arity mismatch. The exact displayed message is -
Generating mesh with CGAL 3D mesh generator
Output from spyder call 'get_cwd':
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/Users/dhariwal/drive backup/Lu group/Zirconia/elasticity/aniso-3D-without-loop.py", line 333, in <module>
problem = NonlinearVariationalProblem(res, w, bcs, J)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/problem.py", line 90, in __init__
F = Form(F, form_compiler_parameters=form_compiler_parameters)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/fem/form.py", line 43, in __init__
ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
return local_jit(*args, **kwargs)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dolfin/jit/jit.py", line 97, in ffc_jit
return ffc.jit(ufl_form, parameters=p)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 217, in jit
module = jit_build(ufl_object, module_name, parameters)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 130, in jit_build
module, signature = dijitso.jit(jitable=ufl_object,
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/dijitso/jit.py", line 165, in jit
header, source, dependencies = generate(jitable, name, signature, params["generator"])
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/jitcompiler.py", line 65, in jit_generate
code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/compiler.py", line 142, in compile_form
return compile_ufl_objects(forms, "form", object_names,
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/compiler.py", line 185, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, kind, parameters)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 89, in analyze_ufl_objects
form_datas = tuple(_analyze_form(form, parameters)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 89, in <genexpr>
form_datas = tuple(_analyze_form(form, parameters)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ffc/analysis.py", line 169, in _analyze_form
form_data = compute_form_data(form,
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-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 "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/check_arities.py", line 177, in check_form_arity
check_integrand_arity(itg.integrand(), arguments, complex_mode)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/algorithms/check_arities.py", line 159, in check_integrand_arity
arg_tuples = map_expr_dag(rules, expr, compress=False)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/corealg/map_dag.py", line 37, in map_expr_dag
result, = map_expr_dags(function, [expression], compress=compress)
File "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-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 "/Users/dhariwal/opt/anaconda3/envs/fenicsproject/lib/python3.9/site-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)))
ArityMismatch: Adding expressions with non-matching form arguments () vs ('v_0',).