Canoe
Comprehensive Atmosphere N' Ocean Engine
output_utils.cpp
Go to the documentation of this file.
1 // C/C++
2 #include <mutex>
3 
4 // application
5 #include <application/application.hpp>
6 
7 // outputs
8 #include "output_utils.hpp"
9 
10 static std::mutex table_mutex;
11 
12 int get_num_variables(std::string grid, AthenaArray<Real> const& data) {
13  int nvar;
14  if (grid == "--C" || grid == "--F") {
15  nvar = data.GetDim2();
16  } else if (grid == "---") {
17  nvar = data.GetDim1();
18  } else {
19  nvar = data.GetDim4();
20  }
21 
22  return nvar;
23 }
24 
26  Application::Logger app("outputs");
27  app->Log("Initialize MetadataTable");
28 
29  table_ = {// short name, long name, units, grid location
30  {"x1", "height at cell center", "m", "--C"},
31  {"x1f", "height at cell boundary", "m", "--F"},
32  {"x2", "distance at cell center", "m", "-C-"},
33  {"x2f", "distance at cell boundary", "m", "-F-"},
34  {"x3", "distance at cell center", "m", "C--"},
35  {"x3f", "distance at cell boundary", "m", "F--"},
36  {"rho", "density", "kg/m^3", "CCC"},
37  {"press", "pressure", "pa", "CCC"},
38  {"vel", "velocity", "m/s", "CCC"},
39  {"vapor", "mass mixing ratio of vapor", "kg/kg", "CCC"},
40  {"temp", "temperature", "K", "CCC"},
41  {"theta", "potential temperature", "K", "CCC"},
42  {"thetav", "virtual potential temperature", "K", "CCC"},
43  {"mse", "moist static energy", "J/kg", "CCC"},
44  {"rh1", "relative humidity 1", "1", "CCC"},
45  {"rh2", "relative humidity 2", "1", "CCC"},
46  {"eps", "turbulent dissipation", "w/kg", "CCC"},
47  {"tke", "turbulent kinetic energy", "J/kg", "CCC"},
48  {"mut", "dynamic turbulent viscosity", "kg/(m.s)", "CCC"},
49  {"radiance", "top-of-atmosphere radiance", "K", "RCC"}};
50 }
51 
53  Application::Logger app("outputs");
54  app->Log("Destroy MetadataTable");
55 }
56 
58  // RAII
59  std::unique_lock<std::mutex> lock(table_mutex);
60 
61  if (myptr_ == nullptr) {
62  myptr_ = new MetadataTable();
63  }
64 
65  return myptr_;
66 }
67 
69  std::unique_lock<std::mutex> lock(table_mutex);
70 
71  if (MetadataTable::myptr_ != nullptr) {
72  delete MetadataTable::myptr_;
73  MetadataTable::myptr_ = nullptr;
74  }
75 }
76 
77 std::string MetadataTable::GetGridType(std::string name) const {
78  int nouts = table_.size();
79  for (int i = 0; i < nouts; ++i) {
80  if (table_[i][0] == name) {
81  return table_[i][3];
82  }
83  }
84 
85  return "";
86 }
87 
88 std::string MetadataTable::GetUnits(std::string name) const {
89  int nouts = table_.size();
90  for (int i = 0; i < nouts; ++i) {
91  if (table_[i][0] == name) {
92  return table_[i][2];
93  }
94  }
95 
96  return "";
97 }
98 
99 std::string MetadataTable::GetLongName(std::string name) const {
100  int nouts = table_.size();
101  for (int i = 0; i < nouts; ++i) {
102  if (table_[i][0] == name) {
103  return table_[i][1];
104  }
105  }
106 
107  return "";
108 }
109 
MetadataTable()
Protected ctor access thru static member function Instance.
static MetadataTable const * GetInstance()
static MetadataTable * myptr_
Pointer to the single MetadataTable instance.
std::string GetLongName(std::string name) const
StringTable table_
static void Destroy()
std::string GetGridType(std::string name) const
std::string GetUnits(std::string name) const
static std::mutex table_mutex
int get_num_variables(std::string grid, AthenaArray< Real > const &data)
__attribute__((weak)) MetadataTable