Skip to content

Commit

Permalink
Fix some codeql warnings (Exawind#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf authored Dec 23, 2024
1 parent ccd0850 commit 4ac2513
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 82 deletions.
10 changes: 3 additions & 7 deletions amr-wind/equation_systems/icns/icns_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ amrex::Array<amrex::LinOpBCType, AMREX_SPACEDIM> 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;
Expand Down
34 changes: 16 additions & 18 deletions amr-wind/physics/VortexRing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
}

Expand Down
34 changes: 16 additions & 18 deletions amr-wind/physics/udfs/CustomScalar.H
Original file line number Diff line number Diff line change
Expand Up @@ -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<amrex::Real> const& /*field*/,
amrex::GeometryData const& /*geom*/,
const amrex::IntVect& iv,
amrex::Array4<amrex::Real> 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<amrex::Real, AMREX_SPACEDIM> 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<amrex::Real, AMREX_SPACEDIM> 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;
Expand Down
8 changes: 2 additions & 6 deletions amr-wind/physics/udfs/CustomScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
36 changes: 17 additions & 19 deletions amr-wind/physics/udfs/CustomVelocity.H
Original file line number Diff line number Diff line change
Expand Up @@ -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<amrex::Real, AMREX_SPACEDIM> bar = {0.0};
// clang-format on
amrex::Real foo{1.0};
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> bar = {0.0};

AMREX_GPU_DEVICE
inline void operator()(
const amrex::IntVect& /*iv*/,
amrex::Array4<amrex::Real> const& /*field*/,
amrex::GeometryData const& /*geom*/,
const amrex::IntVect& iv,
amrex::Array4<amrex::Real> 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<amrex::Real, AMREX_SPACEDIM> 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<amrex::Real, AMREX_SPACEDIM> 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;
Expand Down
24 changes: 10 additions & 14 deletions amr-wind/physics/udfs/CustomVelocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@

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:
// xlo.type = "mass_inflow"
// 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<amrex::Real> 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<amrex::Real> 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");
Expand Down

0 comments on commit 4ac2513

Please sign in to comment.