你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-04 11:36:52 +08:00
PEP8 formatting cleanups.
这个提交包含在:
@@ -25,7 +25,7 @@ class GeneralError(ValueError):
|
||||
"""Handles general errors. Subclasses the ValueError class."""
|
||||
|
||||
def __init__(self, message, *args):
|
||||
|
||||
|
||||
self.message = message
|
||||
super(GeneralError, self).__init__(message, *args)
|
||||
print(Fore.RED)
|
||||
@@ -33,9 +33,9 @@ class GeneralError(ValueError):
|
||||
|
||||
class CmdInputError(ValueError):
|
||||
"""Handles errors in user specified commands. Subclasses the ValueError class."""
|
||||
|
||||
|
||||
def __init__(self, message, *args):
|
||||
|
||||
|
||||
self.message = message
|
||||
super(CmdInputError, self).__init__(message, *args)
|
||||
print(Fore.RED)
|
||||
print(Fore.RED)
|
||||
|
@@ -212,9 +212,9 @@ def run_mpi_sim(args, numbermodelruns, inputfile, usernamespace, optparams=None)
|
||||
rank = comm.rank # rank of this process
|
||||
status = MPI.Status() # get MPI status object
|
||||
name = MPI.Get_processor_name() # get name of processor/host
|
||||
|
||||
|
||||
tsimstart = perf_counter()
|
||||
|
||||
|
||||
if rank == 0: # Master process
|
||||
modelrun = 1
|
||||
numworkers = size - 1
|
||||
@@ -381,7 +381,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
||||
else:
|
||||
inputfilestr = '\nInput file not re-processed'
|
||||
print(Fore.GREEN + '{} {}\n'.format(inputfilestr, '-' * (get_terminal_size()[0] - 1 - len(inputfilestr))))
|
||||
|
||||
|
||||
# Clear arrays for field components
|
||||
G.initialise_field_arrays()
|
||||
|
||||
@@ -439,10 +439,10 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
||||
# Start - Main FDTD calculations #
|
||||
####################################
|
||||
tsolvestart = perf_counter()
|
||||
|
||||
|
||||
# Absolute time
|
||||
abstime = 0
|
||||
|
||||
|
||||
for timestep in tqdm(range(G.iterations), desc='Running simulation, model ' + str(modelrun) + ' of ' + str(numbermodelruns), ncols=get_terminal_size()[0] - 1):
|
||||
# Store field component values for every receiver and transmission line
|
||||
store_outputs(timestep, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
||||
@@ -493,7 +493,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
||||
abstime += 0.5 * G.dt
|
||||
|
||||
tsolveend = perf_counter()
|
||||
|
||||
|
||||
# Write an output file in HDF5 format
|
||||
write_hdf5(outputfile, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
||||
|
||||
|
@@ -47,7 +47,7 @@ def process_geometrycmds(geometry, G):
|
||||
tqdmbar = True
|
||||
else:
|
||||
tqdmbar = False
|
||||
|
||||
|
||||
for object in tqdm(geometry, desc='Processing geometry related cmds', unit='cmds', ncols=get_terminal_size()[0] - 1, disable=tqdmbar):
|
||||
tmp = object.split()
|
||||
|
||||
|
@@ -679,7 +679,7 @@ def process_multicmds(multicmds, G):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires type to be either n (normal) or f (fine)')
|
||||
if tmp[10].lower() == 'f' and (dx * G.dx != G.dx or dy * G.dy != G.dy or dz * G.dz != G.dz):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires the spatial discretisation for the geometry view to be the same as the model for geometry view of type f (fine)')
|
||||
|
||||
|
||||
# Set type of geometry file
|
||||
if tmp[10].lower() == 'n':
|
||||
type = '.vti'
|
||||
|
@@ -62,9 +62,9 @@ def process_singlecmds(singlecmds, G):
|
||||
|
||||
# Number of threads (OpenMP) to use
|
||||
cmd = '#num_threads'
|
||||
os.environ['OMP_WAIT_POLICY'] = 'ACTIVE' # What to do with threads when they are waiting
|
||||
os.environ['OMP_DYNAMIC'] = 'FALSE' #
|
||||
os.environ['OMP_PROC_BIND'] = 'TRUE' # Bind threads to physical cores
|
||||
os.environ['OMP_WAIT_POLICY'] = 'ACTIVE' # What to do with threads when they are waiting
|
||||
os.environ['OMP_DYNAMIC'] = 'FALSE'
|
||||
os.environ['OMP_PROC_BIND'] = 'TRUE' # Bind threads to physical cores
|
||||
|
||||
if singlecmds[cmd] != 'None':
|
||||
tmp = tuple(int(x) for x in singlecmds[cmd].split())
|
||||
@@ -115,15 +115,13 @@ def process_singlecmds(singlecmds, G):
|
||||
raise CmdInputError(cmd + ' requires at least one cell in every dimension')
|
||||
if G.messages:
|
||||
print('Domain size: {:g} x {:g} x {:g}m ({:d} x {:d} x {:d} = {:g} cells)'.format(tmp[0], tmp[1], tmp[2], G.nx, G.ny, G.nz, (G.nx * G.ny * G.nz)))
|
||||
|
||||
# Estimate memory (RAM) usage
|
||||
# Currently this is a pretty loose estimate but seems to match reasonably with memory usage reported when model completes.
|
||||
|
||||
# Estimate memory (RAM) usage (currently this is a pretty loose estimate but seems to match reasonably with memory usage reported when model completes)
|
||||
memestimate = (((G.nx + 1) * (G.ny + 1) * (G.nz + 1) * 13 * np.dtype(floattype).itemsize + (G.nx + 1) * (G.ny + 1) * (G.nz + 1) * 18) * 1.1) + 30e6
|
||||
if memestimate > psutil.virtual_memory().total:
|
||||
raise GeneralError('Estimated memory (RAM) required ~{} exceeds {} available!\n'.format(human_size(memestimate), human_size(psutil.virtual_memory().total)))
|
||||
if G.messages:
|
||||
print('Memory (RAM) required: ~{} ({} detected)'.format(human_size(memestimate), human_size(psutil.virtual_memory().total)))
|
||||
|
||||
|
||||
# Time step CFL limit (use either 2D or 3D) and default PML thickness
|
||||
if G.nx == 1:
|
||||
|
@@ -144,7 +144,7 @@ def process_materials(G):
|
||||
|
||||
Args:
|
||||
G (class): Grid class instance - holds essential parameters describing the model.
|
||||
|
||||
|
||||
Returns:
|
||||
materialsdata (list): List of material IDs, names, and properties to print a table.
|
||||
"""
|
||||
|
@@ -44,7 +44,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
|
||||
"""
|
||||
|
||||
tsimstart = perf_counter()
|
||||
|
||||
|
||||
if numbermodelruns > 1:
|
||||
raise CmdInputError('When a Taguchi optimisation is being carried out the number of model runs argument is not required')
|
||||
|
||||
@@ -139,7 +139,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
|
||||
|
||||
# Rename confirmation experiment output file so that it is retained for each iteraction
|
||||
os.rename(outputfile, os.path.splitext(outputfile)[0] + '_final' + str(iteration + 1) + '.out')
|
||||
|
||||
|
||||
print(Fore.GREEN + '\nTaguchi optimisation, iteration {} completed. History of optimal parameter values {} and of fitness values {}'.format(iteration + 1, dict(optparamshist), fitnessvalueshist) + Style.RESET_ALL)
|
||||
iteration += 1
|
||||
|
||||
@@ -157,7 +157,7 @@ def run_opt_sim(args, numbermodelruns, inputfile, usernamespace):
|
||||
break
|
||||
|
||||
tsimend = perf_counter()
|
||||
|
||||
|
||||
# Save optimisation parameters history and fitness values history to file
|
||||
opthistfile = inputfileparts[0] + '_hist.pickle'
|
||||
with open(opthistfile, 'wb') as f:
|
||||
|
@@ -27,13 +27,14 @@ import textwrap
|
||||
from colorama import init, Fore, Style
|
||||
init()
|
||||
|
||||
|
||||
def logo(version):
|
||||
"""Print gprMax logo, version, and licencing/copyright information.
|
||||
|
||||
Args:
|
||||
version (str): Version number.
|
||||
"""
|
||||
|
||||
|
||||
description = '\n=== Electromagnetic modelling software based on the Finite-Difference Time-Domain (FDTD) method'
|
||||
copyright = 'Copyright (C) 2015-2016: The University of Edinburgh'
|
||||
authors = 'Authors: Craig Warren and Antonis Giannopoulos'
|
||||
@@ -46,7 +47,7 @@ def logo(version):
|
||||
/ _` | '_ \| '__| |\/| |/ _` \ \/ /
|
||||
| (_| | |_) | | | | | | (_| |> <
|
||||
\__, | .__/|_| |_| |_|\__,_/_/\_\\
|
||||
|___/|_|
|
||||
|___/|_|
|
||||
v""" + version
|
||||
|
||||
print('{} {}\n'.format(description, '=' * (get_terminal_size()[0] - len(description) - 1)))
|
||||
@@ -148,11 +149,7 @@ def get_machine_cpu_os():
|
||||
allcpuinfo = subprocess.check_output("cat /proc/cpuinfo", shell=True).decode('utf-8').strip()
|
||||
for line in allcpuinfo.split('\n'):
|
||||
if 'model name' in line:
|
||||
cpuID = re.sub( '.*model name.*:', '', line, 1)
|
||||
cpuID = re.sub('.*model name.*:', '', line, 1)
|
||||
osversion = 'Linux (' + platform.release() + ')'
|
||||
|
||||
return machineID, cpuID, osversion
|
||||
|
||||
|
||||
|
||||
|
||||
|
在新工单中引用
屏蔽一个用户