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

Added derivative basis to Basis class.

parent 749be65c
Branches
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ TODO: ASk whether cfl number should be absolute value
Urgent:
TODO: Add Burgers class completely
TODO: Add 'update_time_step()' to Burgers -> Done
TODO: Add derivative basis to Basis class -> Done
TODO: Add 'solve_exactly()' to Burgers
TODO: Add 'update_right_hand_side()' to Burgers
TODO: Add initialization to Burgers
......
......@@ -28,6 +28,8 @@ class Basis(ABC):
Array of basis.
wavelet : ndarray
Array of wavelet.
derivative: ndarray
Array of derivative basis.
inv_mass : ndarray
Inverse mass matrix.
basis_projection : Tuple[ndarray, ndarray]
......@@ -111,6 +113,29 @@ class Basis(ABC):
"""
pass
@property
@cache
def derivative(self) -> ndarray:
"""Return derivative basis vector."""
return self._build_derivative_vector(x)
@abstractmethod
def _build_derivative_vector(self, eval_point: float) -> ndarray:
"""Construct derivative basis vector.
Parameters
----------
eval_point : float
Evaluation point.
Returns
-------
ndarray
Vector containing derivative basis evaluated at evaluation point.
"""
pass
@property
@cache
def inverse_mass_matrix(self) -> ndarray:
......@@ -261,6 +286,55 @@ class Legendre(Basis):
vector.append(poly)
return np.array(vector)
def _build_derivative_vector(self, eval_point: float) -> ndarray:
"""Construct derivative basis vector.
Parameters
----------
eval_point : float
Evaluation point.
Returns
-------
ndarray
Vector containing derivative basis evaluated at evaluation point.
"""
return self._calculate_derivative_legendre_vector(eval_point)
def _calculate_derivative_legendre_vector(self,
eval_point: float) -> ndarray:
"""Construct derivative Legendre vector.
Parameters
----------
eval_point : float
Evaluation point.
Returns
-------
ndarray
Vector containing derivative Legendre polynomial evaluated at
evaluation point.
"""
derivative_vector = []
leg_vector = self._calculate_legendre_vector(eval_point)
for degree in range(self._polynomial_degree+1):
if degree == 0:
derivative_vector.append(0 * eval_point)
else:
if degree == 1:
derivative_vector.append(1.0+0 * eval_point)
else:
poly = ((2.0 * degree-1) / degree) * (
leg_vector[degree-1]+(
eval_point * derivative_vector[-1]))-(
(degree-1) / degree) * \
derivative_vector[-2]
derivative_vector.append(poly)
return np.array(derivative_vector)
class OrthonormalLegendre(Legendre):
"""Class for orthonormal Legendre basis."""
......@@ -348,6 +422,26 @@ class OrthonormalLegendre(Legendre):
raise ValueError('Invalid value: Alpert\'s wavelet is only available \
up to degree 4 for this application')
def _build_derivative_basis_vector(self, eval_point):
"""Construct derivative basis vector.
Parameters
----------
eval_point : float
Evaluation point.
Returns
-------
ndarray
Vector containing derivative Legendre polynomial evaluated at
evaluation point.
"""
derivative_leg_vector = self._calculate_derivative_legendre_vector(
eval_point)
return np.array([derivative_leg_vector[degree] * np.sqrt(degree+0.5)
for degree in range(self._polynomial_degree+1)])
def _build_inverse_mass_matrix(self) -> ndarray:
"""Construct inverse mass matrix.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment