Skip to content

Use beam variants in the experiment class#47

Merged
jbeilstenedmands merged 11 commits into
mainfrom
use_variants_in_experiment
May 29, 2026
Merged

Use beam variants in the experiment class#47
jbeilstenedmands merged 11 commits into
mainfrom
use_variants_in_experiment

Conversation

@jbeilstenedmands

Copy link
Copy Markdown
Contributor

This replaces the initial use of beam model templating in the experiment class with an approach using variants.

The idea here is that the experiment should be a simple container for the experiment models (beam, detector, crystal) etc, where each of these is a variant of allowed model classes. So far this is just done for beam:

Beam = std::variant<MonochromaticBeam, PolychromaticBeam>;

This is preferable to using base-class pointers as the different physical models have a different interface (e.g wavelength vs wavelength_range, get_s0 only exists for MonochromaticBeam). For the other models we might have variants being static and scan-varying models, single vs multi-panel detector, etc.

Then we define some beam helper functions in beam_ops to give type safe access and encapsulate the variant handling logic and error handling, with usage:

using beam_ops
auto& beam = require_monochromatic(expt.beam());

While I was here I split experiment.hpp into experiment.hpp and experiment.cxx, also moving out some beam serialization logic and tidied up the tests/CMakeLists.txt.

@dimitrivlachos dimitrivlachos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

@jbeilstenedmands jbeilstenedmands merged commit 5ed2725 into main May 29, 2026
5 checks passed
@jbeilstenedmands jbeilstenedmands deleted the use_variants_in_experiment branch May 29, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants