From 61e02bff3052e6e6687db9a20de40b0655e4dfbb 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: Thu, 2 Jun 2022 21:05:08 +0200 Subject: [PATCH] Contained interval length in mesh. --- DG_Approximation.py | 9 +-------- Initial_Condition.py | 5 ++--- Plotting.py | 14 ++++---------- Troubled_Cell_Detector.py | 7 ------- projection_utils.py | 10 ++++------ 5 files changed, 11 insertions(+), 34 deletions(-) diff --git a/DG_Approximation.py b/DG_Approximation.py index fd33f4c..63a9cbd 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -15,7 +15,7 @@ Urgent: TODO: Put basis initialization for plots in function -> Done TODO: Contain cell length in mesh -> Done TODO: Contain bounds in mesh -> Done -TODO: Contain interval length in mesh +TODO: Contain interval length in mesh -> Done TODO: Contain number of grid cells in mesh TODO: Create data dict for mesh separately TODO: Create data dict for basis separately @@ -96,14 +96,10 @@ class DGScheme: Attributes ---------- - interval_len : float - Length of the interval between left and right boundary. basis : Basis object Basis for calculation. mesh : Mesh Mesh for calculation. - inv_mass : ndarray - Inverse mass matrix. Methods ------- @@ -192,9 +188,6 @@ class DGScheme: print(len(self._mesh.cells)) print(type(self._mesh.cells)) - # Set additional necessary instance variables - self._interval_len = right_bound-left_bound - # Throw an error if there are extra keyword arguments if len(kwargs) > 0: extra = ', '.join('"%s"' % k for k in list(kwargs.keys())) diff --git a/Initial_Condition.py b/Initial_Condition.py index a5a3f1a..e7bd2a2 100644 --- a/Initial_Condition.py +++ b/Initial_Condition.py @@ -97,11 +97,10 @@ class InitialCondition(ABC): """ left_bound, right_bound = mesh.bounds - interval_len = right_bound-left_bound while x < left_bound: - x += interval_len + x += mesh.interval_len while x > right_bound: - x -= interval_len + x -= mesh.interval_len return self._get_point(x) @abstractmethod diff --git a/Plotting.py b/Plotting.py index 66b932e..d7c5119 100644 --- a/Plotting.py +++ b/Plotting.py @@ -418,17 +418,12 @@ def plot_results(projection: ndarray, troubled_cell_history: list, colors = {} colors = _check_colors(colors) - # Calculate needed variables - left_bound, right_bound = mesh.bounds - interval_len = right_bound-left_bound - # Plot troubled cells plot_shock_tube(num_grid_cells, troubled_cell_history, time_history) # Determine exact and approximate solution grid, exact = calculate_exact_solution( - mesh, wave_speed, final_time, interval_len, quadrature, - init_cond) + mesh, wave_speed, final_time, quadrature, init_cond) approx = calculate_approximate_solution( projection[:, 1:-1], quadrature.get_eval_points(), basis.polynomial_degree, basis.basis) @@ -436,13 +431,12 @@ def plot_results(projection: ndarray, troubled_cell_history: list, # Plot multiwavelet solution (fine and coarse grid) if coarse_projection is not None: coarse_mesh = Mesh(num_grid_cells=num_grid_cells//2, - num_ghost_cells=1, left_bound=left_bound, - right_bound=right_bound) + num_ghost_cells=1, left_bound=mesh.bounds[0], + right_bound=mesh.bounds[1]) # Plot exact and approximate solutions for coarse mesh coarse_grid, coarse_exact = calculate_exact_solution( - coarse_mesh, wave_speed, final_time, interval_len, quadrature, - init_cond) + coarse_mesh, wave_speed, final_time, quadrature, init_cond) coarse_approx = calculate_approximate_solution( coarse_projection, quadrature.get_eval_points(), basis.polynomial_degree, basis.basis) diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index e1ac2a0..24d9a8b 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -21,11 +21,6 @@ class TroubledCellDetector(ABC): Detects troubled cells, i.e., cells in the mesh containing instabilities. - Attributes - ---------- - interval_len : float - Length of the interval between left and right boundary. - Methods ------- get_name() @@ -62,8 +57,6 @@ class TroubledCellDetector(ABC): self._wave_speed = wave_speed self._num_grid_cells = num_grid_cells self._final_time = final_time - left_bound, right_bound = mesh.bounds - self._interval_len = right_bound - left_bound self._basis = basis self._init_cond = init_cond self._quadrature = quadrature diff --git a/projection_utils.py b/projection_utils.py index 0b6f0b6..6bfd9b3 100644 --- a/projection_utils.py +++ b/projection_utils.py @@ -132,8 +132,8 @@ def calculate_approximate_solution( def calculate_exact_solution( mesh: Mesh, wave_speed: float, final_time: - float, interval_len: float, quadrature: Quadrature, init_cond: - InitialCondition) -> Tuple[ndarray, ndarray]: + float, quadrature: Quadrature, + init_cond: InitialCondition) -> Tuple[ndarray, ndarray]: """Calculate exact solution. Parameters @@ -144,8 +144,6 @@ def calculate_exact_solution( Speed of wave in rightward direction. final_time : float Final time for which approximation is calculated. - interval_len : float - Length of the interval between left and right boundary. quadrature : Quadrature object Quadrature for evaluation. init_cond : InitialCondition object @@ -161,7 +159,7 @@ def calculate_exact_solution( """ grid = [] exact = [] - num_periods = np.floor(wave_speed * final_time / interval_len) + num_periods = np.floor(wave_speed * final_time / mesh.interval_len) for cell_center in mesh.non_ghost_cells: eval_points = cell_center+mesh.cell_len / 2 * \ @@ -171,7 +169,7 @@ def calculate_exact_solution( for eval_point in eval_points: new_entry = init_cond.calculate(mesh, eval_point - wave_speed * final_time - + num_periods * interval_len) + + num_periods * mesh.interval_len) eval_values.append(new_entry) grid.append(eval_points) -- GitLab