I tried to modify the example from the above mentionned tutorial with the information in the link you provided:
import gmsh
import numpy as np
from dolfinx.fem import (Constant, dirichletbc, Function, FunctionSpace, assemble_scalar,
form, locate_dofs_geometrical, locate_dofs_topological)
from dolfinx.fem.petsc import LinearProblem
from dolfinx.io import XDMFFile
from dolfinx.mesh import create_unit_cube, locate_entities
from dolfinx.plot import create_vtk_mesh
from ufl import (SpatialCoordinate, TestFunction, TrialFunction,
dx, grad, inner)
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
mesh = create_unit_cube(MPI.COMM_WORLD, 10, 10, 10)
Q = FunctionSpace(mesh, ("DG", 0))
def Omega_0(x):
return x[1] <= 0.5
def Omega_1(x):
return x[1] >= 0.5
kappa = Function(Q)
cells_0 = locate_entities(mesh, mesh.topology.dim, Omega_0)
cells_1 = locate_entities(mesh, mesh.topology.dim, Omega_1)
k_1 = Constant(mesh, np.array([[4,0,0],[0,5,0],[0,0,6]], dtype=np.float64)) # Anisotropic
kappa.x.array[cells_0] = np.full(len(cells_0), 1.) # Isotropic
kappa.x.array[cells_1] = np.full(len(cells_1), k_1)
V = FunctionSpace(mesh, ("CG", 1))
u, v = TrialFunction(V), TestFunction(V)
a = inner(kappa*grad(u), grad(v)) * dx
x = SpatialCoordinate(mesh)
L = Constant(mesh, ScalarType(1)) * v * dx
dofs = locate_dofs_geometrical(V, lambda x: np.isclose(x[0], 0))
bcs = [dirichletbc(ScalarType(1), dofs, V)]
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()
but I get the error
kappa.x.array[cells_1] = np.full(len(cells_1), k_1)
~~~~~~~~~~~~~^^^^^^^^^
ValueError: setting an array element with a sequence.