Begin moving subgrids into Model class

这个提交包含在:
nmannall
2024-05-15 16:27:03 +01:00
父节点 99dd5f7cb6
当前提交 a31be536d6
共有 4 个文件被更改,包括 22 次插入24 次删除

查看文件

@@ -89,7 +89,6 @@ class FDTDGrid:
self.srcsteps: List[int] = [0, 0, 0] self.srcsteps: List[int] = [0, 0, 0]
self.rxsteps: List[int] = [0, 0, 0] self.rxsteps: List[int] = [0, 0, 0]
self.snapshots = [] self.snapshots = []
self.subgrids = []
@property @property
def dx(self) -> float: def dx(self) -> float:

查看文件

@@ -17,10 +17,9 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import datetime import datetime
import itertools
import logging import logging
import sys import sys
from typing import Any, Tuple from typing import List
import humanize import humanize
import numpy as np import numpy as np
@@ -29,22 +28,19 @@ from colorama import Fore, Style, init
from gprMax.grid.cuda_grid import CUDAGrid from gprMax.grid.cuda_grid import CUDAGrid
from gprMax.grid.opencl_grid import OpenCLGrid from gprMax.grid.opencl_grid import OpenCLGrid
from gprMax.subgrids.grid import SubGridBaseGrid
init() init()
from terminaltables import SingleTable
from tqdm import tqdm from tqdm import tqdm
import gprMax.config as config import gprMax.config as config
from .cython.yee_cell_build import build_electric_components, build_magnetic_components
from .fields_outputs import write_hdf5_outputfile from .fields_outputs import write_hdf5_outputfile
from .geometry_outputs import save_geometry_views from .geometry_outputs import save_geometry_views
from .grid.fdtd_grid import FDTDGrid, dispersion_analysis from .grid.fdtd_grid import FDTDGrid
from .materials import process_materials
from .pml import CFS, build_pml, print_pml_info
from .snapshots import save_snapshots from .snapshots import save_snapshots
from .utilities.host_info import mem_check_build_all, mem_check_run_all, set_omp_threads from .utilities.host_info import set_omp_threads
from .utilities.utilities import get_terminal_width from .utilities.utilities import get_terminal_width
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -67,6 +63,8 @@ class Model:
self.timewindow = 0.0 self.timewindow = 0.0
self.G = self._create_grid() self.G = self._create_grid()
self.subgrids: List[SubGridBaseGrid] = []
# Monitor memory usage # Monitor memory usage
self.p = None self.p = None

查看文件

@@ -36,6 +36,8 @@ class SubGridBaseGrid(FDTDGrid, ABC):
# Name of the grid # Name of the grid
self.name = kwargs["id"] self.name = kwargs["id"]
self.parent_grid: FDTDGrid
self.iterations = 0
self.filter = kwargs["filter"] self.filter = kwargs["filter"]

查看文件

@@ -23,6 +23,7 @@ from typing import List, Tuple, Union
import numpy as np import numpy as np
from gprMax.grid.fdtd_grid import FDTDGrid from gprMax.grid.fdtd_grid import FDTDGrid
from gprMax.model import Model
from gprMax.subgrids.grid import SubGridBaseGrid from gprMax.subgrids.grid import SubGridBaseGrid
from gprMax.user_inputs import MainGridUserInput from gprMax.user_inputs import MainGridUserInput
@@ -85,24 +86,24 @@ class SubGridBase(UserObjectMulti):
sg.ny = 2 * sg.n_boundary_cells_y + sg.nwy sg.ny = 2 * sg.n_boundary_cells_y + sg.nwy
sg.nz = 2 * sg.n_boundary_cells_z + sg.nwz sg.nz = 2 * sg.n_boundary_cells_z + sg.nwz
def set_iterations(self, sg: SubGridBaseGrid, main: FDTDGrid): def set_iterations(self, sg: SubGridBaseGrid, model: Model):
"""Sets number of iterations that will take place in the subgrid.""" """Sets number of iterations that will take place in the subgrid."""
sg.iterations = main.iterations * sg.ratio sg.iterations = model.iterations * sg.ratio
def setup(self, sg: SubGridBaseGrid, grid: FDTDGrid, uip: MainGridUserInput): def setup(self, sg: SubGridBaseGrid, model: Model, uip: MainGridUserInput):
""" "Common setup to both all subgrid types.""" """ "Common setup to both all subgrid types."""
p1 = self.kwargs["p1"] p1 = self.kwargs["p1"]
p2 = self.kwargs["p2"] p2 = self.kwargs["p2"]
p1, p2 = uip.check_box_points(p1, p2, self.__str__()) p1, p2 = uip.check_box_points(p1, p2, self.__str__())
self.set_discretisation(sg, grid) self.set_discretisation(sg, model.G)
# Set temporal discretisation including any inherited time step # Set temporal discretisation including any inherited time step
# stability factor from the main grid # stability factor from the main grid
sg.calculate_dt() sg.calculate_dt()
if grid.dt_mod: if model.dt_mod:
sg.dt = sg.dt * grid.dt_mod sg.dt = sg.dt * model.dt_mod
# Set the indices related to the subgrids main grid placement # Set the indices related to the subgrids main grid placement
self.set_main_grid_indices(sg, uip, p1, p2) self.set_main_grid_indices(sg, uip, p1, p2)
@@ -120,29 +121,27 @@ class SubGridBase(UserObjectMulti):
self.set_working_region_cells(sg) self.set_working_region_cells(sg)
self.set_total_cells(sg) self.set_total_cells(sg)
self.set_iterations(sg, grid) self.set_iterations(sg, model)
self.set_name(sg) self.set_name(sg)
# Copy a reference for the main grid to the sub grid # Copy a reference for the main grid to the sub grid
sg.parent_grid = grid sg.parent_grid = model.G
sg.timewindow = grid.timewindow
# Copy a subgrid reference to self so that children.build(grid, uip) # Copy a subgrid reference to self so that children.build(grid, uip)
# can access the correct grid. # can access the correct grid.
self.subgrid = sg self.subgrid = sg
# Copy over built in materials # Copy over built in materials
sg.materials = [copy(m) for m in grid.materials if m.type == "builtin"] sg.materials = [copy(m) for m in model.G.materials if m.type == "builtin"]
# Don't mix and match different subgrid types # Don't mix and match different subgrid types
for sg_made in grid.subgrids: for sg_made in model.subgrids:
if type(sg) != type(sg_made): if type(sg) != type(sg_made):
logger.exception(f"{self.__str__()} please only use one type of subgrid") logger.exception(f"{self.__str__()} please only use one type of subgrid")
raise ValueError raise ValueError
# Reference the subgrid under the main grid to which it belongs # Reference the subgrid under the main grid to which it belongs
grid.subgrids.append(sg) model.subgrids.append(sg)
class SubGridHSG(SubGridBase): class SubGridHSG(SubGridBase):
@@ -199,7 +198,7 @@ class SubGridHSG(SubGridBase):
self.order = 18 self.order = 18
self.hash = "#subgrid_hsg" self.hash = "#subgrid_hsg"
def build(self, grid: FDTDGrid, uip: MainGridUserInput) -> SubGridHSGUser: def build(self, model: Model, uip: MainGridUserInput) -> SubGridHSGUser:
sg = SubGridHSGUser(**self.kwargs) sg = SubGridHSGUser(**self.kwargs)
self.setup(sg, grid, uip) self.setup(sg, model, uip)
return sg return sg