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

Enforced boundary condition for initial condition in exact solution only.

parent f42c5cdc
Branches
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ TODO: Refactor Boxplot class -> Done
TODO: Enforce periodic boundary condition for projection with decorator -> Done
TODO: Enforce Boxplot bounds with decorator -> Done
TODO: Enforce Boxplot folds with decorator -> Done
TODO: Enforce boundary for initial condition in exact solution only
TODO: Enforce boundary for initial condition in exact solution only -> Done
TODO: Adapt number of ghost cells based on ANN stencil
TODO: Ensure exact solution is calculated in Equation class
TODO: Extract objects from UpdateScheme
......
......@@ -254,10 +254,19 @@ class LinearAdvection(Equation):
grid = np.repeat(mesh.non_ghost_cells, self._quadrature.num_nodes) + \
mesh.cell_len / 2 * np.tile(self._quadrature.nodes, mesh.num_cells)
exact = np.array([self._init_cond.calculate(
mesh=mesh, x=point-self.wave_speed * self.final_time+num_periods *
mesh.interval_len)
# Project points into correct periodic interval
points = np.array([point-self.wave_speed *
self.final_time+num_periods * mesh.interval_len
for point in grid])
left_bound, right_bound = self._mesh.bounds
while np.any(points < left_bound):
points[points < left_bound] += self._mesh.interval_len
while np.any(points) > right_bound:
points[points > right_bound] -= self._mesh.interval_len
exact = np.array([self._init_cond.calculate(mesh=mesh, x=point) for
point in points])
grid = np.reshape(grid, (1, grid.size))
exact = np.reshape(exact, (1, exact.size))
......
......@@ -88,9 +88,6 @@ class InitialCondition(ABC):
def calculate(self, x, mesh):
"""Evaluates function at given x-value.
In evaluation (not training) mode, the x-value is projected
into its periodic interval before evaluating the function.
Parameters
----------
x : float
......@@ -104,12 +101,6 @@ class InitialCondition(ABC):
Value of function evaluates at x-value.
"""
if mesh.mode == 'evaluation':
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, mesh)
@abstractmethod
......
......@@ -83,9 +83,19 @@ def calculate_exact_solution(
grid = np.repeat(mesh.non_ghost_cells, quadrature.num_nodes) + \
mesh.cell_len/2 * np.tile(quadrature.nodes, mesh.num_cells)
exact = np.array([init_cond.calculate(
mesh=mesh, x=point-wave_speed*final_time+num_periods*mesh.interval_len)
# Project points into correct periodic interval
points = np.array([point-wave_speed *
final_time+num_periods * mesh.interval_len
for point in grid])
left_bound, right_bound = mesh.bounds
while np.any(points < left_bound):
points[points < left_bound] += mesh.interval_len
while np.any(points) > right_bound:
points[points > right_bound] -= mesh.interval_len
exact = np.array([init_cond.calculate(mesh=mesh, x=point) for
point in points])
grid = np.reshape(grid, (1, grid.size))
exact = np.reshape(exact, (1, exact.size))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment