From 1ce0303ea1e4827099c16669bc7087c3894dd467 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Thu, 3 Aug 2023 13:37:21 -0700 Subject: [PATCH] Clang-Tidy changes in Src/AmrCore (#3468) --- Src/AmrCore/AMReX_AmrCore.cpp | 2 +- Src/AmrCore/AMReX_AmrMesh.cpp | 96 +++++++++++++++++------------ Src/AmrCore/AMReX_AmrParticles.H | 2 +- Src/AmrCore/AMReX_Cluster.cpp | 17 +++-- Src/AmrCore/AMReX_ErrorList.cpp | 8 ++- Src/AmrCore/AMReX_FillPatchUtil.cpp | 6 +- Src/AmrCore/AMReX_FluxRegister.cpp | 2 +- Src/AmrCore/AMReX_Interpolater.cpp | 8 +-- Src/AmrCore/AMReX_TagBox.cpp | 18 +++--- 9 files changed, 91 insertions(+), 68 deletions(-) diff --git a/Src/AmrCore/AMReX_AmrCore.cpp b/Src/AmrCore/AMReX_AmrCore.cpp index ac35f279b44..502b3f5cb23 100644 --- a/Src/AmrCore/AMReX_AmrCore.cpp +++ b/Src/AmrCore/AMReX_AmrCore.cpp @@ -85,7 +85,7 @@ AmrCore::InitFromScratch (Real time) void AmrCore::regrid (int lbase, Real time, bool) { - if (lbase >= max_level) return; + if (lbase >= max_level) { return; } int new_finest; Vector new_grids(finest_level+2); diff --git a/Src/AmrCore/AMReX_AmrMesh.cpp b/Src/AmrCore/AMReX_AmrMesh.cpp index 46124fee39d..70a8df1dabf 100644 --- a/Src/AmrCore/AMReX_AmrMesh.cpp +++ b/Src/AmrCore/AMReX_AmrMesh.cpp @@ -61,7 +61,7 @@ AmrMesh::AmrMesh (Geometry const& level_0_geom, AmrInfo const& amr_info) finest_level = -1; - if (check_input) checkInput(); + if (check_input) { checkInput(); } } void @@ -187,8 +187,9 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector& n_cell_in, int k = 0; for (int i = 0; i < max_level; i++) { - for (int n = 0; n < AMREX_SPACEDIM; n++,k++) + for (int n = 0; n < AMREX_SPACEDIM; n++,k++) { ref_ratio[i][n] = ratios_vect[k]; + } } } else if (got_int == 1) @@ -344,7 +345,7 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector& n_cell_in, } else { - for (int i = 0; i < AMREX_SPACEDIM; i++) n_cell[i] = n_cell_in[i]; + for (int i = 0; i < AMREX_SPACEDIM; i++) { n_cell[i] = n_cell_in[i]; } } IntVect lo(IntVect::TheZeroVector()), hi(n_cell); @@ -375,15 +376,16 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector& n_cell_in, finest_level = -1; - if (check_input) checkInput(); + if (check_input) { checkInput(); } } int AmrMesh::MaxRefRatio (int lev) const noexcept { int maxval = 0; - for (int n = 0; n& // Add at most one new level int max_crse = std::min(finest_level, max_level-1); - if (new_grids.size() < max_crse+2) new_grids.resize(max_crse+2); + if (new_grids.size() < max_crse+2) { new_grids.resize(max_crse+2); } // // Construct problem domain at each level. @@ -704,7 +706,7 @@ AmrMesh::MakeNewGrids (int lbase, Real time, int& new_finest, Vector& // // Construct initial cluster. // - ClusterList clist(&tagvec[0], static_cast(tagvec.size())); + ClusterList clist(tagvec.data(), static_cast(tagvec.size())); if (use_new_chop) { clist.new_chop(grid_eff); } else { @@ -807,7 +809,7 @@ AmrMesh::MakeNewGrids (Real time) // Add (at most) one level at a time. MakeNewGrids(finest_level,time,new_finest,new_grids); - if (new_finest <= finest_level) break; + if (new_finest <= finest_level) { break; } finest_level = new_finest; DistributionMapping dm(new_grids[new_finest]); @@ -834,7 +836,7 @@ AmrMesh::MakeNewGrids (Real time) int new_finest; MakeNewGrids(0, time, new_finest, new_grids); - if (new_finest < finest_level) break; + if (new_finest < finest_level) { break; } finest_level = new_finest; bool grids_the_same = true; @@ -852,7 +854,7 @@ AmrMesh::MakeNewGrids (Real time) } } } - if (grids_the_same) break; + if (grids_the_same) { break; } } } } @@ -888,56 +890,68 @@ AmrMesh::ProjPeriodic (BoxList& blout, const Box& domain, int ri,rj,rk; for (ri = nist; ri <= niend; ri++) { - if (ri != 0 && !is_per[0]) + if (ri != 0 && !is_per[0]) { continue; - if (ri != 0 && is_per[0]) + } + if (ri != 0 && is_per[0]) { blorig.shift(0,ri*domain.length(0)); + } for (rj = njst; rj <= njend; rj++) { - if (rj != 0 && !is_per[1]) + if (rj != 0 && !is_per[1]) { continue; - if (rj != 0 && is_per[1]) + } + if (rj != 0 && is_per[1]) { blorig.shift(1,rj*domain.length(1)); + } for (rk = nkst; rk <= nkend; rk++) { - if (rk != 0 && !is_per[2]) + if (rk != 0 && !is_per[2]) { continue; - if (rk != 0 && is_per[2]) + } + if (rk != 0 && is_per[2]) { blorig.shift(2,rk*domain.length(2)); + } BoxList tmp(blorig); tmp.intersect(domain); blout.catenate(tmp); - if (rk != 0 && is_per[2]) + if (rk != 0 && is_per[2]) { blorig.shift(2,-rk*domain.length(2)); + } } - if (rj != 0 && is_per[1]) + if (rj != 0 && is_per[1]) { blorig.shift(1,-rj*domain.length(1)); + } } - if (ri != 0 && is_per[0]) + if (ri != 0 && is_per[0]) { blorig.shift(0,-ri*domain.length(0)); + } } } void AmrMesh::checkInput () { - if (max_level < 0) + if (max_level < 0) { amrex::Error("checkInput: max_level not set"); + } // // Check level dependent values. // for (int i = 0; i < max_level; i++) { - if (MaxRefRatio(i) < 2) + if (MaxRefRatio(i) < 2) { amrex::Error("Amr::checkInput: bad ref_ratios"); + } } const Box& domain = Geom(0).Domain(); - if (!domain.ok()) + if (!domain.ok()) { amrex::Error("level 0 domain bad or not set"); + } // // Check that domain size is a multiple of blocking_factor[0]. @@ -946,13 +960,14 @@ AmrMesh::checkInput () for (int idim = 0; idim < AMREX_SPACEDIM; idim++) { int len = domain.length(idim); - if (blocking_factor[0][idim] <= max_grid_size[0][idim]) + if (blocking_factor[0][idim] <= max_grid_size[0][idim]) { if (len%blocking_factor[0][idim] != 0) { amrex::Print() << "domain size in direction " << idim << " is " << len << std::endl; amrex::Print() << "blocking_factor is " << blocking_factor[0][idim] << std::endl; amrex::Error("domain size not divisible by blocking_factor"); } + } } // @@ -963,10 +978,12 @@ AmrMesh::checkInput () for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { int k = blocking_factor[i][idim]; - while ( k > 0 && (k%2 == 0) ) + while ( k > 0 && (k%2 == 0) ) { k /= 2; - if (k != 1) + } + if (k != 1) { amrex::Error("Amr::checkInput: blocking_factor not power of 2. You can bypass this by setting ParmParse runtime parameter amr.check_input=0, although we do not recommend it."); + } } } @@ -991,14 +1008,13 @@ AmrMesh::checkInput () for (int i = 0; i < max_level; i++) { for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if (blocking_factor[i][idim] <= max_grid_size[i][idim]) - if (max_grid_size[i][idim]%blocking_factor[i][idim] != 0) { - { - amrex::Print() << "max_grid_size in direction " << idim - << " is " << max_grid_size[i][idim] << std::endl; - amrex::Print() << "blocking_factor is " << blocking_factor[i][idim] << std::endl; - amrex::Error("max_grid_size not divisible by blocking_factor"); - } + if (blocking_factor[i][idim] <= max_grid_size[i][idim]) { + if (max_grid_size[i][idim]%blocking_factor[i][idim] != 0) { + amrex::Print() << "max_grid_size in direction " << idim + << " is " << max_grid_size[i][idim] << std::endl; + amrex::Print() << "blocking_factor is " << blocking_factor[i][idim] << std::endl; + amrex::Error("max_grid_size not divisible by blocking_factor"); + } } } } @@ -1039,16 +1055,16 @@ std::ostream& operator<< (std::ostream& os, AmrMesh const& amr_mesh) os << " verbose = " << amr_mesh.verbose << "\n"; os << " max_level = " << amr_mesh.max_level << "\n"; os << " ref_ratio ="; - for (int lev = 0; lev < amr_mesh.max_level; ++lev) os << " " << amr_mesh.ref_ratio[lev]; + for (int lev = 0; lev < amr_mesh.max_level; ++lev) { os << " " << amr_mesh.ref_ratio[lev]; } os << "\n"; os << " blocking_factor ="; - for (int lev = 0; lev <= amr_mesh.max_level; ++lev) os << " " << amr_mesh.blocking_factor[lev]; + for (int lev = 0; lev <= amr_mesh.max_level; ++lev) { os << " " << amr_mesh.blocking_factor[lev]; } os << "\n"; os << " max_grid_size ="; - for (int lev = 0; lev <= amr_mesh.max_level; ++lev) os << " " << amr_mesh.max_grid_size[lev]; + for (int lev = 0; lev <= amr_mesh.max_level; ++lev) { os << " " << amr_mesh.max_grid_size[lev]; } os << "\n"; os << " n_error_buf ="; - for (int lev = 0; lev < amr_mesh.max_level; ++lev) os << " " << amr_mesh.n_error_buf[lev]; + for (int lev = 0; lev < amr_mesh.max_level; ++lev) { os << " " << amr_mesh.n_error_buf[lev]; } os << "\n"; os << " grid_eff = " << amr_mesh.grid_eff << "\n"; os << " n_proper = " << amr_mesh.n_proper << "\n"; diff --git a/Src/AmrCore/AMReX_AmrParticles.H b/Src/AmrCore/AMReX_AmrParticles.H index aa6260e6952..65036ab4cd4 100644 --- a/Src/AmrCore/AMReX_AmrParticles.H +++ b/Src/AmrCore/AMReX_AmrParticles.H @@ -21,7 +21,7 @@ ParticleContainer_impl BL_PROFILE("ParticleContainer::AssignDensity()"); - if (rho_index != 0) amrex::Abort("AssignDensity only works if rho_index = 0"); + if (rho_index != 0) { amrex::Abort("AssignDensity only works if rho_index = 0"); } BL_ASSERT(NStructReal >= 1); BL_ASSERT(NStructReal >= ncomp); diff --git a/Src/AmrCore/AMReX_Cluster.cpp b/Src/AmrCore/AMReX_Cluster.cpp index d9a5a7e80f4..5383b9301f5 100644 --- a/Src/AmrCore/AMReX_Cluster.cpp +++ b/Src/AmrCore/AMReX_Cluster.cpp @@ -163,8 +163,9 @@ FindCut (const int* hist, // // Check validity of histogram. // - if (len <= 1) + if (len <= 1) { return lo; + } // // First find centermost point where hist == 0 (if any). // @@ -179,20 +180,23 @@ FindCut (const int* hist, if (std::abs(cutpoint-mid) > std::abs(i-mid)) { cutpoint = i; - if (i > mid) + if (i > mid) { break; + } } } } - if (status == HoleCut) + if (status == HoleCut) { return lo + cutpoint; + } // // If we got here, there was no obvious cutpoint, try // finding place where change in second derivative is max. // Vector dhist(len,0); - for (i = 1; i < len-1; i++) + for (i = 1; i < len-1; i++) { dhist[i] = hist[i+1] - 2*hist[i] + hist[i-1]; + } int locmax = -1; for (i = 0+MINOFF; i < len-MINOFF; i++) @@ -213,8 +217,9 @@ FindCut (const int* hist, // // Select location nearest center of range. // - if (std::abs(i-mid) < std::abs(cutpoint-mid)) + if (std::abs(i-mid) < std::abs(cutpoint-mid)) { cutpoint = i; + } } } } @@ -396,7 +401,7 @@ Cluster::new_chop () nlo += hist[dir][i-lo[dir]]; } - if (nlo <= 0 || nlo >= m_len) return chop(); + if (nlo <= 0 || nlo >= m_len) { return chop(); } Long nhi = m_len - nlo; diff --git a/Src/AmrCore/AMReX_ErrorList.cpp b/Src/AmrCore/AMReX_ErrorList.cpp index 91ded63ce3b..783a06504be 100644 --- a/Src/AmrCore/AMReX_ErrorList.cpp +++ b/Src/AmrCore/AMReX_ErrorList.cpp @@ -460,13 +460,15 @@ AMRErrorTag::operator() (TagBoxArray& tba, }); } else #endif - ParallelFor(tba, [=] AMREX_GPU_DEVICE (int bi, int i, int j, int k) noexcept { - Real vol = volume_weighting ? Geometry::Volume(IntVect{AMREX_D_DECL(i,j,k)}, geomdata) : 1.0_rt; + ParallelFor(tba, [=] AMREX_GPU_DEVICE (int bi, int i, int j, int k) noexcept + { + Real vol = volume_weighting ? Geometry::Volume(IntVect{AMREX_D_DECL(i,j,k)}, geomdata) : 1.0_rt; if (datma[bi](i,j,k) * vol >= threshold) { tagma[bi](i,j,k) = tag_update; } - }); + }); + } } else if (m_test == VORT) { diff --git a/Src/AmrCore/AMReX_FillPatchUtil.cpp b/Src/AmrCore/AMReX_FillPatchUtil.cpp index 84db10d2443..a90ba9fc89d 100644 --- a/Src/AmrCore/AMReX_FillPatchUtil.cpp +++ b/Src/AmrCore/AMReX_FillPatchUtil.cpp @@ -15,8 +15,8 @@ namespace amrex int ref_ratio) { InterpCrseFineBndryEMfield(interp_type, - {{AMREX_D_DECL(&crse[0],&crse[1],&crse[2])}}, - {{AMREX_D_DECL(&fine[0],&fine[1],&fine[2])}}, + {{AMREX_D_DECL(crse.data(),crse.data()+1,crse.data()+2)}}, + {{AMREX_D_DECL(fine.data(),fine.data()+1,fine.data()+2)}}, cgeom, fgeom, ref_ratio); } @@ -35,7 +35,7 @@ namespace amrex BL_ASSERT(ngrow == fine[idim]->nGrowVect()); } - if (ngrow.max() == 0) return; + if (ngrow.max() == 0) { return; } bool include_periodic = true; bool include_physbndry = false; diff --git a/Src/AmrCore/AMReX_FluxRegister.cpp b/Src/AmrCore/AMReX_FluxRegister.cpp index 87f6e693fc5..17f4ed6695d 100644 --- a/Src/AmrCore/AMReX_FluxRegister.cpp +++ b/Src/AmrCore/AMReX_FluxRegister.cpp @@ -739,7 +739,7 @@ FluxRegister::OverwriteFlux (Array const& crse_fluxes, Box cdomain = crse_geom.Domain(); for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { - if (crse_geom.isPeriodic(idim)) cdomain.grow(idim, 1); + if (crse_geom.isPeriodic(idim)) { cdomain.grow(idim, 1); } } bool run_on_gpu = Gpu::inLaunchRegion(); diff --git a/Src/AmrCore/AMReX_Interpolater.cpp b/Src/AmrCore/AMReX_Interpolater.cpp index 80c00a24175..a5947f18aab 100644 --- a/Src/AmrCore/AMReX_Interpolater.cpp +++ b/Src/AmrCore/AMReX_Interpolater.cpp @@ -475,7 +475,7 @@ CellConservativeLinear::interp (const FArrayBox& crse, BCRec const* bcrp = (run_on_gpu) ? async_bcr.data() : bcr.data(); Elixir cceli; - if (run_on_gpu) cceli = ccfab.elixir(); + if (run_on_gpu) { cceli = ccfab.elixir(); } #else BCRec const* bcrp = bcr.data(); #endif @@ -628,7 +628,7 @@ CellQuadratic::interp (const FArrayBox& crse, BCRec const* bcrp = (run_on_gpu) ? async_bcr.data() : bcr.data(); Elixir seli; - if (run_on_gpu) seli = sfab.elixir(); + if (run_on_gpu) { seli = sfab.elixir(); } #else BCRec const* bcrp = bcr.data(); #endif @@ -1033,7 +1033,7 @@ CellQuartic::interp (const FArrayBox& crse, FArrayBox tmpz(bz, ncomp); #ifdef AMREX_USE_GPU Elixir tmpz_eli; - if (run_on_gpu) tmpz_eli = tmpz.elixir(); + if (run_on_gpu) { tmpz_eli = tmpz.elixir(); } #endif Array4 const& tmpzarr = tmpz.array(); AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, bz, ncomp, i, j, k, n, @@ -1048,7 +1048,7 @@ CellQuartic::interp (const FArrayBox& crse, FArrayBox tmpy(by, ncomp); #ifdef AMREX_USE_GPU Elixir tmpy_eli; - if (run_on_gpu) tmpy_eli = tmpy.elixir(); + if (run_on_gpu) { tmpy_eli = tmpy.elixir(); } #endif Array4 const& tmpyarr = tmpy.array(); #if (AMREX_SPACEDIM == 2) diff --git a/Src/AmrCore/AMReX_TagBox.cpp b/Src/AmrCore/AMReX_TagBox.cpp index f80daf81265..1efc1e5e870 100644 --- a/Src/AmrCore/AMReX_TagBox.cpp +++ b/Src/AmrCore/AMReX_TagBox.cpp @@ -98,9 +98,9 @@ TagBox::buffer (const IntVect& a_nbuff, const IntVect& a_nwid) noexcept for (int kk = kmin; kk <= kmax && !to_buf; ++kk) { for (int jj = jmin; jj <= jmax && !to_buf; ++jj) { for (int ii = imin; ii <= imax && !to_buf; ++ii) { - if (a(ii,jj,kk) == TagBox::SET) to_buf = true; + if (a(ii,jj,kk) == TagBox::SET) { to_buf = true; } }}} - if (to_buf) a(i,j,k) = TagBox::BUF; + if (to_buf) { a(i,j,k) = TagBox::BUF; } } }); } else @@ -195,7 +195,7 @@ TagBox::get_itags(Vector& ar, const Box& tilebx) const noexcept stb += stride[idim] * (tilebx.smallEnd(idim) - domain.smallEnd(idim)); } - if (ar.size() < Ntb) ar.resize(Ntb); + if (ar.size() < Ntb) { ar.resize(Ntb); } const TagType* const p0 = dataPtr() + stb; // +stb to the lower corner of tilebox int* iptr = ar.dataPtr(); @@ -364,7 +364,7 @@ TagBoxArray::mapPeriodicRemoveDuplicates (const Geometry& geom) Array4 const& msk = owner_mask->const_array(mfi); AMREX_LOOP_3D(box, i, j, k, { - if (!msk(i,j,k)) tag(i,j,k) = TagBox::CLEAR; + if (!msk(i,j,k)) { tag(i,j,k) = TagBox::CLEAR; } }); } @@ -375,7 +375,7 @@ TagBoxArray::mapPeriodicRemoveDuplicates (const Geometry& geom) void TagBoxArray::local_collate_cpu (Gpu::PinnedVector& v) const { - if (this->local_size() == 0) return; + if (this->local_size() == 0) { return; } Vector count(this->local_size()); #ifdef AMREX_USE_OMP @@ -388,7 +388,7 @@ TagBoxArray::local_collate_cpu (Gpu::PinnedVector& v) const int c = 0; AMREX_LOOP_3D(bx,i,j,k, { - if (arr(i,j,k) != TagBox::CLEAR) ++c; + if (arr(i,j,k) != TagBox::CLEAR) { ++c; } }); count[fai.LocalIndex()] = c; } @@ -398,7 +398,7 @@ TagBoxArray::local_collate_cpu (Gpu::PinnedVector& v) const v.resize(offset.back()); - if (v.empty()) return; + if (v.empty()) { return; } #ifdef AMREX_USE_OMP #pragma omp parallel @@ -425,7 +425,7 @@ void TagBoxArray::local_collate_gpu (Gpu::PinnedVector& v) const { const int nfabs = this->local_size(); - if (nfabs == 0) return; + if (nfabs == 0) { return; } constexpr int block_size = 128; Vector nblocks(nfabs); @@ -496,7 +496,7 @@ TagBoxArray::local_collate_gpu (Gpu::PinnedVector& v) const std::partial_sum(hv_ntags.begin(), hv_ntags.end(), hv_tags_offset.begin()+1); int ntotaltags = hv_tags_offset.back(); - if (ntotaltags == 0) return; + if (ntotaltags == 0) { return; } Gpu::NonManagedDeviceVector dv_tags_offset(ntotblocks); int* dp_tags_offset = dv_tags_offset.data();