Hi everyone. Recently, I try to convert my program based on FEniCS 2019 to the new version FEniCSx. I meet a problem for transforming the following code to the current version due to lack of some functions, e.g., dolfin_element.evaluate_basis_all
import fenics as fe
def construct_measurement_matrix(xs, V):
# This function generate measurement matrix
# xs: measurement points
# V: function space generated by FEniCS
# Example:
# Let V be a function space generated by FEniCS
# u is a function genrated by FEniCS based on function space V
# points = np.array([(0,0), (0.5,0.5)])
# S = construct_measurement_matrix(ponits, V)
# S@u.vector()[:] is a vector (u[0, 0], u[0.5, 0.5])
nx, dim = xs.shape
mesh = V.mesh()
coords = mesh.coordinates()
cells = mesh.cells()
dolfin_element = V.dolfin_element()
dofmap = V.dofmap()
bbt = mesh.bounding_box_tree()
sdim = dolfin_element.space_dimension()
v = np.zeros(sdim)
rows = np.zeros(nx*sdim, dtype='int')
cols = np.zeros(nx*sdim, dtype='int')
vals = np.zeros(nx*sdim)
for k in range(nx):
# Loop over all interpolation points
x = xs[k, :]
if dim > 1:
p = fe.Point(x[0], x[1])
elif dim == 1:
p = fe.Point(x)
# Find cell for the point
cell_id = bbt.compute_first_entity_collision(p)
# Vertex coordinates for the cell
xvert = coords[cells[cell_id, :], :]
# Evaluate the basis functions for the cell at x
v = dolfin_element.evaluate_basis_all(x, xvert, cell_id)
jj = np.arange(sdim*k, sdim*(k+1))
rows[jj] = k
# Find the dofs for the cell
cols[jj] = dofmap.cell_dofs(cell_id)
vals[jj] = v
ij = np.concatenate((np.array([rows]), np.array([cols])), axis=0)
M = sps.csr_matrix((vals, ij), shape=(nx, V.dim()))
return M
Any help would be great to have!
Junxiong Jia