Skip to content

Commit

Permalink
fix: speeding up element getter
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Jan 5, 2024
1 parent e4a2fac commit c260d9f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions LoopStructural/interpolators/supports/_3d_structured_tetra.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(
(self.neighbours[self.neighbours >= 0].flatten().shape[0], 3), dtype=int
)
self.cg = None
self._elements = None

self._init_face_table()

@property
Expand All @@ -53,7 +55,9 @@ def n_cells(self) -> int:

@property
def elements(self):
return self.get_elements()
if self._elements is None:
self._elements = self.get_elements()
return self._elements

@property
def element_size(self):
Expand Down Expand Up @@ -83,7 +87,7 @@ def barycentre(self) -> np.ndarray:
barycentres of all tetrahedrons
"""

tetra = self.get_elements()
tetra = self.elements
barycentre = np.sum(self.nodes[tetra][:, :, :], axis=1) / 4.0
return barycentre

Expand All @@ -102,7 +106,7 @@ def _init_face_table(self):
# flatten both of these arrays so we effectively have a table with pairs of neighbours
# disgard the negative neighbours because these are border neighbours
rows = np.tile(np.arange(self.n_elements)[:, None], (1, 4))
elements = self.get_elements()
elements = self.elements
neighbours = self.get_neighbours()
# add array of bool to the location where there are elements for each node

Expand Down

0 comments on commit c260d9f

Please sign in to comment.