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

Contained interval length in mesh.

parent 042719cf
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ Urgent:
TODO: Put basis initialization for plots in function -> Done
TODO: Contain cell length in mesh -> Done
TODO: Contain bounds in mesh -> Done
TODO: Contain interval length in mesh
TODO: Contain interval length in mesh -> Done
TODO: Contain number of grid cells in mesh
TODO: Create data dict for mesh separately
TODO: Create data dict for basis separately
......@@ -96,14 +96,10 @@ class DGScheme:
Attributes
----------
interval_len : float
Length of the interval between left and right boundary.
basis : Basis object
Basis for calculation.
mesh : Mesh
Mesh for calculation.
inv_mass : ndarray
Inverse mass matrix.
Methods
-------
......@@ -192,9 +188,6 @@ class DGScheme:
print(len(self._mesh.cells))
print(type(self._mesh.cells))
# Set additional necessary instance variables
self._interval_len = right_bound-left_bound
# Throw an error if there are extra keyword arguments
if len(kwargs) > 0:
extra = ', '.join('"%s"' % k for k in list(kwargs.keys()))
......
......@@ -97,11 +97,10 @@ class InitialCondition(ABC):
"""
left_bound, right_bound = mesh.bounds
interval_len = right_bound-left_bound
while x < left_bound:
x += interval_len
x += mesh.interval_len
while x > right_bound:
x -= interval_len
x -= mesh.interval_len
return self._get_point(x)
@abstractmethod
......
......@@ -418,17 +418,12 @@ def plot_results(projection: ndarray, troubled_cell_history: list,
colors = {}
colors = _check_colors(colors)
# Calculate needed variables
left_bound, right_bound = mesh.bounds
interval_len = right_bound-left_bound
# Plot troubled cells
plot_shock_tube(num_grid_cells, troubled_cell_history, time_history)
# Determine exact and approximate solution
grid, exact = calculate_exact_solution(
mesh, wave_speed, final_time, interval_len, quadrature,
init_cond)
mesh, wave_speed, final_time, quadrature, init_cond)
approx = calculate_approximate_solution(
projection[:, 1:-1], quadrature.get_eval_points(),
basis.polynomial_degree, basis.basis)
......@@ -436,13 +431,12 @@ def plot_results(projection: ndarray, troubled_cell_history: list,
# Plot multiwavelet solution (fine and coarse grid)
if coarse_projection is not None:
coarse_mesh = Mesh(num_grid_cells=num_grid_cells//2,
num_ghost_cells=1, left_bound=left_bound,
right_bound=right_bound)
num_ghost_cells=1, left_bound=mesh.bounds[0],
right_bound=mesh.bounds[1])
# Plot exact and approximate solutions for coarse mesh
coarse_grid, coarse_exact = calculate_exact_solution(
coarse_mesh, wave_speed, final_time, interval_len, quadrature,
init_cond)
coarse_mesh, wave_speed, final_time, quadrature, init_cond)
coarse_approx = calculate_approximate_solution(
coarse_projection, quadrature.get_eval_points(),
basis.polynomial_degree, basis.basis)
......
......@@ -21,11 +21,6 @@ class TroubledCellDetector(ABC):
Detects troubled cells, i.e., cells in the mesh containing instabilities.
Attributes
----------
interval_len : float
Length of the interval between left and right boundary.
Methods
-------
get_name()
......@@ -62,8 +57,6 @@ class TroubledCellDetector(ABC):
self._wave_speed = wave_speed
self._num_grid_cells = num_grid_cells
self._final_time = final_time
left_bound, right_bound = mesh.bounds
self._interval_len = right_bound - left_bound
self._basis = basis
self._init_cond = init_cond
self._quadrature = quadrature
......
......@@ -132,8 +132,8 @@ def calculate_approximate_solution(
def calculate_exact_solution(
mesh: Mesh, wave_speed: float, final_time:
float, interval_len: float, quadrature: Quadrature, init_cond:
InitialCondition) -> Tuple[ndarray, ndarray]:
float, quadrature: Quadrature,
init_cond: InitialCondition) -> Tuple[ndarray, ndarray]:
"""Calculate exact solution.
Parameters
......@@ -144,8 +144,6 @@ def calculate_exact_solution(
Speed of wave in rightward direction.
final_time : float
Final time for which approximation is calculated.
interval_len : float
Length of the interval between left and right boundary.
quadrature : Quadrature object
Quadrature for evaluation.
init_cond : InitialCondition object
......@@ -161,7 +159,7 @@ def calculate_exact_solution(
"""
grid = []
exact = []
num_periods = np.floor(wave_speed * final_time / interval_len)
num_periods = np.floor(wave_speed * final_time / mesh.interval_len)
for cell_center in mesh.non_ghost_cells:
eval_points = cell_center+mesh.cell_len / 2 * \
......@@ -171,7 +169,7 @@ def calculate_exact_solution(
for eval_point in eval_points:
new_entry = init_cond.calculate(mesh, eval_point
- wave_speed * final_time
+ num_periods * interval_len)
+ num_periods * mesh.interval_len)
eval_values.append(new_entry)
grid.append(eval_points)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment