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

Add helper functions for sampling/calculating direction in interactors #1301

Merged
merged 6 commits into from
Jul 1, 2024

Conversation

amandalund
Copy link
Contributor

As discussed in #1291, this adds a couple helper functions for the physics interactors. Any suggestions for better names would be welcome.

@amandalund amandalund added physics Particles, processes, and stepping algorithms minor Minor internal changes or fixes labels Jun 30, 2024
@amandalund amandalund requested a review from sethrj June 30, 2024 16:18
Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

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

Thanks Amanda! It's definitely an improvement to unify these implementations (though there might be a couple in the neutron physics too, and eventually optical as well, so perhaps we should move the helper utils to phys?)

Comment on lines 41 to 44
inline CELER_FUNCTION Real3 calc_exiting_direction(real_type inc_momentum,
real_type out_momentum,
Real3 const& inc_dir,
Real3 const& out_dir)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about a little detail helper:

struct Momentum {
    real_type magnitude;
    Real3 const& direction;
};

so the components are more strongly associated:

result.direction =  calc_exiting_direction(
    {inc_momentum_.value(), inc_direction_},
    {gamma_energy_.value(), secondary_->direction});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that.

Comment on lines 22 to 24
* Sample azimuthal angle, calculate Cartesian vector, and rotate direction.
*/
struct CartesianTransformSampler
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like ...

Suggested change
* Sample azimuthal angle, calculate Cartesian vector, and rotate direction.
*/
struct CartesianTransformSampler
* Sample an exiting direction from a polar cosine and incident direction.
*
* Combine an already-sampled change in polar cosine (dot product of incident
* and exiting) with a sampled uniform azimuthal direction, and apply that
* rotation to the original track's incident direction.
*/
struct ExitingDirectionSampler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better, thanks!

@@ -3,54 +3,62 @@
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/em/interactor/detail/Utils.hh
//! \file celeritas/phys/PhysicsUtils.hh
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about InteractionUtils? 😅 or is that the final "bring me a rock" that will break the camel's back...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did ask for it... sounds good!

*/
inline CELER_FUNCTION Real3 calc_exiting_direction(Momentum inc_momentum,
Momentum out_momentum)
{
Copy link
Member

Choose a reason for hiding this comment

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

Should we take the opportunity to add assertions on magnitude > 0? (Or >= 0?)

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

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

Thank you! That's an itch that I've wanted to scratch since we finished the initial round of EM physics.

@sethrj sethrj merged commit b935f36 into celeritas-project:develop Jul 1, 2024
29 checks passed
@amandalund amandalund deleted the physics-helpers branch July 1, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Minor internal changes or fixes physics Particles, processes, and stepping algorithms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants