OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
InterfaceFile.hpp
Go to the documentation of this file.
1
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
30struct SimulationContext;
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
59 void readInflows(SimulationContext& ctx, double current_time);
60
62 void writeOutfallResults(const SimulationContext& ctx, double current_time);
63
65 void closeFiles();
66
68 double getFlow(int node_idx, double frac) const;
69
71 double getQuality(int node_idx, int pollut_idx, double frac) const;
72
74 int getNumIfaceNodes() const { return data_.count; }
75
77 int getIfaceNode(int index) const;
78
80 double getFrac() const { return iface_frac_; }
81
82private:
83 InterfaceFileSoA data_;
84 FILE* infile_ = nullptr;
85 FILE* outfile_ = nullptr;
86
87 double old_time_ = 0.0;
88 double new_time_ = 0.0;
89 int n_iface_polluts_ = 0;
90 int n_values_per_node_ = 1;
91 int iface_flow_units_ = 0;
92 int iface_step_ = 0;
93 double iface_frac_ = 0.0;
94
95 std::vector<int> pollut_map_;
96
98 int readFileHeader(SimulationContext& ctx);
99
101 bool readNextPeriod();
102
104 void setOldValues();
105
107 void writeFileHeader(const SimulationContext& ctx);
108
110 static bool isOutletNode(const SimulationContext& ctx, int node_idx);
111};
112
113} // namespace iface
114} // namespace openswmm
115
116#endif // OPENSWMM_INTERFACE_FILE_HPP
Definition InterfaceFile.hpp:51
int getNumIfaceNodes() const
Get number of interface nodes currently active.
Definition InterfaceFile.hpp:74
void closeFiles()
Close all interface files.
Definition InterfaceFile.cpp:421
void init(SimulationContext &ctx)
Definition InterfaceFile.cpp:64
double getFrac() const
Get the interpolation fraction (set during readInflows)
Definition InterfaceFile.hpp:80
void readInflows(SimulationContext &ctx, double current_time)
Read next set of inflow values from upstream interface file.
Definition InterfaceFile.cpp:270
int getIfaceNode(int index) const
Get the node index for a given interface file entry.
Definition InterfaceFile.cpp:471
void writeOutfallResults(const SimulationContext &ctx, double current_time)
Write current outfall results to downstream interface file.
Definition InterfaceFile.cpp:328
double getFlow(int node_idx, double frac) const
Get interpolated interface flow for a node.
Definition InterfaceFile.cpp:436
int openFiles(const std::string &infile_path, const std::string &outfile_path)
Open routing interface files for reading/writing.
Definition InterfaceFile.cpp:80
double getQuality(int node_idx, int pollut_idx, double frac) const
Get interpolated interface quality for a node and pollutant.
Definition InterfaceFile.cpp:450
Definition Controls.cpp:24
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
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