From 76e3c1a53a27f7d3f0ffa37e3c7bf99df817a325 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 12:44:38 +0200 Subject: [PATCH] Vectorized 'apply()' in MinMod limiter. --- scripts/tcd/Limiter.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/tcd/Limiter.py b/scripts/tcd/Limiter.py index bf9137f..258cee1 100644 --- a/scripts/tcd/Limiter.py +++ b/scripts/tcd/Limiter.py @@ -134,15 +134,23 @@ class MinMod(Limiter): """ new_projection = projection.copy() + + # If no troubled cells are detected, return copy + if len(cells) == 0: + return new_projection + + # Set mask to limit complete projection cell_slopes = self._set_cell_slope(projection) modification_mask = self._determine_mask(projection, cell_slopes) - for cell in cells: - if not modification_mask[cell]: - 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+1] = adapted_projection + cells = np.array(cells) + mask = np.zeros_like(new_projection, dtype=bool) + mask[self._erase_degree+1:, cells+1] = np.tile( + np.logical_not(modification_mask)[cells], + (len(projection)-self._erase_degree-1, 1)) + + # Limit troubled cells for higher degrees + new_projection[mask] = 0 + return new_projection def _determine_mask(self, projection, slopes): -- GitLab