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

Inflow-outflow boundary condition #1066

Merged
merged 84 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
d6027cf
Initial setup for the inflow-outflow BC that manages both kind of cel…
mukul1992 Feb 13, 2024
e9cd5a9
add comment for header ifdef
mukul1992 Feb 14, 2024
659ba97
set up advection and projection BCs
mukul1992 Feb 22, 2024
407a120
temporary fix to use an external hydro repo
mukul1992 Feb 29, 2024
e8cb980
initial changes to add the outflow correction
mukul1992 Feb 29, 2024
b549cb6
additional changes to enable mass in-out BC, along with udf capabilities
mukul1992 Mar 8, 2024
fc6f538
Mukul's test files for the in-out BC
mukul1992 Apr 4, 2024
757dd95
ignoring all plt and chk files
mukul1992 Apr 4, 2024
6d388b7
set up garbage values at outflow for testing
mukul1992 Apr 5, 2024
bd6c9fe
intermediate changes for custom fill at MIO boundaries
mukul1992 Apr 5, 2024
e8eae20
added options to toggle initial iterations for testing
mukul1992 Apr 8, 2024
ec5f4bb
rebasing upstream changes
mukul1992 Apr 9, 2024
71e095d
adding print statements for testing
mukul1992 Apr 13, 2024
07c4323
inplementing custom Neumann fill-patch correctly before the nodal pro…
mukul1992 Apr 15, 2024
f7602a5
intermediate changes in the BC routines for the in-out BC
mukul1992 Apr 19, 2024
c8b445e
debug build cmake config
mukul1992 Apr 20, 2024
1ca5a90
input file updates
mukul1992 Apr 20, 2024
da53980
playing around with if-else on zero velocity values at the bndry
mukul1992 Apr 20, 2024
99f4cf8
activating enforce solvability routine
mukul1992 Apr 20, 2024
3c88c9d
redefining ext_dir and foextrap conditions for the in-out BC
mukul1992 Apr 23, 2024
7b0d5d9
using physical custom velocity BCs instead of garbage
mukul1992 Apr 23, 2024
9e798e6
printing macvel and velocity plotfiles for debugging
mukul1992 May 2, 2024
6a21922
more print messages for debugging and changes in Godunov_trans_xbc an…
mukul1992 May 7, 2024
82ccb5b
enabling Dirichlet operations for the in-out BC
mukul1992 May 13, 2024
3f894d5
not doing the custom Neumann fills to corner cells
mukul1992 May 13, 2024
cd765bc
input fileupdates
mukul1992 May 13, 2024
6fedafa
adding back the Neumann fills for corner cells
mukul1992 May 15, 2024
cda21b3
clean up, adding/removing print statements
mukul1992 May 15, 2024
05a0207
clean up gitignore
mukul1992 May 17, 2024
f28f80f
define new UDF TwoLayer and restore CustomVelocity for PR
mukul1992 May 17, 2024
edfe4b7
clean up print messages etc for draft PR, and rebase
mukul1992 May 18, 2024
89c0add
printing information for debugging
mukul1992 May 23, 2024
8dfc642
perturbing initial condition for testing and debugging
mukul1992 May 23, 2024
124fc23
resolved corner cell issue by adding a periodic boundary fill before …
mukul1992 May 23, 2024
618ff2f
change std::array to amrex::Array
mukul1992 May 23, 2024
f9eb0b7
debugging for mac-velocity fill issue at i=0
mukul1992 May 24, 2024
e77f20e
replaced user_1 with new direction_dependent BCType in amrex
mukul1992 Jun 6, 2024
4c9aac4
commenting out debug statements for umac boundary fill checking
mukul1992 Jun 7, 2024
60bee5a
reactivating some plotfile printing for debugging/digging
mukul1992 Jun 13, 2024
074e71f
modified function calls to reflect name changes in hydro
mukul1992 Jun 23, 2024
3cda624
Added function to call the hydro routine for enforcing inflow-outflow…
mukul1992 Jun 23, 2024
01e1dc0
simpler one-way flow test
mukul1992 Jun 24, 2024
b0f9c18
accepting vector velocities for TwoLayer udf
mukul1992 Jun 26, 2024
b00b97d
add directional conditions in y and z-directions
mukul1992 Jun 27, 2024
d4ac92b
change input files to have flow along both x and y
mukul1992 Jun 29, 2024
6e66714
renamed input file to match with naming of other test files
mukul1992 Jul 8, 2024
6ff0782
simplify x-y planar flow cases for debugging
mukul1992 Jul 9, 2024
927cd94
printing time from UDF fordebugging
mukul1992 Jul 9, 2024
201d0a5
simplifying mass_inflow case for asymmetry test
mukul1992 Jul 9, 2024
d18f42e
increasing run time for the test to allow for convergence
mukul1992 Jul 13, 2024
a92c52f
input file update
mukul1992 Jul 30, 2024
5830c00
clean up, remove print statements meant for debugging
mukul1992 Jul 30, 2024
833928e
remove couple of remaining print statements
mukul1992 Jul 30, 2024
79e4669
change logic to use IntVect instead of booleans
mukul1992 Jul 31, 2024
4392755
attempting to add an internal flag indicating presence of inout bndry
mukul1992 Aug 1, 2024
b63e6d6
define internal inout bndry flag in Field class instead of BCIface
mukul1992 Aug 2, 2024
31e8f80
add print statements to debug MAC-fill
mukul1992 Aug 9, 2024
fb704db
add mass-inflow-outflow condition to routine that fills MAC vel valid…
mukul1992 Aug 12, 2024
d9dddd2
clean up and customize the TwoLayer UDF
mukul1992 Aug 12, 2024
ab20628
remove testing folder from index
mukul1992 Aug 12, 2024
2ae8fdb
add inout test to cmake test suite
mukul1992 Aug 12, 2024
7933313
undo change for external hydro which is probably unnecessary
mukul1992 Aug 12, 2024
07be53d
apply clang-format
mukul1992 Aug 12, 2024
3da31bb
more clang-format
mukul1992 Aug 14, 2024
d7ba5ab
removed files that are moved to hydro from the upstream repo
mukul1992 Aug 14, 2024
43c8298
minor clang-format
mukul1992 Aug 14, 2024
0fc4bdb
one more formatting change
mukul1992 Aug 14, 2024
b9c1a7d
pass by reference and make type conversions explicit
mukul1992 Aug 14, 2024
1b5a15f
format new change
mukul1992 Aug 14, 2024
fdc1eb6
use simpler path to use internal inout flag in advection
mukul1992 Aug 14, 2024
e587ab2
use hydro routines for edge BCs
mukul1992 Aug 14, 2024
4e0c6eb
use Dirichlet for in-out boundary diffusion
mukul1992 Aug 15, 2024
9644abc
do not enforce in-out solvability before nodal projection in initial …
mukul1992 Aug 15, 2024
33f3400
fix format issue
mukul1992 Aug 15, 2024
a0f0d18
change copy to const references to satisfy clang-tidy
mukul1992 Aug 19, 2024
0e7f21b
do not fill outflow velocities to MAC valid cells
mukul1992 Aug 19, 2024
b6075ca
correct sibling fill bug
mukul1992 Aug 20, 2024
04a9953
clang-format FieldFillPatchOps
mukul1992 Aug 20, 2024
1366af0
remove files from index
mukul1992 Aug 20, 2024
adc7022
Use Async Arena instead of Elixir
mukul1992 Aug 20, 2024
cf6ff03
add documentation about inout BC
mukul1992 Aug 21, 2024
d12f4e2
clang-format change
mukul1992 Aug 21, 2024
285db73
correct spelling and minor change in docs
mukul1992 Aug 21, 2024
1965601
Merge branch 'main' into inoutbc
asalmgren Aug 21, 2024
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
2 changes: 1 addition & 1 deletion amr-wind/boundary_conditions/BCInterface.H
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
virtual void operator()(const amrex::Real value = 0.0);

