Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another way to fix the UDF MAC fills #1092

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions amr-wind/core/FieldBCOps.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

namespace amr_wind {

namespace {
template <int face_dir>
struct FaceOp
{
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int operator()(const int idir)
{
return (idir == face_dir) ? 1 : 0;
}
};

} // namespace

class Field;

/** Interface to setup up boundary conditions on a field
Expand Down Expand Up @@ -42,6 +54,8 @@ public:
struct FieldBCNoOp
{
using FunctorType = FieldBCNoOp;
template <int /* Index */>
using FunctorFType = FieldBCNoOp;

AMREX_GPU_HOST
constexpr FieldBCNoOp() = default;
Expand All @@ -50,6 +64,11 @@ struct FieldBCNoOp
constexpr explicit FieldBCNoOp(const Field& /*unused*/) {}

FunctorType operator()() const { return *this; }
template <typename T>
T opf() const
{
return *this;
}

AMREX_GPU_DEVICE
void operator()(
Expand Down Expand Up @@ -110,7 +129,7 @@ struct ConstDirichlet
/** Sets constant values on specified boundaries
* \ingroup field_fillpatch
*/
template <typename InflowOp, typename WallOp>
template <typename InflowOp, typename WallOp, int face_dir = -1>
struct DirichletOp
{
using InflowOpType = InflowOp;
Expand Down Expand Up @@ -168,10 +187,13 @@ struct DirichletOp
continue;
}

// Check if the point in question is on the boundary
// Check if the point in question is on the boundary, which
// depends on the location of the field variable
const int bigEnd_for_floc =
domain_box.bigEnd(idir) + FaceOp<face_dir>()(idir);
const bool is_bndry =
(ori.isLow() ? (iv[idir] < domain_box.smallEnd(idir))
: (iv[idir] > domain_box.bigEnd(idir)));
: (iv[idir] > bigEnd_for_floc));
if (!is_bndry) {
continue;
}
Expand Down Expand Up @@ -204,10 +226,17 @@ struct DirichletOp
struct FieldBCDirichlet
{
using FunctorType = DirichletOp<ConstDirichlet, ConstDirichlet>;
template <int Index>
using FunctorFType = DirichletOp<ConstDirichlet, ConstDirichlet, Index>;

explicit FieldBCDirichlet(const Field& fld) : m_field(fld) {}

inline FunctorType operator()() const { return FunctorType(m_field); }
template <typename T>
inline T opf() const
{
return T(m_field);
}

const Field& m_field;
};
Expand All @@ -218,6 +247,8 @@ struct BCOpCreator
using InflowOpType = typename InflowOp::DeviceType;
using WallOpType = typename WallOp::DeviceType;
using FunctorType = DirichletOp<InflowOpType, WallOpType>;
template <int Index>
using FunctorFType = DirichletOp<InflowOpType, WallOpType, Index>;

explicit BCOpCreator(const Field& fld)
: m_field(fld), m_inflow_op(fld), m_wall_op(fld)
Expand All @@ -235,6 +266,14 @@ struct BCOpCreator
m_wall_op.device_instance()};
}

template <typename T>
inline T opf() const
{
return T{
m_field, m_inflow_op.device_instance(),
m_wall_op.device_instance()};
}

const Field& m_field;
InflowOp m_inflow_op;
WallOp m_wall_op;
Expand Down
32 changes: 30 additions & 2 deletions amr-wind/core/FieldFillPatchOps.H
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
{
public:
using Functor = typename BCOpCreator::FunctorType;
template <int Index>
using FunctorF = typename BCOpCreator::template FunctorFType<Index>;
/**
* @param field Field whose patches are filled by this instance
* @param mesh The mesh instance to determine amrex::Geometry at a level
Expand Down Expand Up @@ -270,13 +272,34 @@
{

if (lev == 0) {
amrex::PhysBCFunct<amrex::GpuBndryFuncFab<Functor>> physbc(
m_mesh.Geom(lev), bcrec, bc_functor());
amrex::PhysBCFunct<amrex::GpuBndryFuncFab<FunctorF<0>>> physbcx(
m_mesh.Geom(lev), bcrec, bc_functor_f<FunctorF<0>>());
amrex::PhysBCFunct<amrex::GpuBndryFuncFab<FunctorF<1>>> physbcy(
m_mesh.Geom(lev), bcrec, bc_functor_f<FunctorF<1>>());
amrex::PhysBCFunct<amrex::GpuBndryFuncFab<FunctorF<2>>> physbcz(
m_mesh.Geom(lev), bcrec, bc_functor_f<FunctorF<2>>());
int i = 0;
std::cout << "sibling fields FPSL dir i = 0 (umac)\n";
amrex::FillPatchSingleLevel(
*mfabs[i], nghost, time, {ffabs[i]}, {time}, 0, 0, 1,
m_mesh.Geom(lev), physbcx, i);
i = 1;
std::cout << "sibling fields FPSL dir i = 1 (vmac)\n";
amrex::FillPatchSingleLevel(
*mfabs[i], nghost, time, {ffabs[i]}, {time}, 0, 0, 1,
m_mesh.Geom(lev), physbcy, i);
i = 2;
std::cout << "sibling fields FPSL dir i = 2 (wmac)\n";
amrex::FillPatchSingleLevel(
*mfabs[i], nghost, time, {ffabs[i]}, {time}, 0, 0, 1,
m_mesh.Geom(lev), physbcz, i);
/*
for (int i = 0; i < static_cast<int>(mfabs.size()); i++) {
amrex::FillPatchSingleLevel(
*mfabs[i], nghost, time, {ffabs[i]}, {time}, 0, 0, 1,
m_mesh.Geom(lev), physbc, i);
}
*/
Fixed Show fixed Hide fixed
} else {
amrex::PhysBCFunct<amrex::GpuBndryFuncFab<Functor>> cphysbc(
m_mesh.Geom(lev - 1), bcrec, bc_functor());
Expand Down Expand Up @@ -386,6 +409,11 @@

protected:
Functor bc_functor() { return m_op(); }
template <typename T>
T bc_functor_f()
{
return m_op.template opf<T>();
}

void check_face_mapper()
{
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/equation_systems/icns/icns_advection.H
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ struct AdvectionOp<ICNS, fvm::Godunov>
// MAC projection
m_macproj_op(fstate, dt);

// Fill mac velocities using velocity BCs
std::cout << "// Fill mac velocities using velocity BCs\n";
if (fvm::Godunov::nghost_state > 0) {
amrex::Array<Field*, AMREX_SPACEDIM> mac_vel = {
AMREX_D_DECL(&u_mac, &v_mac, &w_mac)};
Expand Down
21 changes: 21 additions & 0 deletions amr-wind/physics/udfs/Rankine.H
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@
vel_ref[2] + 0.0)};

field(iv[0], iv[1], iv[2], dcomp + comp) = vel[orig_comp + comp];

amrex::IntVect ivhh(AMREX_D_DECL(41, 12, 1));
amrex::IntVect ivhi(AMREX_D_DECL(40, 12, 1));
amrex::IntVect ivlo(AMREX_D_DECL(0, 12, 1));
amrex::IntVect ivlm(AMREX_D_DECL(-1, 12, 1));
if (iv == ivlo)

Check warning on line 53 in amr-wind/physics/udfs/Rankine.H

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

statement should be inside braces [readability-braces-around-statements]
amrex::Print()
<< "Rankine.H op: filling " << vel[orig_comp + comp]
<< " at i=0" << std::endl;
if (iv == ivlm)

Check warning on line 57 in amr-wind/physics/udfs/Rankine.H

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

statement should be inside braces [readability-braces-around-statements]
amrex::Print()
<< "Rankine.H op: filling " << vel[orig_comp + comp]
<< " at i=-1" << std::endl;
if (iv == ivhi)

Check warning on line 61 in amr-wind/physics/udfs/Rankine.H

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

statement should be inside braces [readability-braces-around-statements]
amrex::Print()
<< "Rankine.H op: filling " << vel[orig_comp + comp]
<< " at i=40" << std::endl;
if (iv == ivhh)

Check warning on line 65 in amr-wind/physics/udfs/Rankine.H

View workflow job for this annotation

GitHub Actions / Lint-clang-tidy

statement should be inside braces [readability-braces-around-statements]
amrex::Print()
<< "Rankine.H op: filling " << vel[orig_comp + comp]
<< " at i=41" << std::endl;
}
};
using DeviceType = DeviceOp;
Expand Down
6 changes: 5 additions & 1 deletion test/test_files/rankine/rankine.inp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ xlo.type = "mass_inflow"
xlo.density = 1.0
xlo.velocity.inflow_type = Rankine
xlo.temperature = 300.0
xhi.type = "pressure_outflow"
xhi.type = "mass_inflow"
xhi.density = 1.0
xhi.velocity.inflow_type = Rankine
xhi.temperature = 300.0
#xhi.type = "pressure_outflow"
ylo.type = "slip_wall"
yhi.type = "slip_wall"
zlo.type = "slip_wall"
Expand Down
Loading