diff --git a/Basis_Function.py b/Basis_Function.py index da720f3479947e091712f989a213c586fb241ec0..14315ad7341c96d5e5379955eaf542dc98972b76 100644 --- a/Basis_Function.py +++ b/Basis_Function.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- -""" +"""Module for polynomial basis. + @author: Laura C. Kühle """ +from functools import cache import numpy as np from sympy import Symbol, integrate -from functools import cache from projection_utils import calculate_approximate_solution @@ -24,9 +25,16 @@ class Basis: Array of basis. wavelet : ndarray Array of wavelet. - inv_mass: ndarray + inv_mass : ndarray Inverse mass matrix. - basis_projection: ndarray + basis_projection : Tuple[ndarray, ndarray] + Two arrays containing integrals of all basis vector + combinations evaluated on the left and right cell boundary, + respectively. + wavelet_projection : Tuple[ndarray, ndarray] + Two arrays containing integrals of all basis vector/ + wavelet vector combinations evaluated on the left and right cell + boundary, respectively. Methods @@ -35,8 +43,9 @@ class Basis: Calculate cell averages for a given projection. """ + def __init__(self, polynomial_degree): - """Initializes Vector. + """Initialize Basis. Parameters ---------- @@ -58,7 +67,7 @@ class Basis: return self._build_basis_vector(x) def _build_basis_vector(self, eval_point): - """Constructs basis vector. + """Construct basis vector. Parameters ---------- @@ -76,11 +85,11 @@ class Basis: @property @cache def wavelet(self): - """Return basis vector.""" + """Return wavelet vector.""" return self._build_wavelet_vector(z) def _build_wavelet_vector(self, eval_point): - """Constructs wavelet vector. + """Construct wavelet vector. Parameters ---------- @@ -102,7 +111,7 @@ class Basis: return self._build_inverse_mass_matrix() def _build_inverse_mass_matrix(self): - """Constructs inverse mass matrix. + """Construct inverse mass matrix. Returns ------- @@ -192,8 +201,9 @@ class Basis: class Legendre(Basis): """Class for Legendre basis.""" + def _build_basis_vector(self, eval_point): - """Constructs basis vector. + """Construct basis vector. Parameters ---------- @@ -209,7 +219,7 @@ class Legendre(Basis): return self._calculate_legendre_vector(eval_point) def _calculate_legendre_vector(self, eval_point): - """Constructs Legendre vector. + """Construct Legendre vector. Parameters ---------- @@ -239,8 +249,9 @@ class Legendre(Basis): class OrthonormalLegendre(Legendre): """Class for orthonormal Legendre basis.""" + def _build_basis_vector(self, eval_point): - """Constructs basis vector. + """Construct basis vector. Parameters ---------- @@ -258,7 +269,7 @@ class OrthonormalLegendre(Legendre): for degree in range(self._polynomial_degree+1)] def _build_wavelet_vector(self, eval_point): - """Constructs wavelet vector. + """Construct wavelet vector. Parameters ---------- @@ -323,6 +334,14 @@ class OrthonormalLegendre(Legendre): up to degree 4 for this application') def _build_inverse_mass_matrix(self): + """Construct inverse mass matrix. + + Returns + ------- + ndarray + Inverse mass matrix. + + """ mass_matrix = [] for i in range(self._polynomial_degree+1): new_row = [] @@ -337,21 +356,26 @@ class OrthonormalLegendre(Legendre): @property @cache def basis_projections(self): - """Returns basis projection. + """Return basis projection. + + Construct matrices containing the integrals of the + product of two basis vectors for every degree combination evaluated + at the left and right cell boundary. Returns ------- - ndarray - Array containing the basis projection based on the integrals of - the product of two basis vectors for each degree combination. + left_basis_projection : ndarray + Array containing the left basis projection. + right_basis_projection : ndarray + Array containing the right basis projection. """ - basis_projection_left = self._build_basis_matrix(z, 0.5 * (z - 1)) - basis_projection_right = self._build_basis_matrix(z, 0.5 * (z + 1)) - return basis_projection_left, basis_projection_right + left_basis_projection = self._build_basis_matrix(z, 0.5 * (z - 1)) + right_basis_projection = self._build_basis_matrix(z, 0.5 * (z + 1)) + return left_basis_projection, right_basis_projection def _build_basis_matrix(self, first_param, second_param): - """Constructs a basis matrix. + """Construct a basis matrix. Parameters ---------- @@ -380,25 +404,29 @@ class OrthonormalLegendre(Legendre): @property @cache def multiwavelet_projections(self): - """Returns wavelet projection. + """Return wavelet projection. + + Construct matrices containing the integrals of the + product of a basis vector and a wavelet vector for every degree + combination evaluated at the left and right cell boundary. Returns ------- - ndarray - Array containing the multiwavelet projection based on the integrals - of the product of a basis vector and a wavelet vector for each - degree combination. + left_wavelet_projection : ndarray + Array containing the left multiwavelet projection. + right_wavelet_projection : ndarray + Array containing the right multiwavelet projection. """ - wavelet_projection_left = self._build_multiwavelet_matrix( + left_wavelet_projection = self._build_multiwavelet_matrix( z, -0.5*(z-1), True) - wavelet_projection_right = self._build_multiwavelet_matrix( + right_wavelet_projection = self._build_multiwavelet_matrix( z, 0.5*(z+1), False) - return wavelet_projection_left, wavelet_projection_right + return left_wavelet_projection, right_wavelet_projection def _build_multiwavelet_matrix(self, first_param, second_param, is_left_matrix): - """Constructs a multiwavelet matrix. + """Construct a multiwavelet matrix. Parameters ---------- @@ -439,7 +467,7 @@ class OrthonormalLegendre(Legendre): Notes ----- - To increase speed. this function uses a simplified calculation + To increase speed, this function uses a simplified calculation specific to the orthonormal Legendre polynomial basis. Parameters @@ -459,7 +487,6 @@ class OrthonormalLegendre(Legendre): projection. """ - cell_averages = np.array([projection[0] / np.sqrt(2)]) if add_reconstructions: @@ -478,11 +505,6 @@ class OrthonormalLegendre(Legendre): def _calculate_reconstructions(self, projection): """Calculate left and right reconstructions for a given projection. - Notes - ----- - To increase speed. this function uses a simplified calculation - specific to the orthonormal Legendre polynomial basis. - Parameters ---------- projection : ndarray @@ -495,8 +517,12 @@ class OrthonormalLegendre(Legendre): right_reconstruction : list List containing right reconstructions for given projection. - """ + Notes + ----- + To increase speed. this function uses a simplified calculation + specific to the orthonormal Legendre polynomial basis. + """ left_reconstructions = [ sum(projection[degree][cell] * (-1)**degree * np.sqrt(degree + 0.5)