Dear all,
I want to have multiple subdomains based on each cell. For example, I have 100 cells in my mesh, then I need to have 100 subdomains, in order to do the integration around each cell. I know this can be done by a For loop. However, when there are thousands of cells, it will take a lot of time to do the for loop at every time step. The code attached below is my thought to do that, but it fails.
- Can anyone help me with this problem?
- Or if you have a better idea to do the integration around each point, please let me know?
- Is there a way to find the index of points during “interpolate”?
Thanks a lot for your time and help!
import numpy as np
from mpi4py import MPI
import ufl
from dolfinx import fem, io, mesh, plot, common, geometry
from ufl import ds, dx, grad, inner
# Create mesh and define function space
msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (1, 1)), n=(10, 10),
cell_type=mesh.CellType.quadrilateral)
V = fem.FunctionSpace(msh, ("CG", 1))
Q = fem.FunctionSpace(msh, ("DG", 0))
P = fem.Function(Q)
T = fem.Function(V)
T.interpolate(lambda x: x[0] + 2 * x[1])
R = 0.02
def f_(x):
a = np.array(x[0])
b = np.array(x[1])
subcells = mesh.locate_entities(msh, msh.topology.dim, lambda y: np.sqrt((y[0]-a)**2 + (y[1]-b)**2) <= R)
subdm = mesh.meshtags(msh, msh.topology.dim, subcells, np.array([point_index], dtype = np.int32))
#here the point_index should be the index of each point and the length should be equal to subcells
dx_subdm = ufl.Measure("dx", subdomain_data = subdm)
return fem.assemble_scalar(fem.form(T * dx_subdm(point_index)))
P.interpolate(f_)
print(P.x.array)