OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
RdiiInterface.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
47
48#ifndef OPENSWMM_RDII_INTERFACE_HPP
49#define OPENSWMM_RDII_INTERFACE_HPP
50
51#include <cstdio>
52#include <string>
53#include <vector>
54
55namespace openswmm {
56
58
59namespace rdii_iface {
60
61static const char RDII_FILE_STAMP[] = "SWMM5-RDII";
62
67public:
69
76 int openForRead(SimulationContext& ctx, const std::string& path);
77
84 int openForWrite(const std::string& path, int rdii_step,
85 const std::vector<int>& node_idx);
86
91 void applyFlows(SimulationContext& ctx, double current_date);
92
98 void saveFlows(double current_date, const std::vector<double>& node_flows);
99
100 void close();
101
102 bool isOpen() const { return fp_ != nullptr; }
103 bool isWriting() const { return writing_; }
104 int step() const { return rdii_step_; }
105
106private:
107 std::FILE* fp_ = nullptr;
108 bool writing_ = false;
109 bool binary_ = true;
110
111 int rdii_step_ = 0;
112 int flow_units_ = 0;
113 std::vector<int> node_idx_;
114 std::vector<float> flows_;
115 double start_date_ = 0.0;
116 double end_date_ = 0.0;
117 bool have_record_ = false;
118
119 int readBinaryHeader(SimulationContext& ctx);
120 int readTextHeader(SimulationContext& ctx);
121 bool readNextRecord();
122};
123
124} // namespace rdii_iface
125} // namespace openswmm
126
127#endif // OPENSWMM_RDII_INTERFACE_HPP
RDII interface file manager (USE = read/override, SAVE = export).
Definition RdiiInterface.hpp:66
bool isWriting() const
Definition RdiiInterface.hpp:103
int openForRead(SimulationContext &ctx, const std::string &path)
Open an existing RDII file for reading (USE mode).
Definition RdiiInterface.cpp:52
bool isOpen() const
Definition RdiiInterface.hpp:102
~RdiiInterfaceFile()
Definition RdiiInterface.hpp:68
void applyFlows(SimulationContext &ctx, double current_date)
USE mode: add the file's RDII flows for current_date to ctx.nodes.rdii_inflow (step-aligned,...
Definition RdiiInterface.cpp:216
int openForWrite(const std::string &path, int rdii_step, const std::vector< int > &node_idx)
Open an RDII file for writing (SAVE mode, binary format).
Definition RdiiInterface.cpp:240
int step() const
Definition RdiiInterface.hpp:104
void close()
Definition RdiiInterface.cpp:286
void saveFlows(double current_date, const std::vector< double > &node_flows)
SAVE mode: write one record (date + per-node flows in cfs).
Definition RdiiInterface.cpp:269
Definition RdiiInterface.cpp:41
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353