-
Notifications
You must be signed in to change notification settings - Fork 31
Quad spin push #1219
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
Open
cemitch99
wants to merge
11
commits into
BLAST-ImpactX:development
Choose a base branch
from
cemitch99:add_quad_spin_push
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Quad spin push #1219
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c4f7fd
Add spin helper mixin class.
cemitch99 7e65a71
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5721e60
Update sign to use A. Dragt sign convention in quaternion.
cemitch99 1b3524d
Add spin push operator.
cemitch99 6d09dc2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 61b4919
Fix compile-time errors.
cemitch99 5b8689a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2c49d00
Apply suggestions from code review
cemitch99 3c61f98
Change spin push operator to named function.
cemitch99 63bfc4c
Add gyromagnetic anomaly value to reference particle.
cemitch99 f40e8bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* Copyright 2022-2023 The Regents of the University of California, through Lawrence | ||
| * Berkeley National Laboratory (subject to receipt of any required | ||
| * approvals from the U.S. Dept. of Energy). All rights reserved. | ||
| * | ||
| * This file is part of ImpactX. | ||
| * | ||
| * Authors: Chad Mitchell | ||
| * License: BSD-3-Clause-LBNL | ||
| */ | ||
| #ifndef IMPACTX_ELEMENTS_MIXIN_SPIN_TRANSPORT_H | ||
| #define IMPACTX_ELEMENTS_MIXIN_SPIN_TRANSPORT_H | ||
|
|
||
| #include "particles/ImpactXParticleContainer.H" | ||
|
|
||
| #include <ablastr/constant.H> | ||
|
|
||
| #include <AMReX_Math.H> | ||
| #include <AMReX_Extension.H> | ||
| #include <AMReX_REAL.H> | ||
cemitch99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| namespace impactx::elements::mixin | ||
| { | ||
| /** This is a helper class for applying a spin map generated by a three-component vector | ||
| * lambda, whose magnitude defines the angle of rotation and whose direction defines | ||
| * the axis of rotation. | ||
| */ | ||
| struct SpinTransport | ||
| { | ||
| /** Rotate the spin vector (sx,sy,sz). | ||
| * | ||
| * @param[in] lambdax generator x-component | ||
| * @param[in] lambday generator y-component | ||
| * @param[in] lambdaz generator z-component | ||
| * @param[inout] sx spin vector x-component | ||
| * @param[inout] sy spin vector y-component | ||
| * @param[inout] sz spin vector z-component | ||
| */ | ||
| template<typename T_Real> | ||
cemitch99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE | ||
| void rotate_spin ( | ||
| amrex::ParticleReal lambdax, | ||
| amrex::ParticleReal lambday, | ||
| amrex::ParticleReal lambdaz, | ||
| amrex::ParticleReal sx, | ||
| amrex::ParticleReal sy, | ||
| amrex::ParticleReal sz | ||
cemitch99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) const | ||
| { | ||
| using namespace amrex::literals; // for _prt | ||
|
|
||
| // Compute quaternion coefficients | ||
| amrex::ParticleReal angle = std::sqrt(lambdax*lambdax+lambday*lambday+lambdaz*lambdaz); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the angle ever be zero (e.g., for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can. I handle that case in lines 55-57 below. |
||
| auto const [sin_half_angle, cos_half_angle] = amrex::Math::sincos(angle/2_prt); | ||
cemitch99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| amrex::ParticleReal w0 = cos_half_angle; | ||
| amrex::ParticleReal w1 = (angle==0_prt) ? 0_prt : -(lambdax/angle)*sin_half_angle; | ||
| amrex::ParticleReal w2 = (angle==0_prt) ? 0_prt : -(lambday/angle)*sin_half_angle; | ||
| amrex::ParticleReal w3 = (angle==0_prt) ? 0_prt : -(lambdaz/angle)*sin_half_angle; | ||
|
|
||
| // Apply rotation | ||
| amrex::ParticleReal sxout = (1_prt-2_prt*(w2*w2+w3*w3))*sx + 2_prt*(w1*w2+w0*w3)*sy + 2_prt*(w1*w3-w0*w2)*sz; | ||
| amrex::ParticleReal syout = 2_prt*(w1*w2-w0*w3)*sx + (1_prt-2_prt*(w1*w1+w3*w3))*sy + 2_prt*(w0*w1+w2*w3)*sz; | ||
| amrex::ParticleReal szout = 2_prt*(w0*w2+w1*w3)*sx + 2_prt*(w2*w3-w0*w1)*sy + (1_prt-2_prt*(w1*w1+w2*w2))*sz; | ||
|
|
||
| // Update spin vector | ||
| sx = sxout; | ||
| sy = syout; | ||
| sz = szout; | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| } // namespace impactx::elements::mixin | ||
|
|
||
| #endif // IMPACTX_ELEMENTS_MIXIN_SPIN_TRANSPORT_H | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to a named function.