44 amrex::ParticleReal a,
45 amrex::ParticleReal b,
46 amrex::ParticleReal c,
50 using namespace amrex::literals;
54 std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> roots;
55 amrex::ParticleReal x1 = 0.0_prt;
56 amrex::ParticleReal x2 = 0.0_prt;
57 amrex::ParticleReal x3 = 0.0_prt;
59 amrex::ParticleReal Q = (3.0_prt*a*c - powi<2>(b))/(9.0_prt * powi<2>(a));
60 amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*powi<2>(a)*d - 2.0_prt*powi<3>(b))/(54.0_prt*powi<3>(a));
61 amrex::ParticleReal discriminant = powi<3>(Q) + powi<2>(R);
64 amrex::ParticleReal tol = 1.0e-12;
65 if (discriminant > tol) {
68 "Impactx::diagnostics::CubicRootsTrig",
69 "Polynomial appearing in CubicRootsTrig has one or more complex "
70 "(non-real) roots. Only the real part is returned. This "
71 "suggests a loss of numerical precision in computation of the "
72 "eigenemittances. Treat eigenemittance values with caution.",
73 ablastr::warn_manager::WarnPriority::medium
76 std::cout <<
"Polynomial in CubicRoots has one or more complex roots." <<
"\n";
78 }
else if (Q == 0.0_prt) {
87 amrex::ParticleReal theta = std::acos(R/std::sqrt(-powi<3>(Q)));
88 x1 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt) - b/(3.0_prt*a);
89 x2 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt + 2.0_prt*pi/3.0_prt) - b/(3.0_prt*a);
90 x3 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt + 4.0_prt*pi/3.0_prt) - b/(3.0_prt*a);
94 roots = std::make_tuple(x1,x2,x3);
116 amrex::ParticleReal a,
117 amrex::ParticleReal b,
118 amrex::ParticleReal c,
119 amrex::ParticleReal d
122 using namespace amrex::literals;
126 std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> roots;
127 amrex::ParticleReal x1 = 0_prt;
128 amrex::ParticleReal x2 = 0_prt;
129 amrex::ParticleReal x3 = 0_prt;
131 amrex::ParticleReal Q = (3_prt*a*c - powi<2>(b))/(9_prt * powi<2>(a));
132 amrex::ParticleReal R = (9_prt*a*b*c - 27_prt*powi<2>(a)*d - 2_prt*powi<3>(b))/(54_prt*powi<3>(a));
133 amrex::ParticleReal discriminant = powi<3>(Q) + powi<2>(R);
138 Complex Dc(discriminant,0_prt);
142 amrex::ParticleReal xire = -0.5_prt;
143 amrex::ParticleReal xiim = std::sqrt(3_prt)*0.5_prt;
158 Complex z3 = Qc/(powi<2>(xi)*C) - powi<2>(xi)*C;
159 x1 = z2.
m_real - b/(3_prt*a);
160 x2 = z1.
m_real - b/(3_prt*a);
161 x3 = z3.
m_real - b/(3_prt*a);
164 roots = std::make_tuple(x1,x2,x3);