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
这个提交包含在:
nmannall
2024-05-14 14:48:45 +01:00
父节点 6ab48e4b5f
当前提交 7cfe57948a
共有 2 个文件被更改,包括 18 次插入9 次删除

查看文件

@@ -131,33 +131,34 @@ class Domain(UserObjectSingle):
super().__init__(**kwargs) super().__init__(**kwargs)
self.order = 3 self.order = 3
def build(self, G, uip): def build(self, model, uip):
try: 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: except KeyError:
logger.exception(f"{self.__str__()} please specify a point") logger.exception(f"{self.__str__()} please specify a point")
raise raise
if G.nx == 0 or G.ny == 0 or G.nz == 0: if model.nx == 0 or model.ny == 0 or model.nz == 0:
logger.exception(f"{self.__str__()} requires at least one cell in " f"every dimension") logger.exception(f"{self.__str__()} requires at least one cell in every dimension")
raise ValueError raise ValueError
logger.info( logger.info(
f"Domain size: {self.kwargs['p1'][0]:g} x {self.kwargs['p1'][1]:g} x " 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"{self.kwargs['p1'][2]:g}m ({model.nx:d} x {model.ny:d} x {model.nz:d} = "
+ f"{(G.nx * G.ny * G.nz):g} cells)" + f"{(model.nx * model.ny * model.nz):g} cells)"
) )
# Calculate time step at CFL limit; switch off appropriate PMLs for 2D # 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" config.get_model_config().mode = "2D TMx"
G.pmls["thickness"]["x0"] = 0 G.pmls["thickness"]["x0"] = 0
G.pmls["thickness"]["xmax"] = 0 G.pmls["thickness"]["xmax"] = 0
elif G.ny == 1: elif model.ny == 1:
config.get_model_config().mode = "2D TMy" config.get_model_config().mode = "2D TMy"
G.pmls["thickness"]["y0"] = 0 G.pmls["thickness"]["y0"] = 0
G.pmls["thickness"]["ymax"] = 0 G.pmls["thickness"]["ymax"] = 0
elif G.nz == 1: elif model.nz == 1:
config.get_model_config().mode = "2D TMz" config.get_model_config().mode = "2D TMz"
G.pmls["thickness"]["z0"] = 0 G.pmls["thickness"]["z0"] = 0
G.pmls["thickness"]["zmax"] = 0 G.pmls["thickness"]["zmax"] = 0

查看文件

@@ -56,6 +56,10 @@ class Model:
def __init__(self): def __init__(self):
self.title = "" self.title = ""
self.nx = 0
self.ny = 0
self.nz = 0
self.G = self._create_grid() self.G = self._create_grid()
# Monitor memory usage # Monitor memory usage
self.p = None self.p = None
@@ -127,6 +131,10 @@ class Model:
def build_geometry(self): def build_geometry(self):
logger.info(config.get_model_config().inputfilestr) 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() self.G.build()
def reuse_geometry(self): def reuse_geometry(self):