Hello,
I have a mesh symmetric about, say, y = x
,
and would like to build a mapping: cellmap= [[2,1], [3,4]]
I
The dolfin version is : 2019.1.0
import time
import numpy as np
from dolfin import *
Nx = Ny = 21
mesh = RectangleMesh(Point(0.0, 0.0), Point(1, 1), Nx, Ny, "crossed")
class Southeast(SubDomain):
def inside(self, x, on_boundary):
return x[0] >= x[1]
southeast = Southeast()
submesh = SubMesh(mesh, southeast)
gdim = mesh.geometry().dim()
cellmap = np.zeros([submesh.num_cells(), 3], dtype=int)
subindex = 0
# to optimize
tic = time.perf_counter()
for subcell in cells(submesh):
cellmap[subindex, 0] = subcell.index()
for cell in cells(mesh):
if cell.contains(subcell.midpoint()):
cellmap[subindex, 1] = cell.index()
break
for cell in cells(mesh):
if cell.contains(Point(subcell.midpoint().y(), subcell.midpoint().x())):
cellmap[subindex, 2] = cell.index()
break
subindex += 1
print(cellmap.T)
toc = time.perf_counter()
print(f"Map cells in {toc - tic:0.4f} seconds")
It is working.
For small Nx, it is OK.
For large Nx, for example, Nx = 101, it takes centuries.
Could you help me to optimize this script?
Many thanks.