From 074f94d4a111fa09130795456f0808b6575312ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BChle=2C=20Laura=20Christine=20=28lakue103=29?= <laura.kuehle@uni-duesseldorf.de> Date: Fri, 28 Oct 2022 10:36:58 +0200 Subject: [PATCH] Reworked limit masking to apply over array instead of cell. --- scripts/tcd/Limiter.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/scripts/tcd/Limiter.py b/scripts/tcd/Limiter.py index 235f1c5..bf9137f 100644 --- a/scripts/tcd/Limiter.py +++ b/scripts/tcd/Limiter.py @@ -135,11 +135,9 @@ class MinMod(Limiter): """ new_projection = projection.copy() cell_slopes = self._set_cell_slope(projection) + modification_mask = self._determine_mask(projection, cell_slopes) for cell in cells: - is_good_cell = self._determine_modification(projection, cell, - cell_slopes) - - if not is_good_cell: + if not modification_mask[cell]: adapted_projection = projection[:, cell+1].copy() for i in range(len(adapted_projection)): if i > self._erase_degree: @@ -147,22 +145,20 @@ class MinMod(Limiter): new_projection[:, cell+1] = adapted_projection return new_projection - def _determine_modification(self, projection, cell, slopes): - """Determines whether limiting is applied. + def _determine_mask(self, projection, slopes): + """Determine limiting mask. Parameters ---------- projection : ndarray Matrix of projection for each polynomial degree. - cell : int - Index of cell. slopes : ndarray Vector of slopes of projection cells. Returns ------- - bool - Flag whether cell should be adjusted. + ndarray + Mask whether cells should be adjusted. """ forward_slopes = (projection[0, 2:]-projection[0, 1:-1]) * (0.5**0.5) @@ -175,7 +171,7 @@ class MinMod(Limiter): backward_slopes <= 0)) slope_mask = np.logical_or(pos_mask, neg_mask) - return slope_mask[cell] + return slope_mask @staticmethod def _set_cell_slope(projection): @@ -240,25 +236,21 @@ class ModifiedMinMod(MinMod): """Returns string of class name concatenated with the erase-degree.""" return self.__class__.__name__ + str(self._erase_degree) - def _determine_modification(self, projection, cell, slopes): - """Determines whether limiting is applied. + def _determine_mask(self, projection, slopes): + """Determine limiting mask. Parameters ---------- projection : ndarray Matrix of projection for each polynomial degree. - cell : int - Index of cell. slopes : ndarray Vector of slopes of projection cells. Returns ------- - bool - Flag whether cell should be adjusted. + ndarray + Mask whether cells should be adjusted. """ - if abs(slopes[cell]) <= self._threshold: - return True - - return super()._determine_modification(projection, cell, slopes) + return np.logical_or(abs(slopes) <= self._threshold, + super()._determine_mask(projection, slopes)) -- GitLab