forked from ECP-WarpX/WarpX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to load external particle fields from file (ECP-WarpX#4997)
* Update documentation * Allocate fields * Always parse filename * Add option "FromFile" in external particles fields * Create two separate examples * Update documentation * Allocate aux array * Update aux to take into account copy * Add external fields from file to auxiliary data * Update tests * Remove debugging Print statements * If averaged PSATD is used, we copy Efield_avg_fp to Efield_aux, otherwise copy Efield_fp. * Do not access cells that have invalid data when summing external fields * Update path of checkpoint files * Update comments * Update number of components * Fix clang tidy error * Make the code compatible with momentum-conserving gather * Add Python interface and tests * Use PICMI version that defined LoadAppliedField * Update file names * Update PICMI standard version * Allocate dedicated MultiFabs for external particle fields * Some clean-up * Performance optimization: do not use external fields in gather kernel * Allow external particle fields and external grid fields to be simultaneously defined * External fields are incompatible with the moving window * Support load balancing * Update Source/Initialization/WarpXInitData.cpp * Update Source/Initialization/WarpXInitData.cpp --------- Co-authored-by: Remi Lehe <[email protected]>
- Loading branch information
Showing
19 changed files
with
497 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Examples/Tests/LoadExternalField/PICMI_inputs_3d_particle_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# --- Input file for loading initial field from openPMD file. | ||
|
||
from pywarpx import picmi | ||
|
||
constants = picmi.constants | ||
|
||
################################# | ||
####### GENERAL PARAMETERS ###### | ||
################################# | ||
|
||
max_steps = 300 | ||
|
||
max_grid_size = 40 | ||
nx = max_grid_size | ||
ny = max_grid_size | ||
nz = max_grid_size | ||
|
||
xmin = -1 | ||
xmax = 1 | ||
ymin = xmin | ||
ymax = xmax | ||
zmin = 0 | ||
zmax = 5 | ||
|
||
number_per_cell = 200 | ||
|
||
################################# | ||
############ NUMERICS ########### | ||
################################# | ||
|
||
verbose = 1 | ||
dt = 4.4e-7 | ||
use_filter = 0 | ||
|
||
# Order of particle shape factors | ||
particle_shape = 1 | ||
|
||
################################# | ||
############ PLASMA ############# | ||
################################# | ||
|
||
ion_dist = picmi.ParticleListDistribution( | ||
x=0.0, | ||
y=0.2, | ||
z=2.5, | ||
ux=9.5e-05*constants.c, | ||
uy=0.0*constants.c, | ||
uz=1.34e-4*constants.c, | ||
weight=1.0 | ||
) | ||
|
||
ions = picmi.Species( | ||
particle_type='H', | ||
name='proton', charge='q_e',mass="m_p", | ||
warpx_do_not_deposit=1, | ||
initial_distribution=ion_dist | ||
) | ||
|
||
################################# | ||
######## INITIAL FIELD ########## | ||
################################# | ||
|
||
applied_field = picmi.LoadAppliedField( | ||
read_fields_from_path="../../../../openPMD-example-datasets/example-femm-3d.h5", | ||
load_E=False | ||
) | ||
|
||
################################# | ||
###### GRID AND SOLVER ########## | ||
################################# | ||
|
||
grid = picmi.Cartesian3DGrid( | ||
number_of_cells=[nx, ny, nz], | ||
warpx_max_grid_size=max_grid_size, | ||
lower_bound=[xmin, ymin, zmin], | ||
upper_bound=[xmax, ymax, zmax], | ||
lower_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], | ||
upper_boundary_conditions=['dirichlet', 'dirichlet', 'dirichlet'], | ||
lower_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'], | ||
upper_boundary_conditions_particles=['absorbing', 'absorbing', 'absorbing'] | ||
) | ||
solver = picmi.ElectrostaticSolver(grid=grid) | ||
|
||
################################# | ||
######### DIAGNOSTICS ########### | ||
################################# | ||
|
||
particle_diag = picmi.ParticleDiagnostic( | ||
name='diag1', | ||
period=300, | ||
species=[ions], | ||
data_list = ['ux', 'uy', 'uz', 'x', 'y', 'z', 'weighting'], | ||
write_dir='.', | ||
warpx_file_prefix='Python_LoadExternalParticleField3D_plt' | ||
) | ||
field_diag = picmi.FieldDiagnostic( | ||
name='diag1', | ||
grid=grid, | ||
period=300, | ||
data_list = ['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'], | ||
write_dir='.', | ||
warpx_file_prefix='Python_LoadExternalParticleField3D_plt' | ||
) | ||
|
||
################################# | ||
####### SIMULATION SETUP ######## | ||
################################# | ||
|
||
sim = picmi.Simulation( | ||
solver=solver, | ||
max_steps=max_steps, | ||
verbose=verbose, | ||
warpx_serialize_initial_conditions=False, | ||
warpx_grid_type='collocated', | ||
warpx_do_dynamic_scheduling=False, | ||
warpx_use_filter=use_filter, | ||
time_step_size=dt, | ||
particle_shape=particle_shape | ||
) | ||
|
||
sim.add_applied_field(applied_field) | ||
|
||
sim.add_species( | ||
ions, | ||
layout=picmi.PseudoRandomLayout( | ||
n_macroparticles_per_cell=number_per_cell, grid=grid | ||
) | ||
) | ||
|
||
sim.add_diagnostic(field_diag) | ||
sim.add_diagnostic(particle_diag) | ||
|
||
################################# | ||
##### SIMULATION EXECUTION ###### | ||
################################# | ||
|
||
#sim.write_input_file('PICMI_inputs_3d') | ||
sim.step(max_steps) |
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
Examples/Tests/LoadExternalField/inputs_rz_particle_fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
warpx.serialize_initial_conditions = 0 | ||
warpx.do_dynamic_scheduling = 0 | ||
particles.do_tiling = 0 | ||
|
||
particles.B_ext_particle_init_style = "read_from_file" | ||
particles.read_fields_from_path = "../../../../openPMD-example-datasets/example-femm-thetaMode.h5" | ||
|
||
warpx.grid_type = collocated | ||
warpx.do_electrostatic = labframe | ||
|
||
################################# | ||
####### GENERAL PARAMETERS ###### | ||
################################# | ||
max_step = 300 | ||
amr.n_cell = 40 40 | ||
warpx.numprocs = 1 1 | ||
amr.max_level = 0 | ||
geometry.dims = RZ | ||
|
||
geometry.prob_lo = 0.0 0.0 | ||
geometry.prob_hi = 1.0 5.0 | ||
|
||
################################# | ||
###### Boundary Condition ####### | ||
################################# | ||
boundary.field_lo = none pec | ||
boundary.field_hi = pec pec | ||
boundary.potential_lo_x = 0 | ||
boundary.potential_hi_x = 0 | ||
boundary.potential_lo_y = 0 | ||
boundary.potential_hi_y = 0 | ||
boundary.potential_lo_z = 0 | ||
boundary.potential_hi_z = 0 | ||
|
||
################################# | ||
############ NUMERICS ########### | ||
################################# | ||
warpx.serialize_initial_conditions = 1 | ||
warpx.verbose = 1 | ||
warpx.const_dt = 4.40917904849092e-7 | ||
warpx.use_filter = 0 | ||
|
||
# Order of particle shape factors | ||
algo.particle_shape = 1 | ||
|
||
################################# | ||
############ PLASMA ############# | ||
################################# | ||
particles.species_names = proton | ||
proton.injection_style = "SingleParticle" | ||
proton.single_particle_pos = 0.0 0.2 2.5 | ||
proton.single_particle_u = 9.506735958279367e-05 0.0 0.00013435537232359165 | ||
proton.single_particle_weight = 1.0 | ||
proton.do_not_deposit = 1 | ||
proton.mass = m_p | ||
proton.charge = q_e | ||
|
||
# Diagnostics | ||
diagnostics.diags_names = diag1 chk | ||
diag1.intervals = 300 | ||
diag1.diag_type = Full | ||
|
||
chk.intervals = 150 | ||
chk.diag_type = Full | ||
chk.format = checkpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
Regression/Checksum/benchmarks_json/LoadExternalFieldRZParticles.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"lev=0": { | ||
"Br": 0.6380326770459374, | ||
"Bt": 0.0, | ||
"Bz": 4.850698699951099, | ||
"Er": 0.0, | ||
"Et": 0.0, | ||
"Ez": 0.0, | ||
"jr": 0.0, | ||
"jt": 0.0, | ||
"jz": 0.0 | ||
}, | ||
"proton": { | ||
"particle_momentum_x": 1.2945379007125463e-23, | ||
"particle_momentum_y": 7.901629565307941e-23, | ||
"particle_momentum_z": 2.0004592432172922e-23, | ||
"particle_position_x": 0.12402004585603355, | ||
"particle_position_y": 4.363249204658946, | ||
"particle_theta": 0.22200801011337173, | ||
"particle_weight": 1.0 | ||
} | ||
} |
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
Regression/Checksum/benchmarks_json/Python_LoadExternalParticleField3D.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"lev=0": { | ||
"Bx": 29.8448958859583, | ||
"By": 29.844895885958305, | ||
"Bz": 197.55124310523018, | ||
"Ex": 0.0, | ||
"Ey": 0.0, | ||
"Ez": 0.0, | ||
"jx": 0.0, | ||
"jy": 0.0, | ||
"jz": 0.0 | ||
}, | ||
"proton": { | ||
"particle_momentum_x": 1.2118953253556959e-23, | ||
"particle_momentum_y": 7.822512598009088e-23, | ||
"particle_momentum_z": 2.2761898274347412e-23, | ||
"particle_position_x": 0.12238072371983327, | ||
"particle_position_y": 0.009653941154598592, | ||
"particle_position_z": 4.317544769595657, | ||
"particle_weight": 1.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.