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

Improved use of 'self.__init__()'

parent 0e079c4c
Branches
No related tags found
No related merge requests found
...@@ -10,6 +10,10 @@ class InitialCondition(object): ...@@ -10,6 +10,10 @@ class InitialCondition(object):
def __init__(self, left_bound, right_bound, config): def __init__(self, left_bound, right_bound, config):
self._left_bound = left_bound self._left_bound = left_bound
self._right_bound = right_bound self._right_bound = right_bound
self._reset(config)
def _reset(self, config):
self._interval_len = self._right_bound-self._left_bound self._interval_len = self._right_bound-self._left_bound
def get_name(self): def get_name(self):
...@@ -27,8 +31,8 @@ class InitialCondition(object): ...@@ -27,8 +31,8 @@ class InitialCondition(object):
class Sine(InitialCondition): class Sine(InitialCondition):
def __init__(self, left_bound, right_bound, config): def _reset(self, config):
super().__init__(left_bound, right_bound, config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._factor = config.pop('factor', 2) self._factor = config.pop('factor', 2)
...@@ -38,9 +42,6 @@ class Sine(InitialCondition): ...@@ -38,9 +42,6 @@ class Sine(InitialCondition):
class Box(InitialCondition): class Box(InitialCondition):
def __init__(self, left_bound, right_bound, config):
super().__init__(left_bound, right_bound, config)
def _get_point(self, x): def _get_point(self, x):
if x < -1: if x < -1:
x = x + 2 x = x + 2
...@@ -53,8 +54,8 @@ class Box(InitialCondition): ...@@ -53,8 +54,8 @@ class Box(InitialCondition):
class FourPeakWave(InitialCondition): class FourPeakWave(InitialCondition):
def __init__(self, left_bound, right_bound, config): def _reset(self, config):
super().__init__(left_bound, right_bound, config) super()._reset(config)
# Set additional necessary parameter # Set additional necessary parameter
self._alpha = 10 self._alpha = 10
...@@ -82,8 +83,8 @@ class FourPeakWave(InitialCondition): ...@@ -82,8 +83,8 @@ class FourPeakWave(InitialCondition):
class Linear(InitialCondition): class Linear(InitialCondition):
def __init__(self, left_bound, right_bound, config): def _reset(self, config):
super().__init__(left_bound, right_bound, config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._factor = config.pop('factor', 1) self._factor = config.pop('factor', 1)
...@@ -93,8 +94,8 @@ class Linear(InitialCondition): ...@@ -93,8 +94,8 @@ class Linear(InitialCondition):
class LinearAbsolut(InitialCondition): class LinearAbsolut(InitialCondition):
def __init__(self, left_bound, right_bound, config): def _reset(self, config):
super().__init__(left_bound, right_bound, config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._factor = config.pop('factor', 1) self._factor = config.pop('factor', 1)
...@@ -104,8 +105,8 @@ class LinearAbsolut(InitialCondition): ...@@ -104,8 +105,8 @@ class LinearAbsolut(InitialCondition):
class DiscontinuousConstant(InitialCondition): class DiscontinuousConstant(InitialCondition):
def __init__(self, left_bound, right_bound, config): def _reset(self, config):
super().__init__(left_bound, right_bound, config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._x0 = config.pop('x0', 0) self._x0 = config.pop('x0', 0)
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
class Limiter(object): class Limiter(object):
def __init__(self, config): def __init__(self, config):
self._reset(config)
def _reset(self, config):
pass pass
def get_name(self): def get_name(self):
...@@ -17,17 +20,12 @@ class Limiter(object): ...@@ -17,17 +20,12 @@ class Limiter(object):
class NoLimiter(Limiter): class NoLimiter(Limiter):
def __init__(self, config):
super().__init__(config)
def apply(self, projection, cell): def apply(self, projection, cell):
return projection[:, cell] return projection[:, cell]
class MinMod(Limiter): class MinMod(Limiter):
def __init__(self, config): def _reset(self, config):
super().__init__(config)
# Unpack necessary configurations # Unpack necessary configurations
self._erase_degree = config.pop('erase_degree', 0) self._erase_degree = config.pop('erase_degree', 0)
...@@ -65,8 +63,8 @@ class MinMod(Limiter): ...@@ -65,8 +63,8 @@ class MinMod(Limiter):
class ModifiedMinMod(MinMod): class ModifiedMinMod(MinMod):
def __init__(self, config): def _reset(self, config):
super().__init__(config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._cell_len = config.pop('cell_len') self._cell_len = config.pop('cell_len')
......
...@@ -8,6 +8,9 @@ import numpy.polynomial.legendre as leg ...@@ -8,6 +8,9 @@ import numpy.polynomial.legendre as leg
class Quadrature(object): class Quadrature(object):
def __init__(self, config): def __init__(self, config):
self._reset(config)
def _reset(self, config):
self._eval_points = None self._eval_points = None
self._weights = None self._weights = None
self._num_eval_points = None self._num_eval_points = None
...@@ -26,8 +29,8 @@ class Quadrature(object): ...@@ -26,8 +29,8 @@ class Quadrature(object):
class Gauss(Quadrature): class Gauss(Quadrature):
def __init__(self, config): def _reset(self, config):
super().__init__(config) super()._reset(config)
# Unpack necessary configurations # Unpack necessary configurations
self._num_eval_points = config.pop('num_eval_points', 6) self._num_eval_points = config.pop('num_eval_points', 6)
......
...@@ -32,6 +32,11 @@ class TroubledCellDetector(object): ...@@ -32,6 +32,11 @@ class TroubledCellDetector(object):
self._init_cond = init_cond self._init_cond = init_cond
self._quadrature = quadrature self._quadrature = quadrature
self._reset(config)
def _reset(self, config):
pass
def get_name(self): def get_name(self):
return self.__class__.__name__ return self.__class__.__name__
...@@ -133,21 +138,12 @@ class TroubledCellDetector(object): ...@@ -133,21 +138,12 @@ class TroubledCellDetector(object):
class NoDetection(TroubledCellDetector): 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): def get_cells(self, projection):
return [] return []
class WaveletDetector(TroubledCellDetector): class WaveletDetector(TroubledCellDetector):
def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, def _reset(self, config):
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)
# Set fixed basis and wavelet vectors # Set fixed basis and wavelet vectors
self._basis = OrthonormalLegendre(self._polynom_degree).get_vector(x) self._basis = OrthonormalLegendre(self._polynom_degree).get_vector(x)
self._wavelet = AlpertsWavelet(self._polynom_degree).get_vector(x) self._wavelet = AlpertsWavelet(self._polynom_degree).get_vector(x)
...@@ -306,10 +302,8 @@ class WaveletDetector(TroubledCellDetector): ...@@ -306,10 +302,8 @@ class WaveletDetector(TroubledCellDetector):
class Boxplot(WaveletDetector): class Boxplot(WaveletDetector):
def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, def _reset(self, config):
basis, init_cond, quadrature): super()._reset(config)
super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound,
basis, init_cond, quadrature)
# Unpack necessary configurations # Unpack necessary configurations
self._fold_len = config.pop('fold_len', 16) self._fold_len = config.pop('fold_len', 16)
...@@ -356,10 +350,8 @@ class Boxplot(WaveletDetector): ...@@ -356,10 +350,8 @@ class Boxplot(WaveletDetector):
class Theoretical(WaveletDetector): class Theoretical(WaveletDetector):
def __init__(self, config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound, def _reset(self, config):
basis, init_cond, quadrature): super()._reset(config)
super().__init__(config, mesh, wave_speed, polynom_degree, num_grid_cells, final_time, left_bound, right_bound,
basis, init_cond, quadrature)
# Unpack necessary configurations # Unpack necessary configurations
self._cutoff_factor = config.pop('cutoff_factor', np.sqrt(2) * self._cell_len) self._cutoff_factor = config.pop('cutoff_factor', np.sqrt(2) * self._cell_len)
......
...@@ -76,9 +76,6 @@ class UpdateScheme(object): ...@@ -76,9 +76,6 @@ class UpdateScheme(object):
class SSPRK3(UpdateScheme): 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 # Override method of superclass
def _apply_stability_method(self, projection, cfl_number): def _apply_stability_method(self, projection, cfl_number):
original_projection = projection original_projection = projection
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment