OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
RunoffInterface.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
62
63#ifndef OPENSWMM_RUNOFF_INTERFACE_HPP
64#define OPENSWMM_RUNOFF_INTERFACE_HPP
65
66#include <string>
67#include <vector>
68#include <cstdio>
69
70namespace openswmm {
71
73
74namespace runoff_iface {
75
76static constexpr int N_FIXED_RESULTS = 8;
77static const char FILE_STAMP[] = "SWMM5-RUNOFF";
78
83public:
85
90 int openForWrite(const std::string& path, int n_subcatch, int n_pollut,
91 int flow_units);
92
97 int openForRead(const std::string& path, int n_subcatch, int n_pollut,
98 int flow_units);
99
105 void saveResults(const SimulationContext& ctx, double dt);
106
116 bool readResults(SimulationContext& ctx, double* dt_out = nullptr);
117
119 void close();
120
121 bool isOpen() const { return fp_ != nullptr; }
122
123private:
124 std::FILE* fp_ = nullptr;
125 bool writing_ = false;
126 int n_subcatch_ = 0;
127 int n_pollut_ = 0;
128 int n_results_ = 0;
129 int flow_units_ = 0;
130 int unit_system_ = 0;
131 int step_count_ = 0;
132 long max_steps_pos_ = 0;
133 std::vector<float> buf_;
134};
135
136} // namespace runoff_iface
137} // namespace openswmm
138
139#endif // OPENSWMM_RUNOFF_INTERFACE_HPP
Runoff interface file manager.
Definition RunoffInterface.hpp:82
~RunoffInterfaceFile()
Definition RunoffInterface.hpp:84
int openForWrite(const std::string &path, int n_subcatch, int n_pollut, int flow_units)
Open file for writing (SAVE mode).
Definition RunoffInterface.cpp:49
bool readResults(SimulationContext &ctx, double *dt_out=nullptr)
Read one timestep of runoff results from file.
Definition RunoffInterface.cpp:193
void close()
Close the file and finalize header (write step count for SAVE mode).
Definition RunoffInterface.cpp:240
int openForRead(const std::string &path, int n_subcatch, int n_pollut, int flow_units)
Open file for reading (USE mode).
Definition RunoffInterface.cpp:87
bool isOpen() const
Definition RunoffInterface.hpp:121
void saveResults(const SimulationContext &ctx, double dt)
Save one timestep of runoff results to file.
Definition RunoffInterface.cpp:134
Definition RunoffInterface.cpp:37
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353