diff --git a/Initial_Condition.py b/Initial_Condition.py index a559f4c09e94250182a3e1f8783061ce7b2ad8af..6af61e51f57734c78ba848841f536fe021b7aa0e 100644 --- a/Initial_Condition.py +++ b/Initial_Condition.py @@ -10,6 +10,10 @@ class InitialCondition(object): def __init__(self, left_bound, right_bound, config): self._left_bound = left_bound self._right_bound = right_bound + + self._reset(config) + + def _reset(self, config): self._interval_len = self._right_bound-self._left_bound def get_name(self): @@ -27,8 +31,8 @@ class InitialCondition(object): class Sine(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._factor = config.pop('factor', 2) @@ -38,9 +42,6 @@ class Sine(InitialCondition): class Box(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) - def _get_point(self, x): if x < -1: x = x + 2 @@ -53,8 +54,8 @@ class Box(InitialCondition): class FourPeakWave(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) + def _reset(self, config): + super()._reset(config) # Set additional necessary parameter self._alpha = 10 @@ -82,8 +83,8 @@ class FourPeakWave(InitialCondition): class Linear(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._factor = config.pop('factor', 1) @@ -93,8 +94,8 @@ class Linear(InitialCondition): class LinearAbsolut(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._factor = config.pop('factor', 1) @@ -104,8 +105,8 @@ class LinearAbsolut(InitialCondition): class DiscontinuousConstant(InitialCondition): - def __init__(self, left_bound, right_bound, config): - super().__init__(left_bound, right_bound, config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._x0 = config.pop('x0', 0) diff --git a/Limiter.py b/Limiter.py index f2e69da8773112ce6f94d87d7e11fd5315ffa2ec..892a4fe4f9e4ca5741c9ebaa3032ab053368a8c9 100644 --- a/Limiter.py +++ b/Limiter.py @@ -7,6 +7,9 @@ class Limiter(object): def __init__(self, config): + self._reset(config) + + def _reset(self, config): pass def get_name(self): @@ -17,17 +20,12 @@ class Limiter(object): class NoLimiter(Limiter): - def __init__(self, config): - super().__init__(config) - def apply(self, projection, cell): return projection[:, cell] class MinMod(Limiter): - def __init__(self, config): - super().__init__(config) - + def _reset(self, config): # Unpack necessary configurations self._erase_degree = config.pop('erase_degree', 0) @@ -65,8 +63,8 @@ class MinMod(Limiter): class ModifiedMinMod(MinMod): - def __init__(self, config): - super().__init__(config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._cell_len = config.pop('cell_len') diff --git a/Quadrature.py b/Quadrature.py index bc68aa8106b3b2ab735b7cf5fa0c98fdef3db64c..fc3babfac75b4bfdd2f64c084113206b6801a83b 100644 --- a/Quadrature.py +++ b/Quadrature.py @@ -8,6 +8,9 @@ import numpy.polynomial.legendre as leg class Quadrature(object): def __init__(self, config): + self._reset(config) + + def _reset(self, config): self._eval_points = None self._weights = None self._num_eval_points = None @@ -26,8 +29,8 @@ class Quadrature(object): class Gauss(Quadrature): - def __init__(self, config): - super().__init__(config) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._num_eval_points = config.pop('num_eval_points', 6) diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index 328428c11ee96e7514d83a8a9b85596e5210fad6..8adf214b07e8724ea06e62d66d959311da19183c 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -32,6 +32,11 @@ class TroubledCellDetector(object): self._init_cond = init_cond self._quadrature = quadrature + self._reset(config) + + def _reset(self, config): + pass + def get_name(self): return self.__class__.__name__ @@ -133,21 +138,12 @@ class TroubledCellDetector(object): class NoDetection(TroubledCellDetector): - def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature): - super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature) - def get_cells(self, projection): return [] class WaveletDetector(TroubledCellDetector): - def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature): - super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature) - + def _reset(self, config): # Set fixed basis and wavelet vectors self._basis = OrthonormalLegendre(self._polynom_degree).get_vector(x) self._wavelet = AlpertsWavelet(self._polynom_degree).get_vector(x) @@ -306,10 +302,8 @@ class WaveletDetector(TroubledCellDetector): class Boxplot(WaveletDetector): - def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature): - super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._fold_len = config.pop('fold_len', 16) @@ -356,10 +350,8 @@ class Boxplot(WaveletDetector): class Theoretical(WaveletDetector): - def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature): - super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, - basis, init_cond, quadrature) + def _reset(self, config): + super()._reset(config) # Unpack necessary configurations self._cutoff_factor = config.pop('cutoff_factor', np.sqrt(2) * self._cell_len) diff --git a/Update_Scheme.py b/Update_Scheme.py index d1ed6857c579c729f1c8f687b158e958532f85c1..2f10cd2c832bfcb1550706c6a0f00c922c6437d1 100644 --- a/Update_Scheme.py +++ b/Update_Scheme.py @@ -76,9 +76,6 @@ class UpdateScheme(object): class SSPRK3(UpdateScheme): - def __init__(self, polynom_degree, num_grid_cells, detector, limiter): - super().__init__(polynom_degree, num_grid_cells, detector, limiter) - # Override method of superclass def _apply_stability_method(self, projection, cfl_number): original_projection = projection