OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SpatialFrame.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
42
43#ifndef OPENSWMM_ENGINE_SPATIAL_FRAME_HPP
44#define OPENSWMM_ENGINE_SPATIAL_FRAME_HPP
45
46#include <string>
47#include <vector>
48#include <cstdint>
49
50namespace openswmm {
51
52// ============================================================================
53// Forward declarations for 2D coupling (R30)
54// ============================================================================
55
66public:
73 virtual ~ICouplingPoint() = default;
74
80 virtual int object_index() const noexcept = 0;
81
87 virtual const char* object_type() const noexcept = 0;
88
97 virtual void exchange_to_2d(double value) = 0;
98
104 virtual double receive_from_2d() const = 0;
105};
106
107// ============================================================================
108// SpatialFrame
109// ============================================================================
110
124 // -----------------------------------------------------------------------
125 // Coordinate reference system
126 // -----------------------------------------------------------------------
127
141 std::string crs;
142
147 bool is_geographic = false;
148
149 // -----------------------------------------------------------------------
150 // Map extents (from [MAP] DIMENSIONS)
151 // -----------------------------------------------------------------------
152
154 double map_x1 = 0.0;
155
157 double map_y1 = 0.0;
158
160 double map_x2 = 0.0;
161
163 double map_y2 = 0.0;
164
169 std::string map_units;
170
171 // -----------------------------------------------------------------------
172 // Node coordinates (indexed parallel to NodeData)
173 // -----------------------------------------------------------------------
174
176 std::vector<double> node_x;
177
179 std::vector<double> node_y;
180
185 std::vector<uint8_t> node_has_xy;
186
187 // -----------------------------------------------------------------------
188 // Link coordinates (one point per link — nominal centroid or from-node)
189 // -----------------------------------------------------------------------
190
192 std::vector<double> link_x;
193
195 std::vector<double> link_y;
196
197 // -----------------------------------------------------------------------
198 // Subcatchment centroid coordinates
199 // -----------------------------------------------------------------------
200
202 std::vector<double> subcatch_x;
203
205 std::vector<double> subcatch_y;
206
207 // -----------------------------------------------------------------------
208 // Link vertices (polyline points between from-node and to-node)
209 // -----------------------------------------------------------------------
210
212 std::vector<std::vector<double>> link_vertices_x;
213
215 std::vector<std::vector<double>> link_vertices_y;
216
217 // -----------------------------------------------------------------------
218 // Subcatchment polygon vertices
219 // -----------------------------------------------------------------------
220
223 std::vector<std::vector<double>> subcatch_polygon_x;
224
226 std::vector<std::vector<double>> subcatch_polygon_y;
227
228 // -----------------------------------------------------------------------
229 // Gage coordinates
230 // -----------------------------------------------------------------------
231
233 std::vector<double> gage_x;
234
236 std::vector<double> gage_y;
237
238 // -----------------------------------------------------------------------
239 // 2D coupling interface (R30)
240 // -----------------------------------------------------------------------
241
252 std::vector<ICouplingPoint*> coupling_points;
253
264 if (point)
265 coupling_points.push_back(point);
266 }
267
273 bool has_2d_coupling() const noexcept { return !coupling_points.empty(); }
274
283 node_x.shrink_to_fit();
284 node_y.shrink_to_fit();
285 link_x.shrink_to_fit();
286 link_y.shrink_to_fit();
287 subcatch_x.shrink_to_fit();
288 subcatch_y.shrink_to_fit();
289 gage_x.shrink_to_fit();
290 gage_y.shrink_to_fit();
291
292 link_vertices_x.shrink_to_fit();
293 for (auto& v : link_vertices_x)
294 v.shrink_to_fit();
295 link_vertices_y.shrink_to_fit();
296 for (auto& v : link_vertices_y)
297 v.shrink_to_fit();
298
299 subcatch_polygon_x.shrink_to_fit();
300 for (auto& v : subcatch_polygon_x)
301 v.shrink_to_fit();
302 subcatch_polygon_y.shrink_to_fit();
303 for (auto& v : subcatch_polygon_y)
304 v.shrink_to_fit();
305 }
306};
307
308} /* namespace openswmm */
309
310#endif /* OPENSWMM_ENGINE_SPATIAL_FRAME_HPP */
Abstract coupling point between a 1D SWMM object and a 2D mesh cell.
Definition SpatialFrame.hpp:65
virtual ~ICouplingPoint()=default
Destroy the concrete coupling point through its interface.
virtual void exchange_to_2d(double value)=0
Deliver a 1D-side sample to the concrete coupling implementation.
virtual int object_index() const noexcept=0
Identify the referenced 1D object within its type-specific table.
virtual double receive_from_2d() const =0
Read the sample provided by the concrete 2D coupling implementation.
virtual const char * object_type() const noexcept=0
Identify the referenced 1D object category.
Definition ExchangeLaw.hpp:60
Spatial frame containing CRS and georeferenced coordinates.
Definition SpatialFrame.hpp:123
double map_x2
Map extent maximum X (right).
Definition SpatialFrame.hpp:160
std::vector< double > link_x
Link centroid X coordinates.
Definition SpatialFrame.hpp:192
void shrink_to_fit()
Request capacity reduction for coordinate and vertex arrays.
Definition SpatialFrame.hpp:282
void register_coupling_point(ICouplingPoint *point)
Append a borrowed coupling point without deduplication.
Definition SpatialFrame.hpp:263
std::vector< double > subcatch_x
Subcatchment centroid X.
Definition SpatialFrame.hpp:202
std::vector< double > node_x
Node X coordinates (easting or longitude).
Definition SpatialFrame.hpp:176
std::vector< double > gage_x
Gage X coordinates.
Definition SpatialFrame.hpp:233
std::vector< double > gage_y
Gage Y coordinates.
Definition SpatialFrame.hpp:236
std::string crs
CRS specification string.
Definition SpatialFrame.hpp:141
std::vector< std::vector< double > > subcatch_polygon_y
Per-subcatchment polygon Y vertices.
Definition SpatialFrame.hpp:226
double map_x1
Map extent minimum X (left).
Definition SpatialFrame.hpp:154
bool has_2d_coupling() const noexcept
Check whether the registration vector contains any entries.
Definition SpatialFrame.hpp:273
bool is_geographic
True if the CRS represents geographic coordinates (lon/lat).
Definition SpatialFrame.hpp:147
std::vector< std::vector< double > > link_vertices_x
Per-link X vertices. link_vertices_x[link_idx] is a vector of X coords.
Definition SpatialFrame.hpp:212
std::vector< double > link_y
Link centroid Y coordinates.
Definition SpatialFrame.hpp:195
std::vector< std::vector< double > > subcatch_polygon_x
Per-subcatchment X vertices. Multiple rings are concatenated with explicit closures; the final ring m...
Definition SpatialFrame.hpp:223
std::vector< uint8_t > node_has_xy
G-X2 (2026-09-19): 1 when the node's coordinates were authored ([COORDINATES], the GeoPackage geometr...
Definition SpatialFrame.hpp:185
double map_y1
Map extent minimum Y (bottom).
Definition SpatialFrame.hpp:157
std::vector< double > node_y
Node Y coordinates (northing or latitude).
Definition SpatialFrame.hpp:179
double map_y2
Map extent maximum Y (top).
Definition SpatialFrame.hpp:163
std::string map_units
Map units string from [MAP] UNITS keyword.
Definition SpatialFrame.hpp:169
std::vector< double > subcatch_y
Subcatchment centroid Y.
Definition SpatialFrame.hpp:205
std::vector< std::vector< double > > link_vertices_y
Per-link Y vertices. link_vertices_y[link_idx] is a vector of Y coords.
Definition SpatialFrame.hpp:215
std::vector< ICouplingPoint * > coupling_points
Registered 2D coupling points.
Definition SpatialFrame.hpp:252