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

DRAFT PR: inflow-outflow boundary condition #1066

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

mukul1992
Copy link
Contributor

@mukul1992 mukul1992 commented May 18, 2024

Summary

Enabling the mass_inflow_outflow (MIO) BC which allows for both inflow and outflow cells in a boundary.

Pull request type

Please check the type of change introduced:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Checklist

The following is included:

  • new unit-test(s)
  • new regression test(s)
  • documentation for new capability

This PR was tested by running:

  • the unit tests
    • on GPU
    • on CPU
  • the regression tests
    • on GPU
    • on CPU (macOS M3, gcc-13)

Additional background

This functionality would be required for coupling with ERF and was started after discussions with @gdeskos and @mchurchf, along with @asalmgren, as it was a desired functionality within AMR-Wind too. Additionally, @hgopalan has expressed interest, and @marchdf has helped along the way.

Description

The changes required can be organized into six categories:

  1. adding MIO as one of the BCs, mapping it to a custom math BC, and adding the mechanics required for enabling UDFs.
  2. the new TwoLayer UDF for testing, currently it implements a simple two-layer x-direction flow in opposite directions as a test, but this UDF can be modified to test progressively more complex cases, finishing with a regression test case such as vortex initialization and advection across the boundary.
  3. the custom Neumann function for filling the outflow boundary cells in MassInflowOutflowBC.cpp
  4. adding the inflow and outflow conditions in the WENO upwinding functions to map to ext_dir and foextrap behavior respectively.
  5. calling the enforceSolvability routine in AMReX-Hydro before the mac-projection, which adjusts the outflux to match with influx (will link to the corresponding PR in Hydro).
  6. the cmake scripts and input files for testing, these can be reorganized and cleaned up ultimately into a proper regression test as development completes. The input file being used for testing is input_inout.

@marchdf marchdf marked this pull request as draft May 20, 2024 14:24
Copy link
Contributor

@marchdf marchdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a first quick pass.

const int nlevels = m_field.repo().num_active_levels();
const bool ib = (idim == 0), jb = (idim == 1), kb = (idim == 2);

amrex::Print() << "***** Applying MIO custom Neumann fills at orientation: " << idx << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove debug statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I am keeping them until all the bugs are ironed out an will clean things up when it's ready to merge

const auto islow = m_ori.isLow();
const auto ishigh = m_ori.isHigh();
const int nlevels = m_field.repo().num_active_levels();
const bool ib = (idim == 0), jb = (idim == 1), kb = (idim == 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these bools are implicetly cast to ints later. I would prefer something like const amrex::IntVect ivp = {blah} and then you can just iv + ivp in the parallelfor loops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

amr-wind/boundary_conditions/BCInterface.H Outdated Show resolved Hide resolved
amr-wind/boundary_conditions/scalar_bcs.H Outdated Show resolved Hide resolved
if (bclo == BCType::ext_dir) {
if (bclo == BCType::ext_dir ||
(bclo == BCType::user_1 && velp >= 0.0)) {
//Print() << "trans_xbc_domlo_extdir triggered at " << i << " " << j << " " << k << " " << n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we get close to merging, let's remove all these print statements.

@@ -79,6 +79,7 @@ macro(init_amrex_hydro)
else()
set(CMAKE_PREFIX_PATH ${AMReX-Hydro_DIR} ${CMAKE_PREFIX_PATH})
find_package(AMReX-Hydro CONFIG REQUIRED)
add_subdirectory(${AMReX-Hydro_DIR} build)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? Feels strange

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed it to compile with an external AMReX-Hydro, but it may just be my inexperience with CMake. I will look into it..

{
struct DeviceOp
{
// clang-format off
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this block


namespace amr_wind::udf {

TwoLayer::TwoLayer(const Field& /*fld*/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up this cpp and H files from comments and clang format off stuff

@@ -6,6 +6,9 @@
#include "amr-wind/core/field_ops.H"
#include "amr-wind/wind_energy/ABL.H"

// for debugging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these later

@@ -0,0 +1,71 @@
# This is a 2D poiseuille flow when run to steady state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these into test/test_files and then add to test/CMakeLists.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes sense

@marchdf
Copy link
Contributor

marchdf commented May 22, 2024

Most of my comments right now are just noting the obvious things to clean up before actually merging. Thank you for taking this task on!!

@mbkuhn
Copy link
Contributor

mbkuhn commented May 22, 2024

Speaking of merging, it looks like there are some complicated merge conflicts between this branch and main. It may be helpful to rebase your branch to upstream/main to remove some of those conflicts and get the unrelated parts of this branch up-to-date. Removing the merge conflicts will also allow the CI tests to run.

@mukul1992
Copy link
Contributor Author

@marchdf Yes, I will certainly clean up all the debug statements and incorporate other changes you recommended.

@mbkuhn Yes, I will do the rebase over the next week along with cleaning things up.

Thanks for the early feedback!

@mukul1992
Copy link
Contributor Author

PS. I have been able to rebase this code with the latest changes in the Exawind/amr-wind repo. I have also updated the amrex submod in the index (let me know if I did it incorrectly). And have updated the BCType from user_1 to direction_dependent in the code.
And finally, here's the draft PR for AMReX-Hydro that includes the outflow-correction for enforcing solvability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants