OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
StorageGeometry.hpp
Go to the documentation of this file.
1
27
28#ifndef OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
29#define OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
30
31#include "NodeData.hpp"
32
33#include <cmath>
34#include <string>
35#include <string_view>
36
37namespace openswmm {
38
40inline constexpr double kStoragePi = 3.141592653589793;
41
50
58 double p1, double p2, double p3) noexcept {
59 if (!storage_shape_is_geometric(s)) return true;
60 if (p1 <= 0.0 || p2 <= 0.0 || p3 < 0.0) return false;
61 if (s == StorageShape::PARABOLOID && p3 == 0.0) return false;
62 return true;
63}
64
83inline bool storage_shape_coeffs(StorageShape s, double p1, double p2, double p3,
84 double& a, double& b, double& c) noexcept {
85 if (!storage_shape_is_geometric(s)) return false;
86 if (!storage_shape_params_valid(s, p1, p2, p3)) return false;
87
88 const double A = p1 / 2.0; // base/top semi-axis length
89 const double B = p2 / 2.0; // base/top semi-axis width
90 const double Z = p3; // side slope (run/rise), or height for PARABOLOID
91
92 switch (s) {
94 a = 0.0;
95 b = 0.0;
96 c = kStoragePi * A * B;
97 return true;
99 a = 2.0 * kStoragePi * B * Z;
100 b = kStoragePi * B / A * Z * Z;
101 c = kStoragePi * A * B;
102 return true;
104 a = kStoragePi * A * B / Z; // Z != 0 guaranteed by params_valid
105 b = 0.0;
106 c = 0.0;
107 return true;
109 a = 2.0 * (p1 + p2) * Z; // 2(L + W)Z — full base dims, not semi-axes
110 b = 4.0 * Z * Z;
111 c = p1 * p2; // L·W
112 return true;
113 default:
114 return false;
115 }
116}
117
123inline const char* storage_shape_keyword(StorageShape s) noexcept {
124 switch (s) {
125 case StorageShape::TABULAR: return "TABULAR";
126 case StorageShape::FUNCTIONAL: return "FUNCTIONAL";
127 case StorageShape::CYLINDRICAL: return "CYLINDRICAL";
128 case StorageShape::CONICAL: return "CONICAL";
129 case StorageShape::PARABOLOID: return "PARABOLIC";
130 case StorageShape::PYRAMIDAL: return "PYRAMIDAL";
131 }
132 return "FUNCTIONAL";
133}
134
141inline bool storage_shape_from_keyword(std::string_view kw, StorageShape& out) noexcept {
142 if (kw == "TABULAR") { out = StorageShape::TABULAR; return true; }
143 if (kw == "FUNCTIONAL") { out = StorageShape::FUNCTIONAL; return true; }
144 if (kw == "CYLINDRICAL") { out = StorageShape::CYLINDRICAL; return true; }
145 if (kw == "CONICAL") { out = StorageShape::CONICAL; return true; }
146 if (kw == "PARABOLIC" || kw == "PARABOLOID")
147 { out = StorageShape::PARABOLOID; return true; }
148 if (kw == "PYRAMIDAL") { out = StorageShape::PYRAMIDAL; return true; }
149 return false;
150}
151
153inline constexpr bool storage_shape_is_valid_code(int v) noexcept {
154 return v >= static_cast<int>(StorageShape::TABULAR) &&
155 v <= static_cast<int>(StorageShape::PYRAMIDAL);
156}
157
158} // namespace openswmm
159
160#endif // OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
Structure-of-Arrays (SoA) storage for all node types.
Definition NodeCoupling.cpp:15
StorageShape
Storage-unit surface-area relation.
Definition NodeData.hpp:88
@ CONICAL
Elliptical cone (p1, p2 = base axes, p3 = side slope)
Definition NodeData.hpp:92
@ PYRAMIDAL
Rectangular pyramid (p1 = length, p2 = width, p3 = side slope)
Definition NodeData.hpp:94
@ TABULAR
Area vs. depth from a curve (StorageData::curve)
Definition NodeData.hpp:89
@ PARABOLOID
Elliptical paraboloid(p1, p2 = top axes, p3 = height ≠ 0)
Definition NodeData.hpp:93
@ CYLINDRICAL
Elliptical cylinder (p1 = major axis, p2 = minor axis)
Definition NodeData.hpp:91
@ FUNCTIONAL
Area = c + a*d^b.
Definition NodeData.hpp:90
constexpr bool storage_shape_is_valid_code(int v) noexcept
True when v is a valid StorageShape ordinal (C API boundary check).
Definition StorageGeometry.hpp:153
bool storage_shape_from_keyword(std::string_view kw, StorageShape &out) noexcept
Parse a shape keyword (caller upper-cases first).
Definition StorageGeometry.hpp:141
constexpr double kStoragePi
π to the precision legacy uses (src/legacy/engine/consts.h).
Definition StorageGeometry.hpp:40
bool storage_shape_coeffs(StorageShape s, double p1, double p2, double p3, double &a, double &b, double &c) noexcept
Derive the area-relation coefficients for a geometric shape.
Definition StorageGeometry.hpp:83
bool storage_shape_params_valid(StorageShape s, double p1, double p2, double p3) noexcept
Validate raw shape parameters.
Definition StorageGeometry.hpp:57
constexpr bool storage_shape_is_geometric(StorageShape s) noexcept
True when s is one of the four geometric shapes (i.e. its a/b/c are the quadratic coefficients,...
Definition StorageGeometry.hpp:46
const char * storage_shape_keyword(StorageShape s) noexcept
Canonical INP/GeoPackage keyword for a shape.
Definition StorageGeometry.hpp:123