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

Improved 'calculate_cell_average()'.

parent 0cbaa977
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ Urgent:
TODO: Extract do_initial_projection() from DGScheme -> Done
TODO: Move inverse mass matrix to basis -> Done
TODO: Extract calculate_cell_average() from TCD -> Done
TODO: Improve calculate_cell_average()
TODO: Improve calculate_cell_average() -> Done
TODO: Extract calculate_[...]_solution() from Plotting
TODO: Extract plotting from TCD completely
(maybe give indicator which plots are required instead?)
......@@ -334,8 +334,8 @@ class DGScheme:
return calculate_cell_average(
projection=projection[:, 1:-1], stencil_length=stencil_length,
polynomial_degree=self._polynomial_degree, basis=self._basis,
add_reconstructions=add_reconstructions)
polynomial_degree=self._polynomial_degree if add_reconstructions
else -1, basis=self._basis)
def do_initial_projection(initial_condition, basis, quadrature,
......
......@@ -292,8 +292,8 @@ class ArtificialNeuralNetwork(TroubledCellDetector):
projection=projection[
:, cell-num_ghost_cells:cell+num_ghost_cells+1],
stencil_length=self._stencil_len, basis=self._basis,
polynomial_degree=self._polynomial_degree,
add_reconstructions=self._add_reconstructions)
polynomial_degree=self._polynomial_degree if
self._add_reconstructions else -1)
for cell in range(num_ghost_cells,
len(projection[0])-num_ghost_cells)]))
......
......@@ -9,8 +9,8 @@ from Plotting import calculate_approximate_solution
def calculate_cell_average(projection, basis, stencil_length,
polynomial_degree, add_reconstructions=True):
"""Calculates cell averages for a given projection.
polynomial_degree=-1):
"""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
......@@ -24,11 +24,9 @@ def calculate_cell_average(projection, basis, stencil_length,
Basis for calculation.
stencil_length : int
Size of data array.
polynomial_degree : int
Polynomial degree.
add_reconstructions: bool, optional
Flag whether reconstructions of the middle cell are included.
Default: True.
polynomial_degree : int, optional
Polynomial degree for reconstructions of the middle cell. If -1 no
reconstructions will be included. Default: -1.
Returns
-------
......@@ -37,19 +35,18 @@ def calculate_cell_average(projection, basis, stencil_length,
projection.
"""
basis_vector = basis.get_basis_vector()
cell_averages = calculate_approximate_solution(
projection, [0], 0, basis.get_basis_vector())
projection, np.array([0]), 0, basis_vector)
if add_reconstructions:
if polynomial_degree != -1:
left_reconstructions = calculate_approximate_solution(
projection, [-1], polynomial_degree,
basis.get_basis_vector())
projection, np.array([-1]), polynomial_degree, basis_vector)
right_reconstructions = calculate_approximate_solution(
projection, [1], polynomial_degree,
basis.get_basis_vector())
projection, np.array([1]), polynomial_degree, basis_vector)
middle_idx = stencil_length // 2
return np.array(
list(map(np.float64, zip(cell_averages[:, :middle_idx],
return np.array(list(map(
np.float64, zip(cell_averages[:, :middle_idx],
left_reconstructions[:, middle_idx],
cell_averages[:, middle_idx],
right_reconstructions[:, middle_idx],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment