OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Default2DOutputPlugin.hpp
Go to the documentation of this file.
1
19#pragma once
20
21#ifdef OPENSWMM_HAS_2D
22
23#include "../../../../include/openswmm/plugin_sdk/IOutputPlugin.hpp"
24
25#include <string>
26#include <hdf5.h>
27
28namespace openswmm::twoD {
29
30struct MeshData; // forward declaration
31
69class Default2DOutputPlugin final : public IOutputPlugin {
70public:
75 explicit Default2DOutputPlugin(std::string h5_path);
76 ~Default2DOutputPlugin() override;
77
78 // Non-copyable
79 Default2DOutputPlugin(const Default2DOutputPlugin&) = delete;
80 Default2DOutputPlugin& operator=(const Default2DOutputPlugin&) = delete;
81
82 // -----------------------------------------------------------------------
83 // IOutputPlugin interface
84 // -----------------------------------------------------------------------
85
86 PluginState state() const noexcept override { return state_; }
87
88 int initialize(const std::vector<std::string>& init_args,
89 const IPluginComponentInfo* info) override;
90
91 int validate(const SimulationContext& ctx) override;
92
93 int prepare(const SimulationContext& ctx) override;
94
95 int update(const SimulationSnapshot& snapshot) override;
96
97 int finalize(const SimulationContext& ctx) override;
98
99 const char* last_error_message() const noexcept override {
100 return last_error_.c_str();
101 }
102
112 void prepareMeshAndDatasets(const MeshData& mesh);
113
114private:
115 std::string h5_path_;
116 PluginState state_ = PluginState::UNLOADED;
117 std::string last_error_;
118
119 hid_t file_id_ = H5I_INVALID_HID;
120
121 // Dataset handles for time-varying fields (unlimited time dimension)
122 hid_t ds_time_ = H5I_INVALID_HID;
123 hid_t ds_face_depth_ = H5I_INVALID_HID;
124 hid_t ds_face_head_ = H5I_INVALID_HID;
125 hid_t ds_face_grad_hx_ = H5I_INVALID_HID;
126 hid_t ds_face_grad_hy_ = H5I_INVALID_HID;
127 hid_t ds_face_grad_hx_lim_ = H5I_INVALID_HID;
128 hid_t ds_face_grad_hy_lim_ = H5I_INVALID_HID;
129 hid_t ds_face_rainfall_ = H5I_INVALID_HID;
130 hid_t ds_face_coupling_flux_ = H5I_INVALID_HID;
131 hid_t ds_face_net_source_ = H5I_INVALID_HID;
132 hid_t ds_edge_flux_ = H5I_INVALID_HID;
133 hid_t ds_node_head_ = H5I_INVALID_HID;
134
135 hsize_t n_faces_ = 0;
136 hsize_t n_nodes_ = 0;
137 hsize_t n_steps_ = 0;
138
139 // Helpers
140 void writeMeshTopology(const SimulationContext& ctx);
141 hid_t createUnlimitedDataset(const char* name, int rank,
142 const hsize_t* dims,
143 const hsize_t* chunk_dims);
144 void writeStringAttr(hid_t loc, const char* name, const char* value);
145 void extendAndWrite2D(hid_t ds, const double* data, hsize_t n_cols);
146 void extendAndWrite3D(hid_t ds, const double* data, hsize_t dim1, hsize_t dim2);
147};
148
149} // namespace openswmm::twoD
150
151#endif // OPENSWMM_HAS_2D
const double * data
Definition XSectBatch.cpp:567
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:67
StmtPtr prepare(sqlite3 *db, const std::string &sql)
Definition GpkgUtils.hpp:66
Definition NodeCoupling.cpp:15