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 beam eigenemittances to reduced diagnostics. #702

Merged
merged 54 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3000016
Add eigenemittance calculation.
cemitch99 Sep 13, 2024
9584c62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
176405a
Update CovarianceMatrixMath.H
cemitch99 Sep 13, 2024
b51293b
Update EmittanceInvariants.cpp
cemitch99 Sep 13, 2024
6b1e911
Update EmittanceInvariants.H
cemitch99 Sep 13, 2024
4b3fdd1
Update EmittanceInvariants.cpp
cemitch99 Sep 13, 2024
62a11c5
Treat special case of vanishing discriminant in Cardano's formula.
cemitch99 Sep 13, 2024
55ec468
Test from ReducedDiagnostics; update ej ordering.
cemitch99 Sep 13, 2024
ecde532
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
8f22292
Add diagnostic output.
cemitch99 Sep 13, 2024
2297ae5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 13, 2024
db26dde
Comment print statements used for debugging.
cemitch99 Sep 13, 2024
d4f0a14
Update ReducedBeamCharacteristics.cpp
cemitch99 Sep 13, 2024
939909d
Add benchmark example.
cemitch99 Sep 14, 2024
beccb40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2024
d12e44c
Add documentation.
cemitch99 Sep 14, 2024
b3fe78a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 14, 2024
7bd8c5a
Update CMakeLists.txt
cemitch99 Sep 14, 2024
8d001eb
Update CMakeLists.txt
cemitch99 Sep 14, 2024
27e9882
Normalize momenta by mc (dynamical units) for eigenemittances.
cemitch99 Sep 14, 2024
f33bd59
Add alternative routine for cubic roots.
cemitch99 Sep 16, 2024
f22eaae
Update EmittanceInvariants.cpp
cemitch99 Sep 16, 2024
e4a9421
Update CovarianceMatrixMath.H
cemitch99 Sep 16, 2024
1a62b70
Temporarily comment pytest test_transformation.
cemitch99 Sep 16, 2024
8fdee82
Update test_transformation.py
cemitch99 Sep 16, 2024
9070654
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 16, 2024
8cfafc6
Delete commented debugging print statements.
cemitch99 Sep 16, 2024
ea114ff
Update EmittanceInvariants.H
cemitch99 Sep 16, 2024
101803c
Update EmittanceInvariants.cpp
cemitch99 Sep 16, 2024
2ee73f4
Apply suggestions from code review
cemitch99 Sep 19, 2024
96818f2
Update src/particles/diagnostics/EmittanceInvariants.cpp
cemitch99 Sep 19, 2024
e6bd898
Update EmittanceInvariants.cpp
cemitch99 Sep 19, 2024
06b63c2
Add emittance_1,2,3 print.
cemitch99 Sep 24, 2024
0e8ecf1
Finalize print of emittance_1,2,3.
cemitch99 Sep 24, 2024
71bb155
Add ParmParse for optional calculation.
cemitch99 Sep 24, 2024
49d5677
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 24, 2024
3684108
Update test_transformation.py
cemitch99 Sep 24, 2024
c883ee8
Apply suggestions from code review
cemitch99 Sep 25, 2024
0172e10
Update EmittanceInvariants.cpp
cemitch99 Sep 25, 2024
587a095
Update CovarianceMatrixMath.H
cemitch99 Sep 26, 2024
851b46a
Update src/particles/diagnostics/CovarianceMatrixMath.H
cemitch99 Sep 26, 2024
45f21b9
Update CovarianceMatrixMath.H
cemitch99 Sep 26, 2024
59f5b4d
Update CovarianceMatrixMath.H
cemitch99 Sep 26, 2024
53024fa
Use amrex:: math for complex functions.
cemitch99 Sep 26, 2024
534e40f
Avoid copying matrices
ax3l Oct 2, 2024
ed52ed7
Formatting: Whitespaces
ax3l Oct 2, 2024
b922bb4
More general odd-ness test
ax3l Oct 2, 2024
41bee2b
Add conditional emittance output columns.
cemitch99 Oct 5, 2024
e27c30e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2024
4f2d689
Add documentation for user-facing input control.
cemitch99 Oct 5, 2024
d8128ac
Update dataanalysis documentation of eigenemittances.
cemitch99 Oct 5, 2024
4b8f7b3
Update CovarianceMatrixMath.H
cemitch99 Oct 8, 2024
6d61630
Apply suggestions from code review
cemitch99 Oct 8, 2024
345f5b1
Update tests/python/test_transformation.py
ax3l Oct 10, 2024
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
Prev Previous commit
Next Next commit
Add alternative routine for cubic roots.
cemitch99 committed Sep 16, 2024
commit f33bd598a396d5718835b034357d0e8f0bfee785
76 changes: 75 additions & 1 deletion src/particles/diagnostics/CovarianceMatrixMath.H
Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@
#include <ablastr/constant.H>
#include <AMReX_Array.H>
#include <AMReX_REAL.H>
#include <AMReX_GpuComplex.H>
#include <tuple>
#include <cmath>

