From be2f2fa798d2513abb6f470f7906c466a54e4d5d 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: Fri, 3 Jun 2022 16:06:19 +0200 Subject: [PATCH] Replaced getter with property attributes for quadrature. --- DG_Approximation.py | 13 ++++++++----- Plotting.py | 4 ++-- Quadrature.py | 38 ++++++++++++++++---------------------- projection_utils.py | 2 +- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/DG_Approximation.py b/DG_Approximation.py index 136445e..086c8b9 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -11,9 +11,12 @@ TODO: Contemplate containing the quadrature application for plots in Mesh TODO: Contemplate containing coarse mesh generation in Mesh TODO: Contemplate extracting boundary condition from InitialCondition TODO: Contemplate containing boundary condition in Mesh +TODO: Ask whether all quadratures depend on freely chosen num_nodes Urgent: -TODO: Replace getter with property attributes for quadrature +TODO: Replace getter with property attributes for quadrature -> Done +TODO: Rename eval_points in Quadrature to nodes +TODO: Make num_nodes quadrature argument TODO: Remove use of DGScheme from ANN_Data_Generator TODO: Find error in centering for ANN training TODO: Adapt TCD from Soraya @@ -356,11 +359,11 @@ def do_initial_projection(initial_condition, mesh, basis, quadrature, for degree in range(basis.polynomial_degree + 1): new_row.append(np.float64(sum(initial_condition.calculate( mesh, eval_point + mesh.cell_len/2 - * quadrature.get_eval_points()[point] - adjustment) + * quadrature.eval_points[point] - adjustment) * basis.basis[degree].subs( - x, quadrature.get_eval_points()[point]) - * quadrature.get_weights()[point] - for point in range(quadrature.get_num_points())))) + x, quadrature.eval_points[point]) + * quadrature.weights[point] + for point in range(quadrature.num_points)))) new_row = np.array(new_row) output_matrix.append(basis.inverse_mass_matrix @ new_row) diff --git a/Plotting.py b/Plotting.py index 02d6555..38c7dc7 100644 --- a/Plotting.py +++ b/Plotting.py @@ -421,7 +421,7 @@ def plot_results(projection: ndarray, troubled_cell_history: list, grid, exact = calculate_exact_solution( mesh, wave_speed, final_time, quadrature, init_cond) approx = calculate_approximate_solution( - projection[:, 1:-1], quadrature.get_eval_points(), + projection[:, 1:-1], quadrature.eval_points, basis.polynomial_degree, basis.basis) # Plot multiwavelet solution (fine and coarse grid) @@ -434,7 +434,7 @@ def plot_results(projection: ndarray, troubled_cell_history: list, coarse_grid, coarse_exact = calculate_exact_solution( coarse_mesh, wave_speed, final_time, quadrature, init_cond) coarse_approx = calculate_approximate_solution( - coarse_projection, quadrature.get_eval_points(), + coarse_projection, quadrature.eval_points, basis.polynomial_degree, basis.basis) plot_solution_and_approx( coarse_grid, coarse_exact, coarse_approx, colors['coarse_exact'], diff --git a/Quadrature.py b/Quadrature.py index 05ce75f..79c7964 100644 --- a/Quadrature.py +++ b/Quadrature.py @@ -4,6 +4,7 @@ """ from abc import ABC +from numpy import ndarray import numpy.polynomial.legendre as leg @@ -15,6 +16,8 @@ class Quadrature(ABC): Attributes ---------- + name : str + String of class name. num_eval_points : int Number of evaluation points per cell used for approximation. eval_points : ndarray @@ -22,17 +25,6 @@ class Quadrature(ABC): weights : ndarray Weights used for approximation calculation. - Methods - ------- - get_name() - Returns string of class name. - get_num_points() - Returns number of evaluation points. - get_eval_points() - Returns evaluation points. - get_weights() - Returns evaluation weights. - """ def __init__(self, config): """Initializes Quadrature. @@ -58,19 +50,23 @@ class Quadrature(ABC): self._eval_points = None self._weights = None - def get_name(self): - """Returns string of class name.""" + @property + def name(self) -> str: + """Return string of class name.""" return self.__class__.__name__ - def get_num_points(self): + @property + def num_points(self) -> int: """Returns number of evaluation points.""" return self._num_eval_points - def get_eval_points(self): + @property + def eval_points(self) -> ndarray: """Returns evaluation points.""" return self._eval_points - def get_weights(self): + @property + def weights(self) -> ndarray: """Returns evaluation weights.""" return self._weights @@ -80,6 +76,8 @@ class Gauss(Quadrature): Attributes ---------- + name : str + String of class name. num_eval_points : int Number of evaluation points per cell used for approximation. eval_points : ndarray @@ -87,11 +85,6 @@ class Gauss(Quadrature): weights : ndarray Weights used for approximation calculation. - Methods - ------- - get_name() - Returns string of class name. - """ def _reset(self, config): """Resets instance variables. @@ -109,6 +102,7 @@ class Gauss(Quadrature): self._eval_points, self._weights = leg.leggauss(self._num_eval_points) - def get_name(self): + @property + def name(self): """Returns string of class name.""" return self.__class__.__name__ + str(self._num_eval_points) diff --git a/projection_utils.py b/projection_utils.py index f9974ca..f6ace83 100644 --- a/projection_utils.py +++ b/projection_utils.py @@ -170,7 +170,7 @@ def calculate_exact_solution( for cell_center in mesh.non_ghost_cells: eval_points = cell_center+mesh.cell_len / 2 * \ - quadrature.get_eval_points() + quadrature.eval_points eval_values = [] for eval_point in eval_points: -- GitLab