diff --git a/gprMax/gprMax.py b/gprMax/gprMax.py index 310276dc..892fde18 100644 --- a/gprMax/gprMax.py +++ b/gprMax/gprMax.py @@ -30,7 +30,7 @@ import numpy as np from gprMax._version import __version__ from gprMax._version import codename -import gprMax.config +import gprMax.config as config from gprMax.config import c from gprMax.config import e0 from gprMax.config import m0 @@ -126,8 +126,8 @@ def run_main(args): # Flatten a list of lists if any(isinstance(element, list) for element in args.gpu): args.gpu = [val for sublist in args.gpu for val in sublist] - gpus1, allgpustext = detect_check_gpus(args.gpu) - print('with GPU(s): {}'.format(' | '.join(allgpustext))) + config.gpus, allgpustext = detect_check_gpus(args.gpu) + print('GPU(s): {}'.format(' | '.join(allgpustext))) # Process input file with open_path_file(args.inputfile) as inputfile: @@ -167,8 +167,8 @@ def run_main(args): else: if args.task and args.restart: raise GeneralError('Job array and restart modes cannot be used together') - if gprMax.config.gpus: - gprMax.config.gpus = gprMax.config.gpus[0] + if config.gpus: + config.gpus = config.gpus[0] run_std_sim(args, inputfile, usernamespace) diff --git a/gprMax/grid.py b/gprMax/grid.py index 67d82e51..3c88aa98 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -25,12 +25,11 @@ init() import numpy as np np.seterr(invalid='raise') -import gprMax.config +import gprMax.config as config from gprMax.config import c from gprMax.config import floattype from gprMax.config import complextype from gprMax.config import numdispersion -from gprMax.config import gpus as gpu from gprMax.config import hostinfo from gprMax.exceptions import GeneralError from gprMax.materials import Material @@ -211,17 +210,17 @@ class FDTDGrid(Grid): raise GeneralError('Memory (RAM) required ~{} exceeds {} detected!\n'.format(human_size(self.memoryusage), human_size(hostinfo['ram'], a_kilobyte_is_1024_bytes=True))) # Check if model can be run on specified GPU if required - if gpu is not None: - if self.memoryusage - snapsmemsize > gpu.totalmem: - raise GeneralError('Memory (RAM) required ~{} exceeds {} detected on specified {} - {} GPU!\n'.format(human_size(self.memoryusage), human_size(gpu.totalmem, a_kilobyte_is_1024_bytes=True), gpu.deviceID, gpu.name)) + if config.gpus is not None: + if self.memoryusage - snapsmemsize > config.gpus.totalmem: + raise GeneralError('Memory (RAM) required ~{} exceeds {} detected on specified {} - {} GPU!\n'.format(human_size(self.memoryusage), human_size(config.gpus.totalmem, a_kilobyte_is_1024_bytes=True), config.gpus.deviceID, config.gpus.name)) # If the required memory without the snapshots will fit on the GPU then transfer and store snaphots on host - if snapsmemsize != 0 and self.memoryusage - snapsmemsize < gpu.totalmem: - gprMax.config.snapsgpu2cpu = True + if snapsmemsize != 0 and self.memoryusage - snapsmemsize < config.gpus.totalmem: + config.snapsgpu2cpu = True def gpu_set_blocks_per_grid(self): """Set the blocks per grid size used for updating the electric and magnetic field arrays on a GPU.""" - gprMax.config.gpus.bpg = (int(np.ceil(((self.nx + 1) * (self.ny + 1) * (self.nz + 1)) / gpu.tpb[0])), 1, 1) + config.gpus.bpg = (int(np.ceil(((self.nx + 1) * (self.ny + 1) * (self.nz + 1)) / config.gpus.tpb[0])), 1, 1) def gpu_initialise_arrays(self): """Initialise standard field arrays on GPU.""" @@ -340,9 +339,9 @@ def dispersion_analysis(G): minwavelength = minvelocity / results['maxfreq'] # Maximum spatial step - if '3D' in gprMax.config.mode: + if '3D' in config.mode: delta = max(G.dx, G.dy, G.dz) - elif '2D' in gprMax.config.mode: + elif '2D' in config.mode: if G.nx == 1: delta = max(G.dy, G.dz) elif G.ny == 1: diff --git a/gprMax/input_cmds_multiuse.py b/gprMax/input_cmds_multiuse.py index d900e124..75193dac 100644 --- a/gprMax/input_cmds_multiuse.py +++ b/gprMax/input_cmds_multiuse.py @@ -23,7 +23,7 @@ init() import numpy as np from tqdm import tqdm -import gprMax.config +import gprMax.config as config from gprMax.config import z0 from gprMax.config import floattype from gprMax.config import gpus @@ -101,11 +101,11 @@ def process_multicmds(multicmds, G): polarisation = tmp[0].lower() if polarisation not in ('x', 'y', 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z') - if '2D TMx' in gprMax.config.mode and (polarisation == 'y' or polarisation == 'z'): + if '2D TMx' in config.mode and (polarisation == 'y' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x in 2D TMx mode') - elif '2D TMy' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'z'): + elif '2D TMy' in config.mode and (polarisation == 'x' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be y in 2D TMy mode') - elif '2D TMz' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'y'): + elif '2D TMz' in config.mode and (polarisation == 'x' or polarisation == 'y'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be z in 2D TMz mode') xcoord = G.calculate_coord('x', tmp[1]) @@ -172,11 +172,11 @@ def process_multicmds(multicmds, G): polarisation = tmp[0].lower() if polarisation not in ('x', 'y', 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z') - if '2D TMx' in gprMax.config.mode and (polarisation == 'y' or polarisation == 'z'): + if '2D TMx' in config.mode and (polarisation == 'y' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x in 2D TMx mode') - elif '2D TMy' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'z'): + elif '2D TMy' in config.mode and (polarisation == 'x' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be y in 2D TMy mode') - elif '2D TMz' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'y'): + elif '2D TMz' in config.mode and (polarisation == 'x' or polarisation == 'y'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be z in 2D TMz mode') xcoord = G.calculate_coord('x', tmp[1]) @@ -234,7 +234,7 @@ def process_multicmds(multicmds, G): h.calculate_waveform_values(G) if messages: - if '2D' in gprMax.config.mode: + if '2D' in config.mode: print('Hertzian dipole is a line source in 2D with polarity {} at {:g}m, {:g}m, {:g}m,'.format(h.polarisation, h.xcoord * G.dx, h.ycoord * G.dy, h.zcoord * G.dz) + startstop + 'using waveform {} created.'.format(h.waveformID)) else: print('Hertzian dipole with polarity {} at {:g}m, {:g}m, {:g}m,'.format(h.polarisation, h.xcoord * G.dx, h.ycoord * G.dy, h.zcoord * G.dz) + startstop + 'using waveform {} created.'.format(h.waveformID)) @@ -253,11 +253,11 @@ def process_multicmds(multicmds, G): polarisation = tmp[0].lower() if polarisation not in ('x', 'y', 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z') - if '2D TMx' in gprMax.config.mode and (polarisation == 'y' or polarisation == 'z'): + if '2D TMx' in config.mode and (polarisation == 'y' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x in 2D TMx mode') - elif '2D TMy' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'z'): + elif '2D TMy' in config.mode and (polarisation == 'x' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be y in 2D TMy mode') - elif '2D TMz' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'y'): + elif '2D TMz' in config.mode and (polarisation == 'x' or polarisation == 'y'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be z in 2D TMz mode') xcoord = G.calculate_coord('x', tmp[1]) @@ -326,11 +326,11 @@ def process_multicmds(multicmds, G): polarisation = tmp[0].lower() if polarisation not in ('x', 'y', 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z') - if '2D TMx' in gprMax.config.mode and (polarisation == 'y' or polarisation == 'z'): + if '2D TMx' in config.mode and (polarisation == 'y' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x in 2D TMx mode') - elif '2D TMy' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'z'): + elif '2D TMy' in config.mode and (polarisation == 'x' or polarisation == 'z'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be y in 2D TMy mode') - elif '2D TMz' in gprMax.config.mode and (polarisation == 'x' or polarisation == 'y'): + elif '2D TMz' in config.mode and (polarisation == 'x' or polarisation == 'y'): raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be z in 2D TMz mode') xcoord = G.calculate_coord('x', tmp[1]) diff --git a/gprMax/input_cmds_singleuse.py b/gprMax/input_cmds_singleuse.py index 1a0a1e26..f6d2b228 100644 --- a/gprMax/input_cmds_singleuse.py +++ b/gprMax/input_cmds_singleuse.py @@ -28,7 +28,7 @@ init() import numpy as np from scipy import interpolate -import gprMax.config +import gprMax.config as config from gprMax.config import c from gprMax.config import floattype from gprMax.config import gpus as gpu @@ -57,9 +57,9 @@ def process_singlecmds(singlecmds, G): if len(tmp) != 1: raise CmdInputError(cmd + ' requires exactly one parameter') if singlecmds[cmd].lower() == 'y': - gprMax.config.messages = True + config.messages = True elif singlecmds[cmd].lower() == 'n': - gprMax.config.messages = False + config.messages = False else: raise CmdInputError(cmd + ' requires input values of either y or n') @@ -84,34 +84,34 @@ def process_singlecmds(singlecmds, G): raise CmdInputError(cmd + ' requires exactly one parameter to specify the number of threads to use') if tmp[0] < 1: raise CmdInputError(cmd + ' requires the value to be an integer not less than one') - gprMax.config.hostinfo['ompthreads'] = tmp[0] - os.environ['OMP_NUM_THREADS'] = str(gprMax.config.hostinfo['ompthreads']) + config.hostinfo['ompthreads'] = tmp[0] + os.environ['OMP_NUM_THREADS'] = str(config.hostinfo['ompthreads']) elif os.environ.get('OMP_NUM_THREADS'): - gprMax.config.hostinfo['ompthreads'] = int(os.environ.get('OMP_NUM_THREADS')) + config.hostinfo['ompthreads'] = int(os.environ.get('OMP_NUM_THREADS')) else: # Set number of threads to number of physical CPU cores - gprMax.config.hostinfo['ompthreads'] = hostinfo['physicalcores'] - os.environ['OMP_NUM_THREADS'] = str(gprMax.config.hostinfo['ompthreads']) + config.hostinfo['ompthreads'] = hostinfo['physicalcores'] + os.environ['OMP_NUM_THREADS'] = str(config.hostinfo['ompthreads']) - if gprMax.config.messages: - print('CPU (OpenMP) threads: {}'.format(gprMax.config.hostinfo['ompthreads'])) - if gprMax.config.hostinfo['ompthreads'] > hostinfo['physicalcores']: - print(Fore.RED + 'WARNING: You have specified more threads ({}) than available physical CPU cores ({}). This may lead to degraded performance.'.format(gprMax.config.hostinfo['ompthreads'], hostinfo['physicalcores']) + Style.RESET_ALL) + if config.messages: + print('CPU (OpenMP) threads: {}'.format(config.hostinfo['ompthreads'])) + if config.hostinfo['ompthreads'] > hostinfo['physicalcores']: + print(Fore.RED + 'WARNING: You have specified more threads ({}) than available physical CPU cores ({}). This may lead to degraded performance.'.format(config.hostinfo['ompthreads'], hostinfo['physicalcores']) + Style.RESET_ALL) # Print information about any GPU in use - if gprMax.config.messages: + if config.messages: if gpu is not None: print('GPU: {} - {}'.format(gpu.deviceID, gpu.name)) # Print information about precision of main field values - if gprMax.config.messages: + if config.messages: print('Output data type: {}\n'.format(np.dtype(floattype).name)) # Title cmd = '#title' if singlecmds[cmd] is not None: G.title = singlecmds[cmd] - if gprMax.config.messages: + if config.messages: print('Model title: {}'.format(G.title)) # Spatial discretisation @@ -128,7 +128,7 @@ def process_singlecmds(singlecmds, G): G.dx = tmp[0] G.dy = tmp[1] G.dz = tmp[2] - if gprMax.config.messages: + if config.messages: print('Spatial discretisation: {:g} x {:g} x {:g}m'.format(G.dx, G.dy, G.dz)) # Domain @@ -141,35 +141,35 @@ def process_singlecmds(singlecmds, G): G.nz = round_value(tmp[2] / G.dz) if G.nx == 0 or G.ny == 0 or G.nz == 0: raise CmdInputError(cmd + ' requires at least one cell in every dimension') - if gprMax.config.messages: + if config.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))) # Time step CFL limit (either 2D or 3D); switch off appropriate PMLs for 2D if G.nx == 1: G.dt = 1 / (c * np.sqrt((1 / G.dy) * (1 / G.dy) + (1 / G.dz) * (1 / G.dz))) - gprMax.config.mode = '2D TMx' + config.mode = '2D TMx' G.pmlthickness['x0'] = 0 G.pmlthickness['xmax'] = 0 elif G.ny == 1: G.dt = 1 / (c * np.sqrt((1 / G.dx) * (1 / G.dx) + (1 / G.dz) * (1 / G.dz))) - gprMax.config.mode = '2D TMy' + config.mode = '2D TMy' G.pmlthickness['y0'] = 0 G.pmlthickness['ymax'] = 0 elif G.nz == 1: G.dt = 1 / (c * np.sqrt((1 / G.dx) * (1 / G.dx) + (1 / G.dy) * (1 / G.dy))) - gprMax.config.mode = '2D TMz' + config.mode = '2D TMz' G.pmlthickness['z0'] = 0 G.pmlthickness['zmax'] = 0 else: G.dt = 1 / (c * np.sqrt((1 / G.dx) * (1 / G.dx) + (1 / G.dy) * (1 / G.dy) + (1 / G.dz) * (1 / G.dz))) - gprMax.config.mode = '3D' + config.mode = '3D' # Round down time step to nearest float with precision one less than hardware maximum. # Avoids inadvertently exceeding the CFL due to binary representation of floating point number. G.dt = round_value(G.dt, decimalplaces=d.getcontext().prec - 1) - if gprMax.config.messages: - print('Mode: {}'.format(gprMax.config.mode)) + if config.messages: + print('Mode: {}'.format(config.mode)) print('Time step (at CFL limit): {:g} secs'.format(G.dt)) # Time step stability factor @@ -181,7 +181,7 @@ def process_singlecmds(singlecmds, G): if tmp[0] <= 0 or tmp[0] > 1: raise CmdInputError(cmd + ' requires the value of the time step stability factor to be between zero and one') G.dt = G.dt * tmp[0] - if gprMax.config.messages: + if config.messages: print('Time step (modified): {:g} secs'.format(G.dt)) # Time window @@ -206,7 +206,7 @@ def process_singlecmds(singlecmds, G): G.iterations = int(np.ceil(tmp / G.dt)) + 1 else: raise CmdInputError(cmd + ' must have a value greater than zero') - if gprMax.config.messages: + if config.messages: print('Time window: {:g} secs ({} iterations)'.format(G.timewindow, G.iterations)) # PML cells @@ -248,7 +248,7 @@ def process_singlecmds(singlecmds, G): G.srcsteps[0] = round_value(float(tmp[0]) / G.dx) G.srcsteps[1] = round_value(float(tmp[1]) / G.dy) G.srcsteps[2] = round_value(float(tmp[2]) / G.dz) - if gprMax.config.messages: + if config.messages: print('Simple sources will step {:g}m, {:g}m, {:g}m for each model run.'.format(G.srcsteps[0] * G.dx, G.srcsteps[1] * G.dy, G.srcsteps[2] * G.dz)) # rx_steps @@ -260,7 +260,7 @@ def process_singlecmds(singlecmds, G): G.rxsteps[0] = round_value(float(tmp[0]) / G.dx) G.rxsteps[1] = round_value(float(tmp[1]) / G.dy) G.rxsteps[2] = round_value(float(tmp[2]) / G.dz) - if gprMax.config.messages: + if config.messages: print('All receivers will step {:g}m, {:g}m, {:g}m for each model run.'.format(G.rxsteps[0] * G.dx, G.rxsteps[1] * G.dy, G.rxsteps[2] * G.dz)) # Excitation file for user-defined source waveforms @@ -284,7 +284,7 @@ def process_singlecmds(singlecmds, G): if not os.path.isfile(excitationfile): excitationfile = os.path.abspath(os.path.join(G.inputdirectory, excitationfile)) - if gprMax.config.messages: + if config.messages: print('\nExcitation file: {}'.format(excitationfile)) # Get waveform names @@ -326,7 +326,7 @@ def process_singlecmds(singlecmds, G): # Interpolate waveform values w.userfunc = interpolate.interp1d(waveformtime, singlewaveformvalues, **kwargs) - if gprMax.config.messages: + if config.messages: print('User waveform {} created using {} and, if required, interpolation parameters (kind: {}, fill value: {}).'.format(w.ID, timestr, kwargs['kind'], kwargs['fill_value'])) G.waveforms.append(w) diff --git a/gprMax/model_build_run.py b/gprMax/model_build_run.py index 28394ea1..ee99c9f3 100644 --- a/gprMax/model_build_run.py +++ b/gprMax/model_build_run.py @@ -31,13 +31,13 @@ import numpy as np from terminaltables import SingleTable from tqdm import tqdm +import gprMax.config as config from gprMax.config import floattype from gprMax.config import complextype from gprMax.config import cudafloattype from gprMax.config import cudacomplextype from gprMax.config import numdispersion from gprMax.config import hostinfo -from gprMax.config import gpus as gpu from gprMax.config import messages from gprMax.config import progressbars from gprMax.config import snapsgpu2cpu @@ -167,9 +167,10 @@ def run_model(args, currentmodelrun, modelend, numbermodelruns, inputfile, usern G.memory_estimate_basic() G.memory_check() if messages: - print('\nMemory (RAM) required: ~{}\n'.format(human_size(G.memoryusage))) - if gpu: - print('\nGPU memory (RAM) required: ~{}\n'.format(human_size(G.memoryusage))) + memGPU = '' + if config.gpus: + memGPU = ' host + ~{} GPU'.format(human_size(G.memoryusage)) + print('\nMemory (RAM) required: ~{}{}\n'.format(human_size(G.memoryusage), memGPU)) # Initialise an array for volumetric material IDs (solid), boolean # arrays for specifying materials not to be averaged (rigid), @@ -362,7 +363,7 @@ def run_model(args, currentmodelrun, modelend, numbermodelruns, inputfile, usern print('\nOutput file: {}\n'.format(outputfile)) # Main FDTD solving functions for either CPU or GPU - if gpu is None: + if config.gpus is None: tsolve = solve_cpu(currentmodelrun, modelend, G) else: tsolve, memsolve = solve_gpu(currentmodelrun, modelend, G) @@ -386,9 +387,10 @@ def run_model(args, currentmodelrun, modelend, numbermodelruns, inputfile, usern if messages: print() if messages: - print('Memory (RAM) used: ~{}'.format(human_size(p.memory_full_info().uss))) - if gpu: - print('GPU memory (RAM) used: ~{}'.format(human_size(memsolve))) + memGPU = '' + if config.gpus: + memGPU = ' host + ~{} GPU'.format(human_size(memsolve)) + print('\nMemory (RAM) used: ~{}{}'.format(human_size(p.memory_full_info().uss), memGPU)) print('Solving time [HH:MM:SS]: {}'.format(datetime.timedelta(seconds=tsolve))) # If geometry information to be reused between model runs then FDTDGrid @@ -492,7 +494,7 @@ def solve_gpu(currentmodelrun, modelend, G): compiler_opts = None # Create device handle and context on specifc GPU device (and make it current context) - dev = drv.Device(gpu.deviceID) + dev = drv.Device(config.gpus.deviceID) ctx = dev.make_context() # Electric and magnetic field updates - prepare kernels, and get kernel functions @@ -506,8 +508,8 @@ def solve_gpu(currentmodelrun, modelend, G): # Copy material coefficient arrays to constant memory of GPU (must be <64KB) for fields kernels updatecoeffsE = kernels_fields.get_global('updatecoeffsE')[0] updatecoeffsH = kernels_fields.get_global('updatecoeffsH')[0] - if G.updatecoeffsE.nbytes + G.updatecoeffsH.nbytes > gpu.constmem: - raise GeneralError('Too many materials in the model to fit onto constant memory of size {} on {} - {} GPU'.format(human_size(gpu.constmem), gpu.deviceID, gpu.name)) + if G.updatecoeffsE.nbytes + G.updatecoeffsH.nbytes > config.gpus.constmem: + raise GeneralError('Too many materials in the model to fit onto constant memory of size {} on {} - {} GPU'.format(human_size(config.gpus.constmem), config.gpus.deviceID, config.gpus.name)) else: drv.memcpy_htod(updatecoeffsE, G.updatecoeffsE) drv.memcpy_htod(updatecoeffsH, G.updatecoeffsH) @@ -627,7 +629,7 @@ def solve_gpu(currentmodelrun, modelend, G): update_h_gpu(np.int32(G.nx), np.int32(G.ny), np.int32(G.nz), G.ID_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, - G.Ez_gpu.gpudata, block=G.tpb, grid=G.bpg) + G.Ez_gpu.gpudata, block=config.gpus.tpb, grid=config.gpus.bpg) # Update magnetic field components with the PML correction for pml in G.pmls: @@ -648,7 +650,7 @@ def solve_gpu(currentmodelrun, modelend, G): update_e_gpu(np.int32(G.nx), np.int32(G.ny), np.int32(G.nz), G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, - block=G.tpb, grid=G.bpg) + block=config.gpus.tpb, grid=config.gpus.bpg) # If there are any dispersive materials do 1st part of dispersive update # (it is split into two parts as it requires present and updated electric field values). else: @@ -657,7 +659,7 @@ def solve_gpu(currentmodelrun, modelend, G): G.Tx_gpu.gpudata, G.Ty_gpu.gpudata, G.Tz_gpu.gpudata, G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, - block=G.tpb, grid=G.bpg) + block=config.gpus.tpb, grid=config.gpus.bpg) # Update electric field components with the PML correction for pml in G.pmls: @@ -687,7 +689,7 @@ def solve_gpu(currentmodelrun, modelend, G): np.int32(Material.maxpoles), G.updatecoeffsdispersive_gpu.gpudata, G.Tx_gpu.gpudata, G.Ty_gpu.gpudata, G.Tz_gpu.gpudata, G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, - block=G.tpb, grid=G.bpg) + block=config.gpus.tpb, grid=config.gpus.bpg) # Copy output from receivers array back to correct receiver objects if G.rxs: diff --git a/gprMax/pml.py b/gprMax/pml.py index 7e5921d7..76bbd643 100644 --- a/gprMax/pml.py +++ b/gprMax/pml.py @@ -21,6 +21,7 @@ from importlib import import_module import numpy as np from tqdm import tqdm +import gprMax.config as config from gprMax.config import e0 from gprMax.config import z0 from gprMax.config import floattype @@ -302,7 +303,7 @@ class PML(object): G (class): Grid class instance - holds essential parameters describing the model. """ - self.bpg = (int(np.ceil(((self.EPhi1.shape[1] + 1) * (self.EPhi1.shape[2] + 1) * (self.EPhi1.shape[3] + 1)) / G.tpb[0])), 1, 1) + config.gpus.bpg = (int(np.ceil(((self.EPhi1.shape[1] + 1) * (self.EPhi1.shape[2] + 1) * (self.EPhi1.shape[3] + 1)) / config.gpus.tpb[0])), 1, 1) def gpu_initialise_arrays(self): """Initialise PML field and coefficient arrays on GPU.""" @@ -342,7 +343,7 @@ class PML(object): G (class): Grid class instance - holds essential parameters describing the model. """ - self.update_electric_gpu(np.int32(self.xs), np.int32(self.xf), np.int32(self.ys), np.int32(self.yf), np.int32(self.zs), np.int32(self.zf), np.int32(self.EPhi1.shape[1]), np.int32(self.EPhi1.shape[2]), np.int32(self.EPhi1.shape[3]), np.int32(self.EPhi2.shape[1]), np.int32(self.EPhi2.shape[2]), np.int32(self.EPhi2.shape[3]), np.int32(self.thickness), G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, self.EPhi1_gpu.gpudata, self.EPhi2_gpu.gpudata, self.ERA_gpu.gpudata, self.ERB_gpu.gpudata, self.ERE_gpu.gpudata, self.ERF_gpu.gpudata, floattype(self.d), block=G.tpb, grid=self.bpg) + self.update_electric_gpu(np.int32(self.xs), np.int32(self.xf), np.int32(self.ys), np.int32(self.yf), np.int32(self.zs), np.int32(self.zf), np.int32(self.EPhi1.shape[1]), np.int32(self.EPhi1.shape[2]), np.int32(self.EPhi1.shape[3]), np.int32(self.EPhi2.shape[1]), np.int32(self.EPhi2.shape[2]), np.int32(self.EPhi2.shape[3]), np.int32(self.thickness), G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, self.EPhi1_gpu.gpudata, self.EPhi2_gpu.gpudata, self.ERA_gpu.gpudata, self.ERB_gpu.gpudata, self.ERE_gpu.gpudata, self.ERF_gpu.gpudata, floattype(self.d), block=config.gpus.tpb, grid=config.gpus.bpg) def gpu_update_magnetic(self, G): """This functions updates magnetic field components with the PML correction on the GPU. @@ -351,7 +352,7 @@ class PML(object): G (class): Grid class instance - holds essential parameters describing the model. """ - self.update_magnetic_gpu(np.int32(self.xs), np.int32(self.xf), np.int32(self.ys), np.int32(self.yf), np.int32(self.zs), np.int32(self.zf), np.int32(self.HPhi1.shape[1]), np.int32(self.HPhi1.shape[2]), np.int32(self.HPhi1.shape[3]), np.int32(self.HPhi2.shape[1]), np.int32(self.HPhi2.shape[2]), np.int32(self.HPhi2.shape[3]), np.int32(self.thickness), G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, self.HPhi1_gpu.gpudata, self.HPhi2_gpu.gpudata, self.HRA_gpu.gpudata, self.HRB_gpu.gpudata, self.HRE_gpu.gpudata, self.HRF_gpu.gpudata, floattype(self.d), block=G.tpb, grid=self.bpg) + self.update_magnetic_gpu(np.int32(self.xs), np.int32(self.xf), np.int32(self.ys), np.int32(self.yf), np.int32(self.zs), np.int32(self.zf), np.int32(self.HPhi1.shape[1]), np.int32(self.HPhi1.shape[2]), np.int32(self.HPhi1.shape[3]), np.int32(self.HPhi2.shape[1]), np.int32(self.HPhi2.shape[2]), np.int32(self.HPhi2.shape[3]), np.int32(self.thickness), G.ID_gpu.gpudata, G.Ex_gpu.gpudata, G.Ey_gpu.gpudata, G.Ez_gpu.gpudata, G.Hx_gpu.gpudata, G.Hy_gpu.gpudata, G.Hz_gpu.gpudata, self.HPhi1_gpu.gpudata, self.HPhi2_gpu.gpudata, self.HRA_gpu.gpudata, self.HRB_gpu.gpudata, self.HRE_gpu.gpudata, self.HRF_gpu.gpudata, floattype(self.d), block=config.gpus.tpb, grid=config.gpus.bpg) def build_pmls(G, pbar):