From b7f28556efd5f53b007f47a69c7e3e1c5b586708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BChle=2C=20Laura=20Christine=20=28lakue103=29?= <laura.kuehle@uni-duesseldorf.de> Date: Sun, 5 Jun 2022 20:32:30 +0200 Subject: [PATCH] Fixed bug applying wrong boundary condition when generating ANN training data. --- ANN_Data_Generator.py | 7 ------- DG_Approximation.py | 16 ++++++++++------ Initial_Condition.py | 21 +++++++++++---------- projection_utils.py | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ANN_Data_Generator.py b/ANN_Data_Generator.py index f9d2e67..b7600bb 100644 --- a/ANN_Data_Generator.py +++ b/ANN_Data_Generator.py @@ -157,8 +157,6 @@ class TrainingDataGenerator: # Create normalized input data norm_input_matrix = self._normalize_data(input_matrix) - # print(input_matrix) - # print(norm_input_matrix) return {'input_data.raw': input_matrix, 'output_data': output_matrix, 'input_data.normalized': norm_input_matrix} @@ -217,10 +215,6 @@ class TrainingDataGenerator: adjustment = 0 if initial_condition.is_smooth() \ else mesh.non_ghost_cells[self._stencil_length//2] initial_condition.induce_adjustment(-mesh.cell_len/3) - # print(initial_condition.is_smooth()) - # print(mesh.interval_len, mesh.non_ghost_cells, mesh.cell_len) - # print(adjustment, -mesh.cell_len/3) - # print() # Calculate basis coefficients for stencil polynomial_degree = np.random.randint(1, high=5) @@ -229,7 +223,6 @@ class TrainingDataGenerator: basis=self._basis_list[polynomial_degree], quadrature=self._quadrature_list[polynomial_degree], adjustment=adjustment) - # print(projection) input_data[i] = self._basis_list[ polynomial_degree].calculate_cell_average( projection=projection[:, 1:-1], diff --git a/DG_Approximation.py b/DG_Approximation.py index 91070b0..26e3fa9 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -12,13 +12,17 @@ TODO: Contemplate containing coarse mesh generation in Mesh TODO: Contemplate extracting boundary condition from InitialCondition TODO: Contemplate containing boundary condition in Mesh TODO: Ask whether all quadratures depend on freely chosen num_nodes -TODO: Contemplate saving each IC separately +TODO: Contemplate saving training data for each IC separately TODO: Contemplate removing TrainingDataGenerator class Urgent: -TODO: Investigate self-referencing in classes +TODO: Investigate self-referencing in classes -> Done +TODO: Apply self-referencing in Mesh -> Done +TODO: Refactor random_stencil() -> Done +TODO: Fix bug applying wrong boundary condition when generating ANN + training data -> Done +TODO: Find errors in centering for ANN training -> Done TODO: Remove stencil_length as instance variable -TODO: Find errors in centering for ANN training TODO: Adapt TCD from Soraya (Dropbox->...->TEST_troubled-cell-detector->Troubled_Cell_Detector) TODO: Add TC condition to only flag cell if left-adjacent one is flagged as @@ -27,6 +31,8 @@ TODO: Move plot_approximation_results() into plotting script TODO: Add verbose output TODO: Improve file naming (e.g. use '.' instead of '__') TODO: Check whether ghost cells are handled/set correctly +TODO: Unify use of 'length' and 'len' in naming +TODO: Unify use of 'initial_condition' and 'init_cond' in naming TODO: Ensure uniform use of mesh and grid Critical, but not urgent: @@ -44,7 +50,6 @@ TODO: Extract object initialization from DGScheme TODO: Use cfl_number for updating, not just time Currently not critical: -TODO: Unify use of 'length' and 'len' in naming TODO: Replace loops with list comprehension if feasible TODO: Replace loops/list comprehension with vectorization if feasible TODO: Check whether 'projection' is always a ndarray @@ -319,10 +324,9 @@ def do_initial_projection(initial_condition, mesh, basis, quadrature, for eval_point in mesh.non_ghost_cells: new_row = [] - for degree in range(basis.polynomial_degree + 1): new_row.append(np.float64(sum(initial_condition.calculate( - mesh, eval_point + mesh.cell_len/2 + x=eval_point + mesh.cell_len/2 * quadrature.nodes[point] - adjustment) * basis.basis[degree].subs( x, quadrature.nodes[point]) diff --git a/Initial_Condition.py b/Initial_Condition.py index e7bd2a2..3ce562a 100644 --- a/Initial_Condition.py +++ b/Initial_Condition.py @@ -77,18 +77,18 @@ class InitialCondition(ABC): """ pass - def calculate(self, mesh, x): + def calculate(self, x, mesh=None): """Evaluates function at given x-value. - Projects x-value into interval of the periodic function and evaluates - the function. + If a mesh is given, the x-value is projected into its periodic + interval before evaluating the function. Parameters ---------- - mesh : Mesh - Mesh for calculation. x : float Evaluation point of function. + mesh : Mesh, optional + Mesh for calculation. Default: None. Returns ------- @@ -96,11 +96,12 @@ class InitialCondition(ABC): Value of function evaluates at x-value. """ - left_bound, right_bound = mesh.bounds - while x < left_bound: - x += mesh.interval_len - while x > right_bound: - x -= mesh.interval_len + if mesh is not None: + left_bound, right_bound = mesh.bounds + while x < left_bound: + x += mesh.interval_len + while x > right_bound: + x -= mesh.interval_len return self._get_point(x) @abstractmethod diff --git a/projection_utils.py b/projection_utils.py index 2ede5b2..39f825e 100644 --- a/projection_utils.py +++ b/projection_utils.py @@ -202,7 +202,7 @@ def calculate_exact_solution( eval_values = [] for eval_point in eval_points: - new_entry = init_cond.calculate(mesh, eval_point + new_entry = init_cond.calculate(mesh=mesh, x=eval_point - wave_speed * final_time + num_periods * mesh.interval_len) eval_values.append(new_entry) -- GitLab