//! User-defined functions for Dirichlet-type boundaries
std::pair<const std::string, const std::string> get_dirichlet_udfs();
amrex::Array<const std::string, 3> get_dirichlet_udfs();

protected:
//! Setup AMReX mathematical BC types
Expand Down
57 changes: 53 additions & 4 deletions amr-wind/boundary_conditions/BCInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "amr-wind/boundary_conditions/BCInterface.H"
#include "amr-wind/core/FieldRepo.H"
#include "amr-wind/boundary_conditions/FixedGradientBC.H"
#include "amr-wind/boundary_conditions/MassInflowOutflowBC.H"
#include "AMReX_ParmParse.H"

namespace amr_wind {
Expand Down Expand Up @@ -64,6 +65,8 @@ void BCIface::read_bctype()
ibctype[ori] = BC::pressure_outflow;
} else if ((bcstr == "mass_inflow") || (bcstr == "mi")) {
ibctype[ori] = BC::mass_inflow;
} else if ((bcstr == "mass_inflow_outflow") || (bcstr == "mio")) {
ibctype[ori] = BC::mass_inflow_outflow;
} else if ((bcstr == "no_slip_wall") || (bcstr == "nsw")) {
ibctype[ori] = BC::no_slip_wall;
} else if ((bcstr == "slip_wall") || (bcstr == "sw")) {
Expand Down Expand Up @@ -100,18 +103,27 @@ void BCIface::set_bcfuncs()
if (bct == BC::fixed_gradient) {
m_field.register_custom_bc<FixedGradientBC>(ori);
}

if ((m_field.name() == "velocity") // only velocity for now
&& (bct == BC::mass_inflow_outflow)) {

m_field.register_custom_bc<MassInflowOutflowBC>(ori);
}
}
}

