OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
DefaultOutputPlugin.hpp
Go to the documentation of this file.
1
23#ifndef OPENSWMM_ENGINE_DEFAULT_OUTPUT_PLUGIN_HPP
24#define OPENSWMM_ENGINE_DEFAULT_OUTPUT_PLUGIN_HPP
25
26#include "../../../include/openswmm/plugin_sdk/IOutputPlugin.hpp"
27
28#include <string>
29#include <atomic>
30#include <cstdio>
31#include <vector>
32
33namespace openswmm {
34
43class DefaultOutputPlugin final : public IOutputPlugin {
44public:
49 explicit DefaultOutputPlugin(std::string out_path);
50 ~DefaultOutputPlugin() override = default;
51
52 // -----------------------------------------------------------------------
53 // IOutputPlugin interface
54 // -----------------------------------------------------------------------
55
56 PluginState state() const noexcept override { return state_; }
57
58 int initialize(const std::vector<std::string>& init_args,
59 const IPluginComponentInfo* info) override;
60
61 int validate(const SimulationContext& ctx) override;
62
63 int prepare(const SimulationContext& ctx) override;
64
65 int update(const SimulationSnapshot& snapshot) override;
66
67 int finalize(const SimulationContext& ctx) override;
68
69 const char* last_error_message() const noexcept override {
70 return last_error_.c_str();
71 }
72
73private:
74 std::string out_path_;
76 std::string last_error_;
77 int step_count_ = 0;
78
79 FILE* out_file_ = nullptr;
80 int n_subcatch_ = 0;
81 int n_nodes_ = 0;
82 int n_links_ = 0;
83 int n_polluts_ = 0;
84 int n_subcatch_vars_ = 0;
85 int n_node_vars_ = 0;
86 int n_link_vars_ = 0;
87 int flow_units_code_ = 0;
88 long id_start_pos_ = 0;
89 long input_start_pos_ = 0;
90 long output_start_pos_ = 0;
91 int n_periods_ = 0;
92
93 // Unit conversion factors (internal → display), computed once in prepare()
94 double ucf_rainfall_ = 1.0;
95 double ucf_raindepth_ = 1.0;
96 double ucf_evaprate_ = 1.0;
97 double ucf_length_ = 1.0;
98 double ucf_landarea_ = 1.0;
99 double ucf_volume_ = 1.0;
100 double ucf_flow_ = 1.0;
101 int unit_system_ = 0; // 0=US, 1=SI
102
103 // Per-object report flags, captured during prepare() from SimulationContext
104 std::vector<char> subcatch_rpt_flag_;
105 std::vector<char> node_rpt_flag_;
106 std::vector<char> link_rpt_flag_;
107
108 static constexpr int MAGIC_NUMBER = 516114522;
109 static constexpr int VERSION = 60000; // SWMM 6.0.000
110 static constexpr int MAX_SYS_RESULTS = 15;
111
112 void writeHeader(const SimulationContext& ctx);
113 void writeID(const char* id);
114 void writeInt4(int value);
115 void writeReal4(float value);
116 void writeReal8(double value);
117};
118
119} /* namespace openswmm */
120
121#endif /* OPENSWMM_ENGINE_DEFAULT_OUTPUT_PLUGIN_HPP */
Default output plugin: writes SWMM 5.x compatible binary .out file.
Definition DefaultOutputPlugin.hpp:43
int update(const SimulationSnapshot &snapshot) override
Write one output snapshot. Called from the IO thread.
Definition DefaultOutputPlugin.cpp:80
const char * last_error_message() const noexcept override
Get the last error message from this plugin instance.
Definition DefaultOutputPlugin.hpp:69
~DefaultOutputPlugin() override=default
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Definition DefaultOutputPlugin.cpp:39
PluginState state() const noexcept override
Query the current plugin state.
Definition DefaultOutputPlugin.hpp:56
int prepare(const SimulationContext &ctx) override
Open output file(s) and write headers.
Definition DefaultOutputPlugin.cpp:52
int finalize(const SimulationContext &ctx) override
Flush and close output file(s). Called from main thread.
Definition DefaultOutputPlugin.cpp:257
int validate(const SimulationContext &ctx) override
Validate plugin configuration against the simulation model.
Definition DefaultOutputPlugin.cpp:47
Interface for output-writing plugins.
Definition IOutputPlugin.hpp:57
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:179
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:67
@ UNLOADED
Library not yet loaded (or was closed).
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:274
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:92