diff --git a/DG_Approximation.py b/DG_Approximation.py index fd33f4c91589eda2a88553836ff1cafc4f96caa7..63a9cbd6c693c80462584f1bed491ba4ea6cf67b 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 a5a3f1a1f73e0881bdb665f21ab6b311a52c23f7..e7bd2a2c2b13e0a1a3f3eef8dff6e59e7a016b15 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 66b932e9c3b2d2207e71236627ad5af363dc9f11..d7c5119a1b87e2f9c4bbbfb8392b85d23733b0b8 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 e1ac2a0b0402d6ac357ab3d2f42e54eb39b50597..24d9a8b4213c9b459ae32d4c9430397d94d0da72 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 0b6f0b6922d805b69c1dc2f8ced74b4156546946..6bfd9b34da1c67949aa4336ea94a7bdeebf7de8a 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)