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::Real > z_inp_sponge
 Interpolated sponge profile heights [m]. More...
 
amrex::Vector< amrex::Real > U_inp_sponge
 Interpolated target x velocity for sponge damping. More...
 
amrex::Vector< amrex::Real > V_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.queryAdd("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:128
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  int line_no = 0;
73  while(std::getline(input_sponge_reader, line)) {
74  ++line_no;
75  // Blank lines and lines starting with '#' are not data
76  const auto first = line.find_first_not_of(" \t\r");
77  if (first == std::string::npos || line[first] == '#') { continue; }
78  std::istringstream iss_z(line);
79  if (!(iss_z >> z >> U >> V)) {
80  amrex::Abort("input_sponge file " + input_sponge_file + ", line " +
81  std::to_string(line_no) + ": expected three numbers (z U V)");
82  }
83  if (z == zbot) {
84  U_inp_sponge_tmp[0] = U;
85  V_inp_sponge_tmp[0] = V;
86  } else {
87  AMREX_ALWAYS_ASSERT(z > z_inp_sponge_tmp[z_inp_sponge_tmp.size()-1]); // sounding is increasing in height
88  z_inp_sponge_tmp.push_back(z);
89  U_inp_sponge_tmp.push_back(U);
90  V_inp_sponge_tmp.push_back(V);
91  if (z >= ztop) break;
92  }
93  }
94 
95  // At this point, we have an input_sponge from zbot up to
96  // z_inp_sponge_tmp[N-1] >= ztop. Now, interpolate to grid level 0 heights
97  const int Ninp = z_inp_sponge_tmp.size();
98  z_inp_sponge[0] = zbot;
99  U_inp_sponge[0] = U_inp_sponge_tmp[0];
100  V_inp_sponge[0] = V_inp_sponge_tmp[0];
101  for (int k=0; k < Nz; ++k) {
102  z_inp_sponge[k+1] = myhalf * (zlevels_stag[k] + zlevels_stag[k+1]);
103  U_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
104  V_inp_sponge[k+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), z_inp_sponge[k+1], Ninp);
105  }
106  z_inp_sponge[Nz+1] = ztop;
107  U_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), U_inp_sponge_tmp.dataPtr(), ztop, Ninp);
108  V_inp_sponge[Nz+1] = interpolate_1d(z_inp_sponge_tmp.dataPtr(), V_inp_sponge_tmp.dataPtr(), ztop, Ninp);
109  }
110 
111  amrex::Print() << "Successfully read the input_sponge file..." << std::endl;
112  input_sponge_reader.close();
113  }
const Real ztop
Definition: ERF_InitCustomPertVels_ParticleTests.H:4
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
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
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ U
Definition: ERF_IndexDefines.H:166
@ V
Definition: ERF_IndexDefines.H:167
amrex::Vector< amrex::Real > z_inp_sponge
Interpolated sponge profile heights [m].
Definition: ERF_InputSpongeData.H:131
amrex::Vector< amrex::Real > V_inp_sponge
Interpolated target y velocity for sponge damping.
Definition: ERF_InputSpongeData.H:131
amrex::Vector< amrex::Real > U_inp_sponge
Interpolated target x velocity for sponge damping.
Definition: ERF_InputSpongeData.H:131
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.
120  {
123  return z_inp_sponge.size();
124  }
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: