Skip to content
Snippets Groups Projects
Commit 7b60bb58 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Improved docstring for Basis class.

parent 46b1f8f1
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """Module for polynomial basis.
@author: Laura C. Kühle @author: Laura C. Kühle
""" """
from functools import cache
import numpy as np import numpy as np
from sympy import Symbol, integrate from sympy import Symbol, integrate
from functools import cache
from projection_utils import calculate_approximate_solution from projection_utils import calculate_approximate_solution
...@@ -26,7 +27,14 @@ class Basis: ...@@ -26,7 +27,14 @@ class Basis:
Array of wavelet. Array of wavelet.
inv_mass : ndarray inv_mass : ndarray
Inverse mass matrix. 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 Methods
...@@ -35,8 +43,9 @@ class Basis: ...@@ -35,8 +43,9 @@ class Basis:
Calculate cell averages for a given projection. Calculate cell averages for a given projection.
""" """
def __init__(self, polynomial_degree): def __init__(self, polynomial_degree):
"""Initializes Vector. """Initialize Basis.
Parameters Parameters
---------- ----------
...@@ -58,7 +67,7 @@ class Basis: ...@@ -58,7 +67,7 @@ class Basis:
return self._build_basis_vector(x) return self._build_basis_vector(x)
def _build_basis_vector(self, eval_point): def _build_basis_vector(self, eval_point):
"""Constructs basis vector. """Construct basis vector.
Parameters Parameters
---------- ----------
...@@ -76,11 +85,11 @@ class Basis: ...@@ -76,11 +85,11 @@ class Basis:
@property @property
@cache @cache
def wavelet(self): def wavelet(self):
"""Return basis vector.""" """Return wavelet vector."""
return self._build_wavelet_vector(z) return self._build_wavelet_vector(z)
def _build_wavelet_vector(self, eval_point): def _build_wavelet_vector(self, eval_point):
"""Constructs wavelet vector. """Construct wavelet vector.
Parameters Parameters
---------- ----------
...@@ -102,7 +111,7 @@ class Basis: ...@@ -102,7 +111,7 @@ class Basis:
return self._build_inverse_mass_matrix() return self._build_inverse_mass_matrix()
def _build_inverse_mass_matrix(self): def _build_inverse_mass_matrix(self):
"""Constructs inverse mass matrix. """Construct inverse mass matrix.
Returns Returns
------- -------
...@@ -192,8 +201,9 @@ class Basis: ...@@ -192,8 +201,9 @@ class Basis:
class Legendre(Basis): class Legendre(Basis):
"""Class for Legendre basis.""" """Class for Legendre basis."""
def _build_basis_vector(self, eval_point): def _build_basis_vector(self, eval_point):
"""Constructs basis vector. """Construct basis vector.
Parameters Parameters
---------- ----------
...@@ -209,7 +219,7 @@ class Legendre(Basis): ...@@ -209,7 +219,7 @@ class Legendre(Basis):
return self._calculate_legendre_vector(eval_point) return self._calculate_legendre_vector(eval_point)
def _calculate_legendre_vector(self, eval_point): def _calculate_legendre_vector(self, eval_point):
"""Constructs Legendre vector. """Construct Legendre vector.
Parameters Parameters
---------- ----------
...@@ -239,8 +249,9 @@ class Legendre(Basis): ...@@ -239,8 +249,9 @@ class Legendre(Basis):
class OrthonormalLegendre(Legendre): class OrthonormalLegendre(Legendre):
"""Class for orthonormal Legendre basis.""" """Class for orthonormal Legendre basis."""
def _build_basis_vector(self, eval_point): def _build_basis_vector(self, eval_point):
"""Constructs basis vector. """Construct basis vector.
Parameters Parameters
---------- ----------
...@@ -258,7 +269,7 @@ class OrthonormalLegendre(Legendre): ...@@ -258,7 +269,7 @@ class OrthonormalLegendre(Legendre):
for degree in range(self._polynomial_degree+1)] for degree in range(self._polynomial_degree+1)]
def _build_wavelet_vector(self, eval_point): def _build_wavelet_vector(self, eval_point):
"""Constructs wavelet vector. """Construct wavelet vector.
Parameters Parameters
---------- ----------
...@@ -323,6 +334,14 @@ class OrthonormalLegendre(Legendre): ...@@ -323,6 +334,14 @@ class OrthonormalLegendre(Legendre):
up to degree 4 for this application') up to degree 4 for this application')
def _build_inverse_mass_matrix(self): def _build_inverse_mass_matrix(self):
"""Construct inverse mass matrix.
Returns
-------
ndarray
Inverse mass matrix.
"""
mass_matrix = [] mass_matrix = []
for i in range(self._polynomial_degree+1): for i in range(self._polynomial_degree+1):
new_row = [] new_row = []
...@@ -337,21 +356,26 @@ class OrthonormalLegendre(Legendre): ...@@ -337,21 +356,26 @@ class OrthonormalLegendre(Legendre):
@property @property
@cache @cache
def basis_projections(self): 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 Returns
------- -------
ndarray left_basis_projection : ndarray
Array containing the basis projection based on the integrals of Array containing the left basis projection.
the product of two basis vectors for each degree combination. right_basis_projection : ndarray
Array containing the right basis projection.
""" """
basis_projection_left = self._build_basis_matrix(z, 0.5 * (z - 1)) left_basis_projection = self._build_basis_matrix(z, 0.5 * (z - 1))
basis_projection_right = self._build_basis_matrix(z, 0.5 * (z + 1)) right_basis_projection = self._build_basis_matrix(z, 0.5 * (z + 1))
return basis_projection_left, basis_projection_right return left_basis_projection, right_basis_projection
def _build_basis_matrix(self, first_param, second_param): def _build_basis_matrix(self, first_param, second_param):
"""Constructs a basis matrix. """Construct a basis matrix.
Parameters Parameters
---------- ----------
...@@ -380,25 +404,29 @@ class OrthonormalLegendre(Legendre): ...@@ -380,25 +404,29 @@ class OrthonormalLegendre(Legendre):
@property @property
@cache @cache
def multiwavelet_projections(self): 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 Returns
------- -------
ndarray left_wavelet_projection : ndarray
Array containing the multiwavelet projection based on the integrals Array containing the left multiwavelet projection.
of the product of a basis vector and a wavelet vector for each right_wavelet_projection : ndarray
degree combination. 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) 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) 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, def _build_multiwavelet_matrix(self, first_param, second_param,
is_left_matrix): is_left_matrix):
"""Constructs a multiwavelet matrix. """Construct a multiwavelet matrix.
Parameters Parameters
---------- ----------
...@@ -439,7 +467,7 @@ class OrthonormalLegendre(Legendre): ...@@ -439,7 +467,7 @@ class OrthonormalLegendre(Legendre):
Notes 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. specific to the orthonormal Legendre polynomial basis.
Parameters Parameters
...@@ -459,7 +487,6 @@ class OrthonormalLegendre(Legendre): ...@@ -459,7 +487,6 @@ class OrthonormalLegendre(Legendre):
projection. projection.
""" """
cell_averages = np.array([projection[0] / np.sqrt(2)]) cell_averages = np.array([projection[0] / np.sqrt(2)])
if add_reconstructions: if add_reconstructions:
...@@ -478,11 +505,6 @@ class OrthonormalLegendre(Legendre): ...@@ -478,11 +505,6 @@ class OrthonormalLegendre(Legendre):
def _calculate_reconstructions(self, projection): def _calculate_reconstructions(self, projection):
"""Calculate left and right reconstructions for a given 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 Parameters
---------- ----------
projection : ndarray projection : ndarray
...@@ -495,8 +517,12 @@ class OrthonormalLegendre(Legendre): ...@@ -495,8 +517,12 @@ class OrthonormalLegendre(Legendre):
right_reconstruction : list right_reconstruction : list
List containing right reconstructions for given projection. 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 = [ left_reconstructions = [
sum(projection[degree][cell] * (-1)**degree sum(projection[degree][cell] * (-1)**degree
* np.sqrt(degree + 0.5) * np.sqrt(degree + 0.5)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment