From a4da5ed146ce656d4cacccc24c1cbb3064cd305f Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Fri, 5 May 2023 10:36:04 +0100 Subject: [PATCH] Tweaks to inherit any time step mods from main grid to subgrid --- gprMax/cmds_singleuse.py | 2 +- gprMax/grid.py | 5 +---- gprMax/subgrids/subgrid_hsg.py | 2 +- gprMax/subgrids/user_objects.py | 6 +++++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gprMax/cmds_singleuse.py b/gprMax/cmds_singleuse.py index ae451973..ed722d37 100644 --- a/gprMax/cmds_singleuse.py +++ b/gprMax/cmds_singleuse.py @@ -191,7 +191,7 @@ class TimeStepStabilityFactor(UserObjectSingle): raise ValueError G.dt_mod = f - G.calculate_dt() + G.dt = G.dt * G.dt_mod logger.info(f'Time step (modified): {G.dt:g} secs') diff --git a/gprMax/grid.py b/gprMax/grid.py index 069a8de2..a4960727 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -46,7 +46,7 @@ class FDTDGrid: self.dy = 0 self.dz = 0 self.dt = 0 - self.dt_mod = 1 # Time step stability factor + self.dt_mod = None # Time step stability factor self.iteration = 0 # Current iteration number self.iterations = 0 # Total number of iterations self.timewindow = 0 @@ -299,9 +299,6 @@ class FDTDGrid: # binary representation of floating point number. self.dt = round_value(self.dt, decimalplaces=d.getcontext().prec - 1) - # Apply any time step stability factor - self.dt = self.dt * self.dt_mod - class CUDAGrid(FDTDGrid): """Additional grid methods for solving on GPU using CUDA.""" diff --git a/gprMax/subgrids/subgrid_hsg.py b/gprMax/subgrids/subgrid_hsg.py index 007d9177..60e04db7 100644 --- a/gprMax/subgrids/subgrid_hsg.py +++ b/gprMax/subgrids/subgrid_hsg.py @@ -294,4 +294,4 @@ class SubGridHSG(SubGridBaseGrid): f'(({self.nwx} x {self.nwy} x {self.nwz} = {self.nwx * self.nwy * self.nwz} cells)') logger.debug(f'[{self.name}] Total region: {self.nx:d} x {self.ny:d} x {self.nz:d} = ' + f'{(self.nx * self.ny * self.nz):g} cells') - logger.info(f'[{self.name}] Time step (at CFL limit): {self.dt:g} secs') \ No newline at end of file + logger.info(f'[{self.name}] Time step: {self.dt:g} secs') \ No newline at end of file diff --git a/gprMax/subgrids/user_objects.py b/gprMax/subgrids/user_objects.py index d4e12dbd..ef6b38e1 100644 --- a/gprMax/subgrids/user_objects.py +++ b/gprMax/subgrids/user_objects.py @@ -91,8 +91,12 @@ class SubGridBase(UserObjectMulti): self.set_discretisation(sg, grid) - # Set temporal discretisation + # Set temporal discretisation including any inherited time step + # stability factor from the main grid sg.calculate_dt() + if grid.dt_mod: + sg.dt = sg.dt * grid.dt_mod + # Set the indices related to the subgrids main grid placement self.set_main_grid_indices(sg, uip, p1, p2)