OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ReactionSources.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
11
12#pragma once
14#include <algorithm>
15#include <cmath>
16namespace openswmm::transport {
28inline double reactionSourceFactor(const ReactionData& r, const ReactionData::Source& source,
29 double seconds) {
30 if (source.pattern < 0)
31 return 1.;
32 const auto& factors = r.source_patterns[source.pattern].factors;
33 const double count = double(factors.size()), period = r.pattern_timestep * count;
34 const double phase =
35 std::isfinite(period) ? std::fmod(std::max(0., seconds), period) : std::max(0., seconds);
36 const double epsilon = std::min(1e-6, r.pattern_timestep * 1e-6);
37 return factors[std::size_t(
38 std::fmod(std::floor((phase + epsilon) / r.pattern_timestep), count))];
39}
40// FLOWPACED doses arriving water once. SETPOINT raises the complete mixed
41// store only during positive water exchange. Neither injects into a dry store
42// or removes mass when the mixture is above its set point.
60inline double reactionBoosterMass(SimulationContext& ctx, int node, int species, double mass,
61 double mixed_volume, double arriving_volume) {
62 if (!(mixed_volume > 1e-12) || !(arriving_volume > 1e-12))
63 return 0.;
64 auto& r = ctx.reactions;
65 for (const auto& source : r.sources)
66 if (source.booster && source.node == node && source.species == species) {
67 const double strength =
68 source.value * reactionSourceFactor(r, source, ctx.current_time);
69 const double added = source.booster == 1 ? strength * arriving_volume
70 : std::max(0., strength * mixed_volume - mass);
71 if (r.booster_mass.size() != std::size_t(r.n_species()))
72 r.booster_mass.assign(r.n_species(), 0.);
73 r.booster_mass[species] += added;
74 if (r.msx_ledger.armed)
75 r.msx_ledger.inflow[species] += added;
76 return added;
77 }
78 return 0.;
79}
80} // namespace openswmm::transport
The central, reentrant simulation context for the new engine.
Definition Node.cpp:38
Definition ExplicitFvSolver.hpp:53
double reactionSourceFactor(const ReactionData &r, const ReactionData::Source &source, double seconds)
Read a periodic reaction-source pattern factor at an elapsed simulation time.
Definition ReactionSources.hpp:28
double reactionBoosterMass(SimulationContext &ctx, int node, int species, double mass, double mixed_volume, double arriving_volume)
Compute and book the first matching node/species booster inventory addition.
Definition ReactionSources.hpp:60
Definition ReactionData.hpp:186
int pattern
Definition ReactionData.hpp:188
Definition ReactionData.hpp:58
double pattern_timestep
seconds, independent of RATE_UNITS
Definition ReactionData.hpp:193
std::vector< SourcePattern > source_patterns
Definition ReactionData.hpp:194
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
ReactionData reactions
Multispecies reaction system (EPANET-MSX conventions), parsed from the reactions component's config f...
Definition SimulationContext.hpp:624
double current_time
Current simulation time in SECONDS from start_date.
Definition SimulationContext.hpp:489