Skip to content

Commit

Permalink
Clang-Tidy changes in Src/LinearSolvers (#3475)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Aug 5, 2023
1 parent 0dddf9e commit 7ec2e0b
Show file tree
Hide file tree
Showing 32 changed files with 497 additions and 400 deletions.
16 changes: 9 additions & 7 deletions Src/LinearSolvers/MLMG/AMReX_MLABecLap_2D_K.H
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,12 @@ void abec_gsrb_with_line_solve (
// int idir = 1;

// This should be moved outside the kernel!
if (dhy <= dhx) amrex::Abort("dhy is supposed to be much larger than dhx");
if (dhy <= dhx) { amrex::Abort("dhy is supposed to be much larger than dhx"); }

int ilen = hi.y - lo.y + 1;

// This should be moved outside the kernel!
if (ilen > 32) amrex::Abort("abec_gsrb_with_line_solve is hard-wired to be no longer than 32");
if (ilen > 32) { amrex::Abort("abec_gsrb_with_line_solve is hard-wired to be no longer than 32"); }

Array1D<T,0,31> a_ls;
Array1D<T,0,31> b_ls;
Expand Down Expand Up @@ -295,10 +295,12 @@ void abec_gsrb_with_line_solve (
+ bX(i+1,j,0,n)*phi(i+1,j,0,n) );

// We have already accounted for this external boundary in the coefficient of phi(i,j,k,n)
if (i == vlo.x && m0(vlo.x-1,j,0) > 0)
if (i == vlo.x && m0(vlo.x-1,j,0) > 0) {
rho -= dhx*bX(i ,j,0,n)*phi(i-1,j,0,n);
if (i == vhi.x && m3(vhi.x+1,j,0) > 0)
}
if (i == vhi.x && m3(vhi.x+1,j,0) > 0) {
rho -= dhx*bX(i+1,j,0,n)*phi(i+1,j,0,n);
}

a_ls(j-lo.y) = -dhy*bY(i,j,0,n);
b_ls(j-lo.y) = g_m_d;
Expand All @@ -308,11 +310,11 @@ void abec_gsrb_with_line_solve (

if (j == lo.y) {
a_ls(j-lo.y) = T(0.);
if (!(m1(i,vlo.y-1,0) > 0)) r_ls(j-lo.y) += dhy*bY(i,j,0,n)*phi(i,j-1,0,n);
if (!(m1(i,vlo.y-1,0) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j,0,n)*phi(i,j-1,0,n); }
}
if (j == hi.y) {
c_ls(j-lo.y) = T(0.);
if (!(m3(i,vhi.y+1,0) > 0)) r_ls(j-lo.y) += dhy*bY(i,j+1,0,n)*phi(i,j+1,0,n);
if (!(m3(i,vhi.y+1,0) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j+1,0,n)*phi(i,j+1,0,n); }
}
}
// This is the tridiagonal solve
Expand All @@ -323,7 +325,7 @@ void abec_gsrb_with_line_solve (
for (int jj = 1; jj <= ilen-1; jj++) {
gam(jj) = c_ls(jj-1) / bet;
bet = b_ls(jj) - a_ls(jj)*gam(jj);
if (bet == 0) amrex::Abort(">>>TRIDIAG FAILED");
if (bet == 0) { amrex::Abort(">>>TRIDIAG FAILED"); }
u_ls(jj) = (r_ls(jj)-a_ls(jj)*u_ls(jj-1)) / bet;
}

Expand Down
52 changes: 32 additions & 20 deletions Src/LinearSolvers/MLMG/AMReX_MLABecLap_3D_K.H
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void tridiagonal_solve (Array1D<T,0,31>& a_ls, Array1D<T,0,31>& b_ls, Array1D<T,
for (int i = 1; i <= ilen - 1; i++) {
gam(i) = c_ls(i-1) / bet;
bet = b_ls(i) - a_ls(i)*gam(i);
if (bet == 0) amrex::Abort(">>>TRIDIAG FAILED");
if (bet == 0) { amrex::Abort(">>>TRIDIAG FAILED"); }
u_ls(i) = (r_ls(i)-a_ls(i)*u_ls(i-1)) / bet;
}
for (int i = ilen-2; i >= 0; i--) {
Expand Down Expand Up @@ -388,7 +388,7 @@ void abec_gsrb_with_line_solve (
}

// This assertion should be moved outside the kernel for performance!
if (ilen > 32) amrex::Abort("abec_gsrb_with_line_solve is hard-wired to be no longer than 32");
if (ilen > 32) { amrex::Abort("abec_gsrb_with_line_solve is hard-wired to be no longer than 32"); }

Array1D<T,0,31> a_ls;
Array1D<T,0,31> b_ls;
Expand Down Expand Up @@ -435,14 +435,18 @@ void abec_gsrb_with_line_solve (
+ bY(i,j+1,k,n)*phi(i,j+1,k,n) );

// We have already accounted for this external boundary in the coefficient of phi(i,j,k,n)
if (i == vlo.x && m0(vlo.x-1,j,k) > 0)
if (i == vlo.x && m0(vlo.x-1,j,k) > 0) {
rho -= dhx*bX(i ,j,k,n)*phi(i-1,j,k,n);
if (i == vhi.x && m3(vhi.x+1,j,k) > 0)
}
if (i == vhi.x && m3(vhi.x+1,j,k) > 0) {
rho -= dhx*bX(i+1,j,k,n)*phi(i+1,j,k,n);
if (j == vlo.y && m1(i,vlo.y-1,k) > 0)
}
if (j == vlo.y && m1(i,vlo.y-1,k) > 0) {
rho -= dhy*bY(i,j ,k,n)*phi(i,j-1,k,n);
if (j == vhi.y && m4(i,vhi.y+1,k) > 0)
}
if (j == vhi.y && m4(i,vhi.y+1,k) > 0) {
rho -= dhy*bY(i,j+1,k,n)*phi(i,j+1,k,n);
}

a_ls(k-lo.z) = -dhz*bZ(i,j,k,n);
b_ls(k-lo.z) = g_m_d;
Expand All @@ -454,12 +458,12 @@ void abec_gsrb_with_line_solve (
if (k == lo.z)
{
a_ls(k-lo.z) = T(0.);
if (!(m2(i,j,vlo.z-1) > 0)) r_ls(k-lo.z) += dhz*bZ(i,j,k,n)*phi(i,j,k-1,n);
if (!(m2(i,j,vlo.z-1) > 0)) { r_ls(k-lo.z) += dhz*bZ(i,j,k,n)*phi(i,j,k-1,n); }
}
if (k == hi.z)
{
c_ls(k-lo.z) = T(0.);
if (!(m5(i,j,vhi.z+1) > 0)) r_ls(k-lo.z) += dhz*bZ(i,j,k+1,n)*phi(i,j,k+1,n);
if (!(m5(i,j,vhi.z+1) > 0)) { r_ls(k-lo.z) += dhz*bZ(i,j,k+1,n)*phi(i,j,k+1,n); }
}
}

Expand Down Expand Up @@ -511,14 +515,18 @@ void abec_gsrb_with_line_solve (
+ bZ(i,j,k+1,n)*phi(i,j,k+1,n) );

// We have already accounted for this external boundary in the coefficient of phi(i,j,k,n)
if (i == vlo.x && m0(vlo.x-1,j,k) > 0)
if (i == vlo.x && m0(vlo.x-1,j,k) > 0) {
rho -= dhx*bX(i ,j,k,n)*phi(i-1,j,k,n);
if (i == vhi.x && m3(vhi.x+1,j,k) > 0)
}
if (i == vhi.x && m3(vhi.x+1,j,k) > 0) {
rho -= dhx*bX(i+1,j,k,n)*phi(i+1,j,k,n);
if (k == vlo.z && m2(i,j,vlo.z-1) > 0)
}
if (k == vlo.z && m2(i,j,vlo.z-1) > 0) {
rho -= dhz*bZ(i,j ,k,n)*phi(i,j,k-1,n);
if (k == vhi.z && m5(i,j,vhi.z+1) > 0)
}
if (k == vhi.z && m5(i,j,vhi.z+1) > 0) {
rho -= dhz*bZ(i,j,k+1,n)*phi(i,j,k+1,n);
}

a_ls(j-lo.y) = -dhy*bY(i,j,k,n);
b_ls(j-lo.y) = g_m_d;
Expand All @@ -529,12 +537,12 @@ void abec_gsrb_with_line_solve (
if (j == lo.y)
{
a_ls(j-lo.y) = T(0.);
if (!(m1(i,vlo.y-1,k) > 0)) r_ls(j-lo.y) += dhy*bY(i,j,k,n)*phi(i,j-1,k,n);
if (!(m1(i,vlo.y-1,k) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j,k,n)*phi(i,j-1,k,n); }
}
if (j == hi.y)
{
c_ls(j-lo.y) = T(0.);
if (!(m4(i,vhi.y+1,k) > 0)) r_ls(j-lo.y) += dhy*bY(i,j+1,k,n)*phi(i,j+1,k,n);
if (!(m4(i,vhi.y+1,k) > 0)) { r_ls(j-lo.y) += dhy*bY(i,j+1,k,n)*phi(i,j+1,k,n); }
}
}

Expand Down Expand Up @@ -586,14 +594,18 @@ void abec_gsrb_with_line_solve (
+ bZ(i,j,k+1,n)*phi(i,j,k+1,n) );

// We have already accounted for this external boundary in the coefficient of phi(i,j,k,n)
if (j == vlo.y && m1(i,vlo.y-1,k) > 0)
if (j == vlo.y && m1(i,vlo.y-1,k) > 0) {
rho -= dhy*bY(i,j ,k,n)*phi(i,j-1,k,n);
if (j == vhi.y && m4(i,vhi.y+1,k) > 0)
}
if (j == vhi.y && m4(i,vhi.y+1,k) > 0) {
rho -= dhy*bY(i,j+1,k,n)*phi(i,j+1,k,n);
if (k == vlo.z && m2(i,j,vlo.z-1) > 0)
}
if (k == vlo.z && m2(i,j,vlo.z-1) > 0) {
rho -= dhz*bZ(i,j ,k,n)*phi(i,j,k-1,n);
if (k == vhi.z && m5(i,j,vhi.z+1) > 0)
}
if (k == vhi.z && m5(i,j,vhi.z+1) > 0) {
rho -= dhz*bZ(i,j,k+1,n)*phi(i,j,k+1,n);
}

a_ls(i-lo.x) = -dhx*bX(i,j,k,n);
b_ls(i-lo.x) = g_m_d;
Expand All @@ -604,12 +616,12 @@ void abec_gsrb_with_line_solve (
if (i == lo.x)
{
a_ls(i-lo.x) = T(0.);
if (!(m0(vlo.x-1,j,k) > 0)) r_ls(i-lo.x) += dhx*bX(i,j,k,n)*phi(i-1,j,k,n);
if (!(m0(vlo.x-1,j,k) > 0)) { r_ls(i-lo.x) += dhx*bX(i,j,k,n)*phi(i-1,j,k,n); }
}
if (i == hi.x)
{
c_ls(i-lo.x) = T(0.);
if (!(m3(vhi.x+1,j,k) > 0)) r_ls(i-lo.x) += dhx*bX(i+1,j,k,n)*phi(i+1,j,k,n);
if (!(m3(vhi.x+1,j,k) > 0)) { r_ls(i-lo.x) += dhx*bX(i+1,j,k,n)*phi(i+1,j,k,n); }
}
}

Expand Down
12 changes: 6 additions & 6 deletions Src/LinearSolvers/MLMG/AMReX_MLABecLaplacian.H
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ template <typename MF>
void
MLABecLaplacianT<MF>::applyRobinBCTermsCoeffs ()
{
if (!(this->hasRobinBC())) return;
if (!(this->hasRobinBC())) { return; }

const int ncomp = this->getNComp();
bool reset_alpha = false;
Expand All @@ -500,7 +500,7 @@ MLABecLaplacianT<MF>::applyRobinBCTermsCoeffs ()
}

MFItInfo mfi_info;
if (Gpu::notInLaunchRegion()) mfi_info.SetDynamic(true);
if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
Expand All @@ -515,7 +515,7 @@ MLABecLaplacianT<MF>::applyRobinBCTermsCoeffs ()
const Box& bhi = amrex::adjCellHi(vbx,idim);
bool outside_domain_lo = !(domain.contains(blo));
bool outside_domain_hi = !(domain.contains(bhi));
if ((!outside_domain_lo) && (!outside_domain_hi)) continue;
if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
for (int icomp = 0; icomp < ncomp; ++icomp) {
auto const& rbc = (*(this->m_robin_bcval[amrlev]))[mfi].const_array(icomp*3);
if (this->m_lobc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_lo)
Expand Down Expand Up @@ -914,7 +914,7 @@ MLABecLaplacianT<MF>::Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, in
#endif
{
MFItInfo mfi_info;
if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true);
if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
Expand Down Expand Up @@ -1166,7 +1166,7 @@ template <typename MF>
std::unique_ptr<MLLinOpT<MF>>
MLABecLaplacianT<MF>::makeNLinOp (int /*grid_size*/) const
{
if (this->m_overset_mask[0][0] == nullptr) return nullptr;
if (this->m_overset_mask[0][0] == nullptr) { return nullptr; }

const Geometry& geom = this->m_geom[0].back();
const BoxArray& ba = this->m_grids[0].back();
Expand Down Expand Up @@ -1265,7 +1265,7 @@ template <typename MF>
void
MLABecLaplacianT<MF>::copyNSolveSolution (MF& dst, MF const& src) const
{
if (this->m_overset_mask[0].back() == nullptr) return;
if (this->m_overset_mask[0].back() == nullptr) { return; }

const int ncomp = dst.nComp();

Expand Down
4 changes: 2 additions & 2 deletions Src/LinearSolvers/MLMG/AMReX_MLALaplacian.H
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ template <typename MF>
void
MLALaplacianT<MF>::update ()
{
if (MLCellABecLapT<MF>::needsUpdate()) MLCellABecLapT<MF>::update();
if (MLCellABecLapT<MF>::needsUpdate()) { MLCellABecLapT<MF>::update(); }
averageDownCoeffs();
updateSingularFlag();
m_needs_update = false;
Expand Down Expand Up @@ -453,7 +453,7 @@ MLALaplacianT<MF>::Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int r
const RT alpha = m_a_scalar;

MFItInfo mfi_info;
if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true);
if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
Expand Down
12 changes: 7 additions & 5 deletions Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
<< rnorm/(rnorm0) << '\n';
}

if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) break;
if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) { break; }

sh.LocalCopy(s,0,0,ncomp,nghost);
Lp.apply(amrlev, mglev, t, sh, MLLinOpT<MF>::BCMode::Homogeneous, MLLinOpT<MF>::StateMode::Correction);
Expand Down Expand Up @@ -219,7 +219,7 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
<< rnorm/(rnorm0) << '\n';
}

if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) break;
if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) { break; }

if ( omega == 0 )
{
Expand All @@ -238,8 +238,9 @@ MLCGSolverT<MF>::solve_bicgstab (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

if ( ret == 0 && rnorm > eps_rel*rnorm0 && rnorm > eps_abs)
{
if ( verbose > 0 && ParallelDescriptor::IOProcessor() )
if ( verbose > 0 && ParallelDescriptor::IOProcessor() ) {
amrex::Warning("MLCGSolver_BiCGStab:: failed to converge!");
}
ret = 8;
}

Expand Down Expand Up @@ -355,7 +356,7 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
<< rnorm/(rnorm0) << '\n';
}

if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) break;
if ( rnorm < eps_rel*rnorm0 || rnorm < eps_abs ) { break; }

rho_1 = rho;
}
Expand All @@ -370,8 +371,9 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

if ( ret == 0 && rnorm > eps_rel*rnorm0 && rnorm > eps_abs )
{
if ( verbose > 0 && ParallelDescriptor::IOProcessor() )
if ( verbose > 0 && ParallelDescriptor::IOProcessor() ) {
amrex::Warning("MLCGSolver_cg: failed to converge!");
}
ret = 8;
}

Expand Down
14 changes: 7 additions & 7 deletions Src/LinearSolvers/MLMG/AMReX_MLCellABecLap.H
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ template <typename MF>
void
MLCellABecLapT<MF>::update ()
{
if (MLCellLinOpT<MF>::needsUpdate()) MLCellLinOpT<MF>::update();
if (MLCellLinOpT<MF>::needsUpdate()) { MLCellLinOpT<MF>::update(); }
}

template <typename MF>
Expand Down Expand Up @@ -277,7 +277,7 @@ MLCellABecLapT<MF>::applyInhomogNeumannTerm (int amrlev, MF& rhs) const
bool has_inhomog_neumann = this->hasInhomogNeumannBC();
bool has_robin = this->hasRobinBC();

if (!has_inhomog_neumann && !has_robin) return;
if (!has_inhomog_neumann && !has_robin) { return; }

int ncomp = this->getNComp();
const int mglev = 0;
Expand All @@ -302,7 +302,7 @@ MLCellABecLapT<MF>::applyInhomogNeumannTerm (int amrlev, MF& rhs) const
const auto& bndry = *(this->m_bndry_sol[amrlev]);

MFItInfo mfi_info;
if (Gpu::notInLaunchRegion()) mfi_info.SetDynamic(true);
if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
Expand All @@ -329,7 +329,7 @@ MLCellABecLapT<MF>::applyInhomogNeumannTerm (int amrlev, MF& rhs) const
const auto& bvhi = bndry.bndryValues(ohi).array(mfi);
bool outside_domain_lo = !(domain.contains(blo));
bool outside_domain_hi = !(domain.contains(bhi));
if ((!outside_domain_lo) && (!outside_domain_hi)) continue;
if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
for (int icomp = 0; icomp < ncomp; ++icomp) {
const BoundCond bctlo = bdcv[icomp][olo];
const BoundCond bcthi = bdcv[icomp][ohi];
Expand Down Expand Up @@ -509,7 +509,7 @@ MLCellABecLapT<MF>::addInhomogNeumannFlux (
bool has_inhomog_neumann = this->hasInhomogNeumannBC();
bool has_robin = this->hasRobinBC();

if (!has_inhomog_neumann && !has_robin) return;
if (!has_inhomog_neumann && !has_robin) { return; }

int ncomp = this->getNComp();
const int mglev = 0;
Expand All @@ -525,7 +525,7 @@ MLCellABecLapT<MF>::addInhomogNeumannFlux (
const auto& bndry = *this->m_bndry_sol[amrlev];

MFItInfo mfi_info;
if (Gpu::notInLaunchRegion()) mfi_info.SetDynamic(true);
if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }

#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
Expand Down Expand Up @@ -633,7 +633,7 @@ MLCellABecLapT<MF>::applyOverset (int amrlev, MF& rhs) const
auto const& osm = m_overset_mask[amrlev][0]->const_array(mfi);
AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
{
if (osm(i,j,k) == 0) rfab(i,j,k,n) = RT(0.0);
if (osm(i,j,k) == 0) { rfab(i,j,k,n) = RT(0.0); }
});
}
}
Expand Down
Loading

0 comments on commit 7ec2e0b

Please sign in to comment.