OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Report2DVars.hpp
Go to the documentation of this file.
1
15#ifndef OPENSWMM_ENGINE_2D_REPORT2D_VARS_HPP
16#define OPENSWMM_ENGINE_2D_REPORT2D_VARS_HPP
17
18#include "SolverOptions2D.hpp"
19
20#include <cctype>
21#include <cstdio>
22#include <string>
23#include <vector>
24
26
28inline const std::vector<std::string>& tokens() {
29 static const std::vector<std::string> kTokens = {
30 "DEPTH", "VELOCITY", "EDGE_FLUX", "NODE_HEAD", "SPECIES", "RAINFALL",
31 "INFILTRATION", "COUPLING", "GRADIENTS", "CONTINUITY", "ENVELOPES",
32 };
33 return kTokens;
34}
35
36inline bool iequalsTok(const std::string& a, const char* b) {
37 std::size_t i = 0;
38 for (; i < a.size() && b[i]; ++i)
39 if (std::toupper(static_cast<unsigned char>(a[i])) !=
40 std::toupper(static_cast<unsigned char>(b[i]))) return false;
41 return i == a.size() && b[i] == '\0';
42}
43
45inline std::vector<std::string> splitList(const std::string& text) {
46 std::vector<std::string> toks;
47 std::string cur;
48 for (char c : text) {
49 if (c == ',' || c == ' ' || c == '\t' || c == '\r' || c == '\n') {
50 if (!cur.empty()) { toks.push_back(cur); cur.clear(); }
51 } else {
52 cur += c;
53 }
54 }
55 if (!cur.empty()) toks.push_back(cur);
56 return toks;
57}
58
64inline std::string parseMask(const std::string& text, unsigned& mask) {
65 mask = 0;
66 const auto toks = splitList(text);
67 if (toks.empty())
68 return "REPORT_2D_VARIABLES needs DEFAULT|MINIMAL|ALL or a token list";
69 const auto& names = tokens();
70 for (const auto& t : toks) {
71 if (iequalsTok(t, "DEFAULT")) { mask |= DEFAULT_MASK; continue; }
72 if (iequalsTok(t, "MINIMAL")) { mask |= MINIMAL_MASK; continue; }
73 if (iequalsTok(t, "ALL")) { mask |= ALL_MASK; continue; }
74 if (iequalsTok(t, "NONE")) { continue; }
75 bool found = false;
76 for (std::size_t i = 0; i < names.size(); ++i) {
77 if (iequalsTok(t, names[i].c_str())) { mask |= (1u << i); found = true; break; }
78 }
79 if (!found) {
80 std::string all;
81 for (const auto& n : names) { if (!all.empty()) all += "|"; all += n; }
82 return "Unknown REPORT_2D_VARIABLES token '" + t +
83 "' (expected DEFAULT|MINIMAL|ALL|NONE or " + all + ")";
84 }
85 }
86 mask |= DEPTH;
87 return {};
88}
89
91inline std::string formatMask(unsigned mask) {
92 mask &= ALL_MASK;
93 if (mask == DEFAULT_MASK) return "DEFAULT";
94 if (mask == MINIMAL_MASK) return "MINIMAL";
95 if (mask == ALL_MASK) return "ALL";
96 const auto& names = tokens();
97 std::string out;
98 for (std::size_t i = 0; i < names.size(); ++i) {
99 if (mask & (1u << i)) {
100 if (!out.empty()) out += ' ';
101 out += names[i];
102 }
103 }
104 return out.empty() ? std::string("DEPTH") : out;
105}
106
108inline std::string formatSpecies(const std::vector<std::string>& species) {
109 if (species.empty()) return "ALL";
110 std::string out;
111 for (const auto& n : species) {
112 if (!out.empty()) out += ' ';
113 out += n;
114 }
115 return out;
116}
117
119inline std::vector<std::string> parseSpecies(const std::string& text) {
120 auto v = splitList(text);
121 if (v.size() == 1 && iequalsTok(v[0], "ALL")) v.clear();
122 return v;
123}
124
126inline std::string formatStep(double seconds) {
127 const long total = seconds > 0.0 ? static_cast<long>(seconds + 0.5) : 0L;
128 char buf[32];
129 std::snprintf(buf, sizeof(buf), "%02ld:%02ld:%02ld",
130 total / 3600, (total % 3600) / 60, total % 60);
131 return buf;
132}
133
134} // namespace openswmm::twoD::report2d
135
136#endif // OPENSWMM_ENGINE_2D_REPORT2D_VARS_HPP
Configuration options for the 2D surface routing solver.
Dataset groups the 2D results writer can emit ([2D_OPTIONS] REPORT_2D_VARIABLES). One bit per group; ...
Definition Report2DVars.hpp:25
const std::vector< std::string > & tokens()
Group tokens in bit order (index i ↔ bit 1u << i).
Definition Report2DVars.hpp:28
std::string parseMask(const std::string &text, unsigned &mask)
Parse a token list or a preset (DEFAULT | MINIMAL | ALL | NONE) into a bitmask. DEPTH is always inclu...
Definition Report2DVars.hpp:64
std::string formatMask(unsigned mask)
Preset name when the mask equals one, else the space-separated token list.
Definition Report2DVars.hpp:91
std::vector< std::string > splitList(const std::string &text)
Split on whitespace / commas.
Definition Report2DVars.hpp:45
std::string formatStep(double seconds)
HH:MM:SS (REPORT_STEP spelling).
Definition Report2DVars.hpp:126
std::vector< std::string > parseSpecies(const std::string &text)
Species list from text; "ALL" (alone) → empty list.
Definition Report2DVars.hpp:119
@ ALL_MASK
Definition SolverOptions2D.hpp:193
@ DEPTH
Mesh2_face_depth, Mesh2_face_head.
Definition SolverOptions2D.hpp:182
@ MINIMAL_MASK
MINIMAL: depth map + render reconstruction + envelopes only.
Definition SolverOptions2D.hpp:198
@ DEFAULT_MASK
DEFAULT: everything a user renders or plots; solver diagnostics off.
Definition SolverOptions2D.hpp:195
std::string formatSpecies(const std::vector< std::string > &species)
"ALL" for an empty (unfiltered) list, else the space-separated names.
Definition Report2DVars.hpp:108
bool iequalsTok(const std::string &a, const char *b)
Definition Report2DVars.hpp:36