Though the above piece of code works for defining the subdomain, I am getting the following error when I solve for the linear elastic mechanics:
Traceback (most recent call last):
File "Chemo_mechanics.py", line 280, in <module>
solve(a == l, u, bc)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 233, in solve
_solve_varproblem(*args, **kwargs)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/solving.py", line 268, in _solve_varproblem
problem = LinearVariationalProblem(eq.lhs, eq.rhs, u, bcs,
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/problem.py", line 58, in __init__
L = Form(L, form_compiler_parameters=form_compiler_parameters)
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/form.py", line 82, in __init__
self.set_cell_domains(subdomains)
TypeError: set_cell_domains(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.fem.Form, arg0: dolfin.cpp.mesh.MeshFunctionSizet) -> None
Invoked with: <dolfin.fem.form.Form object at 0x7fbba1084720>, <dolfin.cpp.mesh.MeshFunctionDouble object at 0x7fbb98516070>
I am using the MeshFunction of type ‘double’ in the following line of the code:
materials = MeshFunction('double', mesh, 2)
# print(values)
local_values = np.zeros_like(u.vector().get_local())
local_values_material = np.zeros_like(u.vector().get_local())
for cell in cells(mesh):
midpoint = cell.midpoint().array()
i = int(midpoint[0] // dx)
j = int(midpoint[1] // dx)
pos = i + 500*j
local_values[cell.index()] = values[pos]
local_values_material[cell.index()] = material_array[pos]
materials[cell] = local_values_material[cell.index()]
# f.array()[:] = local_values_material[cell.index()]
print(midpoint, i, j , pos)
I think the error lies in using the MeshFunction type ‘double’ instead of ‘size_t’. When I use the type ‘size_t’ in the above code, it is giving me the following error:
Traceback (most recent call last):
File "Chemo_mechanics.py", line 53, in <module>
materials[cell] = local_values_material[cell.index()]
TypeError: __setitem__(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.mesh.MeshFunctionSizet, arg0: int, arg1: int) -> None
2. (self: dolfin.cpp.mesh.MeshFunctionSizet, arg0: dolfin.cpp.mesh.MeshEntity, arg1: int) -> None
Invoked with: <dolfin.cpp.mesh.MeshFunctionSizet object at 0x7f8b582511f0>, <dolfin.cpp.mesh.Cell object at 0x7f8b58c4c870>, 1.0
Could you please help me with resolving this issue. Thank you so much for your help.
Sincerely,
ABS