你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
model build run class
这个提交包含在:
@@ -78,36 +78,30 @@ class Printer():
|
||||
if self.printing:
|
||||
print(str)
|
||||
|
||||
class ModelBuildRun:
|
||||
|
||||
def __init__(self, solver, sim_config, model_config):
|
||||
self.solver = solver
|
||||
self.sim_config = sim_config
|
||||
self.model_config = model_config
|
||||
self.G = solver.get_G()
|
||||
|
||||
def run_model(solver, sim_config, model_config):
|
||||
"""Runs a model - processes the input file; builds the Yee cells; calculates update coefficients; runs main FDTD loop.
|
||||
def tm_grid_update(self):
|
||||
if '2D TMx' in self.model_config.mode:
|
||||
self.G.tmx()
|
||||
elif '2D TMy' in self.model_config.mode:
|
||||
self.G.tmy()
|
||||
elif '2D TMz' in self.model_config.mode:
|
||||
self.G.tmz()
|
||||
|
||||
Args:
|
||||
args (dict): Namespace with command line arguments
|
||||
currentmodelrun (int): Current model run number.
|
||||
modelend (int): Number of last model to run.
|
||||
numbermodelruns (int): Total number of model runs.
|
||||
inputfile (object): File object for the input file.
|
||||
usernamespace (dict): Namespace that can be accessed by user
|
||||
in any Python code blocks in input file.
|
||||
|
||||
Returns:
|
||||
tsolve (int): Length of time (seconds) of main FDTD calculations
|
||||
"""
|
||||
def build_geometry(self):
|
||||
model_config = self.model_config
|
||||
sim_config = self.sim_config
|
||||
G = self.G
|
||||
|
||||
printer = Printer(sim_config)
|
||||
|
||||
# Monitor memory usage
|
||||
p = psutil.Process()
|
||||
|
||||
# Normal model reading/building process; bypassed if geometry information to be reused
|
||||
if not sim_config.geometry_fixed:
|
||||
|
||||
printer.print(model_config.next_model)
|
||||
|
||||
G = solver.get_G()
|
||||
|
||||
# api for multiple scenes / model runs
|
||||
try:
|
||||
scene = model_config.get_scene()
|
||||
@@ -141,26 +135,8 @@ def run_model(solver, sim_config, model_config):
|
||||
pbar.update()
|
||||
pbar.close()
|
||||
|
||||
# Add PEC boundaries to invariant direction in 2D modes
|
||||
# N.B. 2D modes are a single cell slice of 3D grid
|
||||
if '2D TMx' in config.mode:
|
||||
# Ey & Ez components
|
||||
G.ID[1, 0, :, :] = 0
|
||||
G.ID[1, 1, :, :] = 0
|
||||
G.ID[2, 0, :, :] = 0
|
||||
G.ID[2, 1, :, :] = 0
|
||||
elif '2D TMy' in config.mode:
|
||||
# Ex & Ez components
|
||||
G.ID[0, :, 0, :] = 0
|
||||
G.ID[0, :, 1, :] = 0
|
||||
G.ID[2, :, 0, :] = 0
|
||||
G.ID[2, :, 1, :] = 0
|
||||
elif '2D TMz' in config.mode:
|
||||
# Ex & Ey components
|
||||
G.ID[0, :, :, 0] = 0
|
||||
G.ID[0, :, :, 1] = 0
|
||||
G.ID[1, :, :, 0] = 0
|
||||
G.ID[1, :, :, 1] = 0
|
||||
# update grid for tm modes
|
||||
tm_grid_update(model_config)
|
||||
|
||||
# Process any voltage sources (that have resistance) to create a new
|
||||
# material at the source location
|
||||
@@ -224,9 +200,8 @@ def run_model(solver, sim_config, model_config):
|
||||
# set the dispersive update functions based on the model configuration
|
||||
solver.updates.set_dispersive_updates(model_config)
|
||||
|
||||
|
||||
# If geometry information to be reused between model runs
|
||||
else:
|
||||
def reuse_geometry(self):
|
||||
printer = Printer(model_config)
|
||||
inputfilestr = '\n--- Model {}/{}, input file (not re-processed, i.e. geometry fixed): {}'.format(currentmodelrun, modelend, model_config.input_file_path)
|
||||
printer.print(Fore.GREEN + '{} {}\n'.format(model_config.inputfilestr, '-' * (get_terminal_width() - 1 - len(model_config.inputfilestr))) + Style.RESET_ALL)
|
||||
|
||||
@@ -237,6 +212,30 @@ def run_model(solver, sim_config, model_config):
|
||||
for pml in G.pmls:
|
||||
pml.initialise_field_arrays()
|
||||
|
||||
def build(self):
|
||||
"""Runs a model - processes the input file; builds the Yee cells; calculates update coefficients; runs main FDTD loop.
|
||||
|
||||
Args:
|
||||
args (dict): Namespace with command line arguments
|
||||
currentmodelrun (int): Current model run number.
|
||||
modelend (int): Number of last model to run.
|
||||
numbermodelruns (int): Total number of model runs.
|
||||
inputfile (object): File object for the input file.
|
||||
usernamespace (dict): Namespace that can be accessed by user
|
||||
in any Python code blocks in input file.
|
||||
|
||||
Returns:
|
||||
tsolve (int): Length of time (seconds) of main FDTD calculations
|
||||
"""
|
||||
# Monitor memory usage
|
||||
p = psutil.Process()
|
||||
|
||||
# Normal model reading/building process; bypassed if geometry information to be reused
|
||||
if not self.sim_config.geometry_fixed:
|
||||
self.build_geometry()
|
||||
else:
|
||||
self.reuse_geometry()
|
||||
|
||||
# Adjust position of simple sources and receivers if required
|
||||
if G.srcsteps[0] != 0 or G.srcsteps[1] != 0 or G.srcsteps[2] != 0:
|
||||
for source in itertools.chain(G.hertziandipoles, G.magneticdipoles):
|
||||
@@ -273,8 +272,9 @@ def run_model(solver, sim_config, model_config):
|
||||
if args.geometry_only:
|
||||
tsolve = 0
|
||||
|
||||
# Run simulation
|
||||
else:
|
||||
|
||||
def run_model(self):
|
||||
|
||||
# Check and set output directory and filename
|
||||
if not os.path.isdir(config.outputfilepath):
|
||||
os.mkdir(config.outputfilepath)
|
||||
@@ -311,14 +311,9 @@ def run_model(solver, sim_config, model_config):
|
||||
printer.print('\nMemory (RAM) used: ~{}{}'.format(human_size(p.memory_full_info().uss), memGPU))
|
||||
printer.print('Solving time [HH:MM:SS]: {}'.format(datetime.timedelta(seconds=tsolve)))
|
||||
|
||||
# If geometry information to be reused between model runs then FDTDGrid
|
||||
# class instance must be global so that it persists
|
||||
if not args.geometry_fixed:
|
||||
del G
|
||||
|
||||
return tsolve
|
||||
|
||||
|
||||
def solve_cpu(solver, sim_config, model_config):
|
||||
"""
|
||||
Solving using FDTD method on CPU. Parallelised using Cython (OpenMP) for
|
||||
|
在新工单中引用
屏蔽一个用户