namespace impactx::diagnostics
{
@@ -33,7 +35,7 @@ namespace impactx::diagnostics
amrex::ParticleReal,
amrex::ParticleReal,
amrex::ParticleReal>
CubicRoots (
CubicRootsTrig (
amrex::ParticleReal a,
amrex::ParticleReal b,
amrex::ParticleReal c,
@@ -82,6 +84,78 @@ namespace impactx::diagnostics
}


/** Function to return the roots of a cubic polynomial ax^3 + bx^2 + cx + d.
* The algebraic form of Cardano's formula is used.
* This implementation expects three real roots, which is verified
* by checking the sign of the discriminant.
*
* @param[in] a coefficient of cubic term
* @param[in] b coefficient of quadratic term
* @param[in] c coefficient of linear term
* @param[in] d coefficient of constant term
* @returns tuple of three real roots
*/
std::tuple<
amrex::ParticleReal,
amrex::ParticleReal,
amrex::ParticleReal>
CubicRootsAlg (
amrex::ParticleReal a,
amrex::ParticleReal b,
amrex::ParticleReal c,
amrex::ParticleReal d
)
{
using namespace amrex::literals;
using Complex = amrex::GpuComplex<amrex::ParticleReal>;

std::tuple <amrex::ParticleReal,amrex::ParticleReal,amrex::ParticleReal> roots;
amrex::ParticleReal x1 = 0.0_prt;
amrex::ParticleReal x2 = 0.0_prt;
amrex::ParticleReal x3 = 0.0_prt;

amrex::ParticleReal Q = (3.0_prt*a*c - pow(b,2))/(9.0_prt * pow(a,2));
amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*pow(a,2)*d - 2.0_prt*pow(b,3))/(54.0_prt*pow(a,3));
amrex::ParticleReal discriminant = pow(Q,3) + pow(R,2);

// Define complex variable C
Complex Qc(Q,0.0_prt);
Complex Rc(R,0.0_prt);
Complex Dc(discriminant,0.0_prt);
Complex C = pow(-Rc + sqrt(Dc),1.0/3.0);

// Define a cubic root of unity xi
amrex::ParticleReal xire = -1.0/2.0;
amrex::ParticleReal xiim = sqrt(3.0)/2.0;
Complex xi(xire,xiim);

//Three roots in algebraic form.

if (C.m_real == 0.0_prt && C.m_imag == 0.0_prt){ // Special case of a triple root

x1 = - b/(3.0_prt*a);
x2 = - b/(3.0_prt*a);
x3 = - b/(3.0_prt*a);

} else {

Complex z1 = Q/C - C - b/(3.0*a);
Complex z2 = Q/(xi*C) - xi*C - b/(3.0*a);
Complex z3 = Q/(pow(xi,2)*C) - pow(xi,2)*C - b/(3.0*a);
x1 = z2.m_real;
x2 = z1.m_real;
x3 = z3.m_real;
}

//std::cout << "Discriminant, Q, R " << discriminant << " " << Q << " " << R << "\n";
//std::cout << "Re(C), Im(C) " << C.m_real << " " << C.m_imag << "\n";
//std::cout << "Return x1, x2, x3 " << x1 << " " << x2 << " " << x3 << "\n";

roots = std::make_tuple(x1,x2,x3);
return roots;
}


/** Function to take the trace of a square 6x6 matrix.
*
* @param[in] A a square matrix
8 changes: 4 additions & 4 deletions src/particles/diagnostics/EmittanceInvariants.cpp
Original file line number Diff line number Diff line change
@@ -122,14 +122,14 @@ namespace impactx::diagnostics
//std::cout << "Return a,b,c,d " << a << " " << b << " " << c << " " << d << "\n";

// Solve for the roots to obtain the eigenemittances.
roots = CubicRoots(a,b,c,d);
// Caution: The order of e1,e2,e3 should be consistent with the
// order ex,ey,et in the limit of uncoupled transport.
// The order below is important and has been checked.
roots = CubicRootsAlg(a,b,c,d);
Copy link
Member Author

@cemitch99 cemitch99 Sep 16, 2024

Choose a reason for hiding this comment

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

There are two options for this function call - CubicRootsAlg and CubicRootsTrig. The results should be equivalent, modulo differences in numerical precision. This addresses the preceding comment.

amrex::ParticleReal e1 = sqrt(std::get<1>(roots));
amrex::ParticleReal e2 = sqrt(std::get<2>(roots));
amrex::ParticleReal e3 = sqrt(std::get<0>(roots));

// Caution: The order of e1,e2,e3 should be consistent with the
// order ex,ey,et in the limit of uncoupled transport. The
// ordering remains to be carefully checked (TODO).
emittances = std::make_tuple(e1,e2,e3);
return emittances;
}