diff --git a/gprMax/grid.py b/gprMax/grid.py index bf9ac4e4..26a2ddcb 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -23,7 +23,7 @@ from gprMax.constants import c, floattype, complextype from gprMax.materials import Material -class FDTDGrid: +class FDTDGrid(object): """Holds attributes associated with the entire grid. A convenient way for accessing regularly used parameters.""" def __init__(self): @@ -54,25 +54,27 @@ class FDTDGrid: self.hertziandipoles = [] self.magneticdipoles = [] self.transmissionlines = [] + self.rxs = [] self.srcstepx = 0 self.srcstepy = 0 self.srcstepz = 0 self.rxstepx = 0 self.rxstepy = 0 self.rxstepz = 0 - self.rxs = [] self.snapshots = [] - def initialise_std_arrays(self): + def initialise_geometry_arrays(self): """Initialise an array for volumetric material IDs (solid); boolean arrays for specifying whether materials can have dielectric smoothing (rigid); - an array for cell edge IDs (ID); and arrays for the electric and magnetic field components. Solid and ID arrays are initialised to free_space (one); rigid arrays - to allow dielectric smoothing (zero). + and an array for cell edge IDs (ID). Solid and ID arrays are initialised to free_space (one); rigid arrays to allow dielectric smoothing (zero). """ self.solid = np.ones((self.nx + 1, self.ny + 1, self.nz + 1), dtype=np.uint32) self.rigidE = np.zeros((12, self.nx + 1, self.ny + 1, self.nz + 1), dtype=np.int8) self.rigidH = np.zeros((6, self.nx + 1, self.ny + 1, self.nz + 1), dtype=np.int8) self.IDlookup = {'Ex': 0, 'Ey': 1, 'Ez': 2, 'Hx': 3, 'Hy': 4, 'Hz': 5} self.ID = np.ones((6, self.nx + 1, self.ny + 1, self.nz + 1), dtype=np.uint32) + + def initialise_field_arrays(self): + """Initialise arrays for the electric and magnetic field components.""" self.Ex = np.zeros((self.nx, self.ny + 1, self.nz + 1), dtype=floattype) self.Ey = np.zeros((self.nx + 1, self.ny, self.nz + 1), dtype=floattype) self.Ez = np.zeros((self.nx + 1, self.ny + 1, self.nz), dtype=floattype) @@ -80,7 +82,7 @@ class FDTDGrid: self.Hy = np.zeros((self.nx, self.ny + 1, self.nz), dtype=floattype) self.Hz = np.zeros((self.nx, self.ny, self.nz + 1), dtype=floattype) - def initialise_std_updatecoeff_arrays(self): + def initialise_std_update_coeff_arrays(self): """Initialise arrays for storing update coefficients.""" self.updatecoeffsE = np.zeros((len(self.materials), 5), dtype=floattype) self.updatecoeffsH = np.zeros((len(self.materials), 5), dtype=floattype) @@ -109,21 +111,6 @@ def dispersion_check(G): # Find maximum frequency maxfreqs = [] for waveform in G.waveforms: - - # User-defined waveform - if waveform.uservalues is not None: - waveformvalues = waveform.uservalues - - # Built-in waveform - else: - time = np.linspace(0, 1, G.iterations) - time *= (G.iterations * G.dt) - waveformvalues = np.zeros(len(time)) - timeiter = np.nditer(time, flags=['c_index']) - - while not timeiter.finished: - waveformvalues[timeiter.index] = waveform.calculate_value(timeiter[0], G.dt) - timeiter.iternext() if waveform.type == 'sine' or waveform.type == 'contsine': maxfreqs.append(4 * waveform.freq) @@ -132,6 +119,21 @@ def dispersion_check(G): pass else: + # User-defined waveform + if waveform.type == 'user': + waveformvalues = waveform.uservalues + + # Built-in waveform + else: + time = np.linspace(0, 1, G.iterations) + time *= (G.iterations * G.dt) + waveformvalues = np.zeros(len(time)) + timeiter = np.nditer(time, flags=['c_index']) + + while not timeiter.finished: + waveformvalues[timeiter.index] = waveform.calculate_value(timeiter[0], G.dt) + timeiter.iternext() + # Calculate magnitude of frequency spectra of waveform power = 20 * np.log10(np.abs(np.fft.fft(waveformvalues))**2) freqs = np.fft.fftfreq(power.size, d=G.dt) @@ -160,7 +162,7 @@ def dispersion_check(G): resolution = minwavelength / resolvedsteps else: - resolution = 0 + resolution = False return resolution