Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/diagnostics/ReducedBeamCharacteristics.H
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,60 @@
#include "particles/ImpactXParticleContainer.H"
#include "particles/CovarianceMatrix.H"

#include <AMReX_Enum.H>
#include <AMReX_REAL.H>

#include <string>
#include <type_traits>
#include <unordered_map>


namespace impactx::diagnostics
{
/** Which moments to calculate for particles */
AMREX_ENUM(MomentSelection,
None = 0,
Moment = 1, /**< mean, sigma */
MinMax = 2, /**< min/max */
Dispersion = 4, /**< dispersion */
Covariance = 8, /**< cross-plane correlations: emittance, alpha, beta */
Eigenemittance = 16 /**< eigenemittance */
);

constexpr MomentSelection operator| (MomentSelection lhs, MomentSelection rhs) noexcept
{
return static_cast<MomentSelection>(static_cast<std::underlying_type_t<MomentSelection>>(lhs) | static_cast<std::underlying_type_t<MomentSelection>>(rhs));
Copy link
Member Author

Choose a reason for hiding this comment

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

}

constexpr MomentSelection operator& (MomentSelection lhs, MomentSelection rhs) noexcept
{
return static_cast<MomentSelection>(static_cast<std::underlying_type_t<MomentSelection>>(lhs) & static_cast<std::underlying_type_t<MomentSelection>>(rhs));
}

constexpr MomentSelection operator~ (MomentSelection v) noexcept
{
return static_cast<MomentSelection>(~static_cast<std::underlying_type_t<MomentSelection>>(v));
}

constexpr bool is_set (MomentSelection selection, MomentSelection flag) noexcept
{
return (selection & flag) != MomentSelection::None;
}

/** Compute moments of the beam distribution from particle data
*
* This uses an MPI Allreduce and returns a result on all ranks.
*/
std::unordered_map<std::string, amrex::ParticleReal>
reduced_beam_characteristics (ImpactXParticleContainer const & pc);
reduced_beam_characteristics (
ImpactXParticleContainer const & pc,
MomentSelection selection = (
MomentSelection::Moment |
MomentSelection::MinMax |
MomentSelection::Dispersion |
MomentSelection::Covariance
)
);

/** Compute moments of the beam distribution from covariance matrix
*/
Expand Down
Loading
Loading