From 72c85b29d6aff54182ce6d12ace28ef140250cad Mon Sep 17 00:00:00 2001 From: Sai Suraj Date: Tue, 18 Apr 2023 02:06:25 +0530 Subject: [PATCH] Made changes to the reformatted code as per the suggestions given. --- gprMax/hash_cmds_file.py | 4 +- gprMax/hash_cmds_singleuse.py | 4 +- gprMax/updates.py | 32 +++++-------- .../pml_3D_pec_plate/pml_3D_pec_plate.py | 24 ++++------ .../pml_3D_pec_plate/pml_3D_pec_plate_ref.py | 24 ++++------ testing/test_experimental.py | 10 ++-- testing/test_models.py | 47 +++++++------------ 7 files changed, 58 insertions(+), 87 deletions(-) diff --git a/gprMax/hash_cmds_file.py b/gprMax/hash_cmds_file.py index 9dac055d..845b21d5 100644 --- a/gprMax/hash_cmds_file.py +++ b/gprMax/hash_cmds_file.py @@ -178,8 +178,8 @@ def write_processed_file(processedlines): for item in processedlines: f.write(f'{item}') - logger.info(f'Written input commands, after processing any Python code and ' - f'include commands, to file: {processedfile}\n') + logger.info(f'Written input commands, after processing any Python ' + + f'code and include commands, to file: {processedfile}\n') def check_cmd_names(processedlines, checkessential=True): diff --git a/gprMax/hash_cmds_singleuse.py b/gprMax/hash_cmds_singleuse.py index 8edc496d..86ac37cc 100644 --- a/gprMax/hash_cmds_singleuse.py +++ b/gprMax/hash_cmds_singleuse.py @@ -55,7 +55,7 @@ def process_singlecmds(singlecmds): if singlecmds[cmd] is not None: tmp = tuple(int(x) for x in singlecmds[cmd].split()) if len(tmp) != 1: - logger.exception(f'{cmd} requires exactly one parameter to specify ' + logger.exception(f'{cmd} requires exactly one parameter to specify ' + f'the number of CPU OpenMP threads to use') raise ValueError @@ -94,7 +94,7 @@ def process_singlecmds(singlecmds): if singlecmds[cmd] is not None: tmp = singlecmds[cmd].split() if len(tmp) != 1: - logger.exception(f'{cmd} requires exactly one parameter to specify the ' + logger.exception(f'{cmd} requires exactly one parameter to specify the ' + f'time window. Either in seconds or number of iterations.') raise ValueError tmp = tmp[0].lower() diff --git a/gprMax/updates.py b/gprMax/updates.py index 75961ab3..fa063e74 100644 --- a/gprMax/updates.py +++ b/gprMax/updates.py @@ -884,27 +884,19 @@ class OpenCLUpdates: knl_electric_name = getattr(knl_pml_updates_electric, knl_name) knl_magnetic_name = getattr(knl_pml_updates_magnetic, knl_name) - pml.update_electric_dev = self.elwise( - self.ctx, - knl_electric_name['args_opencl'].substitute( - {'REAL': config.sim_config.dtypes['C_float_or_double']} - ), - knl_electric_name['func'].substitute(subs), - f'pml_updates_electric_{knl_name}', - preamble=self.knl_common, - options=config.sim_config.devices['compiler_opts'], - ) + pml.update_electric_dev = self.elwise(self.ctx, + knl_electric_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}), + knl_electric_name['func'].substitute(subs), + 'pml_updates_electric_' + knl_name, + preamble=self.knl_common, + options=config.sim_config.devices['compiler_opts']) - pml.update_magnetic_dev = self.elwise( - self.ctx, - knl_magnetic_name['args_opencl'].substitute( - {'REAL': config.sim_config.dtypes['C_float_or_double']} - ), - knl_magnetic_name['func'].substitute(subs), - f'pml_updates_magnetic_{knl_name}', - preamble=self.knl_common, - options=config.sim_config.devices['compiler_opts'], - ) + pml.update_magnetic_dev = self.elwise(self.ctx, + knl_magnetic_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}), + knl_magnetic_name['func'].substitute(subs), + 'pml_updates_magnetic_' + knl_name, + preamble=self.knl_common, + options=config.sim_config.devices['compiler_opts']) def _set_rx_knl(self): """Receivers - initialises arrays on compute device, prepares kernel and diff --git a/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate.py b/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate.py index eda4698f..e87751e5 100755 --- a/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate.py +++ b/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate.py @@ -29,20 +29,16 @@ rx = gprMax.Rx(p1=(0.038, 0.114, 0.013)) plate = gprMax.Plate(p1=(0.013, 0.013, 0.013), p2=(0.038, 0.113, 0.013), material_id='pec') -gv1 = gprMax.GeometryView( - p1=(0, 0, 0), - p2=(x, y, z), - dl=(dl, dl, dl), - filename=Path(*parts[:-1], f'{parts[-1]}_n'), - output_type='n', -) -gv2 = gprMax.GeometryView( - p1=(0, 0, 0), - p2=(x, y, z), - dl=(dl, dl, dl), - filename=Path(*parts[:-1], f'{parts[-1]}_f'), - output_type='f', -) +gv1 = gprMax.GeometryView(p1=(0, 0, 0), + p2=(x, y, z), + dl=(dl, dl, dl), + filename=Path(*parts[:-1], f'{parts[-1]}_n'), + output_type='n',) +gv2 = gprMax.GeometryView(p1=(0, 0, 0), + p2=(x, y, z), + dl=(dl, dl, dl), + filename=Path(*parts[:-1], f'{parts[-1]}_f'), + output_type='f',) pmls = {'CFS-PML': {'pml': gprMax.PMLProps(formulation='HORIPML', thickness=10), # Parameters from http://dx.doi.org/10.1109/TAP.2018.2823864 diff --git a/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate_ref.py b/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate_ref.py index c1a717c0..f9f42c9f 100755 --- a/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate_ref.py +++ b/testing/models_pmls/pml_3D_pec_plate/pml_3D_pec_plate_ref.py @@ -29,20 +29,16 @@ rx = gprMax.Rx(p1=(0.113, 0.189, 0.088)) plate = gprMax.Plate(p1=(0.088, 0.088, 0.088), p2=(0.113, 0.188, 0.088), material_id='pec') -gv1 = gprMax.GeometryView( - p1=(0, 0, 0), - p2=(x, y, z), - dl=(dl, dl, dl), - filename=Path(*parts[:-1], f'{parts[-1]}_n'), - output_type='n', -) -gv2 = gprMax.GeometryView( - p1=(0, 0, 0), - p2=(x, y, z), - dl=(dl, dl, dl), - filename=Path(*parts[:-1], f'{parts[-1]}_f'), - output_type='f', -) +gv1 = gprMax.GeometryView(p1=(0, 0, 0), + p2=(x, y, z), + dl=(dl, dl, dl), + filename=Path(*parts[:-1], f'{parts[-1]}_n'), + output_type='n',) +gv2 = gprMax.GeometryView(p1=(0, 0, 0), + p2=(x, y, z), + dl=(dl, dl, dl), + filename=Path(*parts[:-1], f'{parts[-1]}_f'), + output_type='f',) pml = gprMax.PMLProps(formulation='HORIPML', thickness=10) diff --git a/testing/test_experimental.py b/testing/test_experimental.py index 586002df..1146f935 100644 --- a/testing/test_experimental.py +++ b/testing/test_experimental.py @@ -81,12 +81,10 @@ realmax = np.where(np.abs(real[:, 1]) == 1)[0][0] difftime = - (timemodel[modelmax] - real[realmax, 0]) # Plot modelled and real data -fig, ax = plt.subplots( - num=f'{modelfile.stem}_vs_{realfile.stem}', - figsize=(20, 10), - facecolor='w', - edgecolor='w', -) +fig, ax = plt.subplots(num=f'{modelfile.stem}_vs_{realfile.stem}', + figsize=(20, 10), + facecolor='w', + edgecolor='w',) ax.plot(timemodel + difftime, model, 'r', lw=2, label='Model') ax.plot(real[:, 0], real[:, 1], 'r', ls='--', lw=2, label='Experiment') ax.set_xlabel('Time [s]') diff --git a/testing/test_models.py b/testing/test_models.py index ad864375..f21bc144 100644 --- a/testing/test_models.py +++ b/testing/test_models.py @@ -130,12 +130,9 @@ for i, model in enumerate(testmodels): # Check that type of float used to store fields matches if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype: - logger.warning( - ( - f'Type of floating point number in test model ({filetest[path + outputstest[0]].dtype}) does not ' - + f'match type in reference solution ({fileref[path + outputsref[0]].dtype})\n' - ) - ) + logger.warning(f'Type of floating point number in test model ' + + f'({filetest[path + outputstest[0]].dtype}) does not ' + + f'match type in reference solution ({fileref[path + outputsref[0]].dtype})\n') float_or_doubleref = fileref[path + outputsref[0]].dtype float_or_doubletest = filetest[path + outputstest[0]].dtype @@ -176,22 +173,18 @@ for i, model in enumerate(testmodels): # Replace any NaNs or Infs from zero division datadiffs[:, i][np.invert(np.isfinite(datadiffs[:, i]))] = 0 - # Store maxi difference + # Store max difference maxdiff = np.amax(np.amax(datadiffs)) testresults[model]['Max diff'] = maxdiff # Plot datasets - fig1, ((ex1, hx1), (ey1, hy1), (ez1, hz1)) = plt.subplots( - nrows=3, - ncols=2, - sharex=False, - sharey='col', - subplot_kw=dict(xlabel='Time [ns]'), - num=f'{model}.in', - figsize=(20, 10), - facecolor='w', - edgecolor='w', - ) + fig1, ((ex1, hx1), (ey1, hy1), (ez1, hz1)) = plt.subplots(nrows=3, ncols=2, + sharex=False, sharey='col', + subplot_kw=dict(xlabel='Time [ns]'), + num=model + '.in', + figsize=(20, 10), + facecolor='w', + edgecolor='w') ex1.plot(timetest, datatest[:, 0], 'r', lw=2, label=model) ex1.plot(timeref, dataref[:, 0], 'g', lw=2, ls='--', label=f'{model}(Ref)') ey1.plot(timetest, datatest[:, 1], 'r', lw=2, label=model) @@ -214,17 +207,13 @@ for i, model in enumerate(testmodels): ax.legend() # Plot diffs - fig2, ((ex2, hx2), (ey2, hy2), (ez2, hz2)) = plt.subplots( - nrows=3, - ncols=2, - sharex=False, - sharey='col', - subplot_kw=dict(xlabel='Time [ns]'), - num=f'Diffs: {model}.in', - figsize=(20, 10), - facecolor='w', - edgecolor='w', - ) + fig2, ((ex2, hx2), (ey2, hy2), (ez2, hz2)) = plt.subplots(nrows=3, ncols=2, + sharex=False, sharey='col', + subplot_kw=dict(xlabel='Time [ns]'), + num='Diffs: ' + model + '.in', + figsize=(20, 10), + facecolor='w', + edgecolor='w') ex2.plot(timeref, datadiffs[:, 0], 'r', lw=2, label='Ex') ey2.plot(timeref, datadiffs[:, 1], 'r', lw=2, label='Ey') ez2.plot(timeref, datadiffs[:, 2], 'r', lw=2, label='Ez')