diff --git a/DG_Approximation.py b/DG_Approximation.py index 136445e4113a178e3e9c029359de9ce0ab597b6d..086c8b9034c6ad43a6063cbfee0f250014073c5e 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 02d65555e871d29610f92e9f4e0992e1fe40e1a5..38c7dc7de09e7c1e1d5faea94d7197a027b9613b 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 05ce75f6dd23291e3ed1b11c3702dcc90fd1ef9e..79c796476a8bb6845f0616e5146cd744c80f8a7a 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 f9974ca0ce5f6f0e54108b866c5cd85742d2a645..f6ace83c00376c8e012ade3708d48c35ccc82c95 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: