I also tried from:
import gmsh
import numpy as np
import pyvista
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_square, locate_entities, locate_entities_boundary
from dolfinx.plot import create_vtk_mesh
from dolfinx.mesh import *
from ufl import (SpatialCoordinate, TestFunction, TrialFunction,
dx, grad, inner)
from mpi4py import MPI
from petsc4py.PETSc import ScalarType
from dolfinx.io import gmshio
mesh, materials, facet_markers = gmshio.read_from_msh("mesh3D.msh", MPI.COMM_WORLD, gdim=3)
class EMod(UserExpression):
def __init__(self,materials,volume_list,rho_list,**kwargs):
super().__init__(**kwargs)
self.materials = materials
self.volume_list = volume_list
self.rho_list = rho_list
def value_shape(self):
return ()
def eval_cell(self,values,x,cell):
values[0] = 0
for i in range(len(self.volume_list)):
if self.materials[cell.index] == self.volume_list[i]:
values[0] = self.rho_list[i]
volume_list = [11,12] # list of physical volume ID's
rho_list = [100,200] # list of pre-defined values
rho = EMod(materials,volume_list,rho_list,degree=1)
#E.x.array[mu_indices] = np.full_like(mu_indices, 200, dtype=ScalarType)
#E.x.array[lambda_indices] = np.full_like(lambda_indices, 500, dtype=ScalarType)
print('done')
The difficulty here is that UserExpression is not being found. I looked around about UserExpression and found it to be deprected. Is it possible to switch over directly to Expression as opposed to UserExpression which was from fenics?