diff --git a/DG_Approximation.py b/DG_Approximation.py index 4eab4c88271c2ad521a603c1230bc5030d016eaf..21b67e12c6f922e7db94d59e7a4a933113f88d7f 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -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, diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index 325d84d741a7150566df66ec1a5a3f8042c09f1c..2d8aaeb737ccff3167aeb76a7890a173ac0c9ac3 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -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)])) diff --git a/projection_utils.py b/projection_utils.py index c4bdec2ac57c6357f28f1914089c932c0461bd8f..e860b102f99160a7a8400f3ca24beeb0ba8ecd15 100644 --- a/projection_utils.py +++ b/projection_utils.py @@ -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,21 +35,20 @@ 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], - left_reconstructions[:, middle_idx], - cell_averages[:, middle_idx], - right_reconstructions[:, middle_idx], - cell_averages[:, middle_idx+1:])))) + return np.array(list(map( + np.float64, zip(cell_averages[:, :middle_idx], + left_reconstructions[:, middle_idx], + cell_averages[:, middle_idx], + right_reconstructions[:, middle_idx], + cell_averages[:, middle_idx+1:])))) return np.array(list(map(np.float64, cell_averages)))