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

#include <ERF_LatLonMap.H>

Collaboration diagram for LatLonMap:

Public Member Functions

 LatLonMap (const amrex::MultiFab &lat, const amrex::MultiFab &lon, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::Geometry &geom0)
 
LatLonStatus locate (amrex::Real req_lat, amrex::Real req_lon, LatLonLocation &loc) const
 
void rotation_at (amrex::Real x, amrex::Real y, amrex::Real &cos_alpha, amrex::Real &sin_alpha) const
 

Private Attributes

amrex::MultiFab m_ll
 
amrex::Box m_dom
 
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_problo
 
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_dx
 

Constructor & Destructor Documentation

◆ LatLonMap()

LatLonMap::LatLonMap ( const amrex::MultiFab &  lat,
const amrex::MultiFab &  lon,
const amrex::BoxArray &  ba2d,
const amrex::DistributionMapping &  dm,
const amrex::Geometry &  geom0 
)
180  : m_problo(geom0.ProbLoArray()),
181  m_dx(geom0.CellSizeArray())
182 {
183  m_dom = geom0.Domain();
184  m_dom.setRange(2,0);
185 
186  // Gather the level-0 mass-point latitude and longitude onto the IO rank.
187  // This is a setup-time, level-0, 2D array, so the gather is affordable and
188  // keeps the search and the inverse map as plain host code.
189  //
190  // The ceiling is one rank holding 2 Reals per level-0 column -- 100 MB or
191  // so for the largest domains ERF is run on -- and a search of that array
192  // per point, once.
193  MultiFab latlon(ba2d, dm, 2, 0);
194  pack_latlon(latlon, lat, lon);
195 
196  BoxArray ba_one(m_dom);
197  Vector<int> pmap(1, ParallelDescriptor::IOProcessorNumber());
198  DistributionMapping dm_one(pmap);
199  m_ll.define(ba_one, dm_one, 2, 0, MFInfo().SetArena(The_Pinned_Arena()));
200  m_ll.ParallelCopy(latlon, 0, 0, 2);
201 
202  // The copy is device-side in a GPU build; the searches are host code
203  Gpu::streamSynchronize();
204 }
void pack_latlon(MultiFab &latlon, const MultiFab &lat, const MultiFab &lon)
Definition: ERF_LatLonMap.cpp:47
amrex::Box m_dom
Definition: ERF_LatLonMap.H:168
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_dx
Definition: ERF_LatLonMap.H:170
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_problo
Definition: ERF_LatLonMap.H:169
amrex::MultiFab m_ll
Definition: ERF_LatLonMap.H:167
Here is the call graph for this function:

Member Function Documentation

◆ locate()

LatLonStatus LatLonMap::locate ( amrex::Real  req_lat,
amrex::Real  req_lon,
LatLonLocation &  loc 
) const
208 {
209  Real out[9] = {Real(0.0), Real(0.0), Real(0.0), Real(0.0), Real(0.0),
210  Real(0.0), Real(0.0), Real(0.0), Real(0.0)};
211 
212  if (ParallelDescriptor::IOProcessor()) {
213  LatLonLocation l;
214  const LatLonStatus status = locate_latlon_on_grid(m_ll.const_array(0), m_dom, m_problo, m_dx,
215  req_lat, req_lon, l);
216  out[0] = l.x; out[1] = l.y;
217  out[2] = l.lat; out[3] = l.lon;
218  out[4] = l.near_lat; out[5] = l.near_lon;
219  out[6] = l.cos_alpha; out[7] = l.sin_alpha;
220  out[8] = static_cast<Real>(static_cast<int>(status));
221  }
222 
223  ParallelDescriptor::Bcast(out, 9, ParallelDescriptor::IOProcessorNumber());
224 
225  loc.x = out[0]; loc.y = out[1];
226  loc.lat = out[2]; loc.lon = out[3];
227  loc.near_lat = out[4]; loc.near_lon = out[5];
228  loc.cos_alpha = out[6]; loc.sin_alpha = out[7];
229  return static_cast<LatLonStatus>(static_cast<int>(std::lround(out[8])));
230 }
LatLonStatus
Definition: ERF_LatLonMap.H:105
LatLonStatus locate_latlon_on_grid(const Array4< const Real > &ll, const Box &dom, const GpuArray< Real, AMREX_SPACEDIM > &problo, const GpuArray< Real, AMREX_SPACEDIM > &dx, Real req_lat, Real req_lon, LatLonLocation &loc)
Definition: ERF_LatLonMap.cpp:113
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_LatLonMap.H:86
amrex::Real cos_alpha
Definition: ERF_LatLonMap.H:101
amrex::Real lat
Definition: ERF_LatLonMap.H:93
amrex::Real x
Definition: ERF_LatLonMap.H:88
amrex::Real near_lat
Definition: ERF_LatLonMap.H:97
amrex::Real y
Definition: ERF_LatLonMap.H:89
amrex::Real sin_alpha
Definition: ERF_LatLonMap.H:102
amrex::Real near_lon
Definition: ERF_LatLonMap.H:98
amrex::Real lon
Definition: ERF_LatLonMap.H:94

Referenced by ObsNudging::resolve_positions(), and ERF::resolve_station_positions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotation_at()

void LatLonMap::rotation_at ( amrex::Real  x,
amrex::Real  y,
amrex::Real &  cos_alpha,
amrex::Real &  sin_alpha 
) const
234 {
235  Real out[2] = {Real(1.0), Real(0.0)};
236 
237  if (ParallelDescriptor::IOProcessor()) {
238  const int i = std::clamp(static_cast<int>(std::floor((x - m_problo[0]) / m_dx[0])),
239  m_dom.smallEnd(0), m_dom.bigEnd(0));
240  const int j = std::clamp(static_cast<int>(std::floor((y - m_problo[1]) / m_dx[1])),
241  m_dom.smallEnd(1), m_dom.bigEnd(1));
242  grid_rotation_from_latlon(m_ll.const_array(0), m_dom, i, j, out[0], out[1]);
243  }
244 
245  ParallelDescriptor::Bcast(out, 2, ParallelDescriptor::IOProcessorNumber());
246  cos_alpha = out[0];
247  sin_alpha = out[1];
248 }
void grid_rotation_from_latlon(const Array4< const Real > &ll, const Box &dom, int i, int j, Real &cos_alpha, Real &sin_alpha)
Definition: ERF_LatLonMap.cpp:63
Real sin_alpha
Definition: ERF_Plotfile2DInterpolator.cpp:29
Real cos_alpha
Definition: ERF_Plotfile2DInterpolator.cpp:28

Referenced by ObsNudging::resolve_positions(), and ERF::resolve_station_positions().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_dom

amrex::Box LatLonMap::m_dom
private

Referenced by LatLonMap(), locate(), and rotation_at().

◆ m_dx

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> LatLonMap::m_dx
private

Referenced by locate(), and rotation_at().

◆ m_ll

amrex::MultiFab LatLonMap::m_ll
private

Referenced by LatLonMap(), locate(), and rotation_at().

◆ m_problo

amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> LatLonMap::m_problo
private

Referenced by locate(), and rotation_at().


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