Skip to content

Commit

Permalink
Clang-Tidy changes in Src/AmrCore (#3468)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Aug 3, 2023
1 parent bee6554 commit 1ce0303
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Src/AmrCore/AMReX_AmrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoxArray> new_grids(finest_level+2);
Expand Down
96 changes: 56 additions & 40 deletions Src/AmrCore/AMReX_AmrMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -187,8 +187,9 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector<int>& 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)
Expand Down Expand Up @@ -344,7 +345,7 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector<int>& 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);
Expand Down Expand Up @@ -375,30 +376,31 @@ AmrMesh::InitAmrMesh (int max_level_in, const Vector<int>& 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<AMREX_SPACEDIM; n++)
for (int n = 0; n<AMREX_SPACEDIM; n++) {
maxval = std::max(maxval,ref_ratio[lev][n]);
}
return maxval;
}

void
AmrMesh::SetDistributionMap (int lev, const DistributionMapping& dmap_in) noexcept
{
++num_setdm;
if (dmap[lev] != dmap_in) dmap[lev] = dmap_in;
if (dmap[lev] != dmap_in) { dmap[lev] = dmap_in; }
}

void
AmrMesh::SetBoxArray (int lev, const BoxArray& ba_in) noexcept
{
++num_setba;
if (grids[lev] != ba_in) grids[lev] = ba_in;
if (grids[lev] != ba_in) { grids[lev] = ba_in; }
}

void
Expand All @@ -412,7 +414,7 @@ AmrMesh::GetLevel (Box const& domain) noexcept
{
Box ccdomain = amrex::enclosedCells(domain);
for (int lev = 0; lev < geom.size(); ++lev) {
if (geom[lev].Domain() == ccdomain) return lev;
if (geom[lev].Domain() == ccdomain) { return lev; }
}
return -1;
}
Expand Down Expand Up @@ -510,7 +512,7 @@ AmrMesh::MakeNewGrids (int lbase, Real time, int& new_finest, Vector<BoxArray>&
// 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.
Expand Down Expand Up @@ -704,7 +706,7 @@ AmrMesh::MakeNewGrids (int lbase, Real time, int& new_finest, Vector<BoxArray>&
//
// Construct initial cluster.
//
ClusterList clist(&tagvec[0], static_cast<Long>(tagvec.size()));
ClusterList clist(tagvec.data(), static_cast<Long>(tagvec.size()));
if (use_new_chop) {
clist.new_chop(grid_eff);
} else {
Expand Down Expand Up @@ -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]);
Expand All @@ -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;
Expand All @@ -852,7 +854,7 @@ AmrMesh::MakeNewGrids (Real time)
}
}
}
if (grids_the_same) break;
if (grids_the_same) { break; }
}
}
}
Expand Down Expand Up @@ -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].
Expand All @@ -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");
}
}
}

//
Expand All @@ -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.");
}
}
}

Expand All @@ -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");
}
}
}
}
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Src/AmrCore/AMReX_AmrParticles.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>

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);
Expand Down
17 changes: 11 additions & 6 deletions Src/AmrCore/AMReX_Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
//
Expand All @@ -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<int> 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++)
Expand All @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions Src/AmrCore/AMReX_ErrorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions Src/AmrCore/AMReX_FillPatchUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Src/AmrCore/AMReX_FluxRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ FluxRegister::OverwriteFlux (Array<MultiFab*,AMREX_SPACEDIM> 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();
Expand Down
Loading

0 comments on commit 1ce0303

Please sign in to comment.