Skip to content

Commit

Permalink
Fix TerrainIF for GPU (#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jan 10, 2025
1 parent a2dc25a commit c7d52ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Source/EB/ERF_InitEB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ void ERF::MakeEBGeometry()
amrex::Print() << "\n Building EB geometry based on idealized terrain." << std::endl;
Real dummy_time = 0.0;
Box bx(surroundingNodes(Geom(0).Domain())); bx.grow(2);
FArrayBox terrain_fab(makeSlab(bx,2,0),1);
static FArrayBox terrain_fab;
if (!terrain_fab.isAllocated()) {
amrex::ExecOnFinalize([&] () { terrain_fab.clear(); });
}
terrain_fab.resize(makeSlab(bx,2,0),1);
prob->init_custom_terrain(Geom(0), terrain_fab, dummy_time);
TerrainIF ebterrain(terrain_fab, Geom(0));
auto gshop = EB2::makeShop(ebterrain);
Expand Down
18 changes: 5 additions & 13 deletions Source/EB/ERF_TerrainIF.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ class TerrainIF
public:

TerrainIF (amrex::FArrayBox& a_z_terrain, amrex::Geometry& a_geom)
: m_terr(a_z_terrain),
m_geom(a_geom)
{
amrex::Print() << " EB type = Terrain " << std::endl;

dx = m_geom.CellSizeArray()[0];
dy = m_geom.CellSizeArray()[1];

terr_arr = m_terr.const_array();
}
: terr_arr(a_z_terrain.const_array()),
dx(a_geom.CellSize(0)),
dy(a_geom.CellSize(1))
{}

AMREX_GPU_HOST_DEVICE inline
amrex::Real operator() (AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z))
Expand All @@ -36,16 +30,14 @@ public:
return -(z - terr_arr(i,j,0));
}

AMREX_GPU_HOST_DEVICE
inline amrex::Real operator() (const amrex::RealArray& p) const noexcept
{
return this->operator() (AMREX_D_DECL(p[0], p[1], p[2]));
}

protected:
amrex::FArrayBox& m_terr;
amrex::Array4<amrex::Real const> terr_arr;

amrex::Geometry& m_geom;
amrex::Real dx, dy;
};

Expand Down

0 comments on commit c7d52ad

Please sign in to comment.