From 4ac2513debaf587a9d4e96b197b71e64ef5834b0 Mon Sep 17 00:00:00 2001 From: "Marc T. Henry de Frahan" Date: Mon, 23 Dec 2024 10:34:15 -0700 Subject: [PATCH] Fix some codeql warnings (#1423) --- .../equation_systems/icns/icns_advection.cpp | 10 ++---- amr-wind/physics/VortexRing.cpp | 34 +++++++++--------- amr-wind/physics/udfs/CustomScalar.H | 34 +++++++++--------- amr-wind/physics/udfs/CustomScalar.cpp | 8 ++--- amr-wind/physics/udfs/CustomVelocity.H | 36 +++++++++---------- amr-wind/physics/udfs/CustomVelocity.cpp | 24 ++++++------- 6 files changed, 64 insertions(+), 82 deletions(-) diff --git a/amr-wind/equation_systems/icns/icns_advection.cpp b/amr-wind/equation_systems/icns/icns_advection.cpp index 47355a63d6..61dbe9ccff 100644 --- a/amr-wind/equation_systems/icns/icns_advection.cpp +++ b/amr-wind/equation_systems/icns/icns_advection.cpp @@ -26,15 +26,11 @@ amrex::Array get_projection_bc( r[dir] = amrex::LinOpBCType::Periodic; } else { auto bc = bctype[amrex::Orientation(dir, side)]; - switch (bc) { - case BC::pressure_outflow: { + if (bc == BC::pressure_outflow) { r[dir] = amrex::LinOpBCType::Dirichlet; - break; - } - default: + } else { r[dir] = amrex::LinOpBCType::Neumann; - break; - }; + } } } return r; diff --git a/amr-wind/physics/VortexRing.cpp b/amr-wind/physics/VortexRing.cpp index 7d682a69e8..cc19537895 100644 --- a/amr-wind/physics/VortexRing.cpp +++ b/amr-wind/physics/VortexRing.cpp @@ -203,26 +203,24 @@ void VortexRing::initialize_velocity(const VortexRingType& vorticity_theta) bclo[dir] = amrex::LinOpBCType::Periodic; bchi[dir] = amrex::LinOpBCType::Periodic; } else { - - switch (bctype[amrex::Orientation(dir, amrex::Orientation::low)]) { - case BC::pressure_outflow: { - bclo[dir] = amrex::LinOpBCType::Dirichlet; - break; + { + auto bc = + bctype[amrex::Orientation(dir, amrex::Orientation::low)]; + if (bc == BC::pressure_outflow) { + bclo[dir] = amrex::LinOpBCType::Dirichlet; + } else { + bclo[dir] = amrex::LinOpBCType::Neumann; + } } - default: - bclo[dir] = amrex::LinOpBCType::Neumann; - break; - }; - - switch (bctype[amrex::Orientation(dir, amrex::Orientation::high)]) { - case BC::pressure_outflow: { - bchi[dir] = amrex::LinOpBCType::Dirichlet; - break; + { + auto bc = + bctype[amrex::Orientation(dir, amrex::Orientation::high)]; + if (bc == BC::pressure_outflow) { + bchi[dir] = amrex::LinOpBCType::Dirichlet; + } else { + bchi[dir] = amrex::LinOpBCType::Neumann; + } } - default: - bchi[dir] = amrex::LinOpBCType::Neumann; - break; - }; } } diff --git a/amr-wind/physics/udfs/CustomScalar.H b/amr-wind/physics/udfs/CustomScalar.H index 737e0383ac..1836076102 100644 --- a/amr-wind/physics/udfs/CustomScalar.H +++ b/amr-wind/physics/udfs/CustomScalar.H @@ -14,34 +14,32 @@ struct CustomScalar { struct DeviceOp { - // clang-format off // Declare parameters here if needed. For example: - // amrex::Real foo{1.0}; - // clang-format on + amrex::Real foo{1.0}; AMREX_GPU_DEVICE inline void operator()( - const amrex::IntVect& /*iv*/, - amrex::Array4 const& /*field*/, - amrex::GeometryData const& /*geom*/, + const amrex::IntVect& iv, + amrex::Array4 const& field, + amrex::GeometryData const& geom, const amrex::Real /*time*/, amrex::Orientation /*ori*/, - const int /*comp*/, - const int /*dcomp*/, - const int /*orig_comp*/) const + const int comp, + const int dcomp, + const int orig_comp) const { // Compute quantities to set the field values. For example: - // clang-format off - // const auto* problo = geom.ProbLo(); - // const auto* dx = geom.CellSize(); - // const auto x = problo[0] + (iv[0] + 0.5) * dx[0]; - // const auto y = problo[1] + (iv[1] + 0.5) * dx[1]; - // const auto z = problo[2] + (iv[2] + 0.5) * dx[2]; - // const amrex::GpuArray vel = {1.0, 0.0, 0.0}; + const auto* problo = geom.ProbLo(); + const auto* dx = geom.CellSize(); + const auto x = problo[0] + (iv[0] + 0.5) * dx[0]; + const auto y = problo[1] + (iv[1] + 0.5) * dx[1]; + const auto z = problo[2] + (iv[2] + 0.5) * dx[2]; + const amrex::GpuArray vel = { + 1.0, 0.0, 0.0}; // Once the above is done, fill the field as: - // field(iv[0], iv[1], iv[2], dcomp + comp) = vel[orig_comp + comp]; - // clang-format on + field(iv[0], iv[1], iv[2], dcomp + comp) = vel[orig_comp + comp]; + amrex::ignore_unused(x, y, z); } }; using DeviceType = DeviceOp; diff --git a/amr-wind/physics/udfs/CustomScalar.cpp b/amr-wind/physics/udfs/CustomScalar.cpp index f192325776..1b5e8abd86 100644 --- a/amr-wind/physics/udfs/CustomScalar.cpp +++ b/amr-wind/physics/udfs/CustomScalar.cpp @@ -16,12 +16,8 @@ CustomScalar::CustomScalar(const Field& fld) // xlo.temperature.inflow_type = CustomScalar // CustomScalar.foo = 1.0 - // clang-format off - //{ - // amrex::ParmParse pp("CustomScalar"); - // pp.query("foo", m_op.foo); - //} - // clang-format on + amrex::ParmParse pp("CustomScalar"); + pp.query("foo", m_op.foo); const int ncomp = fld.num_comp(); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( (ncomp == 1), "CustomScalar requires field with 1 component"); diff --git a/amr-wind/physics/udfs/CustomVelocity.H b/amr-wind/physics/udfs/CustomVelocity.H index b1f7fe014f..4e7a135ba8 100644 --- a/amr-wind/physics/udfs/CustomVelocity.H +++ b/amr-wind/physics/udfs/CustomVelocity.H @@ -14,35 +14,33 @@ struct CustomVelocity { struct DeviceOp { - // clang-format off // Declare parameters here if needed. For example: - // amrex::Real foo{1.0}; - // amrex::GpuArray bar = {0.0}; - // clang-format on + amrex::Real foo{1.0}; + amrex::GpuArray bar = {0.0}; AMREX_GPU_DEVICE inline void operator()( - const amrex::IntVect& /*iv*/, - amrex::Array4 const& /*field*/, - amrex::GeometryData const& /*geom*/, + const amrex::IntVect& iv, + amrex::Array4 const& field, + amrex::GeometryData const& geom, const amrex::Real /*time*/, amrex::Orientation /*ori*/, - const int /*comp*/, - const int /*dcomp*/, - const int /*orig_comp*/) const + const int comp, + const int dcomp, + const int orig_comp) const { // Compute quantities to set the field values. For example: - // clang-format off - // const auto* problo = geom.ProbLo(); - // const auto* dx = geom.CellSize(); - // const auto x = problo[0] + (iv[0] + 0.5) * dx[0]; - // const auto y = problo[1] + (iv[1] + 0.5) * dx[1]; - // const auto z = problo[2] + (iv[2] + 0.5) * dx[2]; - // const amrex::GpuArray vel = {1.0, 0.0, 0.0}; + const auto* problo = geom.ProbLo(); + const auto* dx = geom.CellSize(); + const auto x = problo[0] + (iv[0] + 0.5) * dx[0]; + const auto y = problo[1] + (iv[1] + 0.5) * dx[1]; + const auto z = problo[2] + (iv[2] + 0.5) * dx[2]; + const amrex::GpuArray vel = { + 1.0, 0.0, 0.0}; // Once the above is done, fill the field as: - // field(iv[0], iv[1], iv[2], dcomp + comp) = vel[orig_comp + comp]; - // clang-format on + field(iv[0], iv[1], iv[2], dcomp + comp) = vel[orig_comp + comp]; + amrex::ignore_unused(x, y, z); } }; using DeviceType = DeviceOp; diff --git a/amr-wind/physics/udfs/CustomVelocity.cpp b/amr-wind/physics/udfs/CustomVelocity.cpp index 0aad96ba76..86d6598e76 100644 --- a/amr-wind/physics/udfs/CustomVelocity.cpp +++ b/amr-wind/physics/udfs/CustomVelocity.cpp @@ -8,7 +8,7 @@ namespace amr_wind::udf { -CustomVelocity::CustomVelocity(const Field& /*fld*/) +CustomVelocity::CustomVelocity(const Field& fld) { // This is a where the user can set some user defined variables // This capability can be activated with the following in the input file: @@ -16,19 +16,15 @@ CustomVelocity::CustomVelocity(const Field& /*fld*/) // xlo.velocity.inflow_type = CustomVelocity // CustomVelocity.foo = 1.0 - // clang-format off - //{ - // const int ncomp = fld.num_comp(); - // amrex::ParmParse pp("CustomVelocity"); - // pp.query("foo", m_op.foo); - // amrex::Vector vel(0.0, ncomp); - // pp.getarr("velocity", vel); - // AMREX_ALWAYS_ASSERT(vel.size() == ncomp); - // for (int i = 0; i < ncomp; ++i) { - // m_op.bar[i] = vel[i]; - // } - //} - // clang-format on + const int ncomp = fld.num_comp(); + amrex::ParmParse pp("CustomVelocity"); + pp.query("foo", m_op.foo); + amrex::Vector vel(0.0, ncomp); + pp.getarr("velocity", vel); + AMREX_ALWAYS_ASSERT(vel.size() == ncomp); + for (int i = 0; i < ncomp; ++i) { + m_op.bar[i] = vel[i]; + } amrex::Abort( "Please define the body of this function and the corresponding struct " "in the header file before using it. Then remove this message");