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

#include <ERF_InputSpongeData.H>

Collaboration diagram for InputSpongeData:

Public Member Functions

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

Public Attributes

std::string input_sponge_file = "input_sponge_file.txt"
 
amrex::Vector< amrex::Realz_inp_sponge
 
amrex::Vector< amrex::RealU_inp_sponge
 
amrex::Vector< amrex::RealV_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
22  {
23  // Text input_sounding file
24  amrex::ParmParse pp("erf");
25  pp.query("input_sponge_file", input_sponge_file);
26  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:233
std::string input_sponge_file
Definition: ERF_InputSpongeData.H:108
Here is the call graph for this function:

Member Function Documentation

◆ read_from_file()

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

◆ size()

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

Member Data Documentation

◆ input_sponge_file

std::string InputSpongeData::input_sponge_file = "input_sponge_file.txt"

Referenced by InputSpongeData(), and read_from_file().

◆ 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: