diff --git a/ANN_Data_Generator.py b/ANN_Data_Generator.py index 2d57bafde67ee7d5186f4503241978fc7a357778..4f753dd53ae456b10929797c08a3a8e5d2af3e89 100644 --- a/ANN_Data_Generator.py +++ b/ANN_Data_Generator.py @@ -7,7 +7,14 @@ import os import time import numpy as np -import DG_Approximation +from DG_Approximation import do_initial_projection +from projection_utils import Mesh +from Quadrature import Gauss +from Basis_Function import OrthonormalLegendre + + +basis_list = [OrthonormalLegendre(pol_deg) for pol_deg in range(5)] +quadrature_list = [Gauss({'num_nodes': pol_deg+1}) for pol_deg in range(5)] class TrainingDataGenerator: @@ -204,14 +211,20 @@ class TrainingDataGenerator: # Calculate basis coefficients for stencil polynomial_degree = np.random.randint(1, high=5) - dg_scheme = DG_Approximation.DGScheme( - 'NoDetection', polynomial_degree=polynomial_degree, - num_grid_cells=self._stencil_length, left_bound=left_bound, - right_bound=right_bound, quadrature='Gauss', - quadrature_config={'num_eval_points': polynomial_degree+1}) - input_data[i] = dg_scheme.build_training_data( - adjustment, self._stencil_length, self._add_reconstructions, - initial_condition) + + basis = basis_list[polynomial_degree] + mesh = Mesh(num_grid_cells=self._stencil_length, num_ghost_cells=2, + left_bound=left_bound, right_bound=right_bound) + projection = do_initial_projection( + initial_condition=initial_condition, mesh=mesh, + basis=basis, + quadrature=quadrature_list[polynomial_degree], + adjustment=adjustment) + + input_data[i] = basis.calculate_cell_average( + projection=projection[:, 1:-1], + stencil_length=self._stencil_length, + add_reconstructions=self._add_reconstructions) count += 1 if count % 1000 == 0: diff --git a/DG_Approximation.py b/DG_Approximation.py index 6abea2d35b00f42aa2fc06e566e09f1f0aa4efb1..78190c8b90b32b26013a497a01df703a1591b853 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -16,8 +16,10 @@ TODO: Ask whether all quadratures depend on freely chosen num_nodes Urgent: TODO: Replace getter with property attributes for quadrature -> Done TODO: Rename eval_points in Quadrature to nodes -> Done -TODO: Improve docstring for quadrature -TODO: Remove use of DGScheme from ANN_Data_Generator +TODO: Improve docstring for quadrature -> Done +TODO: Ensure repeatable output through seeds and deterministic models -> Done +TODO: Remove use of DGScheme from ANN_Data_Generator -> Done +TODO: Remove unnecessary instance variables from TrainingDataGenerator TODO: Find error in centering for ANN training TODO: Adapt TCD from Soraya (Dropbox->...->TEST_troubled-cell-detector->Troubled_Cell_Detector) @@ -178,8 +180,8 @@ class DGScheme: left_bound=kwargs.pop('left_bound', -1), right_bound=kwargs.pop('right_bound', 1), num_ghost_cells=2) - print(len(self._mesh.cells)) - print(type(self._mesh.cells)) + # print(len(self._mesh.cells)) + # print(type(self._mesh.cells)) # Throw an error if there are extra keyword arguments if len(kwargs) > 0: @@ -284,43 +286,6 @@ class DGScheme: # Set additional necessary config parameters self._limiter_config['cell_len'] = self._mesh.cell_len - def build_training_data(self, adjustment, stencil_length, - add_reconstructions, initial_condition=None): - """Builds training data set. - - Initializes projection and calculates cell averages and - reconstructions for it. - - Parameters - ---------- - adjustment : float - Extent of adjustment of each evaluation point in x-direction. - stencil_length : int - Size of training data array. - add_reconstructions: bool - Flag whether reconstructions of the middle cell are included. - initial_condition : InitialCondition object, optional - Initial condition used for calculation. - Default: None (i.e. instance variable). - - Returns - ------- - ndarray - Matrix containing cell averages and reconstructions for initial - projection. - - """ - if initial_condition is None: - initial_condition = self._init_cond - projection = do_initial_projection( - initial_condition=initial_condition, mesh=self._mesh, - basis=self._basis, quadrature=self._quadrature, - adjustment=adjustment) - - return self._basis.calculate_cell_average( - projection=projection[:, 1:-1], stencil_length=stencil_length, - add_reconstructions=add_reconstructions) - def do_initial_projection(initial_condition, mesh, basis, quadrature, adjustment=0): diff --git a/config.yaml b/config.yaml index 05e07455eee4aa73a5267772a12aa979f359bff4..ea4e95d8647a575973e24d903d5ea2952be57999 100644 --- a/config.yaml +++ b/config.yaml @@ -1,9 +1,9 @@ -data_dir: 'model-Mar14' +data_dir: 'model-Jun03' random_seed: 1234 # Parameter for Approximation with Troubled Cell Detection Approximation: - plot_dir: 'fig-Mar14' + plot_dir: 'fig-Jun03' schemes: Separation_Test: @@ -36,7 +36,7 @@ Approximation: quadrature: 'Gauss' quadrature_config: - num_eval_points: 12 + num_nodes: 12 update_scheme: 'SSPRK3' Test_Run: