Skip to content

Commit

Permalink
Fix and suppress some warnings (Exawind#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrood-nrel authored Jun 2, 2022
1 parent 4974519 commit da8509f
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
- name: Clone
uses: actions/checkout@v3
- name: Check formatting
uses: DoozyX/clang-format-lint-action@v0.11
uses: DoozyX/clang-format-lint-action@v0.13
with:
source: './amr-wind ./unit_tests ./tools/utilities'
exclude: '.'
extensions: 'H,h,cpp'
clangFormatVersion: 11
clangFormatVersion: 13
CPU:
needs: Formatting
runs-on: ${{matrix.os}}
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/core/SimTime.H
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public:

private:
//! Timestep sizes
amrex::Real m_dt[max_time_states];
amrex::Real m_dt[max_time_states]{0.0};

//! Current simulation time
amrex::Real m_cur_time{0.0};
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/AdvOp_Godunov.H
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct AdvectionOp<
const auto& src_term = fields.src_term;
// cppcheck-suppress constVariable
auto& conv_term = fields.conv_term;
auto& dof_field = fields.field.state(fstate);
const auto& dof_field = fields.field.state(fstate);

auto flux_x =
repo.create_scratch_field(PDE::ndim, 0, amr_wind::FieldLoc::XFACE);
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/AdvOp_MOL.H
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct AdvectionOp<
static_assert(
PDE::ndim == 1, "Invalid number of components for scalar");

auto& repo = fields.repo;
const auto& repo = fields.repo;
const auto& geom = repo.mesh().Geom();

// cppcheck-suppress constVariable
Expand Down
7 changes: 4 additions & 3 deletions amr-wind/equation_systems/icns/icns_advection.H
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct AdvectionOp<ICNS, fvm::Godunov>
void preadvect(const FieldState fstate, const amrex::Real dt)
{

auto& repo = fields.repo;
const auto& repo = fields.repo;
const auto& geom = repo.mesh().Geom();

const auto& src_term = fields.src_term;
Expand Down Expand Up @@ -262,7 +262,7 @@ struct AdvectionOp<ICNS, fvm::Godunov>
const auto& src_term = fields.src_term;
// cppcheck-suppress constVariable
auto& conv_term = fields.conv_term;
auto& dof_field = fields.field.state(fstate);
const auto& dof_field = fields.field.state(fstate);

auto flux_x =
repo.create_scratch_field(ICNS::ndim, 0, amr_wind::FieldLoc::XFACE);
Expand Down Expand Up @@ -375,6 +375,7 @@ struct AdvectionOp<ICNS, fvm::MOL>
void preadvect(const FieldState fstate, const amrex::Real dt)
{

// cppcheck-suppress constVariable
auto& repo = fields.repo;
auto& dof_field = fields.field.state(fstate);

Expand Down Expand Up @@ -406,7 +407,7 @@ struct AdvectionOp<ICNS, fvm::MOL>
void operator()(const FieldState fstate, const amrex::Real /*unused*/)
{

auto& repo = fields.repo;
const auto& repo = fields.repo;
const auto& geom = repo.mesh().Geom();
// cppcheck-suppress constVariable
auto& conv_term = fields.conv_term.state(fstate);
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/icns/icns_diffusion.H
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public:
const FieldState fstate = FieldState::New;
auto& repo = m_pdefields.repo;
const auto& geom = repo.mesh().Geom();
auto& field = m_pdefields.field;
const auto& field = m_pdefields.field;
const auto& density = m_density.state(fstate);
const int nlevels = repo.num_active_levels();
const int ndim = field.num_comp();
Expand Down
1 change: 1 addition & 0 deletions amr-wind/equation_systems/vof/vof_advection.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct AdvectionOp<VOF, fvm::Godunov>
auto& repo = fields.repo;
const auto& geom = repo.mesh().Geom();

// cppcheck-suppress constVariable
auto& dof_field = fields.field;
//
// Advect volume using either the Explicit Lagrangian onto-cell or
Expand Down
2 changes: 2 additions & 0 deletions amr-wind/immersed_boundary/bluff_body/bluff_body_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void apply_mms_vel(CFDSim& sim)
const int nlevels = sim.repo().num_active_levels();

const auto& levelset = sim.repo().get_field("ib_levelset");
// cppcheck-suppress constVariable
auto& velocity = sim.repo().get_field("velocity");
auto& m_conv_taylor_green =
sim.physics_manager().get<ctv::ConvectingTaylorVortex>();
Expand Down Expand Up @@ -78,6 +79,7 @@ void apply_dirichlet_vel(CFDSim& sim, const amrex::Vector<amrex::Real>& vel_bc)
{
const int nlevels = sim.repo().num_active_levels();
auto& geom = sim.mesh().Geom();
// cppcheck-suppress constVariable
auto& velocity = sim.repo().get_field("velocity");
auto& levelset = sim.repo().get_field("ib_levelset");
levelset.fillpatch(sim.time().current_time());
Expand Down
1 change: 1 addition & 0 deletions amr-wind/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ int main(int argc, char* argv[])
return 1;
}

// cppcheck-suppress knownConditionTrueFalse
if (argc >= 2) {
// Look for "-h" or "--help" flag and print usage
for (auto i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/physics/SyntheticTurbulence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void SyntheticTurbulence::update_impl(
const InterpWeights& weights,
const T& velfunc)
{
auto& repo = m_turb_force.repo();
const auto& repo = m_turb_force.repo();
const auto& geom_vec = repo.mesh().Geom();

const int sdir = (*m_wind_profile).shear_dir();
Expand Down
5 changes: 4 additions & 1 deletion amr-wind/physics/multiphase/MultiPhase.H
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ private:
// sum of volume fractions (for vof only)
amrex::Real m_total_volfrac{0.0};

amrex::Real q0, q1, q2, sumvof0;
amrex::Real q0{0.0};
amrex::Real q1{0.0};
amrex::Real q2{0.0};
amrex::Real sumvof0{0.0};
};

} // namespace amr_wind
Expand Down
16 changes: 8 additions & 8 deletions amr-wind/physics/multiphase/MultiPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ void MultiPhase::set_density_via_levelset()
const amrex::Array4<amrex::Real>& phi = levelset.array(mfi);
const amrex::Array4<amrex::Real>& rho = density.array(mfi);
const amrex::Real eps = std::cbrt(2. * dx[0] * dx[1] * dx[2]);
const amrex::Real rho1 = m_rho1;
const amrex::Real rho2 = m_rho2;
const amrex::Real captured_rho1 = m_rho1;
const amrex::Real captured_rho2 = m_rho2;
amrex::ParallelFor(
vbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
amrex::Real smooth_heaviside;
Expand All @@ -255,8 +255,8 @@ void MultiPhase::set_density_via_levelset()
(1.0 + phi(i, j, k) / eps +
1.0 / M_PI * std::sin(phi(i, j, k) * M_PI / eps));
}
rho(i, j, k) = rho1 * smooth_heaviside +
rho2 * (1.0 - smooth_heaviside);
rho(i, j, k) = captured_rho1 * smooth_heaviside +
captured_rho2 * (1.0 - smooth_heaviside);
});
}
}
Expand All @@ -275,12 +275,12 @@ void MultiPhase::set_density_via_vof()
const auto& vbx = mfi.validbox();
const amrex::Array4<amrex::Real>& F = vof.array(mfi);
const amrex::Array4<amrex::Real>& rho = density.array(mfi);
const amrex::Real rho1 = m_rho1;
const amrex::Real rho2 = m_rho2;
const amrex::Real captured_rho1 = m_rho1;
const amrex::Real captured_rho2 = m_rho2;
amrex::ParallelFor(
vbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
rho(i, j, k) =
rho1 * F(i, j, k) + rho2 * (1.0 - F(i, j, k));
rho(i, j, k) = captured_rho1 * F(i, j, k) +
captured_rho2 * (1.0 - F(i, j, k));
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/projection/incflo_apply_nodal_projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ using namespace amrex;
void incflo::set_inflow_velocity(
int lev, amrex::Real time, MultiFab& vel, int nghost)
{
auto& velocity = icns().fields().field;
velocity.set_inflow(lev, time, vel, nghost);
auto& lvelocity = icns().fields().field;
lvelocity.set_inflow(lev, time, vel, nghost);

// TODO fix hack for ABL
auto& phy_mgr = m_sim.physics_manager();
if (phy_mgr.contains("ABL")) {
auto& abl = phy_mgr.get<amr_wind::ABL>();
const auto& bndry_plane = abl.bndry_plane();
bndry_plane.populate_data(lev, time, velocity, vel);
bndry_plane.populate_data(lev, time, lvelocity, vel);
}
}

Expand Down
3 changes: 2 additions & 1 deletion amr-wind/turbulence/LES/OneEqKsgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void OneEqKsgsM84<Transport>::update_turbulent_viscosity(
auto& mu_turb = this->mu_turb();
const amrex::Real Ce = this->m_Ce;
const auto& den = this->m_rho.state(fstate);
auto& repo = mu_turb.repo();
const auto& repo = mu_turb.repo();
const auto& geom_vec = repo.mesh().Geom();

const int nlevels = repo.num_active_levels();
Expand Down Expand Up @@ -231,6 +231,7 @@ void OneEqKsgsM84<Transport>::post_advance_work()
// Update sdr field based on sfs ke

auto& tke = *(this->m_tke);
// cppcheck-suppress constVariable
auto& sdr = *(this->m_sdr);
const amrex::Real Ce = this->m_Ce;

Expand Down
2 changes: 1 addition & 1 deletion amr-wind/turbulence/LES/Smagorinsky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void Smagorinsky<Transport>::update_turbulent_viscosity(const FieldState fstate)
"amr-wind::" + this->identifier() + "::update_turbulent_viscosity");

auto& mu_turb = this->mu_turb();
auto& repo = mu_turb.repo();
const auto& repo = mu_turb.repo();
const auto& vel = m_vel.state(fstate);
const auto& den = m_rho.state(fstate);
const auto& geom_vec = repo.mesh().Geom();
Expand Down
2 changes: 2 additions & 0 deletions amr-wind/turbulence/RANS/KOmegaSST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void KOmegaSST<Transport>::update_turbulent_viscosity(const FieldState fstate)
const auto& den = this->m_rho.state(fstate);
const auto& tke = (*this->m_tke).state(fstate);
const auto& sdr = (*this->m_sdr).state(fstate);
// cppcheck-suppress constVariable
auto& repo = mu_turb.repo();

const int nlevels = repo.num_active_levels();
Expand All @@ -80,6 +81,7 @@ void KOmegaSST<Transport>::update_turbulent_viscosity(const FieldState fstate)

auto& tke_lhs = (this->m_sim).repo().get_field("tke_lhs_src_term");
tke_lhs.setVal(0.0);
// cppcheck-suppress constVariable
auto& sdr_lhs = (this->m_sim).repo().get_field("sdr_lhs_src_term");

const amrex::Real deltaT = (this->m_sim).time().deltaT();
Expand Down
1 change: 1 addition & 0 deletions amr-wind/turbulence/RANS/KOmegaSSTIDDES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void KOmegaSSTIDDES<Transport>::update_turbulent_viscosity(
const auto& geom_vec = repo.mesh().Geom();
auto& tke_lhs = (this->m_sim).repo().get_field("tke_lhs_src_term");
tke_lhs.setVal(0.0);
// cppcheck-suppress constVariable
auto& sdr_lhs = (this->m_sim).repo().get_field("sdr_lhs_src_term");

auto gradK = (this->m_sim.repo()).create_scratch_field(3, 0);
Expand Down
8 changes: 4 additions & 4 deletions amr-wind/utilities/FieldPlaneAveraging.H
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public:
*/
amrex::Real line_derivative_of_average_cell(int ind, int comp) const;

void
output_line_average_ascii(std::string filename, int step, amrex::Real time);
void output_line_average_ascii(
const std::string& filename, int step, amrex::Real time);
void output_line_average_ascii(int step, amrex::Real time);

/** change precision of text file output */
Expand Down Expand Up @@ -179,8 +179,8 @@ public: // public for GPU
velocity magnitude */
amrex::Real line_hvelmag_derivative_of_average_cell(int ind) const;

void
output_line_average_ascii(std::string filename, int step, amrex::Real time);
void output_line_average_ascii(
const std::string& filename, int step, amrex::Real time);
void output_line_average_ascii(int step, amrex::Real time);
};

Expand Down
14 changes: 7 additions & 7 deletions amr-wind/utilities/FieldPlaneAveraging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ FPlaneAveraging<FType>::FPlaneAveraging(

template <typename FType>
void FPlaneAveraging<FType>::output_line_average_ascii(
std::string filename, int step, amrex::Real time)
const std::string& filename, int step, amrex::Real time)
{
BL_PROFILE("amr-wind::FPlaneAveraging::output_line_average_ascii");

Expand Down Expand Up @@ -97,7 +97,7 @@ template <typename FType>
void FPlaneAveraging<FType>::output_line_average_ascii(
int step, amrex::Real time)
{
std::string filename = "plane_average_" + m_field.name() + ".txt";
const std::string filename = "plane_average_" + m_field.name() + ".txt";
output_line_average_ascii(filename, step, time);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ void FPlaneAveraging<FType>::compute_averages(
m_line_average.data(), m_line_average.size());

amrex::Real* line_avg = lavg.data();
const int ncomp = m_ncomp;
const int captured_ncomp = m_ncomp;

#ifdef _OPENMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
Expand Down Expand Up @@ -296,9 +296,9 @@ void FPlaneAveraging<FType>::compute_averages(

const int ind = idxOp(i, j, k);

for (int n = 0; n < ncomp; ++n) {
for (int n = 0; n < captured_ncomp; ++n) {
amrex::Gpu::deviceReduceSum(
&line_avg[ncomp * ind + n],
&line_avg[captured_ncomp * ind + n],
fab_arr(i, j, k, n) * denom, handler);
}
}
Expand Down Expand Up @@ -491,7 +491,7 @@ amrex::Real VelPlaneAveraging::line_hvelmag_average_cell(int ind) const
}

void VelPlaneAveraging::output_line_average_ascii(
std::string filename, int step, amrex::Real time)
const std::string& filename, int step, amrex::Real time)
{
BL_PROFILE("amr-wind::VelPlaneAveraging::output_line_average_ascii");

Expand Down Expand Up @@ -536,7 +536,7 @@ void VelPlaneAveraging::output_line_average_ascii(

void VelPlaneAveraging::output_line_average_ascii(int step, amrex::Real time)
{
std::string filename = "plane_average_" + m_field.name() + ".txt";
const std::string filename = "plane_average_" + m_field.name() + ".txt";
output_line_average_ascii(filename, step, time);
}

Expand Down
4 changes: 2 additions & 2 deletions amr-wind/utilities/SecondMomentAveraging.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public:
};
void line_moment(int comp, amrex::Vector<amrex::Real>& l_vec);

void
output_line_average_ascii(std::string filename, int step, amrex::Real time);
void output_line_average_ascii(
const std::string& filename, int step, amrex::Real time);
void output_line_average_ascii(int step, amrex::Real time);

/** change precision of text file output */
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/SecondMomentAveraging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace amr_wind {

void SecondMomentAveraging::output_line_average_ascii(
std::string filename, int step, amrex::Real time)
const std::string& filename, int step, amrex::Real time)
{
BL_PROFILE("amr-wind::SecondMomentAveraging::output_line_average_ascii");

Expand Down
4 changes: 2 additions & 2 deletions amr-wind/utilities/ThirdMomentAveraging.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public:
};
void line_moment(int comp, amrex::Vector<amrex::Real>& l_vec);

void
output_line_average_ascii(std::string filename, int step, amrex::Real time);
void output_line_average_ascii(
const std::string& filename, int step, amrex::Real time);
void output_line_average_ascii(int step, amrex::Real time);

/** change precision of text file output */
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/ThirdMomentAveraging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace amr_wind {

void ThirdMomentAveraging::output_line_average_ascii(
std::string filename, int step, amrex::Real time)
const std::string& filename, int step, amrex::Real time)
{
BL_PROFILE("amr-wind::ThirdMomentAveraging::output_line_average_ascii");

Expand Down
4 changes: 2 additions & 2 deletions amr-wind/utilities/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void incflo::ReadCheckpointFile()
amrex::Print() << "Restarting from checkpoint " << restart_file
<< std::endl;

Real prob_lo[AMREX_SPACEDIM];
Real prob_hi[AMREX_SPACEDIM];
Real prob_lo[AMREX_SPACEDIM] = {0.0};
Real prob_hi[AMREX_SPACEDIM] = {0.0};

/***************************************************************************
* Load header: set up problem domain (including BoxArray) *
Expand Down
4 changes: 2 additions & 2 deletions amr-wind/wind_energy/ABLBoundaryPlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ void InletData::interpolate(const amrex::Real time)
continue;
}

const int nlevels = m_data_n[ori]->size();
for (int lev = 0; lev < nlevels; ++lev) {
const int lnlevels = m_data_n[ori]->size();
for (int lev = 0; lev < lnlevels; ++lev) {

const auto& datn = (*m_data_n[ori])[lev];
const auto& datnp1 = (*m_data_np1[ori])[lev];
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/wind_energy/ABLWallFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void ABLVelWallFunc::wall_model(
BL_PROFILE("amr-wind::ABLVelWallFunc");

constexpr int idim = 2;
auto& repo = velocity.repo();
const auto& repo = velocity.repo();
const auto& density = repo.get_field("density", rho_state);
const auto& viscosity = repo.get_field("velocity_mueff");
const int nlevels = repo.num_active_levels();
Expand Down
Loading

0 comments on commit da8509f

Please sign in to comment.