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

#include <ERF_InputSpongeData.H>

Collaboration diagram for InputSpongeData:

Public Member Functions

 InputSpongeData ()
 Construct input sponge metadata from the ERF input namespace. More...
 
void read_from_file (const amrex::Geometry &geom, const amrex::Vector< amrex::Real > &zlevels_stag)
 Read and interpolate the input sponge profile onto level-0 heights. More...
 
int size () const
 Return the number of interpolated input sponge samples. More...
 

Public Attributes

std::string input_sponge_file = "input_sponge_file.txt"
 Path to the text file containing the sponge profile. More...
 
amrex::Vector< amrex::Realz_inp_sponge
 Interpolated sponge profile heights [m]. More...
 
amrex::Vector< amrex::RealU_inp_sponge
 Interpolated target x velocity for sponge damping. More...
 
amrex::Vector< amrex::RealV_inp_sponge
 Interpolated target y velocity for sponge damping. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ InputSpongeData()

InputSpongeData::InputSpongeData ( )
inline

Construct input sponge metadata from the ERF input namespace.

25  {
26  // Text input_sounding file
27  amrex::ParmParse pp("erf");
28  pp.query("input_sponge_file", input_sponge_file);
29  }
ParmParse pp("prob")
std::string input_sponge_file
Path to the text file containing the sponge profile.
Definition: ERF_InputSpongeData.H:120
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

Read and interpolate the input sponge profile onto level-0 heights.

Parameters
geomGeometry defining the level-0 vertical domain.
zlevels_stagStaggered vertical coordinates used for interpolation.
38  {
39  const int klo = 0;
40  const int khi = geom.Domain().bigEnd()[AMREX_SPACEDIM-1];
41  const int Nz = geom.Domain().size()[AMREX_SPACEDIM-1];
42 
43  const amrex::Real zbot = zlevels_stag[klo];
44  const amrex::Real ztop = zlevels_stag[khi+1];
45 
46  z_inp_sponge.resize(Nz+2);
47  U_inp_sponge.resize(Nz+2);
48  V_inp_sponge.resize(Nz+2);
49 
50  // Read the input_sponge file
51  amrex::Print() << "input_sponge file location : " << input_sponge_file << std::endl;
52  std::ifstream input_sponge_reader(input_sponge_file);
53  if(!input_sponge_reader.is_open()) {
54  amrex::Error("Error opening the input_sponge file.\n");
55  }
56  else {
57  // Read the contents of the input_sponge file
58  amrex::Print() << "Successfully opened the input_sponge file. Now reading... " << std::endl;
59  std::string line;
60 
61  // First, read the input data into temp vectors; then, interpolate vectors to the
62  // domain lo/hi and cell centers (from level 0)
63  amrex::Vector<amrex::Real> z_inp_sponge_tmp, U_inp_sponge_tmp, V_inp_sponge_tmp;
64 
65  // Add surface
66  z_inp_sponge_tmp.push_back(zbot); // height above sea level [m]
67  U_inp_sponge_tmp.push_back(0);
68  V_inp_sponge_tmp.push_back(0);
69 
70  // Read the vertical profile at each given height
71  amrex::Real z, U, V;
72  while(std::getline(input_sponge_reader, line)) {
73  std::istringstream iss_z(line);
74  iss_z >> z >> U >> V;
75  if (z == zbot) {
76  U_inp_sponge_tmp[0] = U;
77  V_inp_sponge_tmp[0] = V;
78  } else {
79  AMREX_ALWAYS_ASSERT(z > z_inp_sponge_tmp[z_inp_sponge_tmp.size()-1]); // sounding is increasing in height
80  z_inp_sponge_tmp.push_back(z);
81  U_inp_sponge_tmp.push_back(U);
82  V_inp_sponge_tmp.push_back(V);
83  if (z >= ztop) break;
84  }
85  }
86 
87  // At this point, we have an input_sponge from zbot up to
88  // z_inp_sponge_tmp[N-1] >= ztop. Now, interpolate to grid level 0 heights
89  const int Ninp = z_inp_sponge_tmp.size();
90  z_inp_sponge[0] = zbot;
91  U_inp_sponge[0] = U_inp_sponge_tmp[0];
92  V_inp_sponge[0] = V_inp_sponge_tmp[0];
93  for (int k=0; k < Nz; ++k) {
94  z_inp_sponge[k+1] = myhalf * (zlevels_stag[k] + zlevels_stag[k+1]);
95  U_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
96  V_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
97  }
98  z_inp_sponge[Nz+1] = ztop;
99  U_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), ztop, Ninp);
100  V_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), ztop, Ninp);
101  }
102 
103  amrex::Print() << "Successfully read the input_sponge file..." << std::endl;
104  input_sponge_reader.close();
105  }
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
const Real ztop
Definition: ERF_InitCustomPertVels_ParticleTests.H:4
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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:14
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ U
Definition: ERF_IndexDefines.H:123
@ V
Definition: ERF_IndexDefines.H:124
amrex::Vector< amrex::Real > z_inp_sponge
Interpolated sponge profile heights [m].
Definition: ERF_InputSpongeData.H:123
amrex::Vector< amrex::Real > V_inp_sponge
Interpolated target y velocity for sponge damping.
Definition: ERF_InputSpongeData.H:123
amrex::Vector< amrex::Real > U_inp_sponge
Interpolated target x velocity for sponge damping.
Definition: ERF_InputSpongeData.H:123
Here is the call graph for this function:

◆ size()

int InputSpongeData::size ( ) const
inline

Return the number of interpolated input sponge samples.

Returns
Number of stored sponge profile levels.
112  {
115  return z_inp_sponge.size();
116  }
Here is the call graph for this function:

Member Data Documentation

◆ input_sponge_file

InputSpongeData::input_sponge_file = "input_sponge_file.txt"

Path to the text file containing the sponge profile.

Referenced by InputSpongeData(), and read_from_file().

◆ U_inp_sponge

InputSpongeData::U_inp_sponge

Interpolated target x velocity for sponge damping.

Referenced by read_from_file(), and size().

◆ V_inp_sponge

InputSpongeData::V_inp_sponge

Interpolated target y velocity for sponge damping.

Referenced by read_from_file(), and size().

◆ z_inp_sponge

InputSpongeData::z_inp_sponge

Interpolated sponge profile heights [m].

Referenced by read_from_file(), and size().


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