Skip to content
Snippets Groups Projects
Commit 8d1035fa authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Vectorized '_determine_modification()' in MinMod limiter.

parent f8f2061e
No related branches found
No related tags found
No related merge requests found
...@@ -134,20 +134,20 @@ class MinMod(Limiter): ...@@ -134,20 +134,20 @@ class MinMod(Limiter):
""" """
new_projection = projection.copy() new_projection = projection.copy()
cell_slopes = self._set_cell_slope(projection)
for cell in cells: for cell in cells:
cell_slope = self._set_cell_slope(projection, cell)
is_good_cell = self._determine_modification(projection, cell, is_good_cell = self._determine_modification(projection, cell,
cell_slope) cell_slopes)
if not is_good_cell: if not is_good_cell:
adapted_projection = projection[:, cell].copy() adapted_projection = projection[:, cell+1].copy()
for i in range(len(adapted_projection)): for i in range(len(adapted_projection)):
if i > self._erase_degree: if i > self._erase_degree:
adapted_projection[i] = 0 adapted_projection[i] = 0
new_projection[:, cell] = adapted_projection new_projection[:, cell+1] = adapted_projection
return new_projection return new_projection
def _determine_modification(self, projection, cell, cell_slope): def _determine_modification(self, projection, cell, slopes):
"""Determines whether limiting is applied. """Determines whether limiting is applied.
Parameters Parameters
...@@ -156,8 +156,8 @@ class MinMod(Limiter): ...@@ -156,8 +156,8 @@ class MinMod(Limiter):
Matrix of projection for each polynomial degree. Matrix of projection for each polynomial degree.
cell : int cell : int
Index of cell. Index of cell.
cell_slope : float slopes : ndarray
Slope of the given cell. Vector of slopes of projection cells.
Returns Returns
------- -------
...@@ -165,36 +165,37 @@ class MinMod(Limiter): ...@@ -165,36 +165,37 @@ class MinMod(Limiter):
Flag whether cell should be adjusted. Flag whether cell should be adjusted.
""" """
forward_slope = (projection[0][cell+1] forward_slopes = (projection[0, 2:]-projection[0, 1:-1]) * (0.5**0.5)
- projection[0][cell]) * (0.5**0.5) backward_slopes = (projection[0, 1:-1]-projection[0, :-2]) * (0.5**0.5)
backward_slope = (projection[0][cell] pos_mask = np.logical_and(slopes >= 0,
- projection[0][cell-1]) * (0.5**0.5) np.logical_and(forward_slopes >= 0,
backward_slopes >= 0))
return (forward_slope <= 0) & (backward_slope <= 0) \ neg_mask = np.logical_and(slopes <= 0,
& (cell_slope <= 0) \ np.logical_and(forward_slopes <= 0,
| (forward_slope >= 0) & (backward_slope >= 0) & (cell_slope >= 0) backward_slopes <= 0))
slope_mask = np.logical_or(pos_mask, neg_mask)
return slope_mask[cell]
@staticmethod @staticmethod
def _set_cell_slope(projection, cell): def _set_cell_slope(projection):
"""Calculates the slope of the cell. """Calculates the slope of the cell.
Parameters Parameters
---------- ----------
projection : ndarray projection : ndarray
Matrix of projection for each polynomial degree. Matrix of projection for each polynomial degree.
cell : int
Index of cell.
Returns Returns
------- -------
float ndarray
Slope of the given cell. Vector of slopes of projection cells.
""" """
root_vector = np.array([np.sqrt(degree+0.5) root_vector = np.array([np.sqrt(degree+0.5)
for degree in range(len(projection))]) for degree in range(len(projection))])
slope = root_vector[1:] @ projection[1:] slope = root_vector[1:] @ projection[1:]
return slope[cell] return slope[1:-1]
class ModifiedMinMod(MinMod): class ModifiedMinMod(MinMod):
...@@ -239,7 +240,7 @@ class ModifiedMinMod(MinMod): ...@@ -239,7 +240,7 @@ class ModifiedMinMod(MinMod):
"""Returns string of class name concatenated with the erase-degree.""" """Returns string of class name concatenated with the erase-degree."""
return self.__class__.__name__ + str(self._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. """Determines whether limiting is applied.
Parameters Parameters
...@@ -248,8 +249,8 @@ class ModifiedMinMod(MinMod): ...@@ -248,8 +249,8 @@ class ModifiedMinMod(MinMod):
Matrix of projection for each polynomial degree. Matrix of projection for each polynomial degree.
cell : int cell : int
Index of cell. Index of cell.
cell_slope : float slopes : ndarray
Slope of the given cell. Vector of slopes of projection cells.
Returns Returns
------- -------
...@@ -257,7 +258,7 @@ class ModifiedMinMod(MinMod): ...@@ -257,7 +258,7 @@ class ModifiedMinMod(MinMod):
Flag whether cell should be adjusted. Flag whether cell should be adjusted.
""" """
if abs(cell_slope) <= self._threshold: if abs(slopes[cell]) <= self._threshold:
return True return True
return super()._determine_modification(projection, cell, cell_slope) return super()._determine_modification(projection, cell, slopes)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment