Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into googletest-xml-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Sep 27, 2024
2 parents 8918353 + be97d44 commit 83d7b1c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/celeritas/em/distribution/MuBBEnergyDistribution.hh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ MuBBEnergyDistribution::MuBBEnergyDistribution(ParticleTrackView const& particle
Energy electron_cutoff,
Mass electron_mass)
: inc_mass_(value_as<Mass>(particle.mass()))
, total_energy_(value_as<Energy>(particle.energy()) + inc_mass_)
, total_energy_(value_as<Energy>(particle.total_energy()))
, beta_sq_(particle.beta_sq())
, electron_mass_(value_as<Mass>(electron_mass))
, min_energy_(electron_cutoff)
Expand Down
40 changes: 17 additions & 23 deletions src/celeritas/em/interactor/CombinedBremInteractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ class CombinedBremInteractor

// SB and relativistic data
CombinedBremRef const& shared_;
// Incident particle energy
Energy const inc_energy_;
// Incident particle direction
Momentum const inc_momentum_;
// Incident particle
ParticleTrackView const& particle_;
// Incident particle direction
Real3 const& inc_direction_;
// Energy cutoffs
Expand All @@ -88,8 +86,6 @@ class CombinedBremInteractor
MaterialView const& material_;
// Element in which interaction occurs
ElementComponentId const elcomp_id_;
// Incident particle flag for selecting XS correction factor
bool const is_electron_;
// Secondary angular distribution
TsaiUrbanDistribution sample_costheta_;
};
Expand All @@ -110,21 +106,19 @@ CombinedBremInteractor::CombinedBremInteractor(
MaterialView const& material,
ElementComponentId const& elcomp_id)
: shared_(shared)
, inc_energy_(particle.energy())
, inc_momentum_(particle.momentum())
, particle_(particle)
, inc_direction_(direction)
, cutoffs_(cutoffs)
, gamma_cutoff_(cutoffs.energy(shared.rb_data.ids.gamma))
, allocate_(allocate)
, material_(material)
, elcomp_id_(elcomp_id)
, is_electron_(particle.particle_id() == shared.rb_data.ids.electron)
, sample_costheta_(inc_energy_, particle.mass())
, sample_costheta_(particle.energy(), particle.mass())
{
CELER_EXPECT(is_electron_
CELER_EXPECT(particle.particle_id() == shared.rb_data.ids.electron
|| particle.particle_id() == shared.rb_data.ids.positron);
CELER_EXPECT(gamma_cutoff_ > zero_quantity());
CELER_EXPECT(inc_energy_ > gamma_cutoff_);
CELER_EXPECT(particle_.energy() > gamma_cutoff_);
}

//---------------------------------------------------------------------------//
Expand All @@ -144,28 +138,28 @@ CELER_FUNCTION Interaction CombinedBremInteractor::operator()(Engine& rng)

// Sample the bremsstrahlung photon energy
Energy gamma_energy;
if (inc_energy_ >= detail::seltzer_berger_upper_limit())
if (particle_.energy() >= detail::seltzer_berger_upper_limit())
{
detail::RBEnergySampler sample_energy{
shared_.rb_data, inc_energy_, cutoffs_, material_, elcomp_id_};
shared_.rb_data, particle_, cutoffs_, material_, elcomp_id_};
gamma_energy = sample_energy(rng);
}
else
{
detail::SBEnergySampler sample_energy{shared_.sb_differential_xs,
inc_energy_,
gamma_cutoff_,
material_,
elcomp_id_,
shared_.rb_data.electron_mass,
is_electron_};
detail::SBEnergySampler sample_energy{
shared_.sb_differential_xs,
particle_,
gamma_cutoff_,
material_,
elcomp_id_,
particle_.particle_id() == shared_.rb_data.ids.electron};
gamma_energy = sample_energy(rng);
}

