From 7e8e60ec37ed7e837984ae60a50492370721641d Mon Sep 17 00:00:00 2001 From: lakue103 <laura.kuehle@uni-duesseldorf.de> Date: Wed, 7 Oct 2020 13:04:14 +0200 Subject: [PATCH] Implemented argument check for unpacking of configs. --- DG_Approximation.py | 4 ++-- Initial_Condition.py | 5 +++++ Limiter.py | 12 +++++++----- Main.py | 2 +- Quadrature.py | 2 ++ Troubled_Cell_Detector.py | 7 ++++--- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/DG_Approximation.py b/DG_Approximation.py index f0777e5..b785c93 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -9,7 +9,7 @@ TODO: Double-check everything! TODO: Replace loops with list comprehension if feasible TODO: Combine initial projection and approx solution somehow TODO: Investigate why there are no weights in approx calc -TODO: Implement argument check for unpacking of all configs +TODO: Implement argument check for unpacking of all configs -> Done TODO: Change order of methods -> Done for Stability_Method TODO: Change code to not include self. but global variables; NO, do private \ or better protected instance variables instead @@ -95,7 +95,7 @@ class DGScheme(object): self.num_grid_cells, self.final_time, self.history_threshold, self.left_bound, self.right_bound) - + # print(self.detector.get_name()) # print(self.detector.__class__.__name__) # print(Troubled_Cell_Detector.Boxplot.__bases__) diff --git a/Initial_Condition.py b/Initial_Condition.py index 305268a..04c80c8 100644 --- a/Initial_Condition.py +++ b/Initial_Condition.py @@ -35,6 +35,7 @@ class Sine(InitialCondition): # Set name of function self.function_name = 'Sine' + # Unpack necessary configurations self.factor = config.pop('factor', 2) def _get_point(self, x): @@ -66,6 +67,7 @@ class FourPeakWave(InitialCondition): # Set name of function self.function_name = 'FourPeakWave' + # Set additional necessary parameter self.alpha = 10 self.delta = 0.005 self.beta = np.log(2) / (36 * self.delta**2) @@ -97,6 +99,7 @@ class Linear(InitialCondition): # Set name of function self.function_name = 'Linear' + # Unpack necessary configurations self.factor = config.pop('factor', 1) def _get_point(self, x): @@ -110,6 +113,7 @@ class LinearAbsolut(InitialCondition): # Set name of function self.function_name = 'LinearAbsolut' + # Unpack necessary configurations self.factor = config.pop('factor', 1) def _get_point(self, x): @@ -123,6 +127,7 @@ class DiscontinuousConstant(InitialCondition): # Set name of function self.function_name = 'DiscontinuousConstant' + # Unpack necessary configurations self.x0 = config.pop('x0', 0) self.left_factor = config.pop('left_factor', 1) self.right_factor = config.pop('right_factor', 0.5) diff --git a/Limiter.py b/Limiter.py index ba801aa..8cf1501 100644 --- a/Limiter.py +++ b/Limiter.py @@ -18,6 +18,8 @@ class Limiter(object): class NoLimiter(Limiter): def __init__(self, config): + super().__init__(config) + # Set name of function self.function_name = 'NoLimiter' @@ -27,15 +29,14 @@ class NoLimiter(Limiter): class MinMod(Limiter): def __init__(self, config): - # Unpack necessary parameter + super().__init__(config) + + # Unpack necessary configurations self.erase_degree = config.pop('erase_degree', 0) # Set name of function self.function_name = 'MinMod' + str(self.erase_degree) - # Pop unnecessary parameter - config.pop('cell_len') - self.cell = 0 def apply(self, projection, cell): @@ -69,9 +70,10 @@ class MinMod(Limiter): class ModifiedMinMod(MinMod): def __init__(self, config): + super().__init__(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 diff --git a/Main.py b/Main.py index d8bca08..9af8923 100644 --- a/Main.py +++ b/Main.py @@ -32,7 +32,7 @@ init_config['left_factor'] = 3 limiter_config = {} limiter_config['mod_factor'] = 0 -limiter_config['erase_factor'] = 1 +limiter_config['erase_degree'] = 0 quadrature_config = {} quadrature_config['num_eval_points'] = 12 # 12 diff --git a/Quadrature.py b/Quadrature.py index 36f1911..f7c6b19 100644 --- a/Quadrature.py +++ b/Quadrature.py @@ -28,6 +28,8 @@ class Quadrature(object): class Gauss(Quadrature): def __init__(self, config): + super().__init__(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 5b7a08a..9953b7f 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -28,6 +28,8 @@ class TroubledCellDetector(object): class NoDetection(TroubledCellDetector): def __init__(self, config): + super().__init__(config) + # Set name of function self.function_name = 'NoDetection' @@ -37,6 +39,8 @@ class NoDetection(TroubledCellDetector): class WaveletDetector(TroubledCellDetector): def __init__(self, config): + super().__init__(config) + # Unpack necessary configurations self.polynom_degree = config.pop('polynom_degree') self.num_coarse_grid_cells = config.pop('num_grid_cells')//2 @@ -88,9 +92,6 @@ class Boxplot(WaveletDetector): self.fold_len = config.pop('fold_len', 16) self.whisker_len = config.pop('whisker_len', 3) - # Pop unnecessary parameter - config.pop('cell_len') - def _get_cells(self, multiwavelet_coeffs, projection): indexed_coeffs = [[multiwavelet_coeffs[0, i], i]for i in range(self.num_coarse_grid_cells)] -- GitLab