diff --git a/Limiter.py b/Limiter.py new file mode 100644 index 0000000000000000000000000000000000000000..8d653039886af4621795aa96a7da9305db94465f --- /dev/null +++ b/Limiter.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +""" +@author: Laura C. Kühle + +""" +import numpy as np + +class Limiter(object): + + def __init__(self, config): + pass + + def get_name(self): + return self.function_name + + def apply(): + pass + +class NoLimiter(Limiter): + + def __init__(self, config): + # Set name of function + self.function_name = 'NoLimiter' + pass + + def apply(self, projection, cell): + return np.transpose(self.projection)[cell] + + +class MinMod(Limiter): + + def __init__(self, config): + # Unpack necessary parameter + self.erase_degree = config.pop('erase_degree', 0) + + # Set name of function + self.function_name = 'MinMod' + str(self.erase_degree) + + # Pop unncessary parameter + config.pop('cell_len') + + self.projection = [] + self.cell = 0 + pass + + def apply(self, projection, cell): + self.projection = projection + self.cell = cell + self._set_cell_slope() + is_good_cell = self._determine_modification() + + if is_good_cell: + return np.transpose(self.projection)[self.cell] + + adapted_projection = np.transpose(self.projection)[self.cell].copy() + for i in range(len(adapted_projection)): + if (i > self.erase_degree): + adapted_projection[i] = 0 + return adapted_projection + + def _set_cell_slope(self): + slope = [] + transposed_projection = np.transpose(self.projection) + for cell in range(len(transposed_projection)): + new_entry = sum(transposed_projection[cell][degree] + * (degree+0.5)**0.5 + for degree in range(1, len(self.projection))) + slope.append(new_entry) + self.cell_slope = slope[self.cell] + + def _determine_modification(self): + forward_slope = (self.projection[0][self.cell+1] + - self.projection[0][self.cell]) * (0.5**0.5) + backward_slope = (self.projection[0][self.cell] + - self.projection[0][self.cell-1]) * (0.5**0.5) + + if ((forward_slope <= 0) & (backward_slope <= 0) + & (self.cell_slope <= 0)): + return True + if ((forward_slope >= 0) & (backward_slope >= 0) + & (self.cell_slope >= 0)): + return True + return False + + +class ModifiedMinMod(MinMod): + + def __init__(self, config): + # Unpack necessary configurations + self.cell_len = config.pop('cell_len') + self.erase_degree = config.pop('erase_degree', 0) + self.mod_factor = config.pop('mod_factor', 0) + + # Set name of function + self.function_name = 'ModifiedMinMod' + str(self.erase_degree) + + self.projection = [] + self.cell = 0 + pass + + def _determine_modification(self): + if (abs(self.cell_slope) <= self.mod_factor*self.cell_len**2): + return True # former: u_tilde_entry + + return super()._determine_modification()