// Update kinematics of the final state and return this interaction
return detail::BremFinalStateHelper(inc_energy_,
return detail::BremFinalStateHelper(particle_.energy(),
inc_direction_,
inc_momentum_,
particle_.momentum(),
shared_.rb_data.ids.gamma,
gamma_energy,
sample_costheta_(rng),
Expand Down
3 changes: 1 addition & 2 deletions src/celeritas/em/interactor/RelativisticBremInteractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ RelativisticBremInteractor::RelativisticBremInteractor(
, inc_momentum_(particle.momentum())
, inc_direction_(direction)
, allocate_(allocate)
, sample_photon_energy_(
shared, particle.energy(), cutoffs, material, elcomp_id)
, sample_photon_energy_(shared, particle, cutoffs, material, elcomp_id)
, sample_costheta_(inc_energy_, particle.mass())
{
CELER_EXPECT(particle.particle_id() == shared_.ids.electron
Expand Down
8 changes: 2 additions & 6 deletions src/celeritas/em/interactor/SeltzerBergerInteractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class SeltzerBergerInteractor
Momentum const inc_momentum_;
// Incident particle direction
Real3 const& inc_direction_;
// Incident particle flag for selecting XS correction factor
bool const inc_particle_is_electron_;
// Production cutoff for gammas
Energy const gamma_cutoff_;
// Allocate space for a secondary particle
Expand Down Expand Up @@ -116,17 +114,15 @@ CELER_FUNCTION SeltzerBergerInteractor::SeltzerBergerInteractor(
, inc_energy_(particle.energy())
, inc_momentum_(particle.momentum())
, inc_direction_(inc_direction)
, inc_particle_is_electron_(particle.particle_id() == shared_.ids.electron)
, gamma_cutoff_(cutoffs.energy(shared.ids.gamma))
, allocate_(allocate)
, elcomp_id_(elcomp_id)
, sample_photon_energy_(shared.differential_xs,
particle.energy(),
particle,
gamma_cutoff_,
material,
elcomp_id,
shared.electron_mass,
inc_particle_is_electron_)
particle.particle_id() == shared_.ids.electron)
, sample_costheta_(inc_energy_, particle.mass())
{
CELER_EXPECT(particle.particle_id() == shared_.ids.electron
Expand Down
18 changes: 9 additions & 9 deletions src/celeritas/em/interactor/detail/RBEnergySampler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class RBEnergySampler
public:
// Construct with shared and state data
inline CELER_FUNCTION RBEnergySampler(RelativisticBremRef const& shared,
Energy const& inc_energy,
ParticleTrackView const& particle,
CutoffView const& cutoffs,
MaterialView const& material,
ElementComponentId const& elcomp_id);
ElementComponentId elcomp_id);

// Sample the bremsstrahlung photon energy with the given RNG
template<class Engine>
Expand All @@ -72,17 +72,17 @@ class RBEnergySampler
*/
CELER_FUNCTION
RBEnergySampler::RBEnergySampler(RelativisticBremRef const& shared,
Energy const& inc_energy,
ParticleTrackView const& particle,
CutoffView const& cutoffs,
MaterialView const& material,
ElementComponentId const& elcomp_id)
: calc_dxsec_(shared, inc_energy, material, elcomp_id)
ElementComponentId elcomp_id)
: calc_dxsec_(shared, particle, material, elcomp_id)
{
// Min and max kinetic energy limits for sampling the secondary photon
real_type gamma_cutoff = value_as<Energy>(cutoffs.energy(shared.ids.gamma));
tmin_sq_ = ipow<2>(min(gamma_cutoff, inc_energy.value()));
tmax_sq_ = ipow<2>(min(value_as<Energy>(detail::high_energy_limit()),
inc_energy.value()));
tmin_sq_ = ipow<2>(value_as<Energy>(
min(cutoffs.energy(shared.ids.gamma), particle.energy())));
tmax_sq_ = ipow<2>(
value_as<Energy>(min(detail::high_energy_limit(), particle.energy())));

CELER_ENSURE(tmax_sq_ >= tmin_sq_);
}
Expand Down
40 changes: 19 additions & 21 deletions src/celeritas/em/interactor/detail/SBEnergySampler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ class SBEnergySampler
public:
// Construct with shared and state data
inline CELER_FUNCTION SBEnergySampler(SBTable const& differential_xs,
Energy const& inc_energy,
Energy const& gamma_cutoff,
ParticleTrackView const& particle,
Energy gamma_cutoff,
MaterialView const& material,
ElementComponentId const& elcomp_id,
Mass const& inc_mass,
bool const is_electron);
ElementComponentId elcomp_id,
bool is_electron);

// Sample the bremsstrahlung photon energy with the given RNG
template<class Engine>
Expand All @@ -60,17 +59,17 @@ class SBEnergySampler
// Differential cross section table
SBTable const& differential_xs_;
// Incident particle energy
Energy const inc_energy_;
Energy inc_energy_;
// Production cutoff for gammas
Energy const gamma_cutoff_;
Energy gamma_cutoff_;
// Material in which interaction occurs
MaterialView const& material_;
// Element in which interaction occurs
ElementComponentId const elcomp_id_;
ElementComponentId elcomp_id_;
// Incident particle mass
Mass const inc_mass_;
Mass inc_mass_;
// Incident particle identification flag
bool const inc_particle_is_electron_;
bool is_electron_;
// Density correction
real_type density_correction_;
};
Expand All @@ -83,24 +82,23 @@ class SBEnergySampler
*/
CELER_FUNCTION
SBEnergySampler::SBEnergySampler(SBTable const& differential_xs,
Energy const& inc_energy,
Energy const& gamma_cutoff,
ParticleTrackView const& particle,
Energy gamma_cutoff,
MaterialView const& material,
ElementComponentId const& elcomp_id,
Mass const& inc_mass,
bool const is_electron)
ElementComponentId elcomp_id,
bool is_electron)
: differential_xs_(differential_xs)
, inc_energy_(inc_energy)
, inc_energy_(value_as<Energy>(particle.energy()))
, gamma_cutoff_(gamma_cutoff)
, material_(material)
, elcomp_id_(elcomp_id)
, inc_mass_(inc_mass)
, inc_particle_is_electron_(is_electron)
, inc_mass_(value_as<Mass>(particle.mass()))
, is_electron_(is_electron)
{
// Density correction
real_type density_factor = material.electron_density() * migdal_constant();
real_type total_energy_val = inc_energy_.value() + inc_mass_.value();
density_correction_ = density_factor * ipow<2>(total_energy_val);
density_correction_ = density_factor
* ipow<2>(value_as<Energy>(particle.total_energy()));
}

//---------------------------------------------------------------------------//
Expand All @@ -122,7 +120,7 @@ CELER_FUNCTION auto SBEnergySampler::operator()(Engine& rng) -> Energy
SBEnergyDistHelper::EnergySq{density_correction_},
gamma_cutoff_);

if (inc_particle_is_electron_)
if (is_electron_)
{
// Rejection sample without modifying cross section
SBEnergyDistribution<SBElectronXsCorrector> sample_gamma_energy(
Expand Down
7 changes: 3 additions & 4 deletions src/celeritas/em/xs/RBDiffXsCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RBDiffXsCalculator
public:
// Construct with incident electron and current element
inline CELER_FUNCTION RBDiffXsCalculator(RelativisticBremRef const& shared,
Energy energy,
ParticleTrackView const& particle,
MaterialView const& material,
ElementComponentId elcomp_id);

Expand Down Expand Up @@ -116,14 +116,13 @@ class RBDiffXsCalculator
*/
CELER_FUNCTION
RBDiffXsCalculator::RBDiffXsCalculator(RelativisticBremRef const& shared,
Energy energy,
ParticleTrackView const& particle,
MaterialView const& material,
ElementComponentId elcomp_id)
: elem_data_(shared.elem_data[material.element_id(elcomp_id)])
, material_(material)
, element_(material.make_element_view(elcomp_id))
, total_energy_(value_as<units::MevEnergy>(energy)
+ value_as<units::MevMass>(shared.electron_mass))
, total_energy_(value_as<Energy>(particle.total_energy()))
{
real_type density_factor = material.electron_density()
* detail::migdal_constant();
Expand Down
13 changes: 13 additions & 0 deletions src/celeritas/phys/ParticleTrackView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class ParticleTrackView

//// DERIVED PROPERTIES (indirection plus calculation) ////

// Kinetic energy plus rest energy [MeV]
inline CELER_FUNCTION Energy total_energy() const;

// Square of fraction of lightspeed [unitless]
inline CELER_FUNCTION real_type beta_sq() const;

Expand Down Expand Up @@ -255,6 +258,16 @@ CELER_FUNCTION bool ParticleTrackView::is_stable() const

//---------------------------------------------------------------------------//
// COMBINED PROPERTIES
//---------------------------------------------------------------------------//
/*!
* Kinetic energy plus rest energy [MeV].
*/
CELER_FUNCTION auto ParticleTrackView::total_energy() const -> Energy
{
return Energy(value_as<Energy>(this->energy())
+ value_as<units::MevMass>(this->mass()));
}

//---------------------------------------------------------------------------//
/*!
* Square of \f$ \beta \f$, which is the fraction of lightspeed [unitless].
Expand Down
4 changes: 2 additions & 2 deletions test/celeritas/em/RelativisticBrem.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ TEST_F(RelativisticBremTest, dxsec)

// Create the differential cross section
RBDiffXsCalculator dxsec_lpm(model_lpm_->host_ref(),
this->particle_track().energy(),
this->particle_track(),
material_view,
ElementComponentId{0});

// Create the differential cross section
RBDiffXsCalculator dxsec(model_->host_ref(),
this->particle_track().energy(),
this->particle_track(),
material_view,
ElementComponentId{0});

Expand Down
2 changes: 2 additions & 0 deletions test/celeritas/phys/Particle.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ TEST_F(ParticleTestHost, electron)
EXPECT_REAL_EQ(0.0, particle.decay_constant());
EXPECT_FALSE(particle.is_antiparticle());
EXPECT_TRUE(particle.is_stable());
EXPECT_REAL_EQ(1.0109989461, particle.total_energy().value());
EXPECT_SOFT_EQ(0.74453076757415848, particle.beta_sq());
EXPECT_SOFT_EQ(0.86286196322132447,
value_as<units::LightSpeed>(particle.speed()));
Expand Down Expand Up @@ -223,6 +224,7 @@ TEST_F(ParticleTestHost, gamma)
EXPECT_REAL_EQ(10, particle.energy().value());
EXPECT_FALSE(particle.is_antiparticle());
EXPECT_TRUE(particle.is_stable());
EXPECT_REAL_EQ(10, particle.total_energy().value());
EXPECT_REAL_EQ(1.0, particle.beta_sq());
EXPECT_REAL_EQ(1.0, particle.speed().value());
EXPECT_REAL_EQ(10, particle.momentum().value());
Expand Down

0 comments on commit 83d7b1c

Please sign in to comment.