From 2f5f5fcc803d2d3f0c0c2fcde61a99954eb41bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BChle=2C=20Laura=20Christine=20=28lakue103=29?= <laura.kuehle@uni-duesseldorf.de> Date: Fri, 10 Mar 2023 13:17:28 +0100 Subject: [PATCH] Enforced that number of ghost cells is positive for calculations and non-negative for training. --- Snakefile | 4 ++-- scripts/tcd/Equation.py | 9 +++++++++ scripts/tcd/Mesh.py | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Snakefile b/Snakefile index c1fbb0e..1283a16 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 995aba7..e2765d2 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 445ad17..abd4baa 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') -- GitLab