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

Changed 'num_ghost_cells' to be dependent on mesh mode.

parent 5ec8ed86
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ TODO: Discuss how wavelet details should be plotted ...@@ -25,7 +25,7 @@ TODO: Discuss how wavelet details should be plotted
Urgent: Urgent:
TODO: Rename stiffness matrix to volume integral matrix -> Done TODO: Rename stiffness matrix to volume integral matrix -> Done
TODO: Rename boundary matrix to flux matrix -> Done TODO: Rename boundary matrix to flux matrix -> Done
TODO: Change num_ghost_cells to be 1 for calc and 0 for other TODO: Change num_ghost_cells to be 1 for calc and 0 for other -> Done
TODO: Move boundary condition to Mesh class TODO: Move boundary condition to Mesh class
TODO: Ensure exact solution is calculated in Equation class TODO: Ensure exact solution is calculated in Equation class
TODO: Extract objects from UpdateScheme TODO: Extract objects from UpdateScheme
......
...@@ -35,8 +35,7 @@ def main() -> None: ...@@ -35,8 +35,7 @@ def main() -> None:
# Initialize mesh with two ghost cells on each side # Initialize mesh with two ghost cells on each side
mesh = Mesh(num_cells=params.pop('num_mesh_cells', 64), mesh = Mesh(num_cells=params.pop('num_mesh_cells', 64),
left_bound=params.pop('left_bound', -1), left_bound=params.pop('left_bound', -1),
right_bound=params.pop('right_bound', 1), right_bound=params.pop('right_bound', 1))
num_ghost_cells=1)
# Initialize basis # Initialize basis
basis = OrthonormalLegendre(params.pop('polynomial_degree', 2)) basis = OrthonormalLegendre(params.pop('polynomial_degree', 2))
......
...@@ -40,7 +40,7 @@ class TrainingDataGenerator: ...@@ -40,7 +40,7 @@ class TrainingDataGenerator:
self._quadrature_list = [Gauss({'num_nodes': pol_deg+1}) self._quadrature_list = [Gauss({'num_nodes': pol_deg+1})
for pol_deg in range(7)] for pol_deg in range(7)]
self._mesh_list = [Mesh(left_bound=-1, right_bound=1, self._mesh_list = [Mesh(left_bound=-1, right_bound=1,
num_ghost_cells=0, num_cells=2**exp) num_cells=2**exp, training_data_mode=True)
for exp in range(5, 12)] for exp in range(5, 12)]
def build_training_data(self, init_cond_list, num_samples, balance=0.5, def build_training_data(self, init_cond_list, num_samples, balance=0.5,
......
...@@ -25,6 +25,7 @@ class Mesh: ...@@ -25,6 +25,7 @@ class Mesh:
exponential of 2. exponential of 2.
num_ghost_cells : int num_ghost_cells : int
Number of ghost cells on both sides of the mesh, respectively. Number of ghost cells on both sides of the mesh, respectively.
Either 0 during training or 1 during evaluation.
bounds : Tuple[float, float] bounds : Tuple[float, float]
Left and right boundary of the mesh interval. Left and right boundary of the mesh interval.
interval_len : float interval_len : float
...@@ -43,8 +44,7 @@ class Mesh: ...@@ -43,8 +44,7 @@ class Mesh:
""" """
def __init__(self, num_cells: int, num_ghost_cells: int, def __init__(self, num_cells: int, left_bound: float, right_bound: float,
left_bound: float, right_bound: float,
training_data_mode: bool = False) -> None: training_data_mode: bool = False) -> None:
"""Initialize Mesh. """Initialize Mesh.
...@@ -53,8 +53,6 @@ class Mesh: ...@@ -53,8 +53,6 @@ class Mesh:
num_cells : int num_cells : int
Number of cells in the mesh (ghost cells notwithstanding). Has Number of cells in the mesh (ghost cells notwithstanding). Has
to be an exponential of 2. to be an exponential of 2.
num_ghost_cells : int
Number of ghost cells on each side of the mesh.
left_bound : float left_bound : float
Left boundary of the mesh interval. Left boundary of the mesh interval.
right_bound : float right_bound : float
...@@ -71,11 +69,12 @@ class Mesh: ...@@ -71,11 +69,12 @@ class Mesh:
""" """
self._num_cells = num_cells self._num_cells = num_cells
self._mode = 'training' if training_data_mode else 'evaluation' self._mode = 'training' if training_data_mode else 'evaluation'
self._num_ghost_cells = 0
if not training_data_mode: if not training_data_mode:
self._num_ghost_cells = 1
if not math.log(self._num_cells, 2).is_integer(): if not math.log(self._num_cells, 2).is_integer():
raise ValueError('The number of cells in the mesh has to be ' raise ValueError('The number of cells in the mesh has to be '
'an exponential of 2') 'an exponential of 2')
self._num_ghost_cells = num_ghost_cells
self._left_bound = left_bound self._left_bound = left_bound
self._right_bound = right_bound self._right_bound = right_bound
...@@ -128,8 +127,7 @@ class Mesh: ...@@ -128,8 +127,7 @@ class Mesh:
"""Return dictionary with data necessary to construct mesh.""" """Return dictionary with data necessary to construct mesh."""
return {'num_cells': self._num_cells, return {'num_cells': self._num_cells,
'left_bound': self._left_bound, 'left_bound': self._left_bound,
'right_bound': self._right_bound, 'right_bound': self._right_bound}
'num_ghost_cells': self._num_ghost_cells}
def random_stencil(self, stencil_len: int) -> Mesh: def random_stencil(self, stencil_len: int) -> Mesh:
"""Return random stencil. """Return random stencil.
...@@ -156,5 +154,4 @@ class Mesh: ...@@ -156,5 +154,4 @@ class Mesh:
# Return new mesh instance # Return new mesh instance
return Mesh(left_bound=point - stencil_len/2 * mesh_spacing, return Mesh(left_bound=point - stencil_len/2 * mesh_spacing,
right_bound=point + stencil_len/2 * mesh_spacing, right_bound=point + stencil_len/2 * mesh_spacing,
num_cells=stencil_len, num_ghost_cells=0, num_cells=stencil_len, training_data_mode=True)
training_data_mode=True)
...@@ -428,8 +428,9 @@ def plot_results(projection: ndarray, troubled_cell_history: list, ...@@ -428,8 +428,9 @@ def plot_results(projection: ndarray, troubled_cell_history: list,
# Plot multiwavelet solution (fine and coarse mesh) # Plot multiwavelet solution (fine and coarse mesh)
if coarse_projection is not None: if coarse_projection is not None:
coarse_mesh = Mesh(num_cells=mesh.num_cells//2, coarse_mesh = Mesh(num_cells=mesh.num_cells//2,
num_ghost_cells=0, left_bound=mesh.bounds[0], left_bound=mesh.bounds[0],
right_bound=mesh.bounds[1]) right_bound=mesh.bounds[1],
training_data_mode=True)
# Plot exact and approximate solutions for coarse mesh # Plot exact and approximate solutions for coarse mesh
coarse_grid, coarse_exact = calculate_exact_solution( coarse_grid, coarse_exact = calculate_exact_solution(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment