OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
InterfaceFile.hpp
Go to the documentation of this file.
1
20
21#ifndef OPENSWMM_INTERFACE_FILE_HPP
22#define OPENSWMM_INTERFACE_FILE_HPP
23
24#include <vector>
25#include <string>
26#include <cstdio>
27
28namespace openswmm {
29
31
32namespace iface {
33
34// ============================================================================
35// SoA for interface node data (flows + quality per node)
36// ============================================================================
37
39 int count = 0;
40 std::vector<int> node_idx;
41 std::vector<double> old_values;
42 std::vector<double> new_values;
43
44 void resize(int n);
45};
46
47// ============================================================================
48// InterfaceManager — manages reading/writing of routing interface files
49// ============================================================================
50
52public:
53 void init(SimulationContext& ctx);
54
56 int openFiles(const std::string& infile_path, const std::string& outfile_path);
57
61
63 void writeFileHeader(const SimulationContext& ctx);
64
66 void readInflows(SimulationContext& ctx, double current_time);
67
69 void writeOutfallResults(const SimulationContext& ctx, double current_time);
70
72 void closeFiles();
73
75 double getFlow(int node_idx, double frac) const;
76
78 double getQuality(int node_idx, int pollut_idx, double frac) const;
79
81 int getNumIfaceNodes() const { return data_.count; }
82
84 int getIfaceNode(int index) const;
85
87 double getFrac() const { return iface_frac_; }
88
89private:
90 InterfaceFileSoA data_;
91 FILE* infile_ = nullptr;
92 FILE* outfile_ = nullptr;
93
94 double old_time_ = 0.0;
95 double new_time_ = 0.0;
96 int n_iface_polluts_ = 0;
97 int n_values_per_node_ = 1;
98 int iface_flow_units_ = 0;
99 int iface_step_ = 0;
100 double iface_frac_ = 0.0;
101
102 std::vector<int> pollut_map_;
103
105 bool readNextPeriod();
106
108 void setOldValues();
109
111 static bool isOutletNode(const SimulationContext& ctx, int node_idx);
112};
113
114} // namespace iface
115} // namespace openswmm
116
117#endif // OPENSWMM_INTERFACE_FILE_HPP
Definition InterfaceFile.hpp:51
int getNumIfaceNodes() const
Get number of interface nodes currently active.
Definition InterfaceFile.hpp:81
int readFileHeader(SimulationContext &ctx)
Definition InterfaceFile.cpp:112
void closeFiles()
Close all interface files.
Definition InterfaceFile.cpp:435
void init(SimulationContext &ctx)
Definition InterfaceFile.cpp:64
double getFrac() const
Get the interpolation fraction (set during readInflows)
Definition InterfaceFile.hpp:87
void readInflows(SimulationContext &ctx, double current_time)
Read next set of inflow values from upstream interface file.
Definition InterfaceFile.cpp:274
int getIfaceNode(int index) const
Get the node index for a given interface file entry.
Definition InterfaceFile.cpp:485
void writeOutfallResults(const SimulationContext &ctx, double current_time)
Write current outfall results to downstream interface file.
Definition InterfaceFile.cpp:339
void writeFileHeader(const SimulationContext &ctx)
Write the outflows file header. Called from SWMMEngine::start().
Definition InterfaceFile.cpp:382
double getFlow(int node_idx, double frac) const
Get interpolated interface flow for a node.
Definition InterfaceFile.cpp:450
int openFiles(const std::string &infile_path, const std::string &outfile_path)
Open routing interface files for reading/writing.
Definition InterfaceFile.cpp:84
double getQuality(int node_idx, int pollut_idx, double frac) const
Get interpolated interface quality for a node and pollutant.
Definition InterfaceFile.cpp:464
Definition InterfaceFile.cpp:43
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:292
Definition InterfaceFile.hpp:38
std::vector< int > node_idx
Node indices in this model.
Definition InterfaceFile.hpp:40
void resize(int n)
Definition InterfaceFile.cpp:52
std::vector< double > new_values
Current timestep values (flow + polluts per node)
Definition InterfaceFile.hpp:42
int count
Definition InterfaceFile.hpp:39
std::vector< double > old_values
Previous timestep values (flow + polluts per node)
Definition InterfaceFile.hpp:41