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

Changes for coupling with ERF using MultiBlock #1297

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

Conversation

mukul1992
Copy link
Contributor

Summary

These changes allow coupling with ERF via the MultiBlock mechanism. It includes maintaining a pointer to the multiblock container which is defined in the coupling driver. For reading ERF data, it uses the ABL boundary plane mechanism by defining a read_erf function in the driver and passing it to a function pointer in AMR-Wind.

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 (MacOS M3 arch, GCC 13)
  • the regression tests
    • on GPU
    • on CPU (MacOS M3 arch, GCC 13)

CMakeLists.txt Outdated Show resolved Hide resolved
@@ -58,6 +63,14 @@ public:
SimTime& time() { return m_time; }
const SimTime& time() const { return m_time; }

#ifdef ERF_AW_MULTIBLOCK
void set_mbc(MultiBlockContainer* mbc) { m_mbc = mbc; }
Copy link
Contributor

Choose a reason for hiding this comment

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

raw pointers make me nervous. Is there some way we could be using unique_ptr instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay thanks for the suggestion.. I'll surely look into this, it's always good to have a more robust code.

CMakeLists.txt Show resolved Hide resolved
amr-wind/incflo.H Outdated Show resolved Hide resolved
@@ -7,6 +7,10 @@
#include "amr-wind/utilities/ncutils/nc_interface.H"
#include <AMReX_BndryRegister.H>

#ifdef ERF_AW_MULTIBLOCK
#include "amr-wind/wind_energy/ABLReadERFFcn.H"
class MultiBlockContainer;
Copy link
Contributor

Choose a reason for hiding this comment

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

are these needed? Like the build breaks without them? I see you do it in a bunch of places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean the ifdefs? I could remove them from all places where they are not strictly required. My thinking was that maybe you would prefer using the ifdefs to keep out the multiblock stuff as much as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean the forward declarations.

amr-wind/utilities/index_operations.H Outdated Show resolved Hide resolved
amr-wind/wind_energy/ABLBoundaryPlane.cpp Outdated Show resolved Hide resolved
@@ -47,6 +47,20 @@ public:
void init_tke(const amrex::Geometry& geom, amrex::MultiFab& tke) const;

private:
// ABL-with-bubble
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the bubble thing something you want to keep? Or was this just a debug thing? If you want to keep it, it might be better to move this to the physics folder/class. Would you be ok with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a debug thing where Bruce was using temperature in lieu of a scalar. I would like to use the scalar instead so I'll make that change at some point.

amr-wind/wind_energy/ABLReadERFFcn.H Outdated Show resolved Hide resolved
cmake/amr-wind-utils.cmake Outdated Show resolved Hide resolved
@marchdf
Copy link
Contributor

marchdf commented Oct 16, 2024

Good work, @mukul1992 ! Left a bunch of questions mostly.

@mukul1992
Copy link
Contributor Author

Thanks for the comments @marchdf @jrood-nrel.

I should have referenced this while creating the PR, but here's the driver repo for the ERF/AMR-Wind coupling. This may clarify the cmake related changes and some of the code changes.

nc += fld->num_comp();
}

// FIXME: need to generalize to lev > 0 somehow

Check notice

Code scanning / CodeQL

FIXME comment

FIXME comment: need to generalize to lev > 0 somehow
const int lev = 0;
for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
auto ori = oit();
// FIXME: would be safer and less storage to not allocate all of

Check notice

Code scanning / CodeQL

FIXME comment

FIXME comment: would be safer and less storage to not allocate all of
@@ -758,6 +809,19 @@
return;
}

#ifdef ERF_AMR_WIND_MULTIBLOCK
if (m_out_fmt == "erf-multiblock") {
// m_read_erf = sim.get_read_erf();

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
nc += fld->num_comp();
}

// FIXME: need to generalize to lev > 0 somehow

Check notice

Code scanning / CodeQL

FIXME comment Note

FIXME comment: need to generalize to lev > 0 somehow
const int lev = 0;
for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
auto ori = oit();
// FIXME: would be safer and less storage to not allocate all of

Check notice

Code scanning / CodeQL

FIXME comment Note

FIXME comment: would be safer and less storage to not allocate all of
@@ -758,6 +809,19 @@
return;
}

#ifdef ERF_AMR_WIND_MULTIBLOCK
if (m_out_fmt == "erf-multiblock") {
// m_read_erf = sim.get_read_erf();

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
@marchdf
Copy link
Contributor

marchdf commented Oct 21, 2024

Sounds good! Let us know how we can help get the CI passing for you or any other issues that we can help with.

Copy link
Contributor

@moprak-nrel moprak-nrel left a comment

Choose a reason for hiding this comment

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

Good work! Have a couple of quick comments.

AMREX_FORCE_INLINE int closest_index_lbound(
const amrex::Vector<amrex::Real>& vec, const amrex::Real value)
{
amrex::Real one_minus_eps = 1.0 - 1.e-8;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Is there a reason for the hardcoded 1e-8 here? should this be closer to std::numeric_limits<amrex::Real>::epsilon(); ?
  2. I'm wondering why this is necessary in the first place for lower_bound? Wouldn't you always be guaranteed that vec[idx -1] < value <= vec[idx] (for idx > 1, and value <= vec[0] otherwise)?

{
const size_t nc = fld->num_comp();
const int nstart =
static_cast<int>(m_components[static_cast<int>(fld->id())]);

const int idx = utils::closest_index(times, time);
int idx;
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Is the intention here to have times[idx] < time <= times[idx+1] for multiblock instead of times[idx] <= time < times[idx+1]?
  2. I'm a bit confused but the 1+eps checks below, are they necessary with lbound?

@@ -758,6 +780,35 @@ void ABLBoundaryPlane::read_header()
m_in_data.define_level_data(ori, pbx, nc);
}
}
} else if (m_out_fmt == "erf-multiblock") {

m_in_times.push_back(-1.0e13); // create space for storing time at erf
Copy link
Contributor

Choose a reason for hiding this comment

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

would std::numeric_limits<amrex::Real>::epsilon() work instead of 1e-13?

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.

5 participants