Rename extents to distiguish between global and local

Add properties to the Model class to access nx, ny, and nz from the
grid.
Rename the extents in the model to reflect the fact they are global
这个提交包含在:
nmannall
2024-05-15 15:21:31 +01:00
父节点 d919d5b3e3
当前提交 332a1204b6
共有 2 个文件被更改,包括 38 次插入14 次删除

查看文件

@@ -133,32 +133,32 @@ class Domain(UserObjectSingle):
def build(self, model, uip): def build(self, model, uip):
try: try:
model.nx, model.ny, model.nz = uip.discretise_point(self.kwargs["p1"]) model.gnx, model.gny, model.gnz = 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 model.nx == 0 or model.ny == 0 or model.nz == 0: if model.gnx == 0 or model.gny == 0 or model.gnz == 0:
logger.exception(f"{self.__str__()} requires at least one cell in 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 ({model.nx:d} x {model.ny:d} x {model.nz:d} = " + f"{self.kwargs['p1'][2]:g}m ({model.gnx:d} x {model.gny:d} x {model.gnz:d} = "
+ f"{(model.nx * model.ny * model.nz):g} cells)" + f"{(model.gnx * model.gny * model.gnz):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
G = model.G G = model.G
if model.nx == 1: if model.gnx == 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 model.ny == 1: elif model.gny == 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 model.nz == 1: elif model.gnz == 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,9 +56,9 @@ class Model:
def __init__(self): def __init__(self):
self.title = "" self.title = ""
self.nx = 0 self.gnx = 0
self.ny = 0 self.gny = 0
self.nz = 0 self.gnz = 0
self.G = self._create_grid() self.G = self._create_grid()
# Monitor memory usage # Monitor memory usage
@@ -70,6 +70,30 @@ class Model:
# later for use with CPU solver. # later for use with CPU solver.
config.get_model_config().ompthreads = set_omp_threads(config.get_model_config().ompthreads) config.get_model_config().ompthreads = set_omp_threads(config.get_model_config().ompthreads)
@property
def nx(self) -> int:
return self.G.nx
@nx.setter
def nx(self, value: int):
self.G.nx = value
@property
def ny(self) -> int:
return self.G.ny
@ny.setter
def ny(self, value: int):
self.G.ny = value
@property
def nz(self) -> int:
return self.G.nz
@nz.setter
def nz(self, value: int):
self.G.nz = value
@property @property
def dx(self) -> float: def dx(self) -> float:
return self.G.dl[0] return self.G.dl[0]
@@ -163,10 +187,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 # TODO: Make this correctly sets local nx, ny and nz when using MPI (likely use a function inside FDTDGrid/MPIGrid)
self.G.nx = self.nx self.G.nx = self.gnx
self.G.ny = self.ny self.G.ny = self.gny
self.G.nz = self.nz self.G.nz = self.gnz
self.G.build() self.G.build()
def reuse_geometry(self): def reuse_geometry(self):