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
32namespace openswmm {
33
42class DefaultOutputPlugin final : public IOutputPlugin {
43public:
48 explicit DefaultOutputPlugin(std::string out_path);
49 ~DefaultOutputPlugin() override = default;
50
51 // -----------------------------------------------------------------------
52 // IOutputPlugin interface
53 // -----------------------------------------------------------------------
54
55 PluginState state() const noexcept override { return state_; }
56
57 int initialize(const std::vector<std::string>& init_args,
58 const IPluginComponentInfo* info) override;
59
60 int validate(const SimulationContext& ctx) override;
61
62 int prepare(const SimulationContext& ctx) override;
63
64 int update(const SimulationSnapshot& snapshot) override;
65
66 int finalize(const SimulationContext& ctx) override;
67
68 const char* last_error_message() const noexcept override {
69 return last_error_.c_str();
70 }
71
72private:
73 std::string out_path_;
75 std::string last_error_;
76 int step_count_ = 0;
77
78 FILE* out_file_ = nullptr;
79 int n_subcatch_ = 0;
80 int n_nodes_ = 0;
81 int n_links_ = 0;
82 int n_polluts_ = 0;
83 int n_subcatch_vars_ = 0;
84 int n_node_vars_ = 0;
85 int n_link_vars_ = 0;
86 long id_start_pos_ = 0;
87 long input_start_pos_ = 0;
88 long output_start_pos_ = 0;
89 int n_periods_ = 0;
90
91 static constexpr int MAGIC_NUMBER = 516114522;
92 static constexpr int VERSION = 52001; // SWMM 5.2.001
93 static constexpr int MAX_SYS_RESULTS = 14;
94
95 void writeHeader(const SimulationContext& ctx);
96 void writeID(const char* id);
97 void writeInt4(int value);
98 void writeReal4(float value);
99 void writeReal8(double value);
100};
101
102} /* namespace openswmm */
103
104#endif /* OPENSWMM_ENGINE_DEFAULT_OUTPUT_PLUGIN_HPP */
Default output plugin: writes SWMM 5.x compatible binary .out file.
Definition DefaultOutputPlugin.hpp:42
int update(const SimulationSnapshot &snapshot) override
Write one output snapshot. Called from the IO thread.
Definition DefaultOutputPlugin.cpp:66
const char * last_error_message() const noexcept override
Get the last error message from this plugin instance.
Definition DefaultOutputPlugin.hpp:68
~DefaultOutputPlugin() override=default
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Definition DefaultOutputPlugin.cpp:36
PluginState state() const noexcept override
Query the current plugin state.
Definition DefaultOutputPlugin.hpp:55
int prepare(const SimulationContext &ctx) override
Open output file(s) and write headers.
Definition DefaultOutputPlugin.cpp:49
int finalize(const SimulationContext &ctx) override
Flush and close output file(s). Called from main thread.
Definition DefaultOutputPlugin.cpp:112
int validate(const SimulationContext &ctx) override
Validate plugin configuration against the simulation model.
Definition DefaultOutputPlugin.cpp:44
Interface for output-writing plugins.
Definition IOutputPlugin.hpp:57
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:57
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:67
@ UNLOADED
Library not yet loaded (or was closed).
Definition Controls.cpp:24
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:90