Source code for wolfgpu.loaders.utils

from math import log10, ceil
import numpy as np
from ..simple_simulation import BoundaryConditionsTypes


[docs] def convert_bc_type(bc_type) -> BoundaryConditionsTypes: # FIXME This mumbo jumbo while waiting for BoundaryConditionsTypes to # be an independant class in WolfHECE. This avoids name clashing between # WolfGPU's BoundaryConditionsTypes and WolfHECE's. if bc_type.__class__.__name__ in ("BoundaryConditionsTypes","BCType_2D"): # We got the B+C from Wolf data structure # We use class name to AVOID loading the WolfHECE huge library # This way one can use the GPU simulator without WolfHECE. return BoundaryConditionsTypes(bc_type.value) elif isinstance(bc_type, int): try: return BoundaryConditionsTypes(bc_type) except Exception: raise Exception(f"Bad type for b.c.: {bc_type} of type {type(bc_type)}, {bc_type.__class__.__name__}") else: raise Exception(f"Bad type for b.c.: {type(bc_type)}, {bc_type.__class__.__name__}")
[docs] def make_impervious_bathymetry(nap: np.ndarray, bathymetry: np.ndarray): """ Create a wall that is ten times has tall as the max bathy. Additional sorcery to make that height something clearly artificial, i.e. 9999. """ assert nap is not None assert bathymetry is not None # FIXME This should be done in the shaders so that computations # are adapted to missing data (instead of providing "default" # data). Note we have discussed that with PA in dec/2023 and # we decided it was OK for the moment. bath_max = np.max( bathymetry) if bath_max > 1: unreachable_height = (10 ** (ceil(log10(np.max( bathymetry))) + 1)) - 1 else: unreachable_height = 999.0 # Each non active cell which has no bathymetry is # filled with a very high bathymetry to enclose the computation # domain. bathymetry[nap == 0] = unreachable_height return bathymetry