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