From 2d16e0bc7e33996bedf4a0aa309461fcc3e77211 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: Mon, 19 Sep 2022 00:32:04 +0200 Subject: [PATCH] Enforced number of mesh cells to be an exponential of 2. --- projection_utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projection_utils.py b/projection_utils.py index 39f825e..27e87af 100644 --- a/projection_utils.py +++ b/projection_utils.py @@ -7,6 +7,7 @@ from __future__ import annotations from functools import cache from typing import Tuple +import math import numpy as np from numpy import ndarray from sympy import Symbol @@ -46,8 +47,8 @@ class Mesh: Parameters ---------- num_grid_cells : int - Number of cells in the mesh (ghost cells notwithstanding). Usually - exponential of 2. + Number of cells in the mesh (ghost cells notwithstanding). Has + to be an exponential of 2. num_ghost_cells : int Number of ghost cells on each side of the mesh. left_bound : float @@ -56,6 +57,9 @@ class Mesh: Right boundary of the mesh interval. """ self._num_grid_cells = num_grid_cells + if not math.log(self._num_grid_cells, 2).is_integer(): + raise ValueError('The number of cells in the mesh has to be an ' + 'exponential of 2') self._num_ghost_cells = num_ghost_cells self._left_bound = left_bound self._right_bound = right_bound -- GitLab