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:
67 virtual ~ICouplingPoint() = default;
68
70 virtual int object_index() const noexcept = 0;
71
73 virtual const char* object_type() const noexcept = 0;
74
76 virtual void exchange_to_2d(double value) = 0;
77
79 virtual double receive_from_2d() const = 0;
80};
81
82// ============================================================================
83// SpatialFrame
84// ============================================================================
85
99 // -----------------------------------------------------------------------
100 // Coordinate reference system
101 // -----------------------------------------------------------------------
102
116 std::string crs;
117
122 bool is_geographic = false;
123
124 // -----------------------------------------------------------------------
125 // Map extents (from [MAP] DIMENSIONS)
126 // -----------------------------------------------------------------------
127
129 double map_x1 = 0.0;
130
132 double map_y1 = 0.0;
133
135 double map_x2 = 0.0;
136
138 double map_y2 = 0.0;
139
144 std::string map_units;
145
146 // -----------------------------------------------------------------------
147 // Node coordinates (indexed parallel to NodeData)
148 // -----------------------------------------------------------------------
149
151 std::vector<double> node_x;
152
154 std::vector<double> node_y;
155
156 // -----------------------------------------------------------------------
157 // Link coordinates (one point per link — nominal centroid or from-node)
158 // -----------------------------------------------------------------------
159
161 std::vector<double> link_x;
162
164 std::vector<double> link_y;
165
166 // -----------------------------------------------------------------------
167 // Subcatchment centroid coordinates
168 // -----------------------------------------------------------------------
169
171 std::vector<double> subcatch_x;
172
174 std::vector<double> subcatch_y;
175
176 // -----------------------------------------------------------------------
177 // Link vertices (polyline points between from-node and to-node)
178 // -----------------------------------------------------------------------
179
181 std::vector<std::vector<double>> link_vertices_x;
182
184 std::vector<std::vector<double>> link_vertices_y;
185
186 // -----------------------------------------------------------------------
187 // Subcatchment polygon vertices
188 // -----------------------------------------------------------------------
189
191 std::vector<std::vector<double>> subcatch_polygon_x;
192
194 std::vector<std::vector<double>> subcatch_polygon_y;
195
196 // -----------------------------------------------------------------------
197 // Gage coordinates
198 // -----------------------------------------------------------------------
199
201 std::vector<double> gage_x;
202
204 std::vector<double> gage_y;
205
206 // -----------------------------------------------------------------------
207 // 2D coupling interface (R30)
208 // -----------------------------------------------------------------------
209
220 std::vector<ICouplingPoint*> coupling_points;
221
227 if (point) coupling_points.push_back(point);
228 }
229
233 bool has_2d_coupling() const noexcept {
234 return !coupling_points.empty();
235 }
236
241 node_x.shrink_to_fit();
242 node_y.shrink_to_fit();
243 link_x.shrink_to_fit();
244 link_y.shrink_to_fit();
245 subcatch_x.shrink_to_fit();
246 subcatch_y.shrink_to_fit();
247 gage_x.shrink_to_fit();
248 gage_y.shrink_to_fit();
249
250 link_vertices_x.shrink_to_fit();
251 for (auto& v : link_vertices_x) v.shrink_to_fit();
252 link_vertices_y.shrink_to_fit();
253 for (auto& v : link_vertices_y) v.shrink_to_fit();
254
255 subcatch_polygon_x.shrink_to_fit();
256 for (auto& v : subcatch_polygon_x) v.shrink_to_fit();
257 subcatch_polygon_y.shrink_to_fit();
258 for (auto& v : subcatch_polygon_y) v.shrink_to_fit();
259 }
260};
261
262} /* namespace openswmm */
263
264#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
virtual void exchange_to_2d(double value)=0
Exchange 1D state to the 2D component at this point.
virtual int object_index() const noexcept=0
Index of the 1D SWMM object (node, link, or subcatch index).
virtual double receive_from_2d() const =0
Receive 2D state from the 2D component at this point.
virtual const char * object_type() const noexcept=0
Type: "NODE", "LINK", or "SUBCATCH".
Definition NodeCoupling.cpp:16
Spatial frame containing CRS and georeferenced coordinates.
Definition SpatialFrame.hpp:98
double map_x2
Map extent maximum X (right).
Definition SpatialFrame.hpp:135
std::vector< double > link_x
Link centroid X coordinates.
Definition SpatialFrame.hpp:161
void shrink_to_fit()
Release excess vector capacity accumulated during parsing.
Definition SpatialFrame.hpp:240
void register_coupling_point(ICouplingPoint *point)
Register a 2D coupling point.
Definition SpatialFrame.hpp:226
std::vector< double > subcatch_x
Subcatchment centroid X.
Definition SpatialFrame.hpp:171
std::vector< double > node_x
Node X coordinates (easting or longitude).
Definition SpatialFrame.hpp:151
std::vector< double > gage_x
Gage X coordinates.
Definition SpatialFrame.hpp:201
std::vector< double > gage_y
Gage Y coordinates.
Definition SpatialFrame.hpp:204
std::string crs
CRS specification string.
Definition SpatialFrame.hpp:116
std::vector< std::vector< double > > subcatch_polygon_y
Per-subcatchment polygon Y vertices.
Definition SpatialFrame.hpp:194
double map_x1
Map extent minimum X (left).
Definition SpatialFrame.hpp:129
bool has_2d_coupling() const noexcept
Returns true if any 2D coupling points are registered.
Definition SpatialFrame.hpp:233
bool is_geographic
True if the CRS represents geographic coordinates (lon/lat).
Definition SpatialFrame.hpp:122
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:181
std::vector< double > link_y
Link centroid Y coordinates.
Definition SpatialFrame.hpp:164
std::vector< std::vector< double > > subcatch_polygon_x
Per-subcatchment polygon X vertices.
Definition SpatialFrame.hpp:191
double map_y1
Map extent minimum Y (bottom).
Definition SpatialFrame.hpp:132
std::vector< double > node_y
Node Y coordinates (northing or latitude).
Definition SpatialFrame.hpp:154
double map_y2
Map extent maximum Y (top).
Definition SpatialFrame.hpp:138
std::string map_units
Map units string from [MAP] UNITS keyword.
Definition SpatialFrame.hpp:144
std::vector< double > subcatch_y
Subcatchment centroid Y.
Definition SpatialFrame.hpp:174
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:184
std::vector< ICouplingPoint * > coupling_points
Registered 2D coupling points.
Definition SpatialFrame.hpp:220