forked from ECP-WarpX/WarpX
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added automated test based on LPI example
Even though the laser ion test is named as a dependency it is running this test again. That should ideally be avoided. It would be good to just run the analysis script as test.
- Loading branch information
Showing
3 changed files
with
88 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
Examples/Physics_applications/laser_ion/analysis_time_avg_diags.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,62 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import numpy as np | ||
import openpmd_api as io | ||
|
||
|
||
def load_field_from_iteration(series, iteration : int, field : str, coord : str = None) -> np.ndarray: | ||
"""Load iteration of field data from file.""" | ||
|
||
it = series.iterations[iteration] | ||
field_obj = it.meshes[f"{field}"] | ||
|
||
if field_obj.scalar: | ||
field_data = field_obj[io.Mesh_Record_Component.SCALAR].load_chunk() | ||
elif coord in [item[0] for item in list(field_obj.items())]: | ||
field_data = field_obj[coord].load_chunk() | ||
else: | ||
raise Exception(f"Specified coordinate: f{coord} is not available for field: f{field}.") | ||
series.flush() | ||
|
||
return field_data | ||
|
||
|
||
def main(): | ||
|
||
field = "E" | ||
coord = "z" | ||
avg_period_steps = 5 | ||
avg_output_step = 100 | ||
|
||
path_tpl_inst = "diags/diagInst/openpmd_%T.h5" | ||
|
||
dir_avg = sys.argv[1] | ||
path_tpl_avg = f"{dir_avg}/openpmd_%T.h5" | ||
|
||
si = io.Series(path_tpl_inst, io.Access.read_only) | ||
sa = io.Series(path_tpl_avg, io.Access.read_only) | ||
|
||
ii0 = si.iterations[0] | ||
fi0 = ii0.meshes[field][coord] | ||
shape = fi0.shape | ||
|
||
data_inst = np.zeros(shape) | ||
|
||
for i in np.arange(avg_output_step-avg_period_steps+1,avg_output_step+1): | ||
data_inst += load_field_from_iteration(si, i, field, coord) | ||
|
||
data_inst = data_inst / avg_period_steps | ||
|
||
data_avg = load_field_from_iteration(sa, avg_output_step, field, coord) | ||
|
||
# Compare the data | ||
if np.allclose(data_inst, data_avg): | ||
print("Test passed: actual data is close to expected data.") | ||
else: | ||
print("Test failed: actual data is not close to expected data.") | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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