diff --git a/Snakefile b/Snakefile index c1fbb0e047d1f7f6b4ab376ed8df9cd1b9e217fc..1283a16dfedc356f75087e3158fc4d1e41aca7c0 100644 --- a/Snakefile +++ b/Snakefile @@ -30,8 +30,7 @@ TODO: Enforce Boxplot folds with decorator -> Done TODO: Enforce boundary for initial condition in exact solution only -> Done TODO: Adapt number of ghost cells based on ANN stencil -> Done TODO: Ensure exact solution is calculated in Equation class -> Done -TODO: Extract objects from UpdateScheme -TODO: Enforce num_ghost_cells to be positive integer for DG (not training) +TODO: Enforce num_ghost_cells to be positive integer for DG -> Done TODO: Add Burger class TODO: Use cfl_number for updating, not just time (equation-related?) @@ -56,6 +55,7 @@ TODO: Add verbose output TODO: Add tests for all functions Not feasible yet or doc-related: +TODO: Extract objects from UpdateScheme TODO: Clean up result plotting (remove object properties of Equation) TODO: Add functions to create each object from dict TODO: Move plot_approximation_results() into plotting script diff --git a/scripts/tcd/Equation.py b/scripts/tcd/Equation.py index 995aba750f5ab282252d85a8bdb1abc7c4df19f8..e2765d25e7f1831dd68588c53f4fa2c3978adb80 100644 --- a/scripts/tcd/Equation.py +++ b/scripts/tcd/Equation.py @@ -53,6 +53,11 @@ class Equation(ABC): cfl_number : float CFL number to ensure stability. + Raises + ------ + ValueError + If number of ghost cells in mesh in not positive. + """ self._quadrature = quadrature self._init_cond = init_cond @@ -62,6 +67,10 @@ class Equation(ABC): self._wave_speed = wave_speed self._cfl_number = cfl_number + if self._mesh.num_ghost_cells <= 0: + raise ValueError('Number of ghost cells for calculations has to ' + 'be positive.') + self._reset() @property diff --git a/scripts/tcd/Mesh.py b/scripts/tcd/Mesh.py index 445ad170a3d3ee72e61b5f4d1529f2782fe1590a..abd4baa90b96f6eb34bc7e4f0d37f8836911a826 100644 --- a/scripts/tcd/Mesh.py +++ b/scripts/tcd/Mesh.py @@ -59,17 +59,22 @@ class Mesh: Right boundary of the mesh interval. num_ghost_cells : int, optional Number of ghost cells on each side of the mesh, respectively. - Default: False. + Default: 1. Raises ------ ValueError - If number of cells is not exponential of 2. + If number of ghost cells is negative. + ValueError + If number of cells is not exponential of 2 (and ghost cells exist). """ self._num_cells = num_cells self._num_ghost_cells = num_ghost_cells if self._num_ghost_cells != 0: + if self._num_ghost_cells < 0: + raise ValueError('The number of ghost cells has to be a ' + 'non-negative integer') if not math.log(self._num_cells, 2).is_integer(): raise ValueError('The number of cells in the mesh has to be ' 'an exponential of 2')