diff options
-rw-r--r-- | Examples/Physics_applications/laser_acceleration/laser_acceleration_PICMI.py | 15 | ||||
-rw-r--r-- | Python/pywarpx/Bucket.py | 4 | ||||
-rw-r--r-- | Python/pywarpx/WarpX.py | 2 | ||||
-rw-r--r-- | Python/pywarpx/picmi.py | 90 |
4 files changed, 109 insertions, 2 deletions
diff --git a/Examples/Physics_applications/laser_acceleration/laser_acceleration_PICMI.py b/Examples/Physics_applications/laser_acceleration/laser_acceleration_PICMI.py index 77cd2e176..b68beece2 100644 --- a/Examples/Physics_applications/laser_acceleration/laser_acceleration_PICMI.py +++ b/Examples/Physics_applications/laser_acceleration/laser_acceleration_PICMI.py @@ -95,6 +95,18 @@ solver = picmi.ElectromagneticSolver(grid=grid, method='CKC', cfl=1.) ########################## +# diagnostics +########################## + +field_diag1 = picmi.FieldDiagnostic(period = 100, + warpx_plot_raw_fields = 1, + warpx_plot_raw_fields_guards = 1, + warpx_plot_finepatch = 1, + warpx_plot_crsepatch = 1) + +part_diag1 = picmi.ParticleDiagnostic(period = 100) + +########################## # simulation setup ########################## @@ -102,7 +114,6 @@ sim = picmi.Simulation(solver = solver, max_steps = max_steps, verbose = 1, cfl = 1.0, - warpx_plot_int = 100, warpx_current_deposition_algo = 3, warpx_charge_deposition_algo = 0, warpx_field_gathering_algo = 0, @@ -112,6 +123,8 @@ sim.add_species(electrons, layout=picmi.GriddedLayout(grid=grid, n_macroparticle sim.add_laser(laser, injection_method=laser_antenna) +sim.add_diagnostic(field_diag1) +sim.add_diagnostic(part_diag1) ########################## # simulation run diff --git a/Python/pywarpx/Bucket.py b/Python/pywarpx/Bucket.py index c73b3dac9..66494a700 100644 --- a/Python/pywarpx/Bucket.py +++ b/Python/pywarpx/Bucket.py @@ -20,6 +20,10 @@ class Bucket(object): except KeyError: return object.__getattr__(self, name) + def check_consistency(self, vname, value, errmsg): + if vname in self.argvattrs: + assert (self.argvattrs[vname] is None) or (self.argvattrs[vname] == value), Exception(errmsg) + def attrlist(self): "Concatenate the attributes into a string" result = [] diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py index 9c4a4b380..f58d4f111 100644 --- a/Python/pywarpx/WarpX.py +++ b/Python/pywarpx/WarpX.py @@ -70,7 +70,7 @@ class WarpX(Bucket): argv = self.create_argv_list() with open(filename, 'w') as ff: - for k, v in kw.iteritems(): + for k, v in kw.items(): ff.write('{0} = {1}\n'.format(k, v)) for arg in argv: diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 1d02f8b29..72778e447 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -462,6 +462,9 @@ class Simulation(picmistandard.PICMI_Simulation): self.lasers[i].initialize_inputs() self.laser_injection_methods[i].initialize_inputs(self.lasers[i]) + for diagnostic in self.diagnostics: + diagnostic.initialize_inputs() + def initialize_warpx(self): if self.warpx_initialized: return @@ -492,3 +495,90 @@ class Simulation(picmistandard.PICMI_Simulation): if self.warpx_initialized: self.warpx_initialized = False pywarpx.warpx.finalize() + + +# ---------------------------- +# Simulation frame diagnostics +# ---------------------------- + + +class FieldDiagnostic(picmistandard.PICMI_FieldDiagnostic): + def init(self, kw): + + self.plot_raw_fields = kw.pop('warpx_plot_raw_fields', None) + self.plot_raw_fields_guards = kw.pop('warpx_plot_raw_fields_guards', None) + self.plot_finepatch = kw.pop('warpx_plot_finepatch', None) + self.plot_crsepatch = kw.pop('warpx_plot_crsepatch', None) + + def initialize_inputs(self): + # --- For now, the period must be the same as plot_int if set + pywarpx.amr.check_consistency('plot_int', self.period, 'The period must be the same for all simulation frame diagnostics') + pywarpx.amr.plot_int = self.period + + if 'rho' in self.field_types: + pywarpx.warpx.plot_rho = 1 + if 'dive' in self.field_types: + pywarpx.warpx.plot_dive = 1 + if 'divb' in self.field_types: + pywarpx.warpx.plot_divb = 1 + if 'F' in self.field_types: + pywarpx.warpx.plot_F = 1 + if 'proc_number' in self.field_types: + pywarpx.warpx.plot_proc_number = 1 + + pywarpx.warpx.plot_raw_fields = self.plot_raw_fields + pywarpx.warpx.plot_raw_fields_guards = self.plot_raw_fields_guards + + pywarpx.amr.check_consistency('plot_finepatch', self.plot_finepatch, 'The fine patch flag must be the same for all simulation frame field diagnostics') + pywarpx.amr.check_consistency('plot_crsepatch', self.plot_crsepatch, 'The coarse patch flag must be the same for all simulation frame field diagnostics') + pywarpx.warpx.plot_finepatch = self.plot_finepatch + pywarpx.warpx.plot_crsepatch = self.plot_crsepatch + +class ElectrostaticFieldDiagnostic(picmistandard.PICMI_ElectrostaticFieldDiagnostic): + def initialize_inputs(self): + # --- For now, the period must be the same as plot_int if set + pywarpx.amr.check_consistency('plot_int', self.period, 'The period must be the same for all simulation frame diagnostics') + pywarpx.amr.plot_int = self.period + + +class ParticleDiagnostic(picmistandard.PICMI_ParticleDiagnostic): + def initialize_inputs(self): + # --- For now, the period must be the same as plot_int if set + pywarpx.amr.check_consistency('plot_int', self.period, 'The period must be the same for all simulation frame diagnostics') + pywarpx.amr.plot_int = self.period + + if 'part_per_cell' in self.particle_data: + pywarpx.warpx.plot_part_per_cell = 1 + if 'part_per_grid' in self.particle_data: + pywarpx.warpx.plot_part_per_grid = 1 + if 'part_per_proc' in self.particle_data: + pywarpx.warpx.plot_part_per_proc = 1 + + +# ---------------------------- +# Lab frame diagnostics +# ---------------------------- + + +class LabFrameFieldDiagnostic(picmistandard.PICMI_LabFrameFieldDiagnostic): + def initialize_inputs(self): + + pywarpx.warpx.check_consistency('num_snapshots_lab', self.num_snapshots, 'The number of snapshots must be the same in all lab frame diagnostics') + pywarpx.warpx.check_consistency('dt_snapshots_lab', self.dt_snapshots, 'The time between snapshots must be the same in all lab frame diagnostics') + + pywarpx.warpx.do_boosted_frame_diagnostic = 1 + pywarpx.warpx.num_snapshots_lab = self.num_snapshots + pywarpx.warpx.dt_snapshots_lab = self.dt_snapshots + pywarpx.warpx.do_boosted_frame_fields = 1 + + +class LabFrameParticleDiagnostic(picmistandard.PICMI_LabFrameParticleDiagnostic): + def initialize_inputs(self): + + pywarpx.warpx.check_consistency('num_snapshots_lab', self.num_snapshots, 'The number of snapshots must be the same in all lab frame diagnostics') + pywarpx.warpx.check_consistency('dt_snapshots_lab', self.dt_snapshots, 'The time between snapshots must be the same in all lab frame diagnostics') + + pywarpx.warpx.do_boosted_frame_diagnostic = 1 + pywarpx.warpx.num_snapshots_lab = self.num_snapshots + pywarpx.warpx.dt_snapshots_lab = self.dt_snapshots + pywarpx.warpx.do_boosted_frame_particles = 1 |