OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
StorageGeometry.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
43
44#ifndef OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
45#define OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
46
47#include "NodeData.hpp"
48
49#include <cmath>
50#include <string>
51#include <string_view>
52
53namespace openswmm {
54
59inline constexpr double kStoragePi = 3.141592654;
60
72
86inline bool storage_shape_params_valid(StorageShape s, double p1, double p2, double p3) noexcept {
88 return true;
89 if (p1 <= 0.0 || p2 <= 0.0 || p3 < 0.0)
90 return false;
91 if (s == StorageShape::PARABOLOID && p3 == 0.0)
92 return false;
93 return true;
94}
95
120inline bool storage_shape_coeffs(StorageShape s, double p1, double p2, double p3, double& a,
121 double& b, double& c) noexcept {
123 return false;
124 if (!storage_shape_params_valid(s, p1, p2, p3))
125 return false;
126
127 const double A = p1 / 2.0; // base/top semi-axis length
128 const double B = p2 / 2.0; // base/top semi-axis width
129 const double Z = p3; // side slope (run/rise), or height for PARABOLOID
130
131 switch (s) {
133 a = 0.0;
134 b = 0.0;
135 c = kStoragePi * A * B;
136 return true;
138 a = 2.0 * kStoragePi * B * Z;
139 b = kStoragePi * B / A * Z * Z;
140 c = kStoragePi * A * B;
141 return true;
143 a = kStoragePi * A * B / Z; // Z != 0 guaranteed by params_valid
144 b = 0.0;
145 c = 0.0;
146 return true;
148 a = 2.0 * (p1 + p2) * Z; // 2(L + W)Z — full base dims, not semi-axes
149 b = 4.0 * Z * Z;
150 c = p1 * p2; // L·W
151 return true;
152 default:
153 return false;
154 }
155}
156
165inline const char* storage_shape_keyword(StorageShape s) noexcept {
166 switch (s) {
168 return "TABULAR";
170 return "FUNCTIONAL";
172 return "CYLINDRICAL";
174 return "CONICAL";
176 return "PARABOLIC";
178 return "PYRAMIDAL";
179 }
180 return "FUNCTIONAL";
181}
182
192inline bool storage_shape_from_keyword(std::string_view kw, StorageShape& out) noexcept {
193 if (kw == "TABULAR") {
195 return true;
196 }
197 if (kw == "FUNCTIONAL") {
199 return true;
200 }
201 if (kw == "CYLINDRICAL") {
203 return true;
204 }
205 if (kw == "CONICAL") {
207 return true;
208 }
209 if (kw == "PARABOLIC" || kw == "PARABOLOID") {
211 return true;
212 }
213 if (kw == "PYRAMIDAL") {
215 return true;
216 }
217 return false;
218}
219
226inline constexpr bool storage_shape_is_valid_code(int v) noexcept {
227 return v >= static_cast<int>(StorageShape::TABULAR) &&
228 v <= static_cast<int>(StorageShape::PYRAMIDAL);
229}
230
231} // namespace openswmm
232
233#endif // OPENSWMM_ENGINE_DATA_STORAGEGEOMETRY_HPP
Structure-of-Arrays (SoA) storage for all node types.
Definition ExchangeLaw.hpp:60
StorageShape
Storage-unit surface-area relation.
Definition NodeData.hpp:99
@ CONICAL
Elliptical cone (p1, p2 = base axes, p3 = side slope)
Definition NodeData.hpp:103
@ PYRAMIDAL
Rectangular pyramid (p1 = length, p2 = width, p3 = side slope)
Definition NodeData.hpp:105
@ TABULAR
Area vs. depth from a curve (StorageData::curve)
Definition NodeData.hpp:100
@ PARABOLOID
Elliptical paraboloid(p1, p2 = top axes, p3 = height ≠ 0)
Definition NodeData.hpp:104
@ CYLINDRICAL
Elliptical cylinder (p1 = major axis, p2 = minor axis)
Definition NodeData.hpp:102
@ FUNCTIONAL
Area = c + a*d^b.
Definition NodeData.hpp:101
constexpr bool storage_shape_is_valid_code(int v) noexcept
Check whether an integer lies in the public storage-shape ordinal interval.
Definition StorageGeometry.hpp:226
bool storage_shape_from_keyword(std::string_view kw, StorageShape &out) noexcept
Parse a shape keyword (caller upper-cases first).
Definition StorageGeometry.hpp:192
constexpr double kStoragePi
π to the precision legacy uses (src/legacy/engine/consts.h: #define PI 3.141592654,...
Definition StorageGeometry.hpp:59
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:120
bool storage_shape_params_valid(StorageShape s, double p1, double p2, double p3) noexcept
Validate raw shape parameters.
Definition StorageGeometry.hpp:86
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:68
const char * storage_shape_keyword(StorageShape s) noexcept
Canonical INP/GeoPackage keyword for a shape.
Definition StorageGeometry.hpp:165