你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 23:14:03 +08:00
Added taskid for job arrays to api function.
Better printing of user namespace dictionary - doesn't print all the __builtins__ Source and receiver steps now stored as a tuple (x, y, z). Added writing of any geometry objects.
这个提交包含在:
@@ -36,6 +36,7 @@ from tqdm import tqdm
|
|||||||
from ._version import __version__
|
from ._version import __version__
|
||||||
from .constants import c, e0, m0, z0
|
from .constants import c, e0, m0, z0
|
||||||
from .exceptions import GeneralError
|
from .exceptions import GeneralError
|
||||||
|
from .fields_outputs import write_hdf5_outputfile
|
||||||
from .fields_update import update_electric, update_magnetic, update_electric_dispersive_multipole_A, update_electric_dispersive_multipole_B, update_electric_dispersive_1pole_A, update_electric_dispersive_1pole_B
|
from .fields_update import update_electric, update_magnetic, update_electric_dispersive_multipole_A, update_electric_dispersive_multipole_B, update_electric_dispersive_1pole_A, update_electric_dispersive_1pole_B
|
||||||
from .grid import FDTDGrid, dispersion_check
|
from .grid import FDTDGrid, dispersion_check
|
||||||
from .input_cmds_geometry import process_geometrycmds
|
from .input_cmds_geometry import process_geometrycmds
|
||||||
@@ -46,7 +47,6 @@ from .materials import Material, process_materials
|
|||||||
from .pml import build_pmls
|
from .pml import build_pmls
|
||||||
from .receivers import store_outputs
|
from .receivers import store_outputs
|
||||||
from .utilities import logo, human_size, get_machine_cpu_os, get_terminal_width
|
from .utilities import logo, human_size, get_machine_cpu_os, get_terminal_width
|
||||||
from .writer_hdf5 import write_hdf5
|
|
||||||
from .yee_cell_build import build_electric_components, build_magnetic_components
|
from .yee_cell_build import build_electric_components, build_magnetic_components
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ def main():
|
|||||||
run_main(args)
|
run_main(args)
|
||||||
|
|
||||||
|
|
||||||
def api(inputfile, n=1, mpi=False, benchmark=False, geometry_only=False, geometry_fixed=False, write_processed=False, opt_taguchi=False):
|
def api(inputfile, n=1, mpi=False, taskid=False, benchmark=False, geometry_only=False, geometry_fixed=False, write_processed=False, opt_taguchi=False):
|
||||||
"""If installed as a module this is the entry point."""
|
"""If installed as a module this is the entry point."""
|
||||||
|
|
||||||
class ImportArguments:
|
class ImportArguments:
|
||||||
@@ -177,7 +177,7 @@ def run_job_array_sim(args, numbermodelruns, inputfile, usernamespace, optparams
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
modelrun = args.taskid
|
modelrun = args.taskid
|
||||||
|
|
||||||
tsimstart = perf_counter()
|
tsimstart = perf_counter()
|
||||||
if optparams: # If Taguchi optimistaion, add specific value for each parameter to optimise for each experiment to user accessible namespace
|
if optparams: # If Taguchi optimistaion, add specific value for each parameter to optimise for each experiment to user accessible namespace
|
||||||
tmp = {}
|
tmp = {}
|
||||||
@@ -336,11 +336,17 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
|
|
||||||
# Add the current model run to namespace that can be accessed by user in any Python code blocks in input file
|
# Add the current model run to namespace that can be accessed by user in any Python code blocks in input file
|
||||||
usernamespace['current_model_run'] = modelrun
|
usernamespace['current_model_run'] = modelrun
|
||||||
print('Constants/variables available for Python scripting: {}\n'.format(usernamespace))
|
|
||||||
|
|
||||||
# Read input file and process any Python or include commands
|
# Read input file and process any Python or include commands
|
||||||
processedlines = process_python_include_code(inputfile, usernamespace)
|
processedlines = process_python_include_code(inputfile, usernamespace)
|
||||||
|
|
||||||
|
# Print constants/variables in user-accessable namespace
|
||||||
|
uservars = ''
|
||||||
|
for key, value in sorted(usernamespace.items()):
|
||||||
|
if key != '__builtins__':
|
||||||
|
uservars += '{}: {}, '.format(key, value)
|
||||||
|
print('Constants/variables used/available for Python scripting: {{{}}}\n'.format(uservars[:-2]))
|
||||||
|
|
||||||
# Write a file containing the input commands after Python or include commands have been processed
|
# Write a file containing the input commands after Python or include commands have been processed
|
||||||
if args.write_processed:
|
if args.write_processed:
|
||||||
write_processed_file(inputfile, modelrun, numbermodelruns, processedlines)
|
write_processed_file(inputfile, modelrun, numbermodelruns, processedlines)
|
||||||
@@ -357,7 +363,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
m = Material(0, 'pec')
|
m = Material(0, 'pec')
|
||||||
m.se = float('inf')
|
m.se = float('inf')
|
||||||
m.type = 'builtin'
|
m.type = 'builtin'
|
||||||
m.average = False
|
m.averagable = False
|
||||||
G.materials.append(m)
|
G.materials.append(m)
|
||||||
m = Material(1, 'free_space')
|
m = Material(1, 'free_space')
|
||||||
m.type = 'builtin'
|
m.type = 'builtin'
|
||||||
@@ -414,7 +420,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
# Check to see if numerical dispersion might be a problem
|
# Check to see if numerical dispersion might be a problem
|
||||||
resolution = dispersion_check(G)
|
resolution = dispersion_check(G)
|
||||||
if resolution and max((G.dx, G.dy, G.dz)) > resolution:
|
if resolution and max((G.dx, G.dy, G.dz)) > resolution:
|
||||||
print(Fore.RED + '\nWARNING: Potential numerical dispersion in the simulation. Check the spatial discretisation against the smallest wavelength present. Suggested resolution should be less than {:g}m'.format(resolution) + Style.RESET_ALL)
|
print(Fore.RED + '\nWARNING: Potential numerical dispersion in the simulation. Check the spatial discretisation against the smallest wavelength present. Suggested resolution <{:g}m'.format(resolution) + Style.RESET_ALL)
|
||||||
|
|
||||||
# If geometry information to be reused between model runs
|
# If geometry information to be reused between model runs
|
||||||
else:
|
else:
|
||||||
@@ -429,27 +435,27 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
pml.initialise_field_arrays()
|
pml.initialise_field_arrays()
|
||||||
|
|
||||||
# Adjust position of simple sources and receivers if required
|
# Adjust position of simple sources and receivers if required
|
||||||
if G.srcstepx > 0 or G.srcstepy > 0 or G.srcstepz > 0:
|
if G.srcsteps[0] > 0 or G.srcsteps[1] > 0 or G.srcsteps[2] > 0:
|
||||||
for source in itertools.chain(G.hertziandipoles, G.magneticdipoles):
|
for source in itertools.chain(G.hertziandipoles, G.magneticdipoles):
|
||||||
if modelrun == 1:
|
if modelrun == 1:
|
||||||
if source.xcoord + G.srcstepx * (numbermodelruns - 1) > G.nx or source.ycoord + G.srcstepy * (numbermodelruns - 1) > G.ny or source.zcoord + G.srcstepz * (numbermodelruns - 1) > G.nz:
|
if source.xcoord + G.srcsteps[0] * (numbermodelruns - 1) > G.nx or source.ycoord + G.srcsteps[1] * (numbermodelruns - 1) > G.ny or source.zcoord + G.srcsteps[2] * (numbermodelruns - 1) > G.nz:
|
||||||
raise GeneralError('Source(s) will be stepped to a position outside the domain.')
|
raise GeneralError('Source(s) will be stepped to a position outside the domain.')
|
||||||
source.xcoord = source.xcoordbase + (modelrun - 1) * G.srcstepx
|
source.xcoord = source.xcoordbase + (modelrun - 1) * G.srcsteps[0]
|
||||||
source.ycoord = source.ycoordbase + (modelrun - 1) * G.srcstepy
|
source.ycoord = source.ycoordbase + (modelrun - 1) * G.srcsteps[1]
|
||||||
source.zcoord = source.zcoordbase + (modelrun - 1) * G.srcstepz
|
source.zcoord = source.zcoordbase + (modelrun - 1) * G.srcsteps[2]
|
||||||
if G.rxstepx > 0 or G.rxstepy > 0 or G.rxstepz > 0:
|
if G.rxsteps[0] > 0 or G.rxsteps[1] > 0 or G.rxsteps[2] > 0:
|
||||||
for receiver in G.rxs:
|
for receiver in G.rxs:
|
||||||
if modelrun == 1:
|
if modelrun == 1:
|
||||||
if receiver.xcoord + G.rxstepx * (numbermodelruns - 1) > G.nx or receiver.ycoord + G.rxstepy * (numbermodelruns - 1) > G.ny or receiver.zcoord + G.rxstepz * (numbermodelruns - 1) > G.nz:
|
if receiver.xcoord + G.rxsteps[0] * (numbermodelruns - 1) > G.nx or receiver.ycoord + G.rxsteps[1] * (numbermodelruns - 1) > G.ny or receiver.zcoord + G.rxsteps[2] * (numbermodelruns - 1) > G.nz:
|
||||||
raise GeneralError('Receiver(s) will be stepped to a position outside the domain.')
|
raise GeneralError('Receiver(s) will be stepped to a position outside the domain.')
|
||||||
receiver.xcoord = receiver.xcoordbase + (modelrun - 1) * G.rxstepx
|
receiver.xcoord = receiver.xcoordbase + (modelrun - 1) * G.rxsteps[0]
|
||||||
receiver.ycoord = receiver.ycoordbase + (modelrun - 1) * G.rxstepy
|
receiver.ycoord = receiver.ycoordbase + (modelrun - 1) * G.rxsteps[1]
|
||||||
receiver.zcoord = receiver.zcoordbase + (modelrun - 1) * G.rxstepz
|
receiver.zcoord = receiver.zcoordbase + (modelrun - 1) * G.rxsteps[2]
|
||||||
|
|
||||||
# Write files for any geometry views
|
# Write files for any geometry views and geometry object outputs
|
||||||
if not G.geometryviews and args.geometry_only:
|
if not (G.geometryviews or G.geometryobjectswrite) and args.geometry_only:
|
||||||
raise GeneralError('No geometry views found.')
|
raise GeneralError('No geometry views or geometry objects to output found.')
|
||||||
elif G.geometryviews:
|
if G.geometryviews:
|
||||||
print()
|
print()
|
||||||
for i, geometryview in enumerate(G.geometryviews):
|
for i, geometryview in enumerate(G.geometryviews):
|
||||||
geometryview.set_filename(modelrun, numbermodelruns, G)
|
geometryview.set_filename(modelrun, numbermodelruns, G)
|
||||||
@@ -457,7 +463,9 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
pbar = tqdm(total=geoiters, unit='byte', unit_scale=True, desc='Writing geometry file {} of {}, {}'.format(i + 1, len(G.geometryviews), os.path.split(geometryview.filename)[1]), ncols=get_terminal_width() - 1, file=sys.stdout, disable=G.tqdmdisable)
|
pbar = tqdm(total=geoiters, unit='byte', unit_scale=True, desc='Writing geometry file {} of {}, {}'.format(i + 1, len(G.geometryviews), os.path.split(geometryview.filename)[1]), ncols=get_terminal_width() - 1, file=sys.stdout, disable=G.tqdmdisable)
|
||||||
geometryview.write_vtk(modelrun, numbermodelruns, G, pbar)
|
geometryview.write_vtk(modelrun, numbermodelruns, G, pbar)
|
||||||
pbar.close()
|
pbar.close()
|
||||||
# geometryview.write_xdmf(modelrun, numbermodelruns, G)
|
if G.geometryobjectswrite:
|
||||||
|
for geometryobject in G.geometryobjectswrite:
|
||||||
|
geometryobject.write_hdf5(G)
|
||||||
|
|
||||||
# Run simulation (if not doing geometry only)
|
# Run simulation (if not doing geometry only)
|
||||||
if not args.geometry_only:
|
if not args.geometry_only:
|
||||||
@@ -536,7 +544,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
|||||||
tsolveend = perf_counter()
|
tsolveend = perf_counter()
|
||||||
|
|
||||||
# Write an output file in HDF5 format
|
# Write an output file in HDF5 format
|
||||||
write_hdf5(outputfile, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
write_hdf5_outputfile(outputfile, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
||||||
|
|
||||||
if G.messages:
|
if G.messages:
|
||||||
print('Memory (RAM) used: ~{}'.format(human_size(p.memory_info().rss)))
|
print('Memory (RAM) used: ~{}'.format(human_size(p.memory_info().rss)))
|
||||||
|
在新工单中引用
屏蔽一个用户