PEP8 code cleanups.

这个提交包含在:
Craig Warren
2018-01-02 18:14:20 +00:00
父节点 f83ec97fa9
当前提交 4848a8d4d7
共有 15 个文件被更改,包括 83 次插入90 次删除

查看文件

@@ -67,7 +67,7 @@ __global__ void store_outputs(int NRX, int iteration, const int* __restrict__ rx
// NRX: Total number of receivers in the model // NRX: Total number of receivers in the model
// rxs: Array to store field components for receivers - rows are field components; columns are iterations; pages are receivers // rxs: Array to store field components for receivers - rows are field components; columns are iterations; pages are receivers
// E, H: Access to field component arrays // E, H: Access to field component arrays
// Obtain the linear index corresponding to the current thread and use for each receiver // Obtain the linear index corresponding to the current thread and use for each receiver
int rx = blockIdx.x * blockDim.x + threadIdx.x; int rx = blockIdx.x * blockDim.x + threadIdx.x;

查看文件

@@ -29,7 +29,7 @@ kernels_template_fields = Template("""
#define INDEX4D_ID(p, i, j, k) (p)*($NX_ID)*($NY_ID)*($NZ_ID)+(i)*($NY_ID)*($NZ_ID)+(j)*($NZ_ID)+(k) #define INDEX4D_ID(p, i, j, k) (p)*($NX_ID)*($NY_ID)*($NZ_ID)+(i)*($NY_ID)*($NZ_ID)+(j)*($NZ_ID)+(k)
#define INDEX4D_T(p, i, j, k) (p)*($NX_T)*($NY_T)*($NZ_T)+(i)*($NY_T)*($NZ_T)+(j)*($NZ_T)+(k) #define INDEX4D_T(p, i, j, k) (p)*($NX_T)*($NY_T)*($NZ_T)+(i)*($NY_T)*($NZ_T)+(j)*($NZ_T)+(k)
// Material coefficients (read-only) in constant memory (64KB) // Material coefficients (read-only) in constant memory (64KB)_
__device__ __constant__ $REAL updatecoeffsE[$N_updatecoeffsE]; __device__ __constant__ $REAL updatecoeffsE[$N_updatecoeffsE];
__device__ __constant__ $REAL updatecoeffsH[$N_updatecoeffsH]; __device__ __constant__ $REAL updatecoeffsH[$N_updatecoeffsH];
@@ -44,7 +44,7 @@ __global__ void update_e(int NX, int NY, int NZ, const unsigned int* __restrict_
// Args: // Args:
// NX, NY, NZ: Number of cells of the model domain // NX, NY, NZ: Number of cells of the model domain
// ID, E, H: Access to ID and field component arrays // ID, E, H: Access to ID and field component arrays
// Obtain the linear index corresponding to the current thread // Obtain the linear index corresponding to the current thread
int idx = blockIdx.x * blockDim.x + threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x;
@@ -63,13 +63,13 @@ __global__ void update_e(int NX, int NY, int NZ, const unsigned int* __restrict_
int materialEx = ID[INDEX4D_ID(0,i_ID,j_ID,k_ID)]; int materialEx = ID[INDEX4D_ID(0,i_ID,j_ID,k_ID)];
Ex[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEx,0)] * Ex[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEx,2)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i,j-1,k)]) - updatecoeffsE[INDEX2D_MAT(materialEx,3)] * (Hy[INDEX3D_FIELDS(i,j,k)] - Hy[INDEX3D_FIELDS(i,j,k-1)]); Ex[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEx,0)] * Ex[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEx,2)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i,j-1,k)]) - updatecoeffsE[INDEX2D_MAT(materialEx,3)] * (Hy[INDEX3D_FIELDS(i,j,k)] - Hy[INDEX3D_FIELDS(i,j,k-1)]);
} }
// Ey component // Ey component
if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) { if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) {
int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)]; int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)];
Ey[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEy,0)] * Ey[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEy,3)] * (Hx[INDEX3D_FIELDS(i,j,k)] - Hx[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEy,1)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i-1,j,k)]); Ey[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEy,0)] * Ey[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEy,3)] * (Hx[INDEX3D_FIELDS(i,j,k)] - Hx[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEy,1)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i-1,j,k)]);
} }
// Ez component // Ez component
if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) { if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) {
int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)]; int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)];
@@ -89,7 +89,7 @@ __global__ void update_e_dispersive_A(int NX, int NY, int NZ, int MAXPOLES, cons
// NX, NY, NZ: Number of cells of the model domain // NX, NY, NZ: Number of cells of the model domain
// MAXPOLES: Maximum number of dispersive material poles present in model // MAXPOLES: Maximum number of dispersive material poles present in model
// updatedispersivecoeffs, T, ID, E, H: Access to update coefficients, dispersive, ID and field component arrays // updatedispersivecoeffs, T, ID, E, H: Access to update coefficients, dispersive, ID and field component arrays
// Obtain the linear index corresponding to the current thread // Obtain the linear index corresponding to the current thread
int idx = blockIdx.x * blockDim.x + threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x;
@@ -118,7 +118,7 @@ __global__ void update_e_dispersive_A(int NX, int NY, int NZ, int MAXPOLES, cons
} }
Ex[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEx,0)] * Ex[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEx,2)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i,j-1,k)]) - updatecoeffsE[INDEX2D_MAT(materialEx,3)] * (Hy[INDEX3D_FIELDS(i,j,k)] - Hy[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEx,4)] * phi; Ex[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEx,0)] * Ex[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEx,2)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i,j-1,k)]) - updatecoeffsE[INDEX2D_MAT(materialEx,3)] * (Hy[INDEX3D_FIELDS(i,j,k)] - Hy[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEx,4)] * phi;
} }
// Ey component // Ey component
if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) { if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) {
int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)]; int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)];
@@ -129,7 +129,7 @@ __global__ void update_e_dispersive_A(int NX, int NY, int NZ, int MAXPOLES, cons
} }
Ey[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEy,0)] * Ey[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEy,3)] * (Hx[INDEX3D_FIELDS(i,j,k)] - Hx[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEy,1)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i-1,j,k)]) - updatecoeffsE[INDEX2D_MAT(materialEy,4)] * phi; Ey[INDEX3D_FIELDS(i,j,k)] = updatecoeffsE[INDEX2D_MAT(materialEy,0)] * Ey[INDEX3D_FIELDS(i,j,k)] + updatecoeffsE[INDEX2D_MAT(materialEy,3)] * (Hx[INDEX3D_FIELDS(i,j,k)] - Hx[INDEX3D_FIELDS(i,j,k-1)]) - updatecoeffsE[INDEX2D_MAT(materialEy,1)] * (Hz[INDEX3D_FIELDS(i,j,k)] - Hz[INDEX3D_FIELDS(i-1,j,k)]) - updatecoeffsE[INDEX2D_MAT(materialEy,4)] * phi;
} }
// Ez component // Ez component
if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) { if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) {
int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)]; int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)];
@@ -150,7 +150,7 @@ __global__ void update_e_dispersive_B(int NX, int NY, int NZ, int MAXPOLES, cons
// NX, NY, NZ: Number of cells of the model domain // NX, NY, NZ: Number of cells of the model domain
// MAXPOLES: Maximum number of dispersive material poles present in model // MAXPOLES: Maximum number of dispersive material poles present in model
// updatedispersivecoeffs, T, ID, E, H: Access to update coefficients, dispersive, ID and field component arrays // updatedispersivecoeffs, T, ID, E, H: Access to update coefficients, dispersive, ID and field component arrays
// Obtain the linear index corresponding to the current thread // Obtain the linear index corresponding to the current thread
int idx = blockIdx.x * blockDim.x + threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x;
@@ -176,7 +176,7 @@ __global__ void update_e_dispersive_B(int NX, int NY, int NZ, int MAXPOLES, cons
Tx[INDEX4D_T(pole,i_T,j_T,k_T)] = Tx[INDEX4D_T(pole,i_T,j_T,k_T)] - updatecoeffsdispersive[INDEX2D_MATDISP(materialEx,2+(pole*3))] * Ex[INDEX3D_FIELDS(i,j,k)]; Tx[INDEX4D_T(pole,i_T,j_T,k_T)] = Tx[INDEX4D_T(pole,i_T,j_T,k_T)] - updatecoeffsdispersive[INDEX2D_MATDISP(materialEx,2+(pole*3))] * Ex[INDEX3D_FIELDS(i,j,k)];
} }
} }
// Ey component // Ey component
if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) { if ((NX != 1 || NZ != 1) && i > 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) {
int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)]; int materialEy = ID[INDEX4D_ID(1,i_ID,j_ID,k_ID)];
@@ -184,7 +184,7 @@ __global__ void update_e_dispersive_B(int NX, int NY, int NZ, int MAXPOLES, cons
Ty[INDEX4D_T(pole,i_T,j_T,k_T)] = Ty[INDEX4D_T(pole,i_T,j_T,k_T)] - updatecoeffsdispersive[INDEX2D_MATDISP(materialEy,2+(pole*3))] * Ey[INDEX3D_FIELDS(i,j,k)]; Ty[INDEX4D_T(pole,i_T,j_T,k_T)] = Ty[INDEX4D_T(pole,i_T,j_T,k_T)] - updatecoeffsdispersive[INDEX2D_MATDISP(materialEy,2+(pole*3))] * Ey[INDEX3D_FIELDS(i,j,k)];
} }
} }
// Ez component // Ez component
if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) { if ((NX != 1 || NY != 1) && i > 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) {
int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)]; int materialEz = ID[INDEX4D_ID(2,i_ID,j_ID,k_ID)];
@@ -206,7 +206,7 @@ __global__ void update_h(int NX, int NY, int NZ, const unsigned int* __restrict_
// Args: // Args:
// NX, NY, NZ: Number of cells of the model domain // NX, NY, NZ: Number of cells of the model domain
// ID, E, H: Access to ID and field component arrays // ID, E, H: Access to ID and field component arrays
// Obtain the linear index corresponding to the current thread // Obtain the linear index corresponding to the current thread
int idx = blockIdx.x * blockDim.x + threadIdx.x; int idx = blockIdx.x * blockDim.x + threadIdx.x;
@@ -225,13 +225,13 @@ __global__ void update_h(int NX, int NY, int NZ, const unsigned int* __restrict_
int materialHx = ID[INDEX4D_ID(3,i_ID,j_ID,k_ID)]; int materialHx = ID[INDEX4D_ID(3,i_ID,j_ID,k_ID)];
Hx[INDEX3D_FIELDS(i,j,k)] = updatecoeffsH[INDEX2D_MAT(materialHx,0)] * Hx[INDEX3D_FIELDS(i,j,k)] - updatecoeffsH[INDEX2D_MAT(materialHx,2)] * (Ez[INDEX3D_FIELDS(i,j+1,k)] - Ez[INDEX3D_FIELDS(i,j,k)]) + updatecoeffsH[INDEX2D_MAT(materialHx,3)] * (Ey[INDEX3D_FIELDS(i,j,k+1)] - Ey[INDEX3D_FIELDS(i,j,k)]); Hx[INDEX3D_FIELDS(i,j,k)] = updatecoeffsH[INDEX2D_MAT(materialHx,0)] * Hx[INDEX3D_FIELDS(i,j,k)] - updatecoeffsH[INDEX2D_MAT(materialHx,2)] * (Ez[INDEX3D_FIELDS(i,j+1,k)] - Ez[INDEX3D_FIELDS(i,j,k)]) + updatecoeffsH[INDEX2D_MAT(materialHx,3)] * (Ey[INDEX3D_FIELDS(i,j,k+1)] - Ey[INDEX3D_FIELDS(i,j,k)]);
} }
// Hy component // Hy component
if (NY != 1 && i >= 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) { if (NY != 1 && i >= 0 && i < NX && j > 0 && j < NY && k >= 0 && k < NZ) {
int materialHy = ID[INDEX4D_ID(4,i_ID,j_ID,k_ID)]; int materialHy = ID[INDEX4D_ID(4,i_ID,j_ID,k_ID)];
Hy[INDEX3D_FIELDS(i,j,k)] = updatecoeffsH[INDEX2D_MAT(materialHy,0)] * Hy[INDEX3D_FIELDS(i,j,k)] - updatecoeffsH[INDEX2D_MAT(materialHy,3)] * (Ex[INDEX3D_FIELDS(i,j,k+1)] - Ex[INDEX3D_FIELDS(i,j,k)]) + updatecoeffsH[INDEX2D_MAT(materialHy,1)] * (Ez[INDEX3D_FIELDS(i+1,j,k)] - Ez[INDEX3D_FIELDS(i,j,k)]); Hy[INDEX3D_FIELDS(i,j,k)] = updatecoeffsH[INDEX2D_MAT(materialHy,0)] * Hy[INDEX3D_FIELDS(i,j,k)] - updatecoeffsH[INDEX2D_MAT(materialHy,3)] * (Ex[INDEX3D_FIELDS(i,j,k+1)] - Ex[INDEX3D_FIELDS(i,j,k)]) + updatecoeffsH[INDEX2D_MAT(materialHy,1)] * (Ez[INDEX3D_FIELDS(i+1,j,k)] - Ez[INDEX3D_FIELDS(i,j,k)]);
} }
// Hz component // Hz component
if (NZ != 1 && i >= 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) { if (NZ != 1 && i >= 0 && i < NX && j >= 0 && j < NY && k > 0 && k < NZ) {
int materialHz = ID[INDEX4D_ID(5,i_ID,j_ID,k_ID)]; int materialHz = ID[INDEX4D_ID(5,i_ID,j_ID,k_ID)];

查看文件

@@ -100,7 +100,7 @@ class FractalSurface(object):
fractalmax = np.amax(self.fractalsurface) fractalmax = np.amax(self.fractalsurface)
fractalrange = fractalmax - fractalmin fractalrange = fractalmax - fractalmin
self.fractalsurface = self.fractalsurface * ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) \ self.fractalsurface = self.fractalsurface * ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) \
+ self.fractalrange[0] - ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) * fractalmin + self.fractalrange[0] - ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) * fractalmin
class FractalVolume(object): class FractalVolume(object):

查看文件

@@ -218,25 +218,25 @@ class GeometryView(object):
z_materials = np.zeros((n_z_lines), dtype=np.uint32) z_materials = np.zeros((n_z_lines), dtype=np.uint32)
define_fine_geometry(self.nx, define_fine_geometry(self.nx,
self.ny, self.ny,
self.nz, self.nz,
self.xs, self.xs,
self.xf, self.xf,
self.ys, self.ys,
self.yf, self.yf,
self.zs, self.zs,
self.zf, self.zf,
G.dx, G.dx,
G.dy, G.dy,
G.dz, G.dz,
G.ID, G.ID,
points, points,
x_lines, x_lines,
x_materials, x_materials,
y_lines, y_lines,
y_materials, y_materials,
z_lines, z_lines,
z_materials) z_materials)
# Write point data # Write point data
datasize = points.nbytes datasize = points.nbytes

查看文件

@@ -70,18 +70,18 @@ def main():
def api( def api(
inputfile, inputfile,
n=1, n=1,
task=None, task=None,
restart=None, restart=None,
mpi=False, mpi=False,
gpu=None, gpu=None,
benchmark=False, benchmark=False,
geometry_only=False, geometry_only=False,
geometry_fixed=False, geometry_fixed=False,
write_processed=False, write_processed=False,
opt_taguchi=False opt_taguchi=False
): ):
"""If installed as a module this is the entry point.""" """If installed as a module this is the entry point."""
# Print gprMax logo, version, and licencing/copyright information # Print gprMax logo, version, and licencing/copyright information
@@ -165,7 +165,7 @@ def run_main(args):
# Process for simulation with Taguchi optimisation # # Process for simulation with Taguchi optimisation #
#################################################### ####################################################
elif args.opt_taguchi: elif args.opt_taguchi:
if args.mpi_worker: # Special case for MPI spawned workers - they do not need to enter the Taguchi optimisation mode if args.mpi_worker: # Special case for MPI spawned workers - they do not need to enter the Taguchi optimisation mode
run_mpi_sim(args, inputfile, usernamespace) run_mpi_sim(args, inputfile, usernamespace)
else: else:
from gprMax.optimisation_taguchi import run_opt_sim from gprMax.optimisation_taguchi import run_opt_sim
@@ -396,9 +396,9 @@ def run_mpi_sim(args, inputfile, usernamespace, optparams=None):
# Connect to parent # Connect to parent
try: try:
comm = MPI.Comm.Get_parent() # get MPI communicator object comm = MPI.Comm.Get_parent() # get MPI communicator object
rank = comm.Get_rank() # rank of this process rank = comm.Get_rank() # rank of this process
except: except ValueError:
raise ValueError('Could not connect to parent') raise ValueError('Could not connect to parent')
# Ask for work until stop sentinel # Ask for work until stop sentinel

查看文件

@@ -50,10 +50,10 @@ class Grid(object):
self.grid = grid self.grid = grid
def n_edges(self): def n_edges(self):
l = self.nx i = self.nx
m = self.ny j = self.ny
n = self.nz k = self.nz
e = (l * m * (n - 1)) + (m * n * (l - 1)) + (l * n * (m - 1)) e = (i * j * (k - 1)) + (j * k * (i - 1)) + (i * k * (j - 1))
return e return e
def n_nodes(self): def n_nodes(self):
@@ -239,8 +239,8 @@ def dispersion_analysis(G):
# Built-in waveform # Built-in waveform
else: else:
# Time to analyse waveform - 4*pulse_width as using entire # Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT # time window can result in demanding FFT
waveform.calculate_coefficients() waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt) iterations = round_value(4 * waveform.chi / G.dt)
if iterations > G.iterations: if iterations > G.iterations:
@@ -261,7 +261,7 @@ def dispersion_analysis(G):
try: try:
freqthres = np.where(power[freqmaxpower:] < -G.highestfreqthres)[0][0] + freqmaxpower freqthres = np.where(power[freqmaxpower:] < -G.highestfreqthres)[0][0] + freqmaxpower
results['maxfreq'].append(freqs[freqthres]) results['maxfreq'].append(freqs[freqthres])
except: except ValueError:
results['error'] = 'unable to calculate maximum power from waveform, most likely due to undersampling.' results['error'] = 'unable to calculate maximum power from waveform, most likely due to undersampling.'
# If waveform is truncated don't do any further analysis # If waveform is truncated don't do any further analysis

查看文件

@@ -413,7 +413,7 @@ def cylinder(x1, y1, z1, x2, y2, z2, radius, material, averaging='', rotate90ori
def cylindrical_sector(axis, ctr1, ctr2, t1, t2, radius, def cylindrical_sector(axis, ctr1, ctr2, t1, t2, radius,
startingangle, sweptangle, material, averaging=''): startingangle, sweptangle, material, averaging=''):
"""Prints the gprMax #cylindrical_sector command. """Prints the gprMax #cylindrical_sector command.
Args: Args:
@@ -471,7 +471,7 @@ def waveform(shape, amplitude, frequency, identifier):
def hertzian_dipole(polarisation, f1, f2, f3, identifier, def hertzian_dipole(polarisation, f1, f2, f3, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()): t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #hertzian_dipole: polarisation, f1, f2, f3, identifier, [t0, t_remove] """Prints the #hertzian_dipole: polarisation, f1, f2, f3, identifier, [t0, t_remove]
Args: Args:
@@ -545,7 +545,7 @@ def magnetic_dipole(polarisation, f1, f2, f3, identifier,
def voltage_source(polarisation, f1, f2, f3, resistance, identifier, def voltage_source(polarisation, f1, f2, f3, resistance, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()): t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #voltage_source: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove] """Prints the #voltage_source: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove]
Args: Args:
@@ -583,7 +583,7 @@ def voltage_source(polarisation, f1, f2, f3, resistance, identifier,
def transmission_line(polarisation, f1, f2, f3, resistance, identifier, def transmission_line(polarisation, f1, f2, f3, resistance, identifier,
t0=None, t_remove=None, dxdy=None, rotate90origin=()): t0=None, t_remove=None, dxdy=None, rotate90origin=()):
"""Prints the #transmission_line: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove] """Prints the #transmission_line: polarisation, f1, f2, f3, resistance, identifier, [t0, t_remove]
Args: Args:

查看文件

@@ -877,10 +877,7 @@ def process_geometrycmds(geometry, G):
volume.nbins = nbins volume.nbins = nbins
volume.seed = seed volume.seed = seed
volume.weighting = np.array([float(tmp[8]), float(tmp[9]), float(tmp[10])]) volume.weighting = np.array([float(tmp[8]), float(tmp[9]), float(tmp[10])])
try: volume.averaging = averagefractalbox
volume.averaging = averagefractalbox
except:
pass
if G.messages: if G.messages:
if volume.averaging: if volume.averaging:

查看文件

@@ -499,7 +499,7 @@ def process_multicmds(multicmds, G):
try: try:
time = int(tmp[9]) time = int(tmp[9])
# If real floating point value given # If real floating point value given
except: except ValueError:
time = float(tmp[9]) time = float(tmp[9])
if time > 0: if time > 0:
time = round_value((time / G.dt)) + 1 time = round_value((time / G.dt)) + 1
@@ -587,13 +587,8 @@ def process_multicmds(multicmds, G):
material.type = 'debye' material.type = 'debye'
material.poles = poles material.poles = poles
material.averagable = False material.averagable = False
# for pole in range(1, 2 * poles, 2):
# if float(tmp[pole]) > 0 and float(tmp[pole + 1]) > G.dt:
# material.deltaer.append(float(tmp[pole]))
# material.tau.append(float(tmp[pole + 1]))
# else:
# raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires positive values for the permittivity difference, and relaxation times that are greater than the time step for the model.')
for pole in range(1, 2 * poles, 2): for pole in range(1, 2 * poles, 2):
# N.B Not checking if relaxation times are greater than time-step
if float(tmp[pole]) > 0: if float(tmp[pole]) > 0:
material.deltaer.append(float(tmp[pole])) material.deltaer.append(float(tmp[pole]))
material.tau.append(float(tmp[pole + 1])) material.tau.append(float(tmp[pole + 1]))

查看文件

@@ -203,7 +203,7 @@ def process_singlecmds(singlecmds, G):
G.timewindow = (tmp - 1) * G.dt G.timewindow = (tmp - 1) * G.dt
G.iterations = tmp G.iterations = tmp
# If real floating point value given # If real floating point value given
except: except ValueError:
tmp = float(tmp) tmp = float(tmp)
if tmp > 0: if tmp > 0:
G.timewindow = tmp G.timewindow = tmp
@@ -312,7 +312,7 @@ def process_singlecmds(singlecmds, G):
waveformvalues = waveformvalues[:len(waveformtime)] waveformvalues = waveformvalues[:len(waveformtime)]
# Zero-pad end of waveform array if it is shorter than time array # Zero-pad end of waveform array if it is shorter than time array
elif len(waveformvalues) < len(waveformtime): elif len(waveformvalues) < len(waveformtime):
waveformvalues = np.lib.pad(waveformvalues, (0,len(waveformtime)-len(waveformvalues)), 'constant', constant_values=0) waveformvalues = np.lib.pad(waveformvalues, (0, len(waveformtime) - len(waveformvalues)), 'constant', constant_values=0)
# Interpolate waveform values # Interpolate waveform values
w.userfunc = interpolate.interp1d(waveformtime, waveformvalues, **kwargs) w.userfunc = interpolate.interp1d(waveformtime, waveformvalues, **kwargs)

查看文件

@@ -148,14 +148,14 @@ class Material(object):
Args: Args:
freq (float): Frequency used to calculate complex relative permittivity. freq (float): Frequency used to calculate complex relative permittivity.
Returns: Returns:
er (float): Complex relative permittivity. er (float): Complex relative permittivity.
""" """
# This will be permittivity at infinite frequency if the material is dispersive # Permittivity at infinite frequency if the material is dispersive
er = self.er er = self.er
if self.poles > 0: if self.poles > 0:
w = 2 * np.pi * freq w = 2 * np.pi * freq
er += self.se / (w * e0) er += self.se / (w * e0)
@@ -166,10 +166,11 @@ class Material(object):
for pole in range(self.poles): for pole in range(self.poles):
er += (self.deltaer[pole] * self.tau[pole]**2) / (self.tau[pole]**2 + 2j * w * self.alpha[pole] - w**2) er += (self.deltaer[pole] * self.tau[pole]**2) / (self.tau[pole]**2 + 2j * w * self.alpha[pole] - w**2)
elif 'drude' in self.type: elif 'drude' in self.type:
ersum = 0
for pole in range(self.poles): for pole in range(self.poles):
ersum += self.tau[pole]**2 / (w**2 - 1j * w * self.alpha[pole]) ersum += self.tau[pole]**2 / (w**2 - 1j * w * self.alpha[pole])
er -= ersum er -= ersum
return er return er

查看文件

@@ -44,7 +44,7 @@ class Rx(object):
def gpu_initialise_rx_arrays(G): def gpu_initialise_rx_arrays(G):
"""Initialise arrays on GPU for receiver coordinates and to store field components for receivers. """Initialise arrays on GPU for receiver coordinates and to store field components for receivers.
Args: Args:
G (class): Grid class instance - holds essential parameters describing the model. G (class): Grid class instance - holds essential parameters describing the model.
""" """

查看文件

@@ -52,7 +52,7 @@ __global__ void update_hertzian_dipole(int NHERTZDIPOLE, int iteration, $REAL dx
int src = blockIdx.x * blockDim.x + threadIdx.x; int src = blockIdx.x * blockDim.x + threadIdx.x;
if (src < NHERTZDIPOLE) { if (src < NHERTZDIPOLE) {
$REAL dl; $REAL dl;
int i, j, k, polarisation; int i, j, k, polarisation;
@@ -104,7 +104,7 @@ __global__ void update_magnetic_dipole(int NMAGDIPOLE, int iteration, $REAL dx,
int src = blockIdx.x * blockDim.x + threadIdx.x; int src = blockIdx.x * blockDim.x + threadIdx.x;
if (src < NMAGDIPOLE) { if (src < NMAGDIPOLE) {
int i, j, k, polarisation; int i, j, k, polarisation;
i = srcinfo1[INDEX2D_SRCINFO(src,0)]; i = srcinfo1[INDEX2D_SRCINFO(src,0)];
@@ -154,10 +154,10 @@ __global__ void update_voltage_source(int NVOLTSRC, int iteration, $REAL dx, $RE
int src = blockIdx.x * blockDim.x + threadIdx.x; int src = blockIdx.x * blockDim.x + threadIdx.x;
if (src < NVOLTSRC) { if (src < NVOLTSRC) {
$REAL resistance; $REAL resistance;
int i, j, k, polarisation; int i, j, k, polarisation;
i = srcinfo1[INDEX2D_SRCINFO(src,0)]; i = srcinfo1[INDEX2D_SRCINFO(src,0)];
j = srcinfo1[INDEX2D_SRCINFO(src,1)]; j = srcinfo1[INDEX2D_SRCINFO(src,1)];
k = srcinfo1[INDEX2D_SRCINFO(src,2)]; k = srcinfo1[INDEX2D_SRCINFO(src,2)];

查看文件

@@ -217,17 +217,17 @@ class MagneticDipole(Source):
def gpu_initialise_src_arrays(sources, G): def gpu_initialise_src_arrays(sources, G):
"""Initialise arrays on GPU for source coordinates/polarisation, other source information, and source waveform values. """Initialise arrays on GPU for source coordinates/polarisation, other source information, and source waveform values.
Args: Args:
sources (list): List of sources of one class, e.g. HertzianDipoles. sources (list): List of sources of one class, e.g. HertzianDipoles.
G (class): Grid class instance - holds essential parameters describing the model. G (class): Grid class instance - holds essential parameters describing the model.
Returns: Returns:
srcinfo1_gpu (int): numpy array of source cell coordinates and polarisation information. srcinfo1_gpu (int): numpy array of source cell coordinates and polarisation information.
srcinfo2_gpu (float): numpy array of other source information, e.g. length, resistance etc... srcinfo2_gpu (float): numpy array of other source information, e.g. length, resistance etc...
srcwaves_gpu (float): numpy array of source waveform values. srcwaves_gpu (float): numpy array of source waveform values.
""" """
import pycuda.gpuarray as gpuarray import pycuda.gpuarray as gpuarray
srcinfo1 = np.zeros((len(sources), 4), dtype=np.int32) srcinfo1 = np.zeros((len(sources), 4), dtype=np.int32)
@@ -237,14 +237,14 @@ def gpu_initialise_src_arrays(sources, G):
srcinfo1[i, 0] = src.xcoord srcinfo1[i, 0] = src.xcoord
srcinfo1[i, 1] = src.ycoord srcinfo1[i, 1] = src.ycoord
srcinfo1[i, 2] = src.zcoord srcinfo1[i, 2] = src.zcoord
if src.polarisation == 'x': if src.polarisation == 'x':
srcinfo1[i, 3] = 0 srcinfo1[i, 3] = 0
elif src.polarisation == 'y': elif src.polarisation == 'y':
srcinfo1[i, 3] = 1 srcinfo1[i, 3] = 1
elif src.polarisation == 'z': elif src.polarisation == 'z':
srcinfo1[i, 3] = 2 srcinfo1[i, 3] = 2
if src.__class__.__name__ == 'HertzianDipole': if src.__class__.__name__ == 'HertzianDipole':
srcinfo2[i] = src.dl srcinfo2[i] = src.dl
srcwaves[i, :] = src.waveformvaluesJ srcwaves[i, :] = src.waveformvaluesJ
@@ -253,7 +253,7 @@ def gpu_initialise_src_arrays(sources, G):
srcwaves[i, :] = src.waveformvaluesJ srcwaves[i, :] = src.waveformvaluesJ
elif src.__class__.__name__ == 'MagneticDipole': elif src.__class__.__name__ == 'MagneticDipole':
srcwaves[i, :] = src.waveformvaluesM srcwaves[i, :] = src.waveformvaluesM
srcinfo1_gpu = gpuarray.to_gpu(srcinfo1) srcinfo1_gpu = gpuarray.to_gpu(srcinfo1)
srcinfo2_gpu = gpuarray.to_gpu(srcinfo2) srcinfo2_gpu = gpuarray.to_gpu(srcinfo2)
srcwaves_gpu = gpuarray.to_gpu(srcwaves) srcwaves_gpu = gpuarray.to_gpu(srcwaves)

查看文件

@@ -152,7 +152,7 @@ def fft_power(waveform, dt):
""" """
# Calculate magnitude of frequency spectra of waveform (ignore warning from taking a log of any zero values) # Calculate magnitude of frequency spectra of waveform (ignore warning from taking a log of any zero values)
with np.errstate(divide='ignore'): # with np.errstate(divide='ignore'):
power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2) power = 10 * np.log10(np.abs(np.fft.fft(waveform))**2)
# Replace any NaNs or Infs from zero division # Replace any NaNs or Infs from zero division