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
87public:
91
101 int openForWrite(const std::string& path, int n_subcatch, int n_pollut, int flow_units);
102
114 int openForRead(const std::string& path, int n_subcatch, int n_pollut, int flow_units);
115
126 void saveResults(const SimulationContext& ctx, double dt);
127
139 bool readResults(SimulationContext& ctx, double* dt_out = nullptr);
140
145 void close();
146
150 bool isOpen() const { return fp_ != nullptr; }
151
152private:
153 std::FILE* fp_ = nullptr;
154 bool writing_ = false;
155 int n_subcatch_ = 0;
156 int n_pollut_ = 0;
157 int n_results_ = 0;
158 int flow_units_ = 0;
159 int unit_system_ = 0;
160 int step_count_ = 0;
161 long max_steps_pos_ = 0;
162 std::vector<float> buf_;
163};
164
165} // namespace runoff_iface
166} // namespace openswmm
167
168#endif // OPENSWMM_RUNOFF_INTERFACE_HPP
Runoff interface file manager.
Definition RunoffInterface.hpp:86
~RunoffInterfaceFile()
Finalize a SAVE header and close any owned stream through close(). Close/write errors are ignored; ca...
Definition RunoffInterface.hpp:90
int openForWrite(const std::string &path, int n_subcatch, int n_pollut, int flow_units)
Open/truncate a binary runoff output and write a placeholder header.
Definition RunoffInterface.cpp:50
bool readResults(SimulationContext &ctx, double *dt_out=nullptr)
Restore one timestep's native runoff record with legacy unit conversions.
Definition RunoffInterface.cpp:194
void close()
Backpatch SAVE maxSteps then close the owned stream. Safe when closed; ignores seek/write/close failu...
Definition RunoffInterface.cpp:241
int openForRead(const std::string &path, int n_subcatch, int n_pollut, int flow_units)
Open a compatible native runoff file and position at its first record.
Definition RunoffInterface.cpp:89
bool isOpen() const
Test owned stream presence.
Definition RunoffInterface.hpp:150
void saveResults(const SimulationContext &ctx, double dt)
Append one native timestep and project-unit subcatchment result record.
Definition RunoffInterface.cpp:136
Definition RunoffInterface.cpp:38
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390