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

Fixed cell averages and reconstructions to create data with an x-point stencil.

parent a557d401
No related branches found
No related tags found
No related merge requests found
...@@ -112,7 +112,7 @@ class TrainingDataGenerator(object): ...@@ -112,7 +112,7 @@ class TrainingDataGenerator(object):
# Calculating Cell centers for a given 1D domain with n elements, and # Calculating Cell centers for a given 1D domain with n elements, and
# Calculating Corresponding Legendre Basis Coefficients for given polynomial_degree # Calculating Corresponding Legendre Basis Coefficients for given polynomial_degree
num_grid_cells = 3 num_grid_cells = self._stencil_length # former: 3
# Create stencil and basis_coefficients for smooth_function mapped onto stencil # Create stencil and basis_coefficients for smooth_function mapped onto stencil
interval, centers, h = self._build_stencil() interval, centers, h = self._build_stencil()
centers = [center[0] for center in centers] centers = [center[0] for center in centers]
...@@ -126,9 +126,10 @@ class TrainingDataGenerator(object): ...@@ -126,9 +126,10 @@ class TrainingDataGenerator(object):
quadrature_config={'num_eval_points': polynomial_degree+1}) quadrature_config={'num_eval_points': polynomial_degree+1})
if initial_condition.is_smooth(): if initial_condition.is_smooth():
input_data[i] = dg_scheme.build_training_data(0, initial_condition) input_data[i] = dg_scheme.build_training_data(0, self._stencil_length, initial_condition)
else: else:
input_data[i] = dg_scheme.build_training_data(centers[1], initial_condition) input_data[i] = dg_scheme.build_training_data(centers[self._stencil_length//2], self._stencil_length,
initial_condition)
# Update Function ID # Update Function ID
if (i % num_function_samples == num_function_samples - 1) and (function_id != len(initial_conditions)-1): if (i % num_function_samples == num_function_samples - 1) and (function_id != len(initial_conditions)-1):
...@@ -161,8 +162,6 @@ class TrainingDataGenerator(object): ...@@ -161,8 +162,6 @@ class TrainingDataGenerator(object):
# Pick a Random point between the left and right bound # Pick a Random point between the left and right bound
point = np.random.random(1) * (self._right_bound-self._left_bound) + self._left_bound point = np.random.random(1) * (self._right_bound-self._left_bound) + self._left_bound
# if int(10 * point) % 2 == 1:
# point = -point
# Ensure Bounds of x-point stencil are within the left and right bound # Ensure Bounds of x-point stencil are within the left and right bound
while point - self._stencil_length/2 * grid_spacing < self._left_bound\ while point - self._stencil_length/2 * grid_spacing < self._left_bound\
......
...@@ -109,7 +109,6 @@ class DGScheme(object): ...@@ -109,7 +109,6 @@ class DGScheme(object):
# Update projection # Update projection
projection, troubled_cells = self._update_scheme.step(projection, cfl_number) projection, troubled_cells = self._update_scheme.step(projection, cfl_number)
iteration += 1 iteration += 1
if (iteration % self._history_threshold) == 0: if (iteration % self._history_threshold) == 0:
...@@ -185,9 +184,9 @@ class DGScheme(object): ...@@ -185,9 +184,9 @@ class DGScheme(object):
print(np.array(output_matrix).shape) print(np.array(output_matrix).shape)
return np.transpose(np.array(output_matrix)) return np.transpose(np.array(output_matrix))
def build_training_data(self, adjustment, initial_condition=None): def build_training_data(self, adjustment, stencil_length, initial_condition=None):
if initial_condition is None: if initial_condition is None:
initial_condition = self._init_cond initial_condition = self._init_cond
projection = self._do_initial_projection(initial_condition, adjustment) projection = self._do_initial_projection(initial_condition, adjustment)
return self._detector.calculate_cell_average_and_reconstructions(projection[:, 1:-1]) return self._detector.calculate_cell_average_and_reconstructions(projection[:, 1:-1], stencil_length)
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
""" """
@author: Laura C. Kühle, Soraya Terrab (sorayaterrab) @author: Laura C. Kühle, Soraya Terrab (sorayaterrab)
TODO: Fix cell averages and reconstructions to create data with an x-point stencil TODO: Fix cell averages and reconstructions to create data with an x-point stencil -> Done
TODO: Add comments to get_cells() for ArtificialNeuralNetwork -> Done TODO: Add comments to get_cells() for ArtificialNeuralNetwork -> Done
TODO:
""" """
import os import os
...@@ -55,12 +56,20 @@ class TroubledCellDetector(object): ...@@ -55,12 +56,20 @@ class TroubledCellDetector(object):
def get_cells(self, projection): def get_cells(self, projection):
pass pass
def calculate_cell_average_and_reconstructions(self, projection): def calculate_cell_average_and_reconstructions(self, projection, stencil_length):
"""
Calculate the cell averages of all cells in a projection. Reconstructions are only calculated for the middle
cell and added left and right to it, respectively.
Here come some parameter.
"""
cell_averages = self._calculate_approximate_solution(projection, [0], 0) cell_averages = self._calculate_approximate_solution(projection, [0], 0)
left_reconstructions = self._calculate_approximate_solution(projection, [-1], self._polynomial_degree) left_reconstructions = self._calculate_approximate_solution(projection, [-1], self._polynomial_degree)
right_reconstructions = self._calculate_approximate_solution(projection, [1], self._polynomial_degree) right_reconstructions = self._calculate_approximate_solution(projection, [1], self._polynomial_degree)
return np.array(list(map(np.float64, zip(cell_averages[:, 0], left_reconstructions[:, 1], cell_averages[:, 1], middle_idx = stencil_length//2
right_reconstructions[:, 1], cell_averages[:, 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:]))))
def plot_results(self, projection, troubled_cell_history, time_history): def plot_results(self, projection, troubled_cell_history, time_history):
self._plot_shock_tube(troubled_cell_history, time_history) self._plot_shock_tube(troubled_cell_history, time_history)
...@@ -219,7 +228,7 @@ class ArtificialNeuralNetwork(TroubledCellDetector): ...@@ -219,7 +228,7 @@ class ArtificialNeuralNetwork(TroubledCellDetector):
# Calculate input data depending on stencil length # Calculate input data depending on stencil length
input_data = torch.from_numpy(np.vstack([self.calculate_cell_average_and_reconstructions( input_data = torch.from_numpy(np.vstack([self.calculate_cell_average_and_reconstructions(
projection[:, cell-num_ghost_cells:cell+num_ghost_cells+1]) projection[:, cell-num_ghost_cells:cell+num_ghost_cells+1], self._stencil_len)
for cell in range(num_ghost_cells, len(projection[0])-num_ghost_cells)])) for cell in range(num_ghost_cells, len(projection[0])-num_ghost_cells)]))
# Evaluate troubled cell probabilities # Evaluate troubled cell probabilities
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment