OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
DynamicWave.hpp
Go to the documentation of this file.
1
28#ifndef OPENSWMM_DYNAMIC_WAVE_HPP
29#define OPENSWMM_DYNAMIC_WAVE_HPP
30
31#include "XSectBatch.hpp"
32#include "../data/NodeData.hpp"
33#include "../data/LinkData.hpp"
34#include <vector>
35
36namespace openswmm {
37
38struct SimulationContext;
39
40namespace dynwave {
41
42// ============================================================================
43// Constants (matching legacy)
44// ============================================================================
45
46constexpr double OMEGA = 0.5;
47constexpr double DEFAULT_HEADTOL = 0.005;
48constexpr int DEFAULT_MAXTRIALS = 8;
49constexpr double MAXVELOCITY = 50.0;
50constexpr double MINTIMESTEP = 0.001;
51constexpr double EXTRAN_CROWN_CUTOFF = 0.96;
52constexpr double SLOT_CROWN_CUTOFF = 0.985257;
53constexpr double SLOT_WIDTH_FACTOR = 0.001;
54
55// ============================================================================
56// Per-node extended state for DW iterations
57// ============================================================================
58
60 double new_surf_area = 0.0;
61 double old_surf_area = 0.0;
62 double sumdqdh = 0.0;
63 double dYdT = 0.0;
64 bool converged = false;
65 bool is_surcharged = false;
66};
67
68// ============================================================================
69// DW solver — batch-oriented
70// ============================================================================
71
76enum class SurchargeMethod : int {
77 EXTRAN = 0,
78 SLOT = 1,
79 DYNAMIC_SLOT = 2
80};
81
90class DWSolver {
91public:
92 void init(int n_nodes, int n_links, const XSectGroups& groups);
93
103 void setNumThreads(int n);
104
112 int execute(SimulationContext& ctx, double dt);
113
117 double getRoutingStep(const SimulationContext& ctx,
118 double fixed_step, double courant_factor) const;
119
122 double omega = OMEGA;
124
125private:
126 int n_nodes_ = 0;
127 int n_links_ = 0;
128 int num_threads_ = 1;
129 const XSectGroups* groups_ = nullptr;
130
131 // Per-node working state
132 std::vector<DWNodeState> xnode_;
133
134 // Per-link pre-computed geometry (batch-filled by XSectGroups each iteration)
135 std::vector<double> area1_;
136 std::vector<double> area2_;
137 std::vector<double> area_mid_;
138 std::vector<double> hrad_mid_;
139 std::vector<double> width_mid_;
140 std::vector<double> depth1_;
141 std::vector<double> depth2_;
142 std::vector<double> depth_mid_;
143
144 // Per-link momentum working arrays
145 std::vector<double> velocity_;
146 std::vector<double> froude_;
147 std::vector<double> sigma_;
148 std::vector<double> dqdh_;
149 std::vector<double> new_flow_;
150
151 // Per-link area from previous iteration (for unsteady term)
152 std::vector<double> area_old_;
153
154 // Per-link surface area contributions to upstream/downstream nodes
155 // (matching legacy Link[].surfArea1/surfArea2 from dwflow.c findSurfArea)
156 std::vector<double> surf_area1_;
157 std::vector<double> surf_area2_;
158
159 // Per-link upstream geometry (for proper weighted hyd. radius)
160 std::vector<double> hrad1_;
161 std::vector<double> width1_;
162 std::vector<double> width2_;
163
164 // Per-link head values (persisted from computeLinkGeometry for solveMomentumBatch,
165 // may be modified by flow classification for UP_CRITICAL/DN_CRITICAL cases)
166 std::vector<double> h1_;
167 std::vector<double> h2_;
168 std::vector<double> fasnh_;
169
170 // Internal methods
171 void initNodeStates(SimulationContext& ctx);
172 void computeLinkGeometry(SimulationContext& ctx);
173 void solveMomentumBatch(SimulationContext& ctx, double dt, int step);
174 void updateNodeFlows(SimulationContext& ctx);
175 bool updateNodeDepths(SimulationContext& ctx, double dt, int step);
176 void setNodeDepth(SimulationContext& ctx, int node_idx, double dt, int step);
177 double getLinkStep(const SimulationContext& ctx, int link_idx) const;
178
179 // Preissmann slot helpers (matching legacy dwflow.c)
180 double getSlotWidth(double y, double y_full, double w_max, XsectShape shape) const;
181 double getSlotArea(double y, double y_full, double a_full, double slot_width) const;
182 double getSlotHydRad(double y, double y_full, double r_full) const;
183 double getCrownCutoff() const;
184};
185
186} // namespace dynwave
187} // namespace openswmm
188
189#endif // OPENSWMM_DYNAMIC_WAVE_HPP
Cross-section geometry — unified batch + per-element API.
Shape-grouped cross-section manager for batch computation.
Definition XSectBatch.hpp:193
Dynamic wave solver — operates on entire link/node system.
Definition DynamicWave.hpp:90
int execute(SimulationContext &ctx, double dt)
Execute one DW routing timestep.
Definition DynamicWave.cpp:198
void setNumThreads(int n)
Set the number of OpenMP threads for parallel loops.
Definition DynamicWave.cpp:180
SurchargeMethod surcharge_method
Definition DynamicWave.hpp:123
void init(int n_nodes, int n_links, const XSectGroups &groups)
Definition DynamicWave.cpp:141
double head_tol
Definition DynamicWave.hpp:120
double omega
Definition DynamicWave.hpp:122
int max_trials
Definition DynamicWave.hpp:121
double getRoutingStep(const SimulationContext &ctx, double fixed_step, double courant_factor) const
Compute CFL-based variable timestep.
Definition DynamicWave.cpp:1106
constexpr double EXTRAN_CROWN_CUTOFF
EXTRAN surcharge fraction.
Definition DynamicWave.hpp:51
constexpr double OMEGA
Picard under-relaxation.
Definition DynamicWave.hpp:46
constexpr double SLOT_WIDTH_FACTOR
Slot width = y_full * this factor.
Definition DynamicWave.hpp:53
constexpr double DEFAULT_HEADTOL
Convergence tolerance (ft)
Definition DynamicWave.hpp:47
SurchargeMethod
Surcharge method: EXTRAN (classic) or SLOT (Preissmann).
Definition DynamicWave.hpp:76
@ SLOT
Preissmann slot — fictitious narrow slot above crown.
@ DYNAMIC_SLOT
Dynamic slot — slot width varies with flow conditions (experimental) Sharior, S., Hodges,...
@ EXTRAN
Classic EXTRAN approach — dQ/dH for surcharged nodes.
constexpr double MAXVELOCITY
Velocity limiter (ft/s)
Definition DynamicWave.hpp:49
constexpr double MINTIMESTEP
Minimum timestep (s)
Definition DynamicWave.hpp:50
constexpr double SLOT_CROWN_CUTOFF
Preissmann slot crown cutoff.
Definition DynamicWave.hpp:52
constexpr int DEFAULT_MAXTRIALS
Max Picard iterations.
Definition DynamicWave.hpp:48
Definition Controls.cpp:24
XsectShape
Conduit cross-section shape code.
Definition LinkData.hpp:52
double * y
Definition odesolve.c:28
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Definition DynamicWave.hpp:59
bool is_surcharged
TRUE when node depth > crown elevation.
Definition DynamicWave.hpp:65
bool converged
Definition DynamicWave.hpp:64
double dYdT
Definition DynamicWave.hpp:63
double sumdqdh
Definition DynamicWave.hpp:62
double old_surf_area
Surface area from last non-surcharged state.
Definition DynamicWave.hpp:61
double new_surf_area
Definition DynamicWave.hpp:60