Hi everyone, I tried to realize the two different material on the domain with two methods:
one is
def conductor(x):
return x[0] < 0.1 + np.finfo(float).eps
conductor_domain = locate_entities_geometrical(mesh, mesh.topology.dim-1,
conductor, boundary_only=False)
dx = Measure('dx', subdomain_data=conductor_tag)
print(dolfinx.fem.assemble_scalar(dolfinx.Constant(mesh, 1)*dx(1)))
It outputs about 0.11 and should be 0.1
The other method:
V = dolfinx.FunctionSpace(mesh, ('DG', 0))
w = dolfinx.Function(V)
x = V.tabulate_dof_coordinates()
for i in range(x.shape[0]):
if x[i][0] <= 0.1:
w.vector.setValueLocal(i, 6)
else:
w.vector.setValueLocal(i, 2)
with XDMFFile(dolfinx.MPI.comm_world, "w.xdmf",
encoding=XDMFFile.Encoding.HDF5) as file:
file.write(w)
But I cannot save w and it reports “segment error”