From 7cfe57948ac07246adcd5f1e585fdc93b935187b Mon Sep 17 00:00:00 2001 From: nmannall Date: Tue, 14 May 2024 14:48:45 +0100 Subject: [PATCH] Refactor Domain UserObject Model extents nx, ny and nz are now stored in the model. Currently these are copied to FDTDGrid, but will be changed to local grid extents when MPI implementation is added --- gprMax/cmds_singleuse.py | 19 ++++++++++--------- gprMax/model.py | 8 ++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gprMax/cmds_singleuse.py b/gprMax/cmds_singleuse.py index 3a24d5cb..cf562e41 100644 --- a/gprMax/cmds_singleuse.py +++ b/gprMax/cmds_singleuse.py @@ -131,33 +131,34 @@ class Domain(UserObjectSingle): super().__init__(**kwargs) self.order = 3 - def build(self, G, uip): + def build(self, model, uip): try: - G.nx, G.ny, G.nz = uip.discretise_point(self.kwargs["p1"]) + model.nx, model.ny, model.nz = uip.discretise_point(self.kwargs["p1"]) except KeyError: logger.exception(f"{self.__str__()} please specify a point") raise - if G.nx == 0 or G.ny == 0 or G.nz == 0: - logger.exception(f"{self.__str__()} requires at least one cell in " f"every dimension") + if model.nx == 0 or model.ny == 0 or model.nz == 0: + logger.exception(f"{self.__str__()} requires at least one cell in every dimension") raise ValueError logger.info( f"Domain size: {self.kwargs['p1'][0]:g} x {self.kwargs['p1'][1]:g} x " - + f"{self.kwargs['p1'][2]:g}m ({G.nx:d} x {G.ny:d} x {G.nz:d} = " - + f"{(G.nx * G.ny * G.nz):g} cells)" + + f"{self.kwargs['p1'][2]:g}m ({model.nx:d} x {model.ny:d} x {model.nz:d} = " + + f"{(model.nx * model.ny * model.nz):g} cells)" ) # Calculate time step at CFL limit; switch off appropriate PMLs for 2D - if G.nx == 1: + G = model.G + if model.nx == 1: config.get_model_config().mode = "2D TMx" G.pmls["thickness"]["x0"] = 0 G.pmls["thickness"]["xmax"] = 0 - elif G.ny == 1: + elif model.ny == 1: config.get_model_config().mode = "2D TMy" G.pmls["thickness"]["y0"] = 0 G.pmls["thickness"]["ymax"] = 0 - elif G.nz == 1: + elif model.nz == 1: config.get_model_config().mode = "2D TMz" G.pmls["thickness"]["z0"] = 0 G.pmls["thickness"]["zmax"] = 0 diff --git a/gprMax/model.py b/gprMax/model.py index 61177b4a..718747f5 100644 --- a/gprMax/model.py +++ b/gprMax/model.py @@ -56,6 +56,10 @@ class Model: def __init__(self): self.title = "" + self.nx = 0 + self.ny = 0 + self.nz = 0 + self.G = self._create_grid() # Monitor memory usage self.p = None @@ -127,6 +131,10 @@ class Model: def build_geometry(self): logger.info(config.get_model_config().inputfilestr) + # TODO: Make this correctly set local nx, ny and nz when using MPI + self.G.nx = self.nx + self.G.ny = self.ny + self.G.nz = self.nz self.G.build() def reuse_geometry(self):