diff --git a/Basis_Function.py b/Basis_Function.py index 5e69d31b0d896d1df9c6c612200b6b85fae3e363..32af0aa25177b9a86af6da0ee7dcd0887ff51a2f 100644 --- a/Basis_Function.py +++ b/Basis_Function.py @@ -4,6 +4,7 @@ @author: Laura C. Kühle """ +from abc import ABC, abstractmethod from functools import cache from typing import Tuple import numpy as np @@ -16,8 +17,8 @@ x = Symbol('x') z = Symbol('z') -class Basis: - """Class for polynomial basis. +class Basis(ABC): + """Abstract class for polynomial basis. Attributes ---------- @@ -33,7 +34,7 @@ class Basis: Two arrays containing integrals of all basis vector combinations evaluated on the left and right cell boundary, respectively. - wavelet_projection : Tuple[ndarray, ndarray] + multiwavelet_projection : Tuple[ndarray, ndarray] Two arrays containing integrals of all basis vector/ wavelet vector combinations evaluated on the left and right cell boundary, respectively. @@ -68,6 +69,7 @@ class Basis: """Return basis vector.""" return self._build_basis_vector(x) + @abstractmethod def _build_basis_vector(self, eval_point: float) -> ndarray: """Construct basis vector. @@ -90,6 +92,7 @@ class Basis: """Return wavelet vector.""" return self._build_wavelet_vector(z) + @abstractmethod def _build_wavelet_vector(self, eval_point: float) -> ndarray: """Construct wavelet vector. @@ -112,6 +115,7 @@ class Basis: """Return inverse mass matrix.""" return self._build_inverse_mass_matrix() + @abstractmethod def _build_inverse_mass_matrix(self) -> ndarray: """Construct inverse mass matrix. @@ -124,16 +128,18 @@ class Basis: pass @property + @abstractmethod @cache def basis_projection(self) -> Tuple[ndarray, ndarray]: """Return basis projection.""" - return np.array([]), np.array([]) + pass @property + @abstractmethod @cache - def wavelet_projection(self) -> Tuple[ndarray, ndarray]: + def multiwavelet_projection(self) -> Tuple[ndarray, ndarray]: """Return wavelet projection.""" - return np.array([]), np.array([]) + pass def calculate_cell_average(self, projection: ndarray, stencil_length: int, add_reconstructions: bool = True) -> ndarray: @@ -358,7 +364,7 @@ class OrthonormalLegendre(Legendre): @property @cache - def basis_projections(self) -> Tuple[ndarray, ndarray]: + def basis_projection(self) -> Tuple[ndarray, ndarray]: """Return basis projection. Construct matrices containing the integrals of the @@ -407,7 +413,7 @@ class OrthonormalLegendre(Legendre): @property @cache - def multiwavelet_projections(self) -> Tuple[ndarray, ndarray]: + def multiwavelet_projection(self) -> Tuple[ndarray, ndarray]: """Return wavelet projection. Construct matrices containing the integrals of the diff --git a/Initial_Condition.py b/Initial_Condition.py index cd06375818e94b6e27c270c2de50a232d4e38e02..1dd64208a290a47e6f95399bf51c957f27cc8b47 100644 --- a/Initial_Condition.py +++ b/Initial_Condition.py @@ -3,11 +3,12 @@ @author: Laura C. Kühle """ +from abc import ABC, abstractmethod import numpy as np -class InitialCondition: - """Class for initial condition function. +class InitialCondition(ABC): + """Abstract class for initial condition function. Attributes ---------- @@ -76,6 +77,7 @@ class InitialCondition: """ pass + @abstractmethod def randomize(self, config): """Sets all non-determined instance variables to random value. @@ -110,6 +112,7 @@ class InitialCondition: x -= self._interval_len return self._get_point(x) + @abstractmethod def _get_point(self, x): """Evaluates function at given x-value. diff --git a/Limiter.py b/Limiter.py index fbcc6aa9087c9a67ded90606258047c09a2f4711..8b797896e05c205e199c09c3dac0f0d51ad40fc1 100644 --- a/Limiter.py +++ b/Limiter.py @@ -3,10 +3,11 @@ @author: Laura C. Kühle """ +from abc import ABC, abstractmethod -class Limiter: - """Class for limiting function. +class Limiter(ABC): + """Abstract class for limiting function. Methods ------- @@ -27,6 +28,7 @@ class Limiter: """ self._reset(config) + @abstractmethod def _reset(self, config): """Resets instance variables. @@ -42,6 +44,7 @@ class Limiter: """Returns string of class name.""" return self.__class__.__name__ + @abstractmethod def apply(self, projection, cell): """Applies limiting to cell. diff --git a/Quadrature.py b/Quadrature.py index c790f9dce579d58116b423227a6e86f48c7e9418..05ce75f6dd23291e3ed1b11c3702dcc90fd1ef9e 100644 --- a/Quadrature.py +++ b/Quadrature.py @@ -3,11 +3,12 @@ @author: Laura C. Kühle """ +from abc import ABC import numpy.polynomial.legendre as leg -class Quadrature: - """Class for quadrature. +class Quadrature(ABC): + """Abstract class for quadrature. A quadrature is used to determine the approximation of a definite integral of a function. diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index f73caefbb94d8b8992ae1a01c9432f7c280f265b..237d00fa898046ebf82a9e097280b36506a268cc 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -8,14 +8,15 @@ TODO: Adjust Boxplot approach (adjacent cells, outer fence, etc.) TODO: Give detailed description of wavelet detection """ +from abc import ABC, abstractmethod import numpy as np import torch import ANN_Model -class TroubledCellDetector: - """Class for troubled-cell detection. +class TroubledCellDetector(ABC): + """Abstract class for troubled-cell detection. Detects troubled cells, i.e., cells in the mesh containing instabilities. @@ -94,6 +95,7 @@ class TroubledCellDetector: """Returns string of class name.""" return self.__class__.__name__ + @abstractmethod def get_cells(self, projection): """Calculates troubled cells in a given projection. @@ -227,7 +229,7 @@ class ArtificialNeuralNetwork(TroubledCellDetector): class WaveletDetector(TroubledCellDetector): - """Class for troubled-cell detection based on wavelet coefficients. + """Abstract class for wavelet coefficient based troubled-cell detection. ??? @@ -247,7 +249,7 @@ class WaveletDetector(TroubledCellDetector): # Set additional necessary parameter self._num_coarse_grid_cells = self._num_grid_cells//2 self._wavelet_projection_left, self._wavelet_projection_right \ - = self._basis.multiwavelet_projections + = self._basis.multiwavelet_projection def get_cells(self, projection): """Calculates troubled cells in a given projection. @@ -289,6 +291,7 @@ class WaveletDetector(TroubledCellDetector): output_matrix.append(new_entry) return np.transpose(np.array(output_matrix)) + @abstractmethod def _get_cells(self, multiwavelet_coeffs, projection): """Calculates troubled cells using multiwavelet coefficients. @@ -305,7 +308,7 @@ class WaveletDetector(TroubledCellDetector): List of indices for all detected troubled cells. """ - return [] + pass def _calculate_coarse_projection(self, projection): """Calculates coarse projection. @@ -322,7 +325,7 @@ class WaveletDetector(TroubledCellDetector): """ basis_projection_left, basis_projection_right\ - = self._basis.basis_projections + = self._basis.basis_projection # Remove ghost cells projection = projection[:, 1:-1] diff --git a/Update_Scheme.py b/Update_Scheme.py index c44aaf55a4f5da1bdfbfa81eaeef28d45d0f1514..33738af56239c144919e3343a598abb8c94965db 100644 --- a/Update_Scheme.py +++ b/Update_Scheme.py @@ -7,12 +7,13 @@ TODO: Discuss descriptions (matrices, cfl number, right-hand side, TODO: Discuss referencing info on SSPRK3 """ +from abc import ABC, abstractmethod import numpy as np import time -class UpdateScheme: - """Class for updating projections at a time step. +class UpdateScheme(ABC): + """Abstract class for updating projections at a time step. Attributes ---------- @@ -106,6 +107,7 @@ class UpdateScheme: return current_projection, troubled_cells + @abstractmethod def _apply_stability_method(self, projection, cfl_number): """Applies stability method. @@ -125,7 +127,7 @@ class UpdateScheme: List of indices for all detected troubled cells. """ - return projection, [] + pass def _apply_limiter(self, current_projection): """Applies limiter on troubled cells.