ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
InputSpongeData Struct Reference

#include <InputSpongeData.H>

Collaboration diagram for InputSpongeData:

Public Member Functions

 InputSpongeData ()
 
void read_from_file (const std::string input_sponge_file, const amrex::Geometry &geom, const amrex::Vector< amrex::Real > &zlevels_stag)
 
int size () const
 

Public Attributes

amrex::Vector< amrex::Real > z_inp_sponge
 
amrex::Vector< amrex::Real > U_inp_sponge
 
amrex::Vector< amrex::Real > V_inp_sponge
 

Detailed Description

Data structure storing input sponge data. Also handles reading the input file for sponge data

Constructor & Destructor Documentation

◆ InputSpongeData()

InputSpongeData::InputSpongeData ( )
inline
21 {}

Member Function Documentation

◆ read_from_file()

void InputSpongeData::read_from_file ( const std::string  input_sponge_file,
const amrex::Geometry &  geom,
const amrex::Vector< amrex::Real > &  zlevels_stag 
)
inline
26  {
27  const int klo = 0;
28  const int khi = geom.Domain().bigEnd()[AMREX_SPACEDIM-1];
29  const int Nz = geom.Domain().size()[AMREX_SPACEDIM-1];
30  const amrex::Real dz = geom.CellSize()[AMREX_SPACEDIM-1];
31 
32  const bool use_terrain = (zlevels_stag.size() > 0);
33  const amrex::Real zbot = (use_terrain) ? zlevels_stag[klo] : geom.ProbLo(AMREX_SPACEDIM-1);
34  const amrex::Real ztop = (use_terrain) ? zlevels_stag[khi+1] : geom.ProbHi(AMREX_SPACEDIM-1);
35 
36  z_inp_sponge.resize(Nz+2);
37  U_inp_sponge.resize(Nz+2);
38  V_inp_sponge.resize(Nz+2);
39 
40  // Read the input_sponge file
41  amrex::Print() << "input_sponge file location : " << input_sponge_file << std::endl;
42  std::ifstream input_sponge_reader(input_sponge_file);
43  if(!input_sponge_reader.is_open()) {
44  amrex::Error("Error opening the input_sponge file.\n");
45  }
46  else {
47  // Read the contents of the input_sponge file
48  amrex::Print() << "Successfully opened the input_sponge file. Now reading... " << std::endl;
49  std::string line;
50 
51  // First, read the input data into temp vectors; then, interpolate vectors to the
52  // domain lo/hi and cell centers (from level 0)
53  amrex::Vector<amrex::Real> z_inp_sponge_tmp, U_inp_sponge_tmp, V_inp_sponge_tmp;
54 
55  // Add surface
56  z_inp_sponge_tmp.push_back(zbot); // height above sea level [m]
57  U_inp_sponge_tmp.push_back(0);
58  V_inp_sponge_tmp.push_back(0);
59 
60  // Read the vertical profile at each given height
61  amrex::Real z, U, V;
62  while(std::getline(input_sponge_reader, line)) {
63  std::istringstream iss_z(line);
64  iss_z >> z >> U >> V;
65  if (z == zbot) {
66  U_inp_sponge_tmp[0] = U;
67  V_inp_sponge_tmp[0] = V;
68  } else {
69  AMREX_ALWAYS_ASSERT(z > z_inp_sponge_tmp[z_inp_sponge_tmp.size()-1]); // sounding is increasing in height
70  z_inp_sponge_tmp.push_back(z);
71  U_inp_sponge_tmp.push_back(U);
72  V_inp_sponge_tmp.push_back(V);
73  if (z >= ztop) break;
74  }
75  }
76 
77  // At this point, we have an input_sponge from zbot up to
78  // z_inp_sponge_tmp[N-1] >= ztop. Now, interpolate to grid level 0 heights
79  const int Ninp = z_inp_sponge_tmp.size();
80  z_inp_sponge[0] = zbot;
81  U_inp_sponge[0] = U_inp_sponge_tmp[0];
82  V_inp_sponge[0] = V_inp_sponge_tmp[0];
83  for (int k=0; k < Nz; ++k) {
84  z_inp_sponge[k+1] = (use_terrain) ? 0.5 * (zlevels_stag[k] + zlevels_stag[k+1])
85  : zbot + (k + 0.5) * dz;
86  U_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
87  V_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
88  }
89  z_inp_sponge[Nz+1] = ztop;
90  U_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), ztop, Ninp);
91  V_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), ztop, Ninp);
92  }
93 
94  amrex::Print() << "Successfully read the input_sponge file..." << std::endl;
95  input_sponge_reader.close();
96  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real interpolate_1d(const amrex::Real *alpha, const amrex::Real *beta, const amrex::Real alpha_interp, const int alpha_size)
Definition: Interpolation_1D.H:12
@ U
Definition: IndexDefines.H:64
@ V
Definition: IndexDefines.H:65
amrex::Vector< amrex::Real > V_inp_sponge
Definition: InputSpongeData.H:107
amrex::Vector< amrex::Real > z_inp_sponge
Definition: InputSpongeData.H:107
amrex::Vector< amrex::Real > U_inp_sponge
Definition: InputSpongeData.H:107
Here is the call graph for this function:

◆ size()

int InputSpongeData::size ( ) const
inline
99  {
100  AMREX_ALWAYS_ASSERT(z_inp_sponge.size() == U_inp_sponge.size());
101  AMREX_ALWAYS_ASSERT(z_inp_sponge.size() == V_inp_sponge.size());
102  return z_inp_sponge.size();
103  }

Member Data Documentation

◆ U_inp_sponge

amrex::Vector<amrex::Real> InputSpongeData::U_inp_sponge

Referenced by read_from_file(), and size().

◆ V_inp_sponge

amrex::Vector<amrex::Real> InputSpongeData::V_inp_sponge

Referenced by read_from_file(), and size().

◆ z_inp_sponge

amrex::Vector<amrex::Real> InputSpongeData::z_inp_sponge

Referenced by read_from_file(), and size().


The documentation for this struct was generated from the following file: