你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
move print checking
这个提交包含在:
@@ -69,6 +69,16 @@ from .utilities import open_path_file
|
|||||||
from .utilities import round32
|
from .utilities import round32
|
||||||
from .utilities import timer
|
from .utilities import timer
|
||||||
|
|
||||||
|
class Printer():
|
||||||
|
|
||||||
|
def __init__(self, sim_conf):
|
||||||
|
self.printing = sim_conf.general['messages']
|
||||||
|
|
||||||
|
def print(self, str):
|
||||||
|
if self.printing:
|
||||||
|
print(str)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_model(solver, sim_config, model_config):
|
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.
|
"""Runs a model - processes the input file; builds the Yee cells; calculates update coefficients; runs main FDTD loop.
|
||||||
@@ -86,14 +96,15 @@ def run_model(solver, sim_config, model_config):
|
|||||||
tsolve (int): Length of time (seconds) of main FDTD calculations
|
tsolve (int): Length of time (seconds) of main FDTD calculations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
printer = Printer(model_config)
|
||||||
|
|
||||||
# Monitor memory usage
|
# Monitor memory usage
|
||||||
p = psutil.Process()
|
p = psutil.Process()
|
||||||
|
|
||||||
# Normal model reading/building process; bypassed if geometry information to be reused
|
# Normal model reading/building process; bypassed if geometry information to be reused
|
||||||
if not sim_config.geometry_fixed:
|
if not sim_config.geometry_fixed:
|
||||||
|
|
||||||
if sim_config.general['messages']:
|
printer.print(Fore.GREEN + '{} {}\n'.format(model_config.inputfilestr, '-' * (get_terminal_width() - 1 - len(model_config.inputfilestr))) + Style.RESET_ALL)
|
||||||
print(Fore.GREEN + '{} {}\n'.format(model_config.inputfilestr, '-' * (get_terminal_width() - 1 - len(model_config.inputfilestr))) + Style.RESET_ALL)
|
|
||||||
|
|
||||||
G = solver.G
|
G = solver.G
|
||||||
|
|
||||||
@@ -110,8 +121,7 @@ def run_model(solver, sim_config, model_config):
|
|||||||
scene.create_internal_objects(G)
|
scene.create_internal_objects(G)
|
||||||
|
|
||||||
# print PML information
|
# print PML information
|
||||||
if config.general['messages']:
|
printer.print(pml_information(G))
|
||||||
print(pml_information(G))
|
|
||||||
|
|
||||||
# build the PMLS
|
# build the PMLS
|
||||||
pbar = tqdm(total=sum(1 for value in G.pmlthickness.values() if value > 0), desc='Building PML boundaries', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars'])
|
pbar = tqdm(total=sum(1 for value in G.pmlthickness.values() if value > 0), desc='Building PML boundaries', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars'])
|
||||||
@@ -123,7 +133,7 @@ def run_model(solver, sim_config, model_config):
|
|||||||
|
|
||||||
# Build the model, i.e. set the material properties (ID) for every edge
|
# Build the model, i.e. set the material properties (ID) for every edge
|
||||||
# of every Yee cell
|
# of every Yee cell
|
||||||
if config.general['messages']: print()
|
printer.print('')
|
||||||
pbar = tqdm(total=2, desc='Building main grid', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars'])
|
pbar = tqdm(total=2, desc='Building main grid', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars'])
|
||||||
build_electric_components(G.solid, G.rigidE, G.ID, G)
|
build_electric_components(G.solid, G.rigidE, G.ID, G)
|
||||||
pbar.update()
|
pbar.update()
|
||||||
@@ -173,8 +183,7 @@ def run_model(solver, sim_config, model_config):
|
|||||||
# Update estimated memory (RAM) usage
|
# Update estimated memory (RAM) usage
|
||||||
G.memoryusage += int(3 * config.materials['maxpoles'] * (G.nx + 1) * (G.ny + 1) * (G.nz + 1) * np.dtype(config.materials['dispersivedtype']).itemsize)
|
G.memoryusage += int(3 * config.materials['maxpoles'] * (G.nx + 1) * (G.ny + 1) * (G.nz + 1) * np.dtype(config.materials['dispersivedtype']).itemsize)
|
||||||
G.memory_check()
|
G.memory_check()
|
||||||
if config.general['messages']:
|
printer.print('\nMemory (RAM) required - updated (dispersive): ~{}\n'.format(human_size(G.memoryusage)))
|
||||||
print('\nMemory (RAM) required - updated (dispersive): ~{}\n'.format(human_size(G.memoryusage)))
|
|
||||||
|
|
||||||
G.initialise_dispersive_arrays(config.materials['dispersivedtype'])
|
G.initialise_dispersive_arrays(config.materials['dispersivedtype'])
|
||||||
|
|
||||||
@@ -186,29 +195,29 @@ def run_model(solver, sim_config, model_config):
|
|||||||
snapsmemsize += (2 * snap.datasizefield)
|
snapsmemsize += (2 * snap.datasizefield)
|
||||||
G.memoryusage += int(snapsmemsize)
|
G.memoryusage += int(snapsmemsize)
|
||||||
G.memory_check(snapsmemsize=int(snapsmemsize))
|
G.memory_check(snapsmemsize=int(snapsmemsize))
|
||||||
if config.general['messages']:
|
|
||||||
print('\nMemory (RAM) required - updated (snapshots): ~{}\n'.format(human_size(G.memoryusage)))
|
printer.print('\nMemory (RAM) required - updated (snapshots): ~{}\n'.format(human_size(G.memoryusage)))
|
||||||
|
|
||||||
# Process complete list of materials - calculate update coefficients,
|
# Process complete list of materials - calculate update coefficients,
|
||||||
# store in arrays, and build text list of materials/properties
|
# store in arrays, and build text list of materials/properties
|
||||||
materialsdata = process_materials(G)
|
materialsdata = process_materials(G)
|
||||||
if config.general['messages']:
|
|
||||||
print('\nMaterials:')
|
|
||||||
materialstable = SingleTable(materialsdata)
|
materialstable = SingleTable(materialsdata)
|
||||||
materialstable.outer_border = False
|
materialstable.outer_border = False
|
||||||
materialstable.justify_columns[0] = 'right'
|
materialstable.justify_columns[0] = 'right'
|
||||||
print(materialstable.table)
|
|
||||||
|
printer.print('\nMaterials:')
|
||||||
|
printer.print(materialstable.table)
|
||||||
|
|
||||||
# Check to see if numerical dispersion might be a problem
|
# Check to see if numerical dispersion might be a problem
|
||||||
results = dispersion_analysis(G)
|
results = dispersion_analysis(G)
|
||||||
if results['error'] and config.general['messages']:
|
if results['error']:
|
||||||
print(Fore.RED + "\nWARNING: Numerical dispersion analysis not carried out as {}".format(results['error']) + Style.RESET_ALL)
|
printer.print(Fore.RED + "\nWARNING: Numerical dispersion analysis not carried out as {}".format(results['error']) + Style.RESET_ALL)
|
||||||
elif results['N'] < config.numdispersion['mingridsampling']:
|
elif results['N'] < config.numdispersion['mingridsampling']:
|
||||||
raise GeneralError("Non-physical wave propagation: Material '{}' has wavelength sampled by {} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {:g}Hz".format(results['material'].ID, results['N'], results['maxfreq']))
|
raise GeneralError("Non-physical wave propagation: Material '{}' has wavelength sampled by {} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {:g}Hz".format(results['material'].ID, results['N'], results['maxfreq']))
|
||||||
elif results['deltavp'] and np.abs(results['deltavp']) > config.numdispersion['maxnumericaldisp'] and config.general['messages']:
|
elif results['deltavp'] and np.abs(results['deltavp']) > config.numdispersion['maxnumericaldisp']:
|
||||||
print(Fore.RED + "\nWARNING: Potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']) + Style.RESET_ALL)
|
printer.print(Fore.RED + "\nWARNING: Potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']) + Style.RESET_ALL)
|
||||||
elif results['deltavp'] and config.general['messages']:
|
elif results['deltavp']:
|
||||||
print("\nNumerical dispersion analysis: estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']))
|
printer.print("\nNumerical dispersion analysis: estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']))
|
||||||
|
|
||||||
disp_a = update_f.format(model_config.poles, 'A', model_config.precision, model_config.dispersion_type)
|
disp_a = update_f.format(model_config.poles, 'A', model_config.precision, model_config.dispersion_type)
|
||||||
|
|
||||||
@@ -219,8 +228,7 @@ def run_model(solver, sim_config, model_config):
|
|||||||
# If geometry information to be reused between model runs
|
# If geometry information to be reused between model runs
|
||||||
else:
|
else:
|
||||||
inputfilestr = '\n--- Model {}/{}, input file (not re-processed, i.e. geometry fixed): {}'.format(currentmodelrun, modelend, inputfile.name)
|
inputfilestr = '\n--- Model {}/{}, input file (not re-processed, i.e. geometry fixed): {}'.format(currentmodelrun, modelend, inputfile.name)
|
||||||
if config.general['messages']:
|
printer.print(Fore.GREEN + '{} {}\n'.format(inputfilestr, '-' * (get_terminal_width() - 1 - len(inputfilestr))) + Style.RESET_ALL)
|
||||||
print(Fore.GREEN + '{} {}\n'.format(inputfilestr, '-' * (get_terminal_width() - 1 - len(inputfilestr))) + Style.RESET_ALL)
|
|
||||||
|
|
||||||
# Clear arrays for field components
|
# Clear arrays for field components
|
||||||
G.initialise_field_arrays()
|
G.initialise_field_arrays()
|
||||||
@@ -270,12 +278,9 @@ def run_model(solver, sim_config, model_config):
|
|||||||
# Check and set output directory and filename
|
# Check and set output directory and filename
|
||||||
if not os.path.isdir(config.outputfilepath):
|
if not os.path.isdir(config.outputfilepath):
|
||||||
os.mkdir(config.outputfilepath)
|
os.mkdir(config.outputfilepath)
|
||||||
if config.general['messages']:
|
printer.print('\nCreated output directory: {}'.format(config.outputfilepath))
|
||||||
print('\nCreated output directory: {}'.format(config.outputfilepath))
|
|
||||||
outputfile = os.path.join(config.outputfilepath, os.path.splitext(os.path.split(config.inputfilepath)[1])[0] + appendmodelnumber + '.out')
|
outputfile = os.path.join(config.outputfilepath, os.path.splitext(os.path.split(config.inputfilepath)[1])[0] + appendmodelnumber + '.out')
|
||||||
if config.general['messages']:
|
printer.print('\nOutput file: {}\n'.format(outputfile))
|
||||||
print('\nOutput file: {}\n'.format(outputfile))
|
|
||||||
|
|
||||||
# Main FDTD solving functions for either CPU or GPU
|
# Main FDTD solving functions for either CPU or GPU
|
||||||
if config.cuda['gpus'] is None:
|
if config.cuda['gpus'] is None:
|
||||||
tsolve = solve_cpu(currentmodelrun, modelend, G)
|
tsolve = solve_cpu(currentmodelrun, modelend, G)
|
||||||
@@ -300,12 +305,11 @@ def run_model(solver, sim_config, model_config):
|
|||||||
pbar.close()
|
pbar.close()
|
||||||
if config.general['messages']: print()
|
if config.general['messages']: print()
|
||||||
|
|
||||||
if config.general['messages']:
|
|
||||||
memGPU = ''
|
memGPU = ''
|
||||||
if config.cuda['gpus']:
|
if config.cuda['gpus']:
|
||||||
memGPU = ' host + ~{} GPU'.format(human_size(memsolve))
|
memGPU = ' host + ~{} GPU'.format(human_size(memsolve))
|
||||||
print('\nMemory (RAM) used: ~{}{}'.format(human_size(p.memory_full_info().uss), memGPU))
|
printer.print('\nMemory (RAM) used: ~{}{}'.format(human_size(p.memory_full_info().uss), memGPU))
|
||||||
print('Solving time [HH:MM:SS]: {}'.format(datetime.timedelta(seconds=tsolve)))
|
printer.print('Solving time [HH:MM:SS]: {}'.format(datetime.timedelta(seconds=tsolve)))
|
||||||
|
|
||||||
# If geometry information to be reused between model runs then FDTDGrid
|
# If geometry information to be reused between model runs then FDTDGrid
|
||||||
# class instance must be global so that it persists
|
# class instance must be global so that it persists
|
||||||
|
在新工单中引用
屏蔽一个用户