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
60 void resize(int n);
61};
62
63// ============================================================================
64// InterfaceManager — manages reading/writing of routing interface files
65// ============================================================================
66
68public:
69 void init(SimulationContext& ctx);
70
72 int openFiles(const std::string& infile_path, const std::string& outfile_path);
73
77
79 void writeFileHeader(const SimulationContext& ctx);
80
82 void readInflows(SimulationContext& ctx, double current_time);
83
85 void writeOutfallResults(const SimulationContext& ctx, double current_time);
86
88 void closeFiles();
89
91 double getFlow(int node_idx, double frac) const;
92
94 double getQuality(int node_idx, int pollut_idx, double frac) const;
95
97 int getNumIfaceNodes() const { return data_.count; }
98
100 int getIfaceNode(int index) const;
101
103 double getFrac() const { return iface_frac_; }
104
105private:
106 InterfaceFileSoA data_;
107 FILE* infile_ = nullptr;
108 FILE* outfile_ = nullptr;
109
110 double old_time_ = 0.0;
111 double new_time_ = 0.0;
112 int n_iface_polluts_ = 0;
113 int n_values_per_node_ = 1;
114 int iface_flow_units_ = 0;
115 int iface_step_ = 0;
116 double iface_frac_ = 0.0;
117
118 std::vector<int> pollut_map_;
119
121 bool readNextPeriod();
122
124 void setOldValues();
125
127 static bool isOutletNode(const SimulationContext& ctx, int node_idx);
128};
129
130} // namespace iface
131} // namespace openswmm
132
133#endif // OPENSWMM_INTERFACE_FILE_HPP
Definition InterfaceFile.hpp:67
int getNumIfaceNodes() const
Get number of interface nodes currently active.
Definition InterfaceFile.hpp:97
int readFileHeader(SimulationContext &ctx)
Definition InterfaceFile.cpp:128
void closeFiles()
Close all interface files.
Definition InterfaceFile.cpp:451
void init(SimulationContext &ctx)
Definition InterfaceFile.cpp:80
double getFrac() const
Get the interpolation fraction (set during readInflows)
Definition InterfaceFile.hpp:103
void readInflows(SimulationContext &ctx, double current_time)
Read next set of inflow values from upstream interface file.
Definition InterfaceFile.cpp:290
int getIfaceNode(int index) const
Get the node index for a given interface file entry.
Definition InterfaceFile.cpp:501
void writeOutfallResults(const SimulationContext &ctx, double current_time)
Write current outfall results to downstream interface file.
Definition InterfaceFile.cpp:355
void writeFileHeader(const SimulationContext &ctx)
Write the outflows file header. Called from SWMMEngine::start().
Definition InterfaceFile.cpp:398
double getFlow(int node_idx, double frac) const
Get interpolated interface flow for a node.
Definition InterfaceFile.cpp:466
int openFiles(const std::string &infile_path, const std::string &outfile_path)
Open routing interface files for reading/writing.
Definition InterfaceFile.cpp:100
double getQuality(int node_idx, int pollut_idx, double frac) const
Get interpolated interface quality for a node and pollutant.
Definition InterfaceFile.cpp:480
Definition InterfaceFile.cpp:59
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition InterfaceFile.hpp:54
std::vector< int > node_idx
Node indices in this model.
Definition InterfaceFile.hpp:56
void resize(int n)
Definition InterfaceFile.cpp:68
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