OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
GeoPackageOutputPlugin.hpp
Go to the documentation of this file.
1
11#ifndef OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
12#define OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
13
14#include "GpkgUtils.hpp"
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20namespace openswmm::gpkg {
21
23public:
25
26 PluginState state() const noexcept override { return state_; }
27
28 int initialize(const std::vector<std::string>& init_args,
29 const IPluginComponentInfo* info) override;
30
31 int validate(const SimulationContext& ctx) override;
32 int prepare(const SimulationContext& ctx) override;
33 int update(const SimulationSnapshot& snapshot) override;
34 int finalize(const SimulationContext& ctx) override;
35
36 const char* last_error_message() const noexcept override {
37 return error_msg_.c_str();
38 }
39
40private:
42 std::string error_msg_;
43 std::string db_path_;
44 std::string simulation_id_;
45 DbPtr db_;
46 StmtPtr insert_stmt_;
47
48 // Cached variable IDs
49 std::unordered_map<std::string, int> variable_ids_;
50
51 // Batch buffer
52 struct ResultRow {
53 std::string object_type;
54 std::string object_id;
55 int variable_id;
56 double elapsed_time;
57 double value;
58 };
59 std::vector<ResultRow> buffer_;
60 static constexpr size_t FLUSH_THRESHOLD = 5000;
61
62 void flush_buffer();
63 int lookup_variable(const std::string& name, const std::string& obj_type);
64
65 // Unit conversion factors (internal → display), computed once in prepare()
66 double ucf_rainfall_ = 1.0;
67 double ucf_raindepth_ = 1.0;
68 double ucf_evaprate_ = 1.0;
69 double ucf_length_ = 1.0;
70 double ucf_volume_ = 1.0;
71 double ucf_flow_ = 1.0;
72 int unit_system_ = 0; // 0=US, 1=SI
73
74 // Per-object report flags, captured during prepare() from SimulationContext
75 std::vector<char> subcatch_rpt_flag_;
76 std::vector<char> node_rpt_flag_;
77 std::vector<char> link_rpt_flag_;
78};
79
80} // namespace openswmm::gpkg
81
82#endif // OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
RAII wrappers and utilities for SQLite operations in GeoPackage I/O.
Interface for output-writing plugins.
Interface for output-writing plugins.
Definition IOutputPlugin.hpp:57
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:179
Definition GeoPackageOutputPlugin.hpp:22
int update(const SimulationSnapshot &snapshot) override
Write one output snapshot. Called from the IO thread.
Definition GeoPackageOutputPlugin.cpp:103
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Definition GeoPackageOutputPlugin.cpp:22
int prepare(const SimulationContext &ctx) override
Open output file(s) and write headers.
Definition GeoPackageOutputPlugin.cpp:39
int validate(const SimulationContext &ctx) override
Validate plugin configuration against the simulation model.
Definition GeoPackageOutputPlugin.cpp:34
int finalize(const SimulationContext &ctx) override
Flush and close output file(s). Called from main thread.
Definition GeoPackageOutputPlugin.cpp:376
PluginState state() const noexcept override
Query the current plugin state.
Definition GeoPackageOutputPlugin.hpp:26
const char * last_error_message() const noexcept override
Get the last error message from this plugin instance.
Definition GeoPackageOutputPlugin.hpp:36
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:67
@ UNLOADED
Library not yet loaded (or was closed).
Definition GeoPackageInputPlugin.cpp:15
std::unique_ptr< sqlite3_stmt, StmtDeleter > StmtPtr
Definition GpkgUtils.hpp:64
std::unique_ptr< sqlite3, DbDeleter > DbPtr
Definition GpkgUtils.hpp:42
Central, reentrant simulation context.
Definition SimulationContext.hpp:274
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:92