diff --git a/scripts/tcd/Limiter.py b/scripts/tcd/Limiter.py index 099719850f45bcf8aa306e7f7d4f9d229c1bf0e6..235f1c59052a3fdda86ed4dcba185fb99d3c3fa1 100644 --- a/scripts/tcd/Limiter.py +++ b/scripts/tcd/Limiter.py @@ -134,20 +134,20 @@ class MinMod(Limiter): """ new_projection = projection.copy() + cell_slopes = self._set_cell_slope(projection) for cell in cells: - cell_slope = self._set_cell_slope(projection, cell) is_good_cell = self._determine_modification(projection, cell, - cell_slope) + cell_slopes) if not is_good_cell: - adapted_projection = projection[:, cell].copy() + adapted_projection = projection[:, cell+1].copy() for i in range(len(adapted_projection)): if i > self._erase_degree: adapted_projection[i] = 0 - new_projection[:, cell] = adapted_projection + new_projection[:, cell+1] = adapted_projection return new_projection - def _determine_modification(self, projection, cell, cell_slope): + def _determine_modification(self, projection, cell, slopes): """Determines whether limiting is applied. Parameters @@ -156,8 +156,8 @@ class MinMod(Limiter): Matrix of projection for each polynomial degree. cell : int Index of cell. - cell_slope : float - Slope of the given cell. + slopes : ndarray + Vector of slopes of projection cells. Returns ------- @@ -165,36 +165,37 @@ class MinMod(Limiter): Flag whether cell should be adjusted. """ - forward_slope = (projection[0][cell+1] - - projection[0][cell]) * (0.5**0.5) - backward_slope = (projection[0][cell] - - projection[0][cell-1]) * (0.5**0.5) - - return (forward_slope <= 0) & (backward_slope <= 0) \ - & (cell_slope <= 0) \ - | (forward_slope >= 0) & (backward_slope >= 0) & (cell_slope >= 0) + forward_slopes = (projection[0, 2:]-projection[0, 1:-1]) * (0.5**0.5) + backward_slopes = (projection[0, 1:-1]-projection[0, :-2]) * (0.5**0.5) + pos_mask = np.logical_and(slopes >= 0, + np.logical_and(forward_slopes >= 0, + backward_slopes >= 0)) + neg_mask = np.logical_and(slopes <= 0, + np.logical_and(forward_slopes <= 0, + backward_slopes <= 0)) + slope_mask = np.logical_or(pos_mask, neg_mask) + + return slope_mask[cell] @staticmethod - def _set_cell_slope(projection, cell): + def _set_cell_slope(projection): """Calculates the slope of the cell. Parameters ---------- projection : ndarray Matrix of projection for each polynomial degree. - cell : int - Index of cell. Returns ------- - float - Slope of the given cell. + ndarray + Vector of slopes of projection cells. """ root_vector = np.array([np.sqrt(degree+0.5) for degree in range(len(projection))]) slope = root_vector[1:] @ projection[1:] - return slope[cell] + return slope[1:-1] class ModifiedMinMod(MinMod): @@ -239,7 +240,7 @@ 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, cell_slope): + def _determine_modification(self, projection, cell, slopes): """Determines whether limiting is applied. Parameters @@ -248,8 +249,8 @@ class ModifiedMinMod(MinMod): Matrix of projection for each polynomial degree. cell : int Index of cell. - cell_slope : float - Slope of the given cell. + slopes : ndarray + Vector of slopes of projection cells. Returns ------- @@ -257,7 +258,7 @@ class ModifiedMinMod(MinMod): Flag whether cell should be adjusted. """ - if abs(cell_slope) <= self._threshold: + if abs(slopes[cell]) <= self._threshold: return True - return super()._determine_modification(projection, cell, cell_slope) + return super()._determine_modification(projection, cell, slopes)