std::pair<const std::string, const std::string> BCIface::get_dirichlet_udfs()
amrex::Array<const std::string, 3> BCIface::get_dirichlet_udfs()
{
const auto& fname = m_field.name();
const auto& bctype = m_field.bc_type();
const std::string inflow_key = fname + ".inflow_type";
const std::string inflow_outflow_key = fname + ".inflow_outflow_type";
const std::string wall_key = fname + ".wall_type";
std::string inflow_udf{"ConstDirichlet"};
std::string inflow_outflow_udf{"ConstDirichlet"};
std::string wall_udf{"ConstDirichlet"};
bool has_inflow_udf = false;
bool has_inflow_outflow_udf = false;
bool has_wall_udf = false;

for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
Expand All @@ -135,6 +147,22 @@ std::pair<const std::string, const std::string> BCIface::get_dirichlet_udfs()
}
}

if (bct == BC::mass_inflow_outflow) {
if (pp.contains(inflow_outflow_key.c_str())) {
std::string val;
pp.get(inflow_outflow_key.c_str(), val);

if (has_inflow_outflow_udf && (inflow_outflow_udf != val)) {
amrex::Abort(
"BC: Inflow-outflow UDF must be same for all "
"inflow-outflow faces");
} else {
inflow_outflow_udf = val;
has_inflow_outflow_udf = true;
}
}
}

if (bct == BC::slip_wall) {
if (pp.contains(wall_key.c_str())) {
std::string val;
Expand All @@ -151,7 +179,7 @@ std::pair<const std::string, const std::string> BCIface::get_dirichlet_udfs()
}
}

return {inflow_udf, wall_udf};
return {inflow_udf, inflow_outflow_udf, wall_udf};
}

void BCVelocity::set_bcrec()
Expand Down Expand Up @@ -194,6 +222,15 @@ void BCVelocity::set_bcrec()
}
break;

case BC::mass_inflow_outflow:
m_field.set_inout_bndry();
if (side == amrex::Orientation::low) {
set_bcrec_lo(dir, amrex::BCType::direction_dependent);
} else {
set_bcrec_hi(dir, amrex::BCType::direction_dependent);
}
break;

case BC::slip_wall:
case BC::wall_model:
if (side == amrex::Orientation::low) {
Expand Down Expand Up @@ -287,6 +324,15 @@ void BCScalar::set_bcrec()
}
break;

case BC::mass_inflow_outflow:
m_field.set_inout_bndry();
if (side == amrex::Orientation::low) {
set_bcrec_lo(dir, amrex::BCType::direction_dependent);
} else {
set_bcrec_hi(dir, amrex::BCType::direction_dependent);
}
break;

case BC::slip_wall:
case BC::wall_model:
case BC::fixed_gradient:
Expand All @@ -310,15 +356,18 @@ void BCScalar::read_values()
auto& bcval = m_field.bc_values();
const int ndim = m_field.num_comp();
const auto udfs = get_dirichlet_udfs();
const auto const_dirichlet_inflow = udfs.first == "ConstDirichlet";
const auto const_dirichlet_inflow = udfs[0] == "ConstDirichlet";
const auto const_dirichlet_inflow_outflow = udfs[1] == "ConstDirichlet";

for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
auto ori = oit();
const auto& bcid = bcnames[ori];
const auto bct = bctype[ori];

amrex::ParmParse pp(bcid);
if ((bct == BC::mass_inflow) && (const_dirichlet_inflow)) {
if (((bct == BC::mass_inflow) && (const_dirichlet_inflow)) ||
((bct == BC::mass_inflow_outflow) &&
(const_dirichlet_inflow_outflow))) {
pp.getarr(fname.c_str(), bcval[ori], 0, ndim);
} else {
pp.queryarr(fname.c_str(), bcval[ori], 0, ndim);
Expand Down
1 change: 1 addition & 0 deletions amr-wind/boundary_conditions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target_sources(${amr_wind_lib_name}
BCInterface.cpp
FixedGradientBC.cpp
scalar_bcs.cpp
MassInflowOutflowBC.cpp
)

add_subdirectory(wall_models)
31 changes: 31 additions & 0 deletions amr-wind/boundary_conditions/MassInflowOutflowBC.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef MASSINFLOWOUTFLOWBC_H
#define MASSINFLOWOUTFLOWBC_H

#include "amr-wind/core/FieldBCOps.H"
#include "amr-wind/core/FieldRepo.H"

#include "AMReX_Orientation.H"

namespace amr_wind {

/** Custom Neumann fills for the inflow-outflow BC
* \ingroup field_bc
*
* Used to fill the outflow boundary cells for mass-inflow-outflow BC
*/
class MassInflowOutflowBC : public FieldBCIface
{
public:
MassInflowOutflowBC(Field& field, amrex::Orientation ori);

void operator()(Field& field, const FieldState /*rho_state*/) override;

private:
Field& m_field;

amrex::Orientation m_ori;
};

} // namespace amr_wind

#endif /* MASSINFLOWOUTFLOWBC_H */
75 changes: 75 additions & 0 deletions amr-wind/boundary_conditions/MassInflowOutflowBC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

#include "amr-wind/boundary_conditions/MassInflowOutflowBC.H"

namespace amr_wind {

MassInflowOutflowBC::MassInflowOutflowBC(Field& field, amrex::Orientation ori)
: m_field(field), m_ori(ori)
{}

void MassInflowOutflowBC::operator()(
Field& /*field*/, const FieldState /*rho_state*/)
{
const auto& repo = m_field.repo();
const auto& velocity = repo.get_field("velocity");
const int ncomp = m_field.num_comp();
const int idim = m_ori.coordDir();
const auto islow = m_ori.isLow();
const auto ishigh = m_ori.isHigh();
const int nlevels = m_field.repo().num_active_levels();
const amrex::IntVect iv_dir = {
static_cast<int>(idim == 0), static_cast<int>(idim == 1),
static_cast<int>(idim == 2)};

for (int lev = 0; lev < nlevels; ++lev) {
const auto& domain = repo.mesh().Geom(lev).Domain();

amrex::MFItInfo mfi_info{};
if (amrex::Gpu::notInLaunchRegion()) {
mfi_info.SetDynamic(true);
}
#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
for (amrex::MFIter mfi(m_field(lev), mfi_info); mfi.isValid(); ++mfi) {
auto bx = mfi.validbox();
bx.grow(
{static_cast<int>(idim != 0), static_cast<int>(idim != 1),
static_cast<int>(idim != 2)});
const auto& bc_a = m_field(lev).array(mfi);
const auto& vel = velocity(lev).array(mfi);

if (islow && (bx.smallEnd(idim) == domain.smallEnd(idim))) {
amrex::ParallelFor(
amrex::bdryLo(bx, idim),
[=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
const amrex::IntVect iv = {i, j, k};
const amrex::IntVect ivm = iv - iv_dir;
if (vel(ivm[0], ivm[1], ivm[2], idim) < 0) {
for (int n = 0; n < ncomp; n++) {
mukul1992 marked this conversation as resolved.
Show resolved Hide resolved
bc_a(ivm[0], ivm[1], ivm[2], n) =
bc_a(i, j, k, n);
}
}
});
}

if (ishigh && (bx.bigEnd(idim) == domain.bigEnd(idim))) {
amrex::ParallelFor(
amrex::bdryHi(bx, idim),
[=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
const amrex::IntVect iv = {i, j, k};
const amrex::IntVect ivm = iv - iv_dir;
if (vel(i, j, k, idim) > 0) {
for (int n = 0; n < ncomp; n++) {
bc_a(i, j, k, n) =
bc_a(ivm[0], ivm[1], ivm[2], n);
}
}
});
}
}
}
}

} // namespace amr_wind
2 changes: 1 addition & 1 deletion amr-wind/boundary_conditions/scalar_bcs.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void register_scalar_dirichlet(
Field& field,
const amrex::AmrCore& mesh,
const SimTime& time,
const std::pair<const std::string, const std::string>& udfs);
const amrex::Array<const std::string, 3>& udfs);

} // namespace amr_wind::scalar_bc

Expand Down
22 changes: 16 additions & 6 deletions amr-wind/boundary_conditions/scalar_bcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ void register_scalar_dirichlet(
Field& field,
const amrex::AmrCore& mesh,
const SimTime& time,
const std::pair<const std::string, const std::string>& udfs)
const amrex::Array<const std::string, 3>& udfs)
{
const std::string inflow_udf = udfs.first;
const std::string wall_udf = udfs.second;
const std::string& inflow_udf = udfs[0];
const std::string& inflow_outflow_udf = udfs[1];
const std::string& wall_udf = udfs[2];

if ((inflow_udf == "ConstDirichlet") && (wall_udf == "ConstDirichlet")) {
if ((inflow_udf == "ConstDirichlet") &&
(inflow_outflow_udf == "ConstDirichlet") &&
(wall_udf == "ConstDirichlet")) {
return;
}

Expand All @@ -19,7 +22,14 @@ void register_scalar_dirichlet(
"Scalar BC: Only constant dirichlet supported for Wall BC");
}

register_inflow_scalar_dirichlet<ConstDirichlet>(
field, inflow_udf, mesh, time);
if (inflow_udf != "ConstDirichlet") {
register_inflow_scalar_dirichlet<ConstDirichlet>(
field, inflow_udf, mesh, time);
}

if (inflow_outflow_udf != "ConstDirichlet") {
register_inflow_scalar_dirichlet<ConstDirichlet>(
field, inflow_outflow_udf, mesh, time);
}
}
} // namespace amr_wind::scalar_bc
27 changes: 21 additions & 6 deletions amr-wind/boundary_conditions/velocity_bcs.H
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "amr-wind/physics/udfs/BurggrafLid.H"
#include "amr-wind/physics/udfs/Rankine.H"
#include "amr-wind/physics/udfs/CustomVelocity.H"
#include "amr-wind/physics/udfs/TwoLayer.H"

namespace amr_wind::vel_bc {

Expand Down Expand Up @@ -40,6 +41,10 @@ void register_inflow_vel_dirichlet(
using InflowOp = BCOpCreator<udf::CustomVelocity, WallOp>;
field.register_fill_patch_op<FieldFillPatchOps<InflowOp>>(
mesh, time, InflowOp(field));
} else if (inflow_udf == "TwoLayer") {
using InflowOp = BCOpCreator<udf::TwoLayer, WallOp>;
field.register_fill_patch_op<FieldFillPatchOps<InflowOp>>(
mesh, time, InflowOp(field));
} else {
amrex::Abort("Velocity BC: Invalid dirichlet BC type = " + inflow_udf);
}
Expand All @@ -49,12 +54,15 @@ void register_velocity_dirichlet(
Field& field,
const amrex::AmrCore& mesh,
const SimTime& time,
const std::pair<const std::string, const std::string>& udfs)
const amrex::Array<const std::string, 3>& udfs)
{
const std::string inflow_udf = udfs.first;
const std::string wall_udf = udfs.second;
const std::string& inflow_udf = udfs[0];
const std::string& inflow_outflow_udf = udfs[1];
const std::string& wall_udf = udfs[2];

if ((inflow_udf == "ConstDirichlet") && (wall_udf == "ConstDirichlet")) {
if ((inflow_udf == "ConstDirichlet") &&
(inflow_outflow_udf == "ConstDirichlet") &&
(wall_udf == "ConstDirichlet")) {
return;
}

Expand All @@ -63,8 +71,15 @@ void register_velocity_dirichlet(
"Velocity BC: Only constant dirichlet supported for Wall BC");
}

register_inflow_vel_dirichlet<ConstDirichlet>(
field, inflow_udf, mesh, time);
if (inflow_udf != "ConstDirichlet") {
register_inflow_vel_dirichlet<ConstDirichlet>(
field, inflow_udf, mesh, time);
}

if (inflow_outflow_udf != "ConstDirichlet") {
register_inflow_vel_dirichlet<ConstDirichlet>(
field, inflow_outflow_udf, mesh, time);
}
}

} // namespace amr_wind::vel_bc
Expand Down
9 changes: 9 additions & 0 deletions amr-wind/core/Field.H
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ public:
inline bool& in_uniform_space() { return m_mesh_mapped; }
inline bool in_uniform_space() const { return m_mesh_mapped; }

//! Check if any of the boundaries is a mass-inflow-outflow
inline bool has_inout_bndry() const { return m_inout_bndry; }

//! Set the inout_bndry flag
void set_inout_bndry() { m_inout_bndry = true; }

protected:
Field(
FieldRepo& repo,
Expand Down Expand Up @@ -425,6 +431,9 @@ protected:

//! Flag to track mesh mapping (to uniform space) of field
bool m_mesh_mapped{false};

//! Flag to indicate whether any of the boundaries is mass-inflow-outflow
bool m_inout_bndry{false};
};

} // namespace amr_wind
Expand Down
Loading