ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
TerrainDrag Class Reference

#include <ERF_TerrainDrag.H>

Collaboration diagram for TerrainDrag:

Public Member Functions

 TerrainDrag (std::string terrainfile)
 
 ~TerrainDrag ()=default
 
void define_terrain_blank_field (const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, amrex::Geometry &geom, amrex::MultiFab *z_phys_nd)
 
amrex::MultiFab * get_terrain_blank_field ()
 

Private Attributes

amrex::Vector< amrex::Real > m_x_terrain
 
amrex::Vector< amrex::Real > m_y_terrain
 
amrex::Vector< amrex::Real > m_height_terrain
 
std::unique_ptr< amrex::MultiFab > m_terrain_blank
 

Constructor & Destructor Documentation

◆ TerrainDrag()

TerrainDrag::TerrainDrag ( std::string  terrainfile)
explicit
10 {
11  std::ifstream file(terrainfile, std::ios::in);
12  if (!file.good()) {
13  Abort("Cannot find terrain file: " + terrainfile);
14  }
15  // xc yc height
16  Real value1, value2, value3;
17  while (file >> value1 >> value2 >> value3) {
18  m_x_terrain.push_back(value1);
19  m_y_terrain.push_back(value2);
20  m_height_terrain.push_back(value3);
21  }
22  file.close();
23 }
amrex::Vector< amrex::Real > m_height_terrain
Definition: ERF_TerrainDrag.H:30
amrex::Vector< amrex::Real > m_y_terrain
Definition: ERF_TerrainDrag.H:29
amrex::Vector< amrex::Real > m_x_terrain
Definition: ERF_TerrainDrag.H:28

◆ ~TerrainDrag()

TerrainDrag::~TerrainDrag ( )
default

Member Function Documentation

◆ define_terrain_blank_field()

void TerrainDrag::define_terrain_blank_field ( const amrex::BoxArray &  ba,
const amrex::DistributionMapping &  dm,
amrex::Geometry &  geom,
amrex::MultiFab *  z_phys_nd 
)
31 {
32  // Geometry params
33  const auto& dx = geom.CellSizeArray();
34  const auto& prob_lo = geom.ProbLoArray();
35 
36  // Allocate the terrain blank MF
37  // NOTE: 1 ghost cell for averaging to faces
38  m_terrain_blank.reset();
39  m_terrain_blank = std::make_unique<MultiFab>(ba, dm, 1, 1);
40  m_terrain_blank->setVal(0.);
41  const auto xterrain_size = m_x_terrain.size();
42  amrex::Gpu::DeviceVector<amrex::Real> d_xterrain(xterrain_size);
43  amrex::Gpu::DeviceVector<amrex::Real> d_yterrain(xterrain_size);
44  amrex::Gpu::DeviceVector<amrex::Real> d_zterrain(xterrain_size);
45  amrex::Gpu::copy(
46  amrex::Gpu::hostToDevice, m_x_terrain.begin(), m_x_terrain.end(),
47  d_xterrain.begin());
48  amrex::Gpu::copy(
49  amrex::Gpu::hostToDevice, m_y_terrain.begin(), m_y_terrain.end(),
50  d_yterrain.begin());
51  amrex::Gpu::copy(
52  amrex::Gpu::hostToDevice, m_height_terrain.begin(), m_height_terrain.end(),
53  d_zterrain.begin());
54  const auto* xterrain_ptr = d_xterrain.data();
55  const auto* yterrain_ptr = d_yterrain.data();
56  const auto* zterrain_ptr = d_zterrain.data();
57  // Set the terrain blank data
58  for (MFIter mfi(*m_terrain_blank); mfi.isValid(); ++mfi) {
59  Box gtbx = mfi.growntilebox();
60  const Array4<Real>& levelBlank = m_terrain_blank->array(mfi);
61  const Array4<const Real>& z_nd =
62  (z_phys_nd) ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
63  ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
64  // Loop over terrain points
65  for (unsigned ii = 0; ii < xterrain_size; ++ii) {
66  Real ht = zterrain_ptr[ii];
67  Real xt = xterrain_ptr[ii];
68  Real yt = yterrain_ptr[ii];
69  // Physical positions of cell-centers
70  const Real x = prob_lo[0] + (i + 0.5) * dx[0];
71  const Real y = prob_lo[1] + (j + 0.5) * dx[1];
72  Real z = prob_lo[2] + (k + 0.5) * dx[2];
73  if (z_nd) {
74  z = 0.125 * (z_nd(i, j, k) + z_nd(i + 1, j, k) + z_nd(i, j + 1, k) +
75  z_nd(i + 1, j + 1, k) + z_nd(i, j, k + 1) +
76  z_nd(i + 1, j, k + 1) + z_nd(i, j + 1, k + 1) +
77  z_nd(i + 1, j + 1, k + 1));
78  }
79  z = std::max(z, 0.0);
80  const Real cell_radius = std::sqrt(dx[0] * dx[0] + dx[1] * dx[1]);
81  // Proximity to the terrain
82  const Real radius =
83  std::sqrt((x - xt) * (x - xt) + (y - yt) * (y - yt));
84  const Real terrain_point =
85  (radius <= cell_radius && z <= ht) ? 1.0 : 0.0;
86  levelBlank(i, j, k) = terrain_point;
87  if(terrain_point==1){
88  break;
89  }
90  }
91  });
92  } // mfi
93 
94 // Fillboundary for periodic ghost cell copy
95 m_terrain_blank->FillBoundary(geom.periodicity());
96 
97 } // init_terrain_blank_field
std::unique_ptr< amrex::MultiFab > m_terrain_blank
Definition: ERF_TerrainDrag.H:31

◆ get_terrain_blank_field()

amrex::MultiFab* TerrainDrag::get_terrain_blank_field ( )
inline
25 { return m_terrain_blank.get(); }

Member Data Documentation

◆ m_height_terrain

amrex::Vector<amrex::Real> TerrainDrag::m_height_terrain
private

◆ m_terrain_blank

std::unique_ptr<amrex::MultiFab> TerrainDrag::m_terrain_blank
private

Referenced by get_terrain_blank_field().

◆ m_x_terrain

amrex::Vector<amrex::Real> TerrainDrag::m_x_terrain
private

◆ m_y_terrain

amrex::Vector<amrex::Real> TerrainDrag::m_y_terrain
private

The documentation for this class was generated from the following files: