My code:
from fenics import *
# ********* Mesh and I/O *********
mesh_file = XDMFFile(“mesh_scale.xdmf”)
mesh = Mesh()
mesh_file.read(mesh)
mesh_file.close()
class FiberDirections(UserExpression):
def **init**(self, c0, c1, c2, **kwargs):
super().**init**(**kwargs)
self.c0 = c0
self.c1 = c1
self.c2 = c2
def eval(self, values, x):
cell_index = Cell(mesh, x).index()
values[0] = self.c0[cell_index]
values[1] = self.c1[cell_index]
values[2] = self.c2[cell_index]
def value_shape(self):
return (3,)
f00 = MeshFunction(“double”, mesh, “fibers_0.xml”)
f01 = MeshFunction(“double”, mesh, “fibers_1.xml”)
f02 = MeshFunction(“double”, mesh, “fibers_2.xml”)
s00 = MeshFunction(“double”, mesh, “sheets_0.xml”)
s01 = MeshFunction(“double”, mesh, “sheets_1.xml”)
s02 = MeshFunction(“double”, mesh, “sheets_2.xml”)
# Usage:
f0 = FiberDirections(f00, f01, f02)
s0 = FiberDirections(s00, s01, s02)
W = VectorFunctionSpace(mesh, ‘P’, 1)
Q = FunctionSpace(mesh, ‘P’, 1)
X = Function(W)
X.set_allow_extrapolation(True)
# f_in = XDMFFile(“process.xdmf”)
# f_in.read_checkpoint(X,“position”)
with XDMFFile(“u0.xmf”) as outfile:
outfile.write(mesh)
outfile.write_checkpoint(X, “u”, 80, append=True)
F = variable(grad(X))
J = det(F)
C = F.T<em>F
strain = project(inner(f0, C</em>f0), Q)
File(“strain.pvd”) << strain
a = 2400
b = 5.08
a_f = 14600
b_f = 4.15
a_s = 8700
b_s = 1.6
a_fs = 3000
b_fs = 1.3
F = variable(grad(X))
J = det(F)
C = F.T*F
I1 = tr(C)
I3 = det(C)
from ufl import max_value
I_4f = max_value(inner(f0, C<em>f0), 1.0)
I_4s = max_value(inner(s0, C</em>s0), 1.0)
I_8fs = inner(f0, C*s0)
W = a/2.0/b*exp(b*(I1-3))
W += a_f/2.0/b_f*(exp(b_f*(I_4f-1.0)<em>(I_4f-1.0))-1.0)
W += a_s/2.0/b_s</em>(exp(b_s*(I_4s-1.0)<em>(I_4s-1.0))-1.0)
W += a_fs/2.0/b_fs</em>(exp(b_fs*I_8fs*I_8fs)-1.0)
P = diff(W, F)
stress = project(inner(f0, P*f0), Q)
File(“stress.pvd”) << stress
The error:
Traceback (most recent call last):
File “stress.py”, line 114, in
strain = project(inner(f0, C*f0), Q)
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/projection.py”, line 133, in project
form_compiler_parameters=form_compiler_parameters)
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py”, line 430, in assemble_system
assembler.assemble(A_tensor, b_tensor)
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/expression.py”, line 53, in wrapped_eval
self.user_expression.eval(values, x)
File “stress.py”, line 81, in eval
cell_index = Cell(mesh, x).index()
TypeError: **init**(): incompatible constructor arguments. The following argument types are supported:
1. dolfin.cpp.mesh.Cell(arg0: dolfin.cpp.mesh.Mesh, arg1: int)
Invoked with: <dolfin.cpp.mesh.Mesh object at 0x7f28d5385990>, array([10.036433 , 7.3242552, 9.1257265])