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

Hard-coded simplification of cell average and reconstruction calculations for OrthonormalLegendre.

parent 37b4bf22
No related branches found
No related tags found
No related merge requests found
...@@ -412,3 +412,82 @@ class OrthonormalLegendre(Legendre): ...@@ -412,3 +412,82 @@ class OrthonormalLegendre(Legendre):
row.append(np.float64(entry)) row.append(np.float64(entry))
matrix.append(row) matrix.append(row)
return matrix return matrix
def calculate_cell_average(self, projection, stencil_length,
add_reconstructions=True):
"""Calculate cell averages for a given projection.
Calculate the cell averages of all cells in a projection.
If desired, reconstructions are calculated for the middle cell
and added left and right to it, respectively.
Notes
-----
To increase speed. this function uses a simplified calculation
specific to the orthonormal Legendre polynomial basis.
Parameters
----------
projection : ndarray
Matrix of projection for each polynomial degree.
stencil_length : int
Size of data array.
add_reconstructions: bool, optional
Flag whether reconstructions of the middle cell are included.
Default: True.
Returns
-------
ndarray
Matrix containing cell averages (and reconstructions) for given
projection.
"""
cell_averages = np.array([projection[0] / np.sqrt(2)])
if add_reconstructions:
middle_idx = stencil_length // 2
left_reconstructions, right_reconstructions = \
self._calculate_reconstructions(
projection[:, middle_idx:middle_idx+1])
return np.array(list(map(
np.float64, zip(cell_averages[:, :middle_idx],
left_reconstructions,
cell_averages[:, middle_idx],
right_reconstructions,
cell_averages[:, middle_idx+1:]))))
return np.array(list(map(np.float64, cell_averages)))
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
Matrix of projection for each polynomial degree.
Returns
-------
left_reconstruction: list
List containing left reconstructions for given projection.
right_reconstruction: list
List containing right reconstructions for given projection.
"""
left_reconstructions = [
sum(projection[degree][cell] * (-1)**degree
* np.sqrt(degree + 0.5)
for degree in range(self._polynomial_degree+1))
for cell in range(len(projection[0]))]
right_reconstructions = [
sum(projection[degree][cell] * np.sqrt(degree + 0.5)
for degree in range(self._polynomial_degree+1))
for cell in range(len(projection[0]))]
return left_reconstructions, right_reconstructions
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment