diff options
author | 2023-07-26 20:55:34 +0200 | |
---|---|---|
committer | 2023-07-26 18:55:34 +0000 | |
commit | 766d71146a8314a48db88f29b0e0548d1d9c5397 (patch) | |
tree | 630ae577a1856ae0f5fb2e236a4e85b9346566d2 /Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp | |
parent | 4783ad60809fc5fdff164a4ed0cacca4b3fffa70 (diff) | |
download | WarpX-766d71146a8314a48db88f29b0e0548d1d9c5397.tar.gz WarpX-766d71146a8314a48db88f29b0e0548d1d9c5397.tar.zst WarpX-766d71146a8314a48db88f29b0e0548d1d9c5397.zip |
Initialize variables at declaration if it improves readability (#4117)
* init some variables at declaration
* make code more readable
* avoid lossy function result cast
* Update Source/Initialization/WarpXInitData.cpp
Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
* replace with equality
* Revert "replace with equality"
This reverts commit e3164f9e053d345b153d770ae107a7f68c4bb260.
* Update Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp
Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
---------
Co-authored-by: Weiqun Zhang <WeiqunZhang@lbl.gov>
Diffstat (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp')
-rw-r--r-- | Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp index 72c2b7a28..11d9bbd94 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp @@ -452,15 +452,8 @@ void PsatdAlgorithmJConstantInTime::InitializeSpectralCoefficients ( } // Auxiliary variable - amrex::Real tmp; - if (om_s != 0.) - { - tmp = (1._rt - C(i,j,k)) / (ep0 * om2_s); - } - else // om_s = 0 - { - tmp = 0.5_rt * dt2 / ep0; - } + const amrex::Real tmp = (om_s != 0.)? + ((1._rt - C(i,j,k)) / (ep0 * om2_s)):(0.5_rt * dt2 / ep0); // T2 if (is_galilean) @@ -606,18 +599,10 @@ void PsatdAlgorithmJConstantInTime::InitializeSpectralCoefficientsAveraging ( const amrex::Real C1 = std::cos(0.5_rt * om_s * dt); const amrex::Real C3 = std::cos(1.5_rt * om_s * dt); - // S1_om, S3_om - amrex::Real S1_om, S3_om; - if (om_s != 0.) - { - S1_om = std::sin(0.5_rt * om_s * dt) / om_s; - S3_om = std::sin(1.5_rt * om_s * dt) / om_s; - } - else // om_s = 0 - { - S1_om = 0.5_rt * dt; - S3_om = 1.5_rt * dt; - } + const amrex::Real S1_om = (om_s != 0.)? + (std::sin(0.5_rt * om_s * dt) / om_s) : (0.5_rt * dt); + const amrex::Real S3_om = (om_s != 0.)? + (std::sin(1.5_rt * om_s * dt) / om_s) : (1.5_rt * dt); // Psi1 (multiplies E in the update equation for <E>) // Psi1 (multiplies B in the update equation for <B>) |