/home/runner/work/amr-wind/amr-wind/amr-wind/core/MultiParser.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/MultiParser.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
MultiParser.H
Go to the documentation of this file.
1#ifndef MULTIPARSER_H
2#define MULTIPARSER_H
3
5#include "AMReX_ParmParse.H"
6
7namespace amr_wind::utils {
8
18{
19public:
20 MultiParser(const std::string& default_prefix, const std::string& prefix)
21 : m_pp_default(default_prefix), m_pp(prefix)
22 {}
23
25 const amrex::ParmParse& default_params() const { return m_pp_default; }
26
28 const amrex::ParmParse& params() const { return m_pp; }
29
31 bool contains(const std::string& name) const
32 {
33 return m_pp.contains(name.c_str()) ||
34 m_pp_default.contains(name.c_str());
35 }
36
42 void get(const std::string& name, vs::Vector& value) const
43 {
44 amrex::Vector<vs::Vector::value_type> val;
45 getarr(name, val);
46 AMREX_ALWAYS_ASSERT(val.size() == AMREX_SPACEDIM);
47 value.x() = val[0];
48 value.y() = val[1];
49 value.z() = val[2];
50 }
51
57 void query(const std::string& name, vs::Vector& value) const
58 {
59 amrex::Vector<vs::Vector::value_type> val;
60 queryarr(name, val);
61 if (!val.empty()) {
62 AMREX_ALWAYS_ASSERT(val.size() == AMREX_SPACEDIM);
63 value.x() = val[0];
64 value.y() = val[1];
65 value.z() = val[2];
66 }
67 }
68
74 void get_either(const std::string& name, vs::Vector& value) const
75 {
76 amrex::Vector<vs::Vector::value_type> val;
77 getarr(name, val);
78 AMREX_ALWAYS_ASSERT(val.size() == AMREX_SPACEDIM || val.size() == 1);
79 if (val.size() == 1) {
80 value.x() = val[0];
81 value.y() = val[0];
82 value.z() = val[0];
83 } else {
84 value.x() = val[0];
85 value.y() = val[1];
86 value.z() = val[2];
87 }
88 }
89
95 void query_either(const std::string& name, vs::Vector& value) const
96 {
97 amrex::Vector<vs::Vector::value_type> val;
98 queryarr(name, val);
99 if (!val.empty()) {
100 AMREX_ALWAYS_ASSERT(
101 val.size() == AMREX_SPACEDIM || val.size() == 1);
102 if (val.size() == 1) {
103 value.x() = val[0];
104 value.y() = val[0];
105 value.z() = val[0];
106 } else {
107 value.x() = val[0];
108 value.y() = val[1];
109 value.z() = val[2];
110 }
111 }
112 }
113
115 template <typename T>
116 void get(const std::string& name, T& value) const
117 {
118 if (m_pp.contains(name.c_str())) {
119 m_pp.get(name.c_str(), value);
120 } else {
121 m_pp_default.get(name.c_str(), value);
122 }
123 }
124
126 template <typename T>
127 void getarr(const std::string& name, T& value) const
128 {
129 if (m_pp.contains(name.c_str())) {
130 m_pp.getarr(name.c_str(), value);
131 } else {
132 m_pp_default.getarr(name.c_str(), value);
133 }
134 }
135
137 template <typename T>
138 void query(const std::string& name, T& value) const
139 {
140 m_pp_default.query(name.c_str(), value);
141 m_pp.query(name.c_str(), value);
142 }
143
146 template <typename T>
147 void queryarr(const std::string& name, T& value) const
148 {
149 m_pp_default.queryarr(name.c_str(), value);
150 m_pp.queryarr(name.c_str(), value);
151 }
152
153private:
154 amrex::ParmParse m_pp_default;
155 amrex::ParmParse m_pp;
156};
157
158} // namespace amr_wind::utils
159
160#endif /* MULTIPARSER_H */
Definition MultiParser.H:18
void getarr(const std::string &name, T &value) const
Get a vector of values for the given keyword entry from either namespace.
Definition MultiParser.H:127
void query_either(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:95
void get(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:42
void queryarr(const std::string &name, T &value) const
Definition MultiParser.H:147
void get_either(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:74
MultiParser(const std::string &default_prefix, const std::string &prefix)
Definition MultiParser.H:20
bool contains(const std::string &name) const
Check if the keyword is present in either namespace.
Definition MultiParser.H:31
void query(const std::string &name, T &value) const
Query the value for the keyword entry from either namespace.
Definition MultiParser.H:138
const amrex::ParmParse & default_params() const
Return the ParmParse instance for the default namespace.
Definition MultiParser.H:25
amrex::ParmParse m_pp
Definition MultiParser.H:155
const amrex::ParmParse & params() const
Return the ParmParse instance for the specialized namespace.
Definition MultiParser.H:28
void get(const std::string &name, T &value) const
Get the value for the keyword entry from either namespace.
Definition MultiParser.H:116
void query(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:57
amrex::ParmParse m_pp_default
Definition MultiParser.H:154
Definition MultiParser.H:7
Definition vector.H:13
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & z() &noexcept
Definition vector.H:99
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & x() &noexcept
Definition vector.H:97
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & y() &noexcept
Definition vector.H:98