OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
InterfaceFile.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
36
37#ifndef OPENSWMM_INTERFACE_FILE_HPP
38#define OPENSWMM_INTERFACE_FILE_HPP
39
40#include <vector>
41#include <string>
42#include <cstdio>
43
44namespace openswmm {
45
47
48namespace iface {
49
50// ============================================================================
51// SoA for interface node data (flows + quality per node)
52// ============================================================================
53
55 int count = 0;
56 std::vector<int> node_idx;
57 std::vector<double> old_values;
58 std::vector<double> new_values;
59
69 void resize(int n);
70};
71
72// ============================================================================
73// InterfaceManager — manages reading/writing of routing interface files
74// ============================================================================
75
77public:
88 void init(SimulationContext& ctx);
89
103 int openFiles(const std::string& infile_path, const std::string& outfile_path);
104
118
129 void writeFileHeader(const SimulationContext& ctx);
130
144 void readInflows(SimulationContext& ctx, double current_time);
145
157 void writeOutfallResults(const SimulationContext& ctx, double current_time);
158
165 void closeFiles();
166
179 double getFlow(int node_idx, double frac) const;
180
192 double getQuality(int node_idx, int pollut_idx, double frac) const;
193
195 int getNumIfaceNodes() const { return data_.count; }
196
203 int getIfaceNode(int index) const;
204
206 double getFrac() const { return iface_frac_; }
207
208private:
209 InterfaceFileSoA data_;
210 FILE* infile_ = nullptr;
211 FILE* outfile_ = nullptr;
212
213 double old_time_ = 0.0;
214 double new_time_ = 0.0;
215 int n_iface_polluts_ = 0;
216 int n_values_per_node_ = 1;
217 int iface_flow_units_ = 0;
218 int iface_step_ = 0;
219 double iface_frac_ = 0.0;
220
221 std::vector<int> pollut_map_;
222
232 bool readNextPeriod();
233
240 void setOldValues();
241
249 static bool isOutletNode(const SimulationContext& ctx, int node_idx);
250};
251
252} // namespace iface
253} // namespace openswmm
254
255#endif // OPENSWMM_INTERFACE_FILE_HPP
Definition InterfaceFile.hpp:76
int getNumIfaceNodes() const
Get number of interface nodes currently active.
Definition InterfaceFile.hpp:195
int readFileHeader(SimulationContext &ctx)
Read interface units, constituent mapping, nodes and the first data period.
Definition InterfaceFile.cpp:131
void closeFiles()
Close both owned interface streams if open.
Definition InterfaceFile.cpp:507
void init(SimulationContext &ctx)
Close prior files and reset per-run interpolation/mapping metadata.
Definition InterfaceFile.cpp:82
double getFrac() const
Get the interpolation fraction (set during readInflows)
Definition InterfaceFile.hpp:206
void readInflows(SimulationContext &ctx, double current_time)
Advance file periods and add interpolated flow/quality into model source arrays.
Definition InterfaceFile.cpp:336
int getIfaceNode(int index) const
Translate an interface file entry into a project node index.
Definition InterfaceFile.cpp:558
void writeOutfallResults(const SimulationContext &ctx, double current_time)
Append one period of selected outlet flow and pollutant results.
Definition InterfaceFile.cpp:408
void writeFileHeader(const SimulationContext &ctx)
Write the routing interface header for current outlet nodes.
Definition InterfaceFile.cpp:451
double getFlow(int node_idx, double frac) const
Interpolate flow for an interface-entry index.
Definition InterfaceFile.cpp:522
int openFiles(const std::string &infile_path, const std::string &outfile_path)
Open optional text routing interface streams.
Definition InterfaceFile.cpp:102
double getQuality(int node_idx, int pollut_idx, double frac) const
Interpolate a mapped pollutant concentration for an interface entry.
Definition InterfaceFile.cpp:536
Definition InterfaceFile.cpp:61
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition InterfaceFile.hpp:54
std::vector< int > node_idx
Node indices in this model.
Definition InterfaceFile.hpp:56
void resize(int n)
Replace interface-node mappings while retaining value arrays.
Definition InterfaceFile.cpp:70
std::vector< double > new_values
Current timestep values (flow + polluts per node)
Definition InterfaceFile.hpp:58
int count
Definition InterfaceFile.hpp:55
std::vector< double > old_values
Previous timestep values (flow + polluts per node)
Definition InterfaceFile.hpp:57