Whitespace cleanups.

这个提交包含在:
Craig Warren
2016-07-21 16:17:39 +01:00
父节点 e677162d7a
当前提交 e8ebd1498f
共有 15 个文件被更改,包括 147 次插入175 次删除

查看文件

@@ -16,10 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
class GeneralError(ValueError):
"""Handles general errors. Subclasses the ValueError class."""
pass
class CmdInputError(ValueError):
"""Handles errors in user specified commands. Subclasses the ValueError class."""
pass

查看文件

@@ -244,7 +244,6 @@ class GeometryView(object):
self.write_gprmax_info(f, G, materialsonly=True)
def write_gprmax_info(self, f, G, materialsonly=False):
"""Writes gprMax specific information relating material, source, and receiver names to numeric identifiers.

查看文件

@@ -63,6 +63,7 @@ class Grid(object):
co = round_value(float(val) / getattr(self, 'd' + coord))
return co
class FDTDGrid(Grid):
"""Holds attributes associated with the entire grid. A convenient way for accessing regularly used parameters."""
@@ -239,6 +240,7 @@ def Ix(x, y, z, Hy, Hz, G):
Ix = G.dy * (Hy[x, y, z - 1] - Hy[x, y, z]) + G.dz * (Hz[x, y, z] - Hz[x, y - 1, z])
return Ix
def Iy(x, y, z, Hx, Hz, G):
"""Calculates the y-component of current at a grid position.
@@ -256,6 +258,7 @@ def Iy(x, y, z, Hx, Hz, G):
Iy = G.dx * (Hx[x, y, z] - Hx[x, y, z - 1]) + G.dz * (Hz[x - 1, y, z] - Hz[x, y, z])
return Iy
def Iz(x, y, z, Hx, Hy, G):
"""Calculates the z-component of current at a grid position.

查看文件

@@ -35,6 +35,7 @@ Coordinate(x=0.1, y=0.2, z=0.3)
from collections import namedtuple
Coordinate_tuple = namedtuple('Coordinate', ['x', 'y', 'z'])
class Coordinate(Coordinate_tuple):
"""Subclass of a namedtuple where __str__ outputs 'x y z'"""
def __str__(self):

查看文件

@@ -90,7 +90,6 @@ def process_geometrycmds(geometry, G):
if G.messages:
print('Geometry objects from file {} inserted at {:g}m, {:g}m, {:g}m, with corresponding materials file {}.'.format(geofile, xs * G.dx, ys * G.dy, zs * G.dz, matfile))
elif tmp[0] == '#edge:':
if len(tmp) != 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly seven parameters')
@@ -150,7 +149,6 @@ def process_geometrycmds(geometry, G):
if G.messages:
print('Edge from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m of material {} created.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, tmp[7]))
elif tmp[0] == '#plate:':
if len(tmp) < 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters')
@@ -259,7 +257,6 @@ def process_geometrycmds(geometry, G):
if G.messages:
print('Plate from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m of material(s) {} created.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, ', '.join(materialsrequested)))
elif tmp[0] == '#triangle:':
if len(tmp) < 12:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters')
@@ -379,7 +376,6 @@ def process_geometrycmds(geometry, G):
else:
print('Triangle with coordinates {:g}m {:g}m {:g}m, {:g}m {:g}m {:g}m, {:g}m {:g}m {:g}m of material(s) {} created.'.format(x1, y1, z1, x2, y2, z2, x3, y3, z3, ', '.join(materialsrequested)))
elif tmp[0] == '#box:':
if len(tmp) < 8:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least seven parameters')
@@ -471,7 +467,6 @@ def process_geometrycmds(geometry, G):
dielectricsmoothing = 'off'
print('Box from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m of material(s) {} created, dielectric smoothing is {}.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, ', '.join(materialsrequested), dielectricsmoothing))
elif tmp[0] == '#cylinder:':
if len(tmp) < 9:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eight parameters')
@@ -552,7 +547,6 @@ def process_geometrycmds(geometry, G):
dielectricsmoothing = 'off'
print('Cylinder with face centres {:g}m, {:g}m, {:g}m and {:g}m, {:g}m, {:g}m, with radius {:g}m, of material(s) {} created, dielectric smoothing is {}.'.format(x1, y1, z1, x2, y2, z2, r, ', '.join(materialsrequested), dielectricsmoothing))
elif tmp[0] == '#cylindrical_sector:':
if len(tmp) < 10:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least nine parameters')
@@ -676,7 +670,6 @@ def process_geometrycmds(geometry, G):
else:
print('Cylindrical sector with centre {:g}m, {:g}m, radius {:g}m, starting angle {:.1f} degrees, sector angle {:.1f} degrees, of material(s) {} created.'.format(ctr1, ctr2, r, (sectorstartangle / (2 * np.pi)) * 360, (sectorangle / (2 * np.pi)) * 360, ', '.join(materialsrequested)))
elif tmp[0] == '#sphere:':
if len(tmp) < 6:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least five parameters')
@@ -752,7 +745,6 @@ def process_geometrycmds(geometry, G):
dielectricsmoothing = 'off'
print('Sphere with centre {:g}m, {:g}m, {:g}m, radius {:g}m, of material(s) {} created, dielectric smoothing is {}.'.format(xc * G.dx, yc * G.dy, zc * G.dz, r, ', '.join(materialsrequested), dielectricsmoothing))
elif tmp[0] == '#fractal_box:':
if len(tmp) < 14:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least thirteen parameters')
@@ -1044,7 +1036,6 @@ def process_geometrycmds(geometry, G):
if G.messages:
print('Water on surface from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m with depth {:g}m, added to {}.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, filldepth, surface.operatingonID))
if tmp[0] == '#add_grass:':
if len(tmp) < 12:
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires at least eleven parameters')
@@ -1194,7 +1185,6 @@ def process_geometrycmds(geometry, G):
if G.messages:
print('{} blades of grass on surface from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m with fractal dimension {:g}, fractal seeding {}, and range {:g}m to {:g}m, added to {}.'.format(numblades, xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, surface.dimension, surface.seed, float(tmp[8]), float(tmp[9]), surface.operatingonID))
# Process any modifications to the original fractal box then generate it
if volume.fractalsurfaces:
volume.originalxs = volume.xs
@@ -1439,7 +1429,6 @@ def process_geometrycmds(geometry, G):
depth += 1
k -= 1
# Build voxels from any true values of the 3D mask array
waternumID = next((x.numID for x in G.materials if x.ID == 'water'), 0)
grassnumID = next((x.numID for x in G.materials if x.ID == 'grass'), 0)

查看文件

@@ -71,7 +71,6 @@ def process_multicmds(multicmds, G):
G.waveforms.append(w)
# Voltage source
cmdname = '#voltage_source'
if multicmds[cmdname] != 'None':
@@ -132,7 +131,6 @@ def process_multicmds(multicmds, G):
G.voltagesources.append(v)
# Hertzian dipole
cmdname = '#hertzian_dipole'
if multicmds[cmdname] != 'None':
@@ -192,7 +190,6 @@ def process_multicmds(multicmds, G):
G.hertziandipoles.append(h)
# Magnetic dipole
cmdname = '#magnetic_dipole'
if multicmds[cmdname] != 'None':
@@ -359,7 +356,6 @@ def process_multicmds(multicmds, G):
G.rxs.append(r)
# Receiver array
cmdname = '#rx_array'
if multicmds[cmdname] != 'None':
@@ -425,7 +421,6 @@ def process_multicmds(multicmds, G):
print(' Receiver at {:g}m, {:g}m, {:g}m with output(s) {} created.'.format(r.xcoord * G.dx, r.ycoord * G.dy, r.zcoord * G.dz, ', '.join(r.outputs)))
G.rxs.append(r)
# Snapshot
cmdname = '#snapshot'
if multicmds[cmdname] != 'None':
@@ -511,7 +506,6 @@ def process_multicmds(multicmds, G):
# Append the new material object to the materials list
G.materials.append(m)
cmdname = '#add_dispersion_debye'
if multicmds[cmdname] != 'None':
for cmdinstance in multicmds[cmdname]:
@@ -583,7 +577,6 @@ def process_multicmds(multicmds, G):
if G.messages:
print('Lorentz disperion added to {} with delta_epsr={}, omega={} secs, and gamma={} created.'.format(material.ID, ', '.join('%4.2f' % deltaer for deltaer in material.deltaer), ', '.join('%4.3e' % tau for tau in material.tau), ', '.join('%4.3e' % alpha for alpha in material.alpha)))
cmdname = '#add_dispersion_drude'
if multicmds[cmdname] != 'None':
for cmdinstance in multicmds[cmdname]:
@@ -619,7 +612,6 @@ def process_multicmds(multicmds, G):
if G.messages:
print('Drude disperion added to {} with omega={} secs, and gamma={} secs created.'.format(material.ID, ', '.join('%4.3e' % tau for tau in material.tau), ', '.join('%4.3e' % alpha for alpha in material.alpha)))
cmdname = '#soil_peplinski'
if multicmds[cmdname] != 'None':
for cmdinstance in multicmds[cmdname]:
@@ -650,7 +642,6 @@ def process_multicmds(multicmds, G):
# Append the new material object to the materials list
G.mixingmodels.append(s)
# Geometry views (creates VTK-based geometry files)
cmdname = '#geometry_view'
if multicmds[cmdname] != 'None':
@@ -695,7 +686,6 @@ def process_multicmds(multicmds, G):
# Append the new GeometryView object to the geometry views list
G.geometryviews.append(g)
# Complex frequency shifted (CFS) PML parameter
cmdname = '#pml_cfs'
if multicmds[cmdname] != 'None':

查看文件

@@ -50,7 +50,6 @@ def process_singlecmds(singlecmds, G):
else:
raise CmdInputError(cmd + ' requires input values of either y or n')
# Title
cmd = '#title'
if singlecmds[cmd] != 'None':
@@ -58,7 +57,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Model title: {}'.format(G.title))
# Number of processors to run on (OpenMP)
cmd = '#num_threads'
os.environ['OMP_WAIT_POLICY'] = 'active'
@@ -85,7 +83,6 @@ def process_singlecmds(singlecmds, G):
if G.nthreads > psutil.cpu_count(logical=False):
print('\nWARNING: You have specified more threads ({}) than available physical CPU cores ({}). This may lead to degraded performance.'.format(G.nthreads, psutil.cpu_count(logical=False)))
# Spatial discretisation
cmd = '#dx_dy_dz'
tmp = [float(x) for x in singlecmds[cmd].split()]
@@ -103,7 +100,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Spatial discretisation: {:g} x {:g} x {:g}m'.format(G.dx, G.dy, G.dz))
# Domain
cmd = '#domain'
tmp = [float(x) for x in singlecmds[cmd].split()]
@@ -120,7 +116,6 @@ def process_singlecmds(singlecmds, G):
mem = (((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
print('Memory (RAM) usage: ~{} required, {} available'.format(human_size(mem), human_size(psutil.virtual_memory().total)))
# Time step CFL limit (use either 2D or 3D) and default PML thickness
if G.nx == 1:
G.dt = 1 / (c * np.sqrt((1 / G.dy) * (1 / G.dy) + (1 / G.dz) * (1 / G.dz)))
@@ -145,7 +140,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Time step (at {} CFL limit): {:g} secs'.format(G.dtlimit, G.dt))
# Time step stability factor
cmd = '#time_step_stability_factor'
if singlecmds[cmd] != 'None':
@@ -158,7 +152,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Time step (modified): {:g} secs'.format(G.dt))
# Time window
cmd = '#time_window'
tmp = singlecmds[cmd].split()
@@ -182,7 +175,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Time window: {:g} secs ({} iterations)'.format(G.timewindow, G.iterations))
# PML
cmd = '#pml_cells'
if singlecmds[cmd] != 'None':
@@ -196,7 +188,6 @@ def process_singlecmds(singlecmds, G):
if 2 * G.pmlthickness[0] >= G.nx or 2 * G.pmlthickness[1] >= G.ny or 2 * G.pmlthickness[2] >= G.nz or 2 * G.pmlthickness[3] >= G.nx or 2 * G.pmlthickness[4] >= G.ny or 2 * G.pmlthickness[5] >= G.nz:
raise CmdInputError(cmd + ' has too many cells for the domain size')
# src_steps
cmd = '#src_steps'
if singlecmds[cmd] != 'None':
@@ -209,7 +200,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('Simple sources will step {:g}m, {:g}m, {:g}m for each model run.'.format(G.srcstepx * G.dx, G.srcstepy * G.dy, G.srcstepz * G.dz))
# rx_steps
cmd = '#rx_steps'
if singlecmds[cmd] != 'None':
@@ -222,7 +212,6 @@ def process_singlecmds(singlecmds, G):
if G.messages:
print('All receivers will step {:g}m, {:g}m, {:g}m for each model run.'.format(G.rxstepx * G.dx, G.rxstepy * G.dy, G.rxstepz * G.dz))
# Excitation file for user-defined source waveforms
cmd = '#excitation_file'
if singlecmds[cmd] != 'None':

查看文件

@@ -341,7 +341,6 @@ def calculate_ranges_experiments(optparams, optparamsinit, levels, levelsopt, le
levels[0, p] = levels[1, p] - levelsdiff[p]
levels[2, p] = levels[1, p] + levelsdiff[p]
# Update dictionary of parameters to optimise with lists of new values; clear dictionary first
optparams = OrderedDict((key, list()) for key in optparams)
p = 0

查看文件

@@ -43,7 +43,6 @@ def write_hdf5(outputfile, Ex, Ey, Ez, Hx, Hy, Hz, G):
f.attrs['srcsteps'] = (G.srcstepx, G.srcstepy, G.srcstepz)
f.attrs['rxsteps'] = (G.rxstepx, G.rxstepy, G.rxstepz)
# Create group for sources (except transmission lines); add type and positional data attributes
srclist = G.voltagesources + G.hertziandipoles + G.magneticdipoles
for srcindex, src in enumerate(srclist):
@@ -65,7 +64,6 @@ def write_hdf5(outputfile, Ex, Ey, Ez, Hx, Hy, Hz, G):
f['/tls/tl' + str(tlindex + 1) + '/Vtotal'] = tl.Vtotal
f['/tls/tl' + str(tlindex + 1) + '/Itotal'] = tl.Itotal
# Create group, add positional data and write field component arrays for receivers
for rxindex, rx in enumerate(G.rxs):
grp = f.create_group('/rxs/rx' + str(rxindex + 1))

查看文件

@@ -6,6 +6,7 @@ import numpy as np
from gprMax.grid import Grid
class ListCounter():
def __init__(self, npArray):
@@ -16,10 +17,10 @@ class ListCounter():
self.array[self.count] = item
self.count += 1
class EdgeLabels:
def __init__(self, grid):
"""
Class to define some connectivity of for an n x l x m
grid
@@ -37,6 +38,7 @@ class EdgeLabels:
edge = np.array([in_label, out_label])
self.edge_counter.add(edge)
class EdgeMaterials:
def __init__(self, fdtd_grid):
@@ -85,7 +87,6 @@ class SolidLabels():
self.label_counter = ListCounter(self.solid_labels)
def hexCellPicker(self, grid, i, j, k):
"""
This is the ordering of nodes in the hexahedron cell.
@@ -124,6 +125,7 @@ class SolidLabels():
solid_labels = self.hexCellPicker(self.label_grid.grid, i, j, k)
self.label_counter.add(solid_labels)
class SolidManager(Grid):
def __init__(self, label_grid, fdtd_grid):