OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
Default2DOutputPlugin.hpp
Go to the documentation of this file.
1
18
19#pragma once
20
21#ifdef OPENSWMM_HAS_2D
22
24
25#include <string>
26#include <hdf5.h>
27
28namespace openswmm::twoD {
29
30struct MeshData; // forward declaration
31
80class Default2DOutputPlugin final : public IOutputPlugin {
81public:
86 explicit Default2DOutputPlugin(std::string h5_path);
87 ~Default2DOutputPlugin() override;
88
89 // Non-copyable
90 Default2DOutputPlugin(const Default2DOutputPlugin&) = delete;
91 Default2DOutputPlugin& operator=(const Default2DOutputPlugin&) = delete;
92
93 // -----------------------------------------------------------------------
94 // IOutputPlugin interface
95 // -----------------------------------------------------------------------
96
97 PluginState state() const noexcept override { return state_; }
98
99 int initialize(const std::vector<std::string>& init_args,
100 const IPluginComponentInfo* info) override;
101
102 int validate(const SimulationContext& ctx) override;
103
104 int prepare(const SimulationContext& ctx) override;
105
106 int update(const SimulationSnapshot& snapshot) override;
107
108 int finalize(const SimulationContext& ctx) override;
109
110 const char* last_error_message() const noexcept override {
111 return last_error_.c_str();
112 }
113
123 void prepareMeshAndDatasets(const MeshData& mesh);
124
125private:
126 std::string h5_path_;
127 PluginState state_ = PluginState::UNLOADED;
128 std::string last_error_;
129
130 hid_t file_id_ = H5I_INVALID_HID;
131
132 // Dataset handles for time-varying fields (unlimited time dimension)
133 hid_t ds_time_ = H5I_INVALID_HID;
134 hid_t ds_face_depth_ = H5I_INVALID_HID;
135 hid_t ds_face_head_ = H5I_INVALID_HID;
136 hid_t ds_face_grad_hx_ = H5I_INVALID_HID;
137 hid_t ds_face_grad_hy_ = H5I_INVALID_HID;
138 hid_t ds_face_grad_hx_lim_ = H5I_INVALID_HID;
139 hid_t ds_face_grad_hy_lim_ = H5I_INVALID_HID;
140 hid_t ds_face_rainfall_ = H5I_INVALID_HID;
141 hid_t ds_face_coupling_flux_ = H5I_INVALID_HID;
142 hid_t ds_face_net_source_ = H5I_INVALID_HID;
143 hid_t ds_face_vx_ = H5I_INVALID_HID;
144 hid_t ds_face_vy_ = H5I_INVALID_HID;
145 hid_t ds_face_continuity_err_ = H5I_INVALID_HID;
146 hid_t ds_edge_flux_ = H5I_INVALID_HID;
147 hid_t ds_node_head_ = H5I_INVALID_HID;
148
149 // Cumulative envelopes — fixed [nFace], overwritten in place each update()
150 hid_t ds_face_max_depth_ = H5I_INVALID_HID;
151 hid_t ds_face_max_velocity_ = H5I_INVALID_HID;
152 hid_t ds_face_max_continuity_err_ = H5I_INVALID_HID;
153
154 hsize_t n_faces_ = 0;
155 hsize_t n_nodes_ = 0;
156 hsize_t n_steps_ = 0;
157
158 // Helpers
159 void writeMeshTopology(const SimulationContext& ctx);
160 hid_t createUnlimitedDataset(const char* name, int rank,
161 const hsize_t* dims,
162 const hsize_t* chunk_dims);
163 void writeStringAttr(hid_t loc, const char* name, const char* value);
164 void writeDoubleAttr(hid_t loc, const char* name, double value);
165 void extendAndWrite2D(hid_t ds, const double* data, hsize_t n_cols);
166 void extendAndWrite3D(hid_t ds, const double* data, hsize_t dim1, hsize_t dim2);
168 hid_t createFaceEnvelopeDataset(const char* name, const char* long_name,
169 const char* units);
171 void writeFaceEnvelope(hid_t ds, const double* data);
172};
173
174} // namespace openswmm::twoD
175
176#endif // OPENSWMM_HAS_2D
Interface for output-writing plugins.
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:67
StmtPtr prepare(sqlite3 *db, const std::string &sql)
Definition GpkgUtils.hpp:89
Definition NodeCoupling.cpp:15
SoA storage for 2D triangular mesh geometry and topology.
Definition MeshData.hpp:34