I would like to apply an anisotropic thermal conductivity only on a selection of cells in the mesh.
I am trying the following method below but the solver diverges:
VC_mask = dolfinx.mesh.meshtags(mesh, mesh.topology.dim, cells, np.full_like(cells, 2)) # mark everything as isotropic
def marker_VC(x):
mask = np.isclose(x[0], 2.*x[0].max()) # fill mask with False
bb_mask = ((x[0] >= 10) & (x[0] <= 15)) & ((x[1] >= 10) & (x[1] <= 13)) & ((x[2] >= 7) & (x[2] <= 14))
mask = mask | bb_mask
return mask
cells_VC_loc = dolfinx.mesh.locate_entities(mesh, mesh.topology.dim, marker_VC)
el = ufl.TensorElement("DG", mesh.ufl_cell(), 0)
Q = dolfinx.fem.FunctionSpace(mesh, el)
bs = Q.dofmap.bs
k = dolfinx.fem.Function(Q)
# isotropic thermral conductivity value
kx = 1
# anisotropic thermral conductivity value
kx_vc = 10
ky_vc = 20
kz_vc = 30
def isotropic(x):
values = np.zeros((3, 3, x.shape[1]), dtype=np.float64)
values[0, 0] = kx
values[1, 1] = kx
values[2, 2] = kx
return values.reshape((bs, x.shape[1]))
def anisotropic(x):
values = np.zeros((3, 3, x.shape[1]), dtype=np.float64)
values[0, 0] = kx_vc
values[1, 1] = ky_vc
values[2, 2] = kz_vc
return values.reshape((bs, x.shape[1]))
# ISOTROPIC REGION
cells_notVC = porosity_mask.indices[vapor_chambers_mask.values==2]
k.interpolate(isotropic, cells=cells_notVC)
# ANISOTROPIC REGION
cells_VC = vapor_chambers_mask.indices[np.isin(cell_tags.indices, cells_VC_loc)]
k.interpolate(anisotropic, cells=cells_VC)
k.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
Could somebody guide me in the right direction please?

