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

Fix terrain unittest on GPU #1309

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions amr-wind/physics/TerrainDrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,4 @@ void TerrainDrag::pre_init_actions()
{
BL_PROFILE("amr-wind::" + this->identifier() + "::pre_init_actions");
}

int TerrainDrag::return_blank_value(int i, int j, int k)
{
int lev = 0;
amrex::MFIter mfi(m_terrain_blank(lev));
const auto& terrain_blank = m_terrain_blank(lev).const_array(mfi);
return int(terrain_blank(i, j, k));
}

} // namespace amr_wind::terraindrag
57 changes: 57 additions & 0 deletions unit_tests/aw_test_utils/test_utils.H
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,63 @@ inline void field_minmax(
field_max(nlevels, field, max_val);
}

template <typename T, typename FType>
inline T field_probe_impl(
const FType& field,
const int lev,
const int i,
const int j,
const int k,
const int icomp = 0)
{
const amrex::IntVect iv_val = {i, j, k};
T value = amrex::ReduceSum(
field(lev), 0,
[=] AMREX_GPU_HOST_DEVICE(
amrex::Box const& bx,
amrex::Array4<T const> const& field_arr) -> T {
T val = 0.0;

if (bx.contains(iv_val)) {
amrex::Loop(bx, [=, &val](int i0, int j0, int k0) noexcept {
const amrex::IntVect iv = {i0, j0, k0};
if (iv == iv_val) {
val = field_arr(iv, icomp);
}
});
}
return val;
});
return value;
}

inline int field_probe(
const amr_wind::IntField& field,
const int lev,
const int i,
const int j,
const int k,
const int icomp = 0)
{
int value = field_probe_impl<int>(field, lev, i, j, k, icomp);
amrex::ParallelDescriptor::ReduceIntSum(value);
return value;
}

inline amrex::Real field_probe(
const amr_wind::Field& field,
const int lev,
const int i,
const int j,
const int k,
const int icomp = 0)
{
amrex::Real value =
field_probe_impl<amrex::Real>(field, lev, i, j, k, icomp);
amrex::ParallelDescriptor::ReduceRealSum(value);
return value;
}

} // namespace amr_wind_tests::utils

#endif /* TEST_UTILS_H */
10 changes: 5 additions & 5 deletions unit_tests/wind_energy/test_abl_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ TEST_F(TerrainTest, terrain)
pp.addarr("physics", physics);
amr_wind::terraindrag::TerrainDrag terrain_drag(sim());
terrain_drag.post_init_actions();
int value = 100;
const auto& terrain_blank = sim().repo().get_int_field("terrain_blank");
// Outside Point
value = terrain_drag.return_blank_value(5, 5, 1);
EXPECT_EQ(value, tol);
const int value_out = utils::field_probe(terrain_blank, 0, 5, 5, 1);
EXPECT_EQ(value_out, tol);
// Inside Point
value = terrain_drag.return_blank_value(15, 10, 1);
EXPECT_EQ(value, 1 + tol);
const int value_in = utils::field_probe(terrain_blank, 0, 15, 10, 1);
EXPECT_EQ(value_in, 1 + tol);
}

} // namespace amr_wind_tests