diff options
Diffstat (limited to 'Source')
21 files changed, 107 insertions, 214 deletions
diff --git a/Source/AcceleratorLattice/LatticeElementFinder.H b/Source/AcceleratorLattice/LatticeElementFinder.H index 62ac34829..dd9358b19 100644 --- a/Source/AcceleratorLattice/LatticeElementFinder.H +++ b/Source/AcceleratorLattice/LatticeElementFinder.H @@ -122,18 +122,10 @@ struct LatticeElementFinder for (int ie = 0 ; ie < nelements ; ie++) { // Find the mid points between element ie and the ones before and after it. // The first and last element need special handling. - amrex::ParticleReal zcenter_left, zcenter_right; - if (ie == 0) { - zcenter_left = std::numeric_limits<amrex::ParticleReal>::lowest(); - } else { - zcenter_left = 0.5_prt*(ze_arr[ie-1] + zs_arr[ie]); - } - if (ie < nelements - 1) { - zcenter_right = 0.5_prt*(ze_arr[ie] + zs_arr[ie+1]); - } else { - zcenter_right = std::numeric_limits<amrex::ParticleReal>::max(); - } - + const amrex::ParticleReal zcenter_left = (ie == 0)? + (std::numeric_limits<amrex::ParticleReal>::lowest()) : (0.5_prt*(ze_arr[ie-1] + zs_arr[ie])); + const amrex::ParticleReal zcenter_right = (ie < nelements - 1)? + (0.5_prt*(ze_arr[ie] + zs_arr[ie+1])) : (std::numeric_limits<amrex::ParticleReal>::max()); if (zcenter_left <= z_node && z_node < zcenter_right) { indices_arr[iz] = ie; } diff --git a/Source/BoundaryConditions/PML_RZ.cpp b/Source/BoundaryConditions/PML_RZ.cpp index fc468aced..98ed12e7d 100644 --- a/Source/BoundaryConditions/PML_RZ.cpp +++ b/Source/BoundaryConditions/PML_RZ.cpp @@ -89,12 +89,7 @@ PML_RZ::ApplyDamping (amrex::MultiFab* Et_fp, amrex::MultiFab* Ez_fp, // Set tilebox to only include the upper radial cells const int nr_damp = m_ncell; - int nr_damp_min; - if (m_do_pml_in_domain) { - nr_damp_min = nr_domain - nr_damp; - } else { - nr_damp_min = nr_domain; - } + const int nr_damp_min = (m_do_pml_in_domain)?(nr_domain - nr_damp):(nr_domain); tilebox.setSmall(0, nr_damp_min + 1); amrex::ParallelFor( tilebox, Et_fp->nComp(), diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index e10afc2df..c368d2452 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -913,12 +913,9 @@ BTDiagnostics::DefineFieldBufferMultiFab (const int i_buffer, const int lev) amrex::IntVect ref_ratio = amrex::IntVect(1); if (lev > 0 ) ref_ratio = WarpX::RefRatio(lev-1); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - amrex::Real cellsize; - if (idim < WARPX_ZINDEX) { - cellsize = warpx.Geom(lev).CellSize(idim); - } else { - cellsize = dz_lab(warpx.getdt(lev), ref_ratio[m_moving_window_dir]); - } + const amrex::Real cellsize = (idim < WARPX_ZINDEX)? + warpx.Geom(lev).CellSize(idim): + dz_lab(warpx.getdt(lev), ref_ratio[m_moving_window_dir]); const amrex::Real buffer_lo = m_snapshot_domain_lab[i_buffer].lo(idim) + ( buffer_ba.getCellCenteredBox(0).smallEnd(idim) - m_snapshot_box[i_buffer].smallEnd(idim) diff --git a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp index 59247f9cb..9e33a1fc2 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/BackTransformFunctor.cpp @@ -235,30 +235,29 @@ BackTransformFunctor::LorentzTransformZ (amrex::MultiFab& data, amrex::Real gamm for (int mode_comp = 0; mode_comp < n_rcomps; ++mode_comp) { // Back-transform the transverse electric and magnetic fields. // Note that the z-components, Ez, Bz, are not changed by the transform. - amrex::Real e_lab, b_lab, j_lab, rho_lab; // Transform Er_boost & Bt_boost to lab-frame for corresponding mode (mode_comp) - e_lab = gamma_boost * ( arr(i, j, k, n_rcomps*0 + mode_comp) + const amrex::Real er_lab = gamma_boost * ( arr(i, j, k, n_rcomps*0 + mode_comp) + beta_boost * clight * arr(i, j, k, n_rcomps*4+ mode_comp) ); - b_lab = gamma_boost * ( arr(i, j, k, n_rcomps*4 + mode_comp) + const amrex::Real bt_lab = gamma_boost * ( arr(i, j, k, n_rcomps*4 + mode_comp) + beta_boost * inv_clight * arr(i, j, k, n_rcomps*0 + mode_comp) ); // Store lab-frame data in-place - arr(i, j, k, n_rcomps*0 + mode_comp) = e_lab; - arr(i, j, k, n_rcomps*4 + mode_comp) = b_lab; + arr(i, j, k, n_rcomps*0 + mode_comp) = er_lab; + arr(i, j, k, n_rcomps*4 + mode_comp) = bt_lab; // Transform Et_boost & Br_boost to lab-frame for corresponding mode (mode_comp) - e_lab = gamma_boost * ( arr(i, j, k, n_rcomps*1 + mode_comp) + const amrex::Real et_lab = gamma_boost * ( arr(i, j, k, n_rcomps*1 + mode_comp) - beta_boost * clight * arr(i, j, k, n_rcomps*3 + mode_comp) ); - b_lab = gamma_boost * ( arr(i, j, k, n_rcomps*3 + mode_comp) + const amrex::Real br_lab = gamma_boost * ( arr(i, j, k, n_rcomps*3 + mode_comp) - beta_boost * inv_clight * arr(i, j, k, n_rcomps*1 + mode_comp) ); // Store lab-frame data in-place - arr(i, j, k, n_rcomps*1 + mode_comp) = e_lab; - arr(i, j, k, n_rcomps*3 + mode_comp) = b_lab; + arr(i, j, k, n_rcomps*1 + mode_comp) = et_lab; + arr(i, j, k, n_rcomps*3 + mode_comp) = br_lab; // Transform charge density z-component of current density - j_lab = gamma_boost * ( arr(i, j, k, n_rcomps*8 + mode_comp) + const amrex::Real j_lab = gamma_boost * ( arr(i, j, k, n_rcomps*8 + mode_comp) + beta_boost * clight * arr(i, j, k, n_rcomps*9 + mode_comp) ); - rho_lab = gamma_boost * ( arr(i, j, k, n_rcomps*9 + mode_comp) + const amrex::Real rho_lab = gamma_boost * ( arr(i, j, k, n_rcomps*9 + mode_comp) + beta_boost * inv_clight * arr(i, j, k, n_rcomps*8 + mode_comp) ); // Store lab-frame jz and rho in-place arr(i, j, k, n_rcomps*8 + mode_comp) = j_lab; @@ -274,30 +273,30 @@ BackTransformFunctor::LorentzTransformZ (amrex::MultiFab& data, amrex::Real gamm { // Back-transform the transverse electric and magnetic fields. // Note that the z-components, Ez, Bz, are not changed by the transform. - amrex::Real e_lab, b_lab, j_lab, rho_lab; + // Transform Ex_boost (ncomp=0) & By_boost (ncomp=4) to lab-frame - e_lab = gamma_boost * ( arr(i, j, k, 0) + const amrex::Real ex_lab = gamma_boost * ( arr(i, j, k, 0) + beta_boost * clight * arr(i, j, k, 4) ); - b_lab = gamma_boost * ( arr(i, j, k, 4) + const amrex::Real by_lab = gamma_boost * ( arr(i, j, k, 4) + beta_boost * inv_clight * arr(i, j, k, 0) ); // Store lab-frame data in-place - arr(i, j, k, 0) = e_lab; - arr(i, j, k, 4) = b_lab; + arr(i, j, k, 0) = ex_lab; + arr(i, j, k, 4) = by_lab; // Transform Ey_boost (ncomp=1) & Bx_boost (ncomp=3) to lab-frame - e_lab = gamma_boost * ( arr(i, j, k, 1) + const amrex::Real ey_lab = gamma_boost * ( arr(i, j, k, 1) - beta_boost * clight * arr(i, j, k, 3) ); - b_lab = gamma_boost * ( arr(i, j, k, 3) + const amrex::Real bx_lab = gamma_boost * ( arr(i, j, k, 3) - beta_boost * inv_clight * arr(i, j, k, 1) ); // Store lab-frame data in-place - arr(i, j, k, 1) = e_lab; - arr(i, j, k, 3) = b_lab; + arr(i, j, k, 1) = ey_lab; + arr(i, j, k, 3) = bx_lab; // Transform charge density (ncomp=9) // and z-component of current density (ncomp=8) - j_lab = gamma_boost * ( arr(i, j, k, 8) + const amrex::Real j_lab = gamma_boost * ( arr(i, j, k, 8) + beta_boost * clight * arr(i, j, k, 9) ); - rho_lab = gamma_boost * ( arr(i, j, k, 9) + const amrex::Real rho_lab = gamma_boost * ( arr(i, j, k, 9) + beta_boost * inv_clight * arr(i, j, k, 8) ); // Store lab-frame jz and rho in-place arr(i, j, k, 8) = j_lab; diff --git a/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp index c6d0f57df..d3932472c 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp @@ -93,9 +93,8 @@ ParticleReductionFunctor::operator() (amrex::MultiFab& mf_dst, const int dcomp, const amrex::ParticleReal ux = p.rdata(PIdx::ux) / PhysConst::c; const amrex::ParticleReal uy = p.rdata(PIdx::uy) / PhysConst::c; const amrex::ParticleReal uz = p.rdata(PIdx::uz) / PhysConst::c; - amrex::Real value; - if ((do_filter) && (!filter_fn(xw, yw, zw, ux, uy, uz))) value = 0._rt; - else value = map_fn(xw, yw, zw, ux, uy, uz); + const bool filtered_out_flag = ((do_filter) && (filter_fn(xw, yw, zw, ux, uy, uz) == 0.0_prt)); + const amrex::Real value = (filtered_out_flag) ? (0._rt):(map_fn(xw, yw, zw, ux, uy, uz)); amrex::Gpu::Atomic::AddNoRet(&out_array(ii, jj, kk, 0), (amrex::Real)(p.rdata(PIdx::w) * value)); }); if (m_do_average) { diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index b87e60fab..e33810e45 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -125,7 +125,6 @@ Diagnostics::BaseReadParameters () // Get parser strings for particle fields and generate map of parsers std::string parser_str; std::string filter_parser_str = ""; - bool do_parser_filter; const amrex::ParmParse pp_diag_pfield(m_diag_name + ".particle_fields"); for (const auto& var : m_pfield_varnames) { bool do_average = true; @@ -143,7 +142,7 @@ Diagnostics::BaseReadParameters () // Look for and record filter functions. If one is not found, the empty string will be // stored as the filter string, and will be ignored. - do_parser_filter = pp_diag_pfield.query((var + ".filter(x,y,z,ux,uy,uz)").c_str(), filter_parser_str); + const bool do_parser_filter = pp_diag_pfield.query((var + ".filter(x,y,z,ux,uy,uz)").c_str(), filter_parser_str); m_pfield_dofilter.push_back(do_parser_filter); m_pfield_filter_strings.push_back(filter_parser_str); } @@ -158,11 +157,10 @@ Diagnostics::BaseReadParameters () } // Check that species names specified in m_pfield_species are valid - bool p_species_name_is_wrong; // Loop over all species specified above for (const auto& species : m_pfield_species) { // Boolean used to check if species name was misspelled - p_species_name_is_wrong = true; + bool p_species_name_is_wrong = true; // Loop over all species for (int i = 0, n = int(m_all_species_names.size()); i < n; i++) { if (species == m_all_species_names[i]) { @@ -249,17 +247,14 @@ Diagnostics::BaseReadParameters () pp_diag_name.queryarr("species", m_output_species_names); - // Auxiliary variables - std::string species; - bool species_name_is_wrong; // Loop over all fields stored in m_varnames for (const auto& var : m_varnames) { // Check if m_varnames contains a string of the form rho_<species_name> if (var.rfind("rho_", 0) == 0) { // Extract species name from the string rho_<species_name> - species = var.substr(var.find("rho_") + 4); + const std::string species = var.substr(var.find("rho_") + 4); // Boolean used to check if species name was misspelled - species_name_is_wrong = true; + bool species_name_is_wrong = true; // Loop over all species for (int i = 0, n = int(m_all_species_names.size()); i < n; i++) { // Check if species name extracted from the string rho_<species_name> diff --git a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp index 47b90e099..ebf280e8f 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp @@ -99,9 +99,6 @@ void ParticleEnergy::ComputeDiags (int step) // Get number of species const int nSpecies = mypc.nSpecies(); - // Some useful offsets to fill m_data below - int offset_total_species, offset_mean_species, offset_mean_all; - amrex::Real Wtot = 0.0_rt; // Loop over species @@ -169,7 +166,7 @@ void ParticleEnergy::ComputeDiags (int step) // Offset: // 1 value of total energy for all species + // 1 value of total energy for each species - offset_total_species = 1 + i_s; + const int offset_total_species = 1 + i_s; m_data[offset_total_species] = Etot; // Offset: @@ -177,7 +174,7 @@ void ParticleEnergy::ComputeDiags (int step) // 1 value of total energy for each species + // 1 value of mean energy for all species + // 1 value of mean energy for each species - offset_mean_species = 1 + nSpecies + 1 + i_s; + const int offset_mean_species = 1 + nSpecies + 1 + i_s; if (Ws > std::numeric_limits<Real>::min()) { m_data[offset_mean_species] = Etot / Ws; @@ -197,14 +194,14 @@ void ParticleEnergy::ComputeDiags (int step) // Offset: // 1 value of total energy for all species + // 1 value of total energy for each species - offset_total_species = 1 + i_s; + const int offset_total_species = 1 + i_s; m_data[0] += m_data[offset_total_species]; } // Total mean energy. Offset: // 1 value of total energy for all species + // 1 value of total energy for each species - offset_mean_all = 1 + nSpecies; + const int offset_mean_all = 1 + nSpecies; if (Wtot > std::numeric_limits<Real>::min()) { m_data[offset_mean_all] = m_data[0] / Wtot; diff --git a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp index b3f0f142e..6dd2a0db3 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp @@ -127,9 +127,6 @@ void ParticleMomentum::ComputeDiags (int step) // Get number of species const int nSpecies = mypc.nSpecies(); - // Some useful offsets to fill m_data below - int offset_total_species, offset_mean_species, offset_mean_all; - amrex::Real Wtot = 0.0_rt; // Loop over species @@ -177,7 +174,7 @@ void ParticleMomentum::ComputeDiags (int step) // Offset: // 3 values of total momentum for all species + // 3 values of total momentum for each species - offset_total_species = 3 + i_s*3; + const int offset_total_species = 3 + i_s*3; m_data[offset_total_species+0] = Px; m_data[offset_total_species+1] = Py; m_data[offset_total_species+2] = Pz; @@ -187,7 +184,7 @@ void ParticleMomentum::ComputeDiags (int step) // 3 values of total momentum for each species + // 3 values of mean momentum for all species + // 3 values of mean momentum for each species - offset_mean_species = 3 + nSpecies*3 + 3 + i_s*3; + const int offset_mean_species = 3 + nSpecies*3 + 3 + i_s*3; if (Ws > std::numeric_limits<Real>::min()) { m_data[offset_mean_species+0] = Px / Ws; @@ -213,7 +210,7 @@ void ParticleMomentum::ComputeDiags (int step) // Offset: // 3 values of total momentum for all species + // 3 values of total momentum for each species - offset_total_species = 3 + i_s*3; + const int offset_total_species = 3 + i_s*3; m_data[0] += m_data[offset_total_species+0]; m_data[1] += m_data[offset_total_species+1]; m_data[2] += m_data[offset_total_species+2]; @@ -222,7 +219,7 @@ void ParticleMomentum::ComputeDiags (int step) // Total mean momentum. Offset: // 3 values of total momentum for all species + // 3 values of total momentum for each species - offset_mean_all = 3 + nSpecies*3; + const int offset_mean_all = 3 + nSpecies*3; if (Wtot > std::numeric_limits<Real>::min()) { m_data[offset_mean_all+0] = m_data[0] / Wtot; diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 6ae20e446..a97c87122 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -65,12 +65,8 @@ WarpX::Evolve (int numsteps) Real cur_time = t_new[0]; - int numsteps_max; - if (numsteps < 0) { // Note that the default argument is numsteps = -1 - numsteps_max = max_step; - } else { - numsteps_max = istep[0] + numsteps; - } + // Note that the default argument is numsteps = -1 + const int numsteps_max = (numsteps < 0)?(max_step):(istep[0] + numsteps); bool early_params_checked = false; // check typos in inputs after step 1 bool exit_loop_due_to_interrupt_signal = false; diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H index 622f7fa82..ad8194a13 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H @@ -50,14 +50,9 @@ struct CylindricalYeeAlgorithm { // semi-analytically by R. Lehe, and resulted in the following // coefficients. std::array< amrex::Real, 6 > const multimode_coeffs = {{ 0.2105_rt, 1.0_rt, 3.5234_rt, 8.5104_rt, 15.5059_rt, 24.5037_rt }}; - amrex::Real multimode_alpha; - if (n_rz_azimuthal_modes < 7) { - // Use the table of the coefficients - multimode_alpha = multimode_coeffs[n_rz_azimuthal_modes-1]; - } else { - // Use a realistic extrapolation - multimode_alpha = (n_rz_azimuthal_modes - 1._rt)*(n_rz_azimuthal_modes - 1._rt) - 0.4_rt; - } + const amrex::Real multimode_alpha = (n_rz_azimuthal_modes < 7)? + multimode_coeffs[n_rz_azimuthal_modes-1]: // Use the table of the coefficients + (n_rz_azimuthal_modes - 1._rt)*(n_rz_azimuthal_modes - 1._rt) - 0.4_rt; // Use a realistic extrapolation const amrex::Real delta_t = 1._rt / ( std::sqrt( (1._rt + multimode_alpha) / (dx[0]*dx[0]) + 1._rt / (dx[1]*dx[1]) 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>) diff --git a/Source/FieldSolver/SpectralSolver/SpectralHankelTransform/HankelTransform.cpp b/Source/FieldSolver/SpectralSolver/SpectralHankelTransform/HankelTransform.cpp index ddd07acad..5d49322b2 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralHankelTransform/HankelTransform.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralHankelTransform/HankelTransform.cpp @@ -64,12 +64,7 @@ HankelTransform::HankelTransform (int const hankel_order, // NB: When compared with the FBPIC article, all the matrices here // are calculated in transposed form. This is done so as to use the // `dot` and `gemm` functions, in the `transform` method. - int p_denom; - if (hankel_order == azimuthal_mode) { - p_denom = hankel_order + 1; - } else { - p_denom = hankel_order; - } + const int p_denom = (hankel_order == azimuthal_mode)?(hankel_order + 1):(hankel_order); amrex::Vector<amrex::Real> denom(m_nk); for (int ik=0 ; ik < m_nk ; ik++) { diff --git a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp index 7320b7cf1..b8d81000c 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp @@ -68,14 +68,9 @@ SpectralKSpace::SpectralKSpace( const BoxArray& realspace_ba, spectralspace_ba.define( spectral_bl ); // Allocate the components of the k vector: kx, ky (only in 3D), kz - bool only_positive_k; for (int i_dim=0; i_dim<AMREX_SPACEDIM; i_dim++) { - if (i_dim==0) { - // Real-to-complex FFTs: first axis contains only the positive k - only_positive_k = true; - } else { - only_positive_k = false; - } + // Real-to-complex FFTs: first axis contains only the positive k + const auto only_positive_k = (i_dim==0); k_vec[i_dim] = getKComponent(dm, realspace_ba, i_dim, only_positive_k); } } diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index b750c0028..d5a8bfed0 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -636,13 +636,9 @@ WarpX::computeMaxStepBoostAccelerator() { const Real interaction_time_boost = (len_plasma_boost-zmin_domain_boost_step_0)/ (moving_window_v-v_plasma_boost); // Divide by dt, and update value of max_step. - int computed_max_step; - if (do_subcycling){ - computed_max_step = static_cast<int>(interaction_time_boost/dt[0]); - } else { - computed_max_step = - static_cast<int>(interaction_time_boost/dt[maxLevel()]); - } + const auto computed_max_step = (do_subcycling)? + static_cast<int>(interaction_time_boost/dt[0]): + static_cast<int>(interaction_time_boost/dt[maxLevel()]); max_step = computed_max_step; Print()<<"max_step computed in computeMaxStepBoostAccelerator: " <<max_step<<std::endl; @@ -658,15 +654,14 @@ WarpX::InitNCICorrector () { const Geometry& gm = Geom(lev); const Real* dx = gm.CellSize(); - amrex::Real dz, cdtodz; #if defined(WARPX_DIM_3D) - dz = dx[2]; + const auto dz = dx[2]; #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - dz = dx[1]; + const auto dz = dx[1]; #else - dz = dx[0]; + const auto dz = dx[0]; #endif - cdtodz = PhysConst::c * dt[lev] / dz; + const auto cdtodz = PhysConst::c * dt[lev] / dz; // Initialize Godfrey filters // Same filter for fields Ex, Ey and Bz diff --git a/Source/Parallelization/WarpXComm_K.H b/Source/Parallelization/WarpXComm_K.H index 269827496..b97773af2 100644 --- a/Source/Parallelization/WarpXComm_K.H +++ b/Source/Parallelization/WarpXComm_K.H @@ -47,10 +47,6 @@ void warpx_interp (int j, int k, int l, const int kc = (sk == 0) ? amrex::coarsen(k - rk/2, rk) : amrex::coarsen(k, rk); const int lc = (sl == 0) ? amrex::coarsen(l - rl/2, rl) : amrex::coarsen(l, rl); - amrex::Real wj; - amrex::Real wk; - amrex::Real wl; - // Interpolate from coarse grid to fine grid using 2 points // with weights depending on the distance, for both nodal and cell-centered grids const amrex::Real hj = (sj == 0) ? 0.5_rt : 0._rt; @@ -62,9 +58,9 @@ void warpx_interp (int j, int k, int l, for (int jj = 0; jj < nj; jj++) { for (int kk = 0; kk < nk; kk++) { for (int ll = 0; ll < nl; ll++) { - wj = (rj - amrex::Math::abs(j + hj - (jc + jj + hj) * rj)) / static_cast<amrex::Real>(rj); - wk = (rk - amrex::Math::abs(k + hk - (kc + kk + hk) * rk)) / static_cast<amrex::Real>(rk); - wl = (rl - amrex::Math::abs(l + hl - (lc + ll + hl) * rl)) / static_cast<amrex::Real>(rl); + const amrex::Real wj = (rj - amrex::Math::abs(j + hj - (jc + jj + hj) * rj)) / static_cast<amrex::Real>(rj); + const amrex::Real wk = (rk - amrex::Math::abs(k + hk - (kc + kk + hk) * rk)) / static_cast<amrex::Real>(rk); + const amrex::Real wl = (rl - amrex::Math::abs(l + hl - (lc + ll + hl) * rl)) / static_cast<amrex::Real>(rl); res += wj * wk * wl * arr_coarse_zeropad(jc+jj,kc+kk,lc+ll); } } diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H index 9bcec2606..23939bbc2 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H @@ -161,15 +161,7 @@ public: const int c2 = amrex::max(NI1/NI2,1); // multiplier ratio to take into account unsampled pairs - int multiplier_ratio; - if (m_isSameSpecies) - { - multiplier_ratio = 2*max_N - 1; - } - else - { - multiplier_ratio = max_N; - } + const int multiplier_ratio = (m_isSameSpecies)?(2*max_N - 1):(max_N); #if (defined WARPX_DIM_RZ) amrex::ParticleReal * const AMREX_RESTRICT theta1 = soa_1.m_rdata[PIdx::theta]; diff --git a/Source/Particles/Collision/BinaryCollision/ShuffleFisherYates.H b/Source/Particles/Collision/BinaryCollision/ShuffleFisherYates.H index d7a302e3a..42259512b 100644 --- a/Source/Particles/Collision/BinaryCollision/ShuffleFisherYates.H +++ b/Source/Particles/Collision/BinaryCollision/ShuffleFisherYates.H @@ -20,13 +20,12 @@ AMREX_GPU_HOST_DEVICE AMREX_INLINE void ShuffleFisherYates (T_index *array, T_index const is, T_index const ie, amrex::RandomEngine const& engine) { - int j; T_index buf; for (int i = ie-1; i >= static_cast<int>(is+1); --i) { // get random number j: is <= j <= i - j = amrex::Random_int(i-is+1, engine) + is; - // swop the ith array element with the jth + const int j = amrex::Random_int(i-is+1, engine) + is; + // swap the ith array element with the jth buf = array[i]; array[i] = array[j]; array[j] = buf; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 56553575c..60578d57f 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1020,12 +1020,8 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) if (inj_pos->overlapsWith(lo, hi)) { auto index = overlap_box.index(iv); - int r; - if (fine_overlap_box.ok() && fine_overlap_box.contains(iv)) { - r = AMREX_D_TERM(lrrfac[0],*lrrfac[1],*lrrfac[2]); - } else { - r = 1; - } + const int r = (fine_overlap_box.ok() && fine_overlap_box.contains(iv))? + (AMREX_D_TERM(lrrfac[0],*lrrfac[1],*lrrfac[2])) : (1); pcounts[index] = num_ppc*r; // update pcount by checking if cell-corners or cell-center // has non-zero density @@ -1254,14 +1250,11 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) #ifdef WARPX_DIM_RZ // Replace the x and y, setting an angle theta. // These x and y are used to get the momentum and density - Real theta; - if (nmodes == 1 && rz_random_theta) { - // With only 1 mode, the angle doesn't matter so - // choose it randomly. - theta = 2._rt*MathConst::pi*amrex::Random(engine); - } else { - theta = 2._rt*MathConst::pi*r.y + theta_offset; - } + // With only 1 mode, the angle doesn't matter so + // choose it randomly. + const Real theta = (nmodes == 1 && rz_random_theta)? + (2._rt*MathConst::pi*amrex::Random(engine)): + (2._rt*MathConst::pi*r.y + theta_offset); pos.x = xb*std::cos(theta); pos.y = xb*std::sin(theta); #endif @@ -1794,14 +1787,11 @@ PhysicalParticleContainer::AddPlasmaFlux (amrex::Real dt) // Conversion from cylindrical to Cartesian coordinates // Replace the x and y, setting an angle theta. // These x and y are used to get the momentum and flux - Real theta; - if (nmodes == 1 && rz_random_theta) { - // With only 1 mode, the angle doesn't matter so - // choose it randomly. - theta = 2._prt*MathConst::pi*amrex::Random(engine); - } else { - theta = 2._prt*MathConst::pi*r.y; - } + // With only 1 mode, the angle doesn't matter so + // choose it randomly. + const Real theta = (nmodes == 1 && rz_random_theta)? + (2._prt*MathConst::pi*amrex::Random(engine)): + (2._prt*MathConst::pi*r.y); Real const cos_theta = std::cos(theta); Real const sin_theta = std::sin(theta); // Rotate the position @@ -2047,12 +2037,10 @@ PhysicalParticleContainer::Evolve (int lev, if (rho && ! skip_deposition && ! do_not_deposit) { // Deposit charge before particle push, in component 0 of MultiFab rho. - int* AMREX_RESTRICT ion_lev; - if (do_field_ionization){ - ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); - } else { - ion_lev = nullptr; - } + + const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? + pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; + DepositCharge(pti, wp, ion_lev, rho, 0, 0, np_current, thread_num, lev, lev); if (has_buffer){ @@ -2120,12 +2108,9 @@ PhysicalParticleContainer::Evolve (int lev, // Deposit at t_{n+1/2} const amrex::Real relative_time = -0.5_rt * dt; - int* AMREX_RESTRICT ion_lev; - if (do_field_ionization){ - ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); - } else { - ion_lev = nullptr; - } + const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? + pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; + // Deposit inside domains DepositCurrent(pti, wp, uxp, uyp, uzp, ion_lev, &jx, &jy, &jz, 0, np_current, thread_num, @@ -2145,12 +2130,10 @@ PhysicalParticleContainer::Evolve (int lev, // Deposit charge after particle push, in component 1 of MultiFab rho. // (Skipped for electrostatic solver, as this may lead to out-of-bounds) if (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::None) { - int* AMREX_RESTRICT ion_lev; - if (do_field_ionization){ - ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); - } else { - ion_lev = nullptr; - } + + const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? + pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; + DepositCharge(pti, wp, ion_lev, rho, 1, 0, np_current, thread_num, lev, lev); if (has_buffer){ diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index cabe05c6e..dd7845dff 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -162,11 +162,9 @@ WarpXParticleContainer::AddNParticles (int /*lev*/, WARPX_ALWAYS_ASSERT_WITH_MESSAGE(nattr_int <= NumIntComps(), "Too many integer attributes specified"); - int ibegin, iend; - if (uniqueparticles) { - ibegin = 0; - iend = n; - } else { + int ibegin = 0; + int iend = n; + if (!uniqueparticles) { const int myproc = amrex::ParallelDescriptor::MyProc(); const int nprocs = amrex::ParallelDescriptor::NProcs(); const int navg = n/nprocs; @@ -1094,12 +1092,8 @@ WarpXParticleContainer::GetChargeDensity (int lev, bool local) const long np = pti.numParticles(); auto& wp = pti.GetAttribs(PIdx::w); - int* AMREX_RESTRICT ion_lev; - if (do_field_ionization){ - ion_lev = pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr(); - } else { - ion_lev = nullptr; - } + const int* const AMREX_RESTRICT ion_lev = (do_field_ionization)? + pti.GetiAttribs(particle_icomps["ionizationLevel"]).dataPtr():nullptr; DepositCharge(pti, wp, ion_lev, rho.get(), 0, 0, np, thread_num, lev, lev); diff --git a/Source/ablastr/coarsen/average.H b/Source/ablastr/coarsen/average.H index 8f484a187..976ed1fae 100644 --- a/Source/ablastr/coarsen/average.H +++ b/Source/ablastr/coarsen/average.H @@ -104,8 +104,6 @@ namespace ablastr::coarsen::average int const crx = cr[0]; int const cry = cr[1]; int const crz = cr[2]; - int ii, jj, kk; - amrex::Real wx, wy, wz; // Add neutral elements (=0) beyond guard cells in source array (fine) auto const arr_src_safe = [arr_src] @@ -125,16 +123,16 @@ namespace ablastr::coarsen::average for (int kref = 0; kref < numz; ++kref) { for (int jref = 0; jref < numy; ++jref) { for (int iref = 0; iref < numx; ++iref) { - ii = imin + iref; - jj = jmin + jref; - kk = kmin + kref; - wx = (1.0_rt / static_cast<amrex::Real>(numx)) * (1 - sfx) * (1 - scx) // if cell-centered + const int ii = imin + iref; + const int jj = jmin + jref; + const int kk = kmin + kref; + const amrex::Real wx = (1.0_rt / static_cast<amrex::Real>(numx)) * (1 - sfx) * (1 - scx) // if cell-centered + ((amrex::Math::abs(crx - amrex::Math::abs(ii - i * crx))) / static_cast<amrex::Real>(crx * crx)) * sfx * scx; // if nodal - wy = (1.0_rt / static_cast<amrex::Real>(numy)) * (1 - sfy) * (1 - scy) // if cell-centered + const amrex::Real wy = (1.0_rt / static_cast<amrex::Real>(numy)) * (1 - sfy) * (1 - scy) // if cell-centered + ((amrex::Math::abs(cry - amrex::Math::abs(jj - j * cry))) / static_cast<amrex::Real>(cry * cry)) * sfy * scy; // if nodal - wz = (1.0_rt / static_cast<amrex::Real>(numz)) * (1 - sfz) * (1 - scz) // if cell-centered + const amrex::Real wz = (1.0_rt / static_cast<amrex::Real>(numz)) * (1 - sfz) * (1 - scz) // if cell-centered + ((amrex::Math::abs(crz - amrex::Math::abs(kk - k * crz))) / static_cast<amrex::Real>(crz * crz)) * sfz * scz; // if nodal c += wx * wy * wz * arr_src_safe(ii, jj, kk, comp); diff --git a/Source/ablastr/coarsen/sample.H b/Source/ablastr/coarsen/sample.H index 0a338a1c4..a0439bad2 100644 --- a/Source/ablastr/coarsen/sample.H +++ b/Source/ablastr/coarsen/sample.H @@ -84,7 +84,6 @@ namespace ablastr::coarsen::sample const int imin = idx_min[0]; const int jmin = idx_min[1]; const int kmin = idx_min[2]; - int ii, jj, kk; amrex::Real const wx = 1.0_rt / static_cast<amrex::Real>(numx); amrex::Real const wy = 1.0_rt / static_cast<amrex::Real>(numy); amrex::Real const wz = 1.0_rt / static_cast<amrex::Real>(numz); @@ -94,9 +93,9 @@ namespace ablastr::coarsen::sample for (int kref = 0; kref < numz; ++kref) { for (int jref = 0; jref < numy; ++jref) { for (int iref = 0; iref < numx; ++iref) { - ii = imin+iref; - jj = jmin+jref; - kk = kmin+kref; + const int ii = imin+iref; + const int jj = jmin+jref; + const int kk = kmin+kref; c += wx*wy*wz*arr_src(ii,jj,kk,comp); } } |