Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openPMD Beam Input via Source Element #820

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jan 30, 2025

Add a new element Source that reads openPMD files from our beam monitors. Add an example in Python. Close #97

This can also be used to restart a simulation that was checkpointed at a beam monitor.

  • documentation

Follow-Up Ideas

This is designed intentionally as a new element. In the future, we probably restructure our initial distribution logic to also go into this element, so that "from file" is just one of its options.

For other projects, we will implement t-to-s transforms (for WarpX) and other options, as documented in inline TODOs.

Not needed for Sirepo, but we will also add an option to use this from inputs files.

@ax3l ax3l added component: elements Elements/external fields component: distributions beam distributions labels Jan 30, 2025
@ax3l ax3l added this to the Sirepo (FY24/24 Phase 1 SBIR) milestone Jan 30, 2025
@ax3l ax3l requested a review from cemitch99 January 30, 2025 05:04
Comment on lines +23 to +53
/** Unclutter a real_names to openPMD record
*
* TODO: move to ABLASTR
*
* @param fullName name as in real_names variable
* @return pair of openPMD record and component name
*/
inline std::pair< std::string, std::string >
name2openPMD ( const std::string& fullName )
{
std::string record_name = fullName;
std::string component_name = io::RecordComponent::SCALAR;

// we use "_" as separator in names to group vector records
std::size_t const startComp = fullName.find_last_of('_');
if( startComp != std::string::npos ) { // non-scalar
record_name = fullName.substr(0, startComp);
component_name = fullName.substr(startComp + 1u);
}
return make_pair(record_name, component_name);
}

// TODO: move to ablastr
io::RecordComponent get_component_record (
io::ParticleSpecies & species,
std::string comp_name
) {
// handle scalar and non-scalar records by name
const auto [record_name, component_name] = name2openPMD(std::move(comp_name));
return species[record_name][component_name];
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup: deduplicate from BeamMonitor implementation.

ref.set_charge_qe(-1.0).set_mass_MeV(0.510998950).set_kin_energy_MeV(kin_energy_MeV)

# load particle bunch from file
push(pc, elements.Source("../FODO_channel/diags/openPMD/monitor.h5"))
Copy link
Member Author

@ax3l ax3l Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the use case, i.e., checkpoint-restart, it can be useful here to also (re-)set the s position of the reference particle -- and the whole reference particle per se.

We could add a runtime option for this.

For Sirepo, we only need to load an initial distribution for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this, I think you mean--to read in the reference particle data (at the specified s location), and to use this to initialize the reference particle during the restart? If so, I agree that this feature will be needed for checkpoint-restart capability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in that case it would replace the lines just before this line in the script. I think that would make a good runtime option.

###############################################################################
lattice.elements = monitor drift1 quad1 drift2 quad2 drift3
lattice.nslice = 5
lattice.periods = 101 # FODO channel of 101 periods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike run_fodo.py, I don't see user input for a restart in the app input file. Is the intention to add the capability of restart via the app input also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I have not developed this yet. I meant to remove this file from the commit because I only did Python so far.

.def("redistribute",
&ImpactXParticleContainer::Redistribute,
"Redistribute particles in the current mesh in x, y, z"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function no longer needed? Not sure why this is deleted here--how it is related to this PR.

Copy link
Member Author

@ax3l ax3l Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This is actually already exposed in pyAMReX. The binding here overwrote it and, problematically, did not define the proper default arguments that go into Redistribute(...). Just removing it solves this and removes the sloppy duplication that I did by accident.

Co-authored-by: Chad Mitchell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: distributions beam distributions component: elements Elements/external fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add openPMD Beam Input
2 participants