From 766d71146a8314a48db88f29b0e0548d1d9c5397 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 26 Jul 2023 20:55:34 +0200 Subject: 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 * replace with equality * Revert "replace with equality" This reverts commit e3164f9e053d345b153d770ae107a7f68c4bb260. * Update Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp Co-authored-by: Weiqun Zhang --------- Co-authored-by: Weiqun Zhang --- .../PsatdAlgorithmJConstantInTime.cpp | 27 +++++----------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/PsatdAlgorithmJConstantInTime.cpp') 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 ) // Psi1 (multiplies B in the update equation for ) -- cgit v1.2.3