From c7d52adf5c00e2cae9e6c21f9948259e5fadc483 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Thu, 9 Jan 2025 18:50:58 -0800 Subject: [PATCH] Fix TerrainIF for GPU (#2056) --- Source/EB/ERF_InitEB.cpp | 6 +++++- Source/EB/ERF_TerrainIF.H | 18 +++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Source/EB/ERF_InitEB.cpp b/Source/EB/ERF_InitEB.cpp index 532879241..468addac5 100644 --- a/Source/EB/ERF_InitEB.cpp +++ b/Source/EB/ERF_InitEB.cpp @@ -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); diff --git a/Source/EB/ERF_TerrainIF.H b/Source/EB/ERF_TerrainIF.H index bd1222be4..def45dbcd 100644 --- a/Source/EB/ERF_TerrainIF.H +++ b/Source/EB/ERF_TerrainIF.H @@ -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)) @@ -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 terr_arr; - - amrex::Geometry& m_geom; amrex::Real dx, dy; };