How to define different materials / importet 3D geometry (gmsh)

Following Dolfinx discontinous expression, this code can be modified for the syntax in dolfin as follows:

import dolfin

mesh = dolfin.UnitCubeMesh(9, 9, 9)
V = dolfin.FunctionSpace(mesh, "DG", 0)
v = dolfin.Function(V)
x = V.tabulate_dof_coordinates()
mf = dolfin.MeshFunction("size_t", mesh, mesh.topology().dim())
class Obstacle(dolfin.SubDomain):
    def inside(self, x, on_boundary):
        return (dolfin.between(x[1], (0.2, 0.7)) and
                dolfin.between(x[0], (0.3, 0.7)))
Obstacle().mark(mf, 2)
dolfin.XDMFFile("CF.xdmf").write(mf)
for i in range(x.shape[0]):
    if mf.array()[i] == 2:
        v.vector().vec().setValueLocal(i, 2)
    else:
        v.vector().vec().setValueLocal(i, 1)

dolfin.XDMFFile(dolfin.MPI.comm_world, "DG.xdmf").write_checkpoint(v, "v", 0)
2 Likes