Triangle project helper (Cell to point data converter) #322
Replies: 5 comments 15 replies
-
Thank you very much! I'll have a look at it during the weekend. |
Beta Was this translation helpful? Give feedback.
-
I enhanced the code slightly to support tensor-valued data (like the original project-helper does also). However, I'd like to get rid of the for-loop but I have no idea for that right now. def tri_project(values, region):
"""Projection of scalar or vectorial values taken from the mean of the
quadrature point data of cells to mesh-points (for triangles and tetrahedrons).
"""
mesh = region.mesh
cells = mesh.cells
# 1d-reshaped values at cells
dim = int(np.product(values.shape[:-2]))
# mean of values at quadrature points of cells
# reshape mean-values of cells to (ncells, dim)
u = values.T.mean(1).reshape(-1, dim)
# init values at mesh-points
values_points = np.zeros((mesh.npoints, dim))
# loop over mesh-points
for i, point_data in enumerate(values_points):
# mask cells which contain the given point
mask = np.any(np.isin(cells, i), axis=1)
# collect all cells which are connected to the given point
point_cells = np.arange(mesh.ncells)[mask]
# combine connected cell values to mean value at the given point
values_points[i] = u[point_cells].mean(0)
return values_points |
Beta Was this translation helpful? Give feedback.
-
I fired the for-loop. But there is no enhancement at the level of execution time, take a look; A part of the code:
then I got;
It stills no meaningful difference. |
Beta Was this translation helpful? Give feedback.
-
I created a project helper without a loop. First of all: it is not faster 🐢. Second, it is a memory beast 📚 - thanks to the huge array def tri_project_no_loop(values, region):
"""Projection of scalar or vectorial values taken from the mean of the
quadrature point data of cells to mesh-points (for triangles and tetrahedrons).
"""
mesh = region.mesh
# 1d-reshaped values at cells
dim = int(np.product(values.shape[:-2]))
# mean of values at quadrature points of cells
u = values.mean(-2).reshape(dim, mesh.ncells, 1)
# mask cells which contain a specific point of shape (ncells, npoints)
mask = (mesh.cells[..., np.newaxis] == np.arange(mesh.npoints)).any(axis=1)
# # obtain values on mesh-points
return ((u * mask).sum(1) / mask.astype(bool).sum(0)).T |
Beta Was this translation helpful? Give feedback.
-
Hello, Mr. Andreas, I think that the problem of the missing triangle project helper can be solved by this, take a look.
Then, I got this
I hope that this can help.
Beta Was this translation helpful? Give feedback.
All reactions