OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ReactionGeometry.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
11
12#pragma once
16#include <algorithm>
17
18namespace openswmm::transport {
25 return units == ReactionAreaUnits::M2 ? .09290304
26 : units == ReactionAreaUnits::CM2 ? 929.0304
27 : 1.;
28}
29// Contact area is explicit for tanks and non-conduit links. Conduits use the
30// wetted perimeter of the actual section (including tabulated sections),
31// physical routing length and barrel count. No tank shape is inferred.
45inline double reactionWallArea(const SimulationContext& c, bool link_element, int e,
46 bool reference = false) {
47 for (const auto& row : c.reactions.wall_areas)
48 if (row.link == link_element && row.element == e)
49 return row.area;
50 if (!link_element || e < 0 || e >= c.n_links())
51 return 0;
52 const int r = c.link_subtypes.conduit_row(e);
53 if (r < 0)
54 return 0;
55 const double y = reference ? c.links.xsect_y_full[e] : c.links.depth[e];
56 if (!(y > 0))
57 return 0;
58 const auto xs = link::buildXSectParams(c.links, e, &c.transect_tables);
59 const double area = xsect::getAofY(xs, y), radius = xsect::getRofY(xs, y);
60 if (!(radius > 0))
61 return 0;
62 const auto& conduits = c.link_subtypes.conduits;
63 const double length = r < int(conduits.true_length.size()) && conduits.true_length[r] > 0
64 ? conduits.true_length[r]
65 : conduits.length[r];
66 return area / radius * length * std::max(1, conduits.barrels[r]) *
68}
69
78inline double reactionAreaVolume(const SimulationContext& c, bool link_element, int e,
79 double volume) {
80 return volume > .0353147 ? reactionWallArea(c, link_element, e) / (volume * 28.317) : 0.;
81}
82
93inline void reactionWallScales(const SimulationContext& c, bool link_element, int e, double volume,
94 std::vector<double>& scales) {
95 scales.assign(c.reactions.n_species(), 1.);
96 const double reference = reactionWallArea(c, link_element, e, true);
97 const double active = volume > .0353147 ? reactionWallArea(c, link_element, e) : 0;
98 for (int s = 0; s < c.reactions.n_species(); ++s)
100 scales[s] = reference > 0 ? std::clamp(active / reference, 0., 1.) : 0.;
101}
102} // namespace openswmm::transport
The central, reentrant simulation context for the new engine.
Cross-section geometry — unified batch + per-element API.
Definition ExplicitFvSolver.hpp:53
double reactionAreaFactor(ReactionAreaUnits units)
Convert native square feet to configured reaction wall/dry-store area units.
Definition ReactionGeometry.hpp:24
double reactionWallArea(const SimulationContext &c, bool link_element, int e, bool reference=false)
Resolve explicit or hydraulic wetted reaction wall area for an element.
Definition ReactionGeometry.hpp:45
void reactionWallScales(const SimulationContext &c, bool link_element, int e, double volume, std::vector< double > &scales)
Build per-species active-to-reference wall coverage multipliers.
Definition ReactionGeometry.hpp:93
double reactionAreaVolume(const SimulationContext &c, bool link_element, int e, double volume)
Compute active wetted reaction wall area per litre of water.
Definition ReactionGeometry.hpp:78
double getRofY(const XSectParams &xs, double y)
Query native hydraulic radius from depth through the shared host evaluator.
Definition XSection.cpp:256
double getAofY(const XSectParams &xs, double y)
Query native wetted area from depth through the shared host evaluator.
Definition XSection.cpp:250
ReactionAreaUnits
Definition ReactionData.hpp:55
@ CM2
Definition ReactionData.hpp:55
@ M2
Definition ReactionData.hpp:55
double * y
Definition odesolve.c:37
std::vector< double > true_length
Definition LinkSubtypes.hpp:89
std::vector< WallArea > wall_areas
Definition ReactionData.hpp:128
ReactionAreaUnits area_units
Definition ReactionData.hpp:90
int n_species() const noexcept
Count authored reaction species.
Definition ReactionData.hpp:348
std::vector< uint8_t > species_is_wall
0 = BULK, 1 = WALL
Definition ReactionData.hpp:104
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
LinkSubtypes link_subtypes
Relational per-subtype link side-tables (Phase 6) — the link analogue of node_subtypes....
Definition SimulationContext.hpp:588
ReactionData reactions
Multispecies reaction system (EPANET-MSX conventions), parsed from the reactions component's config f...
Definition SimulationContext.hpp:624
LinkData links
All link state and properties.
Definition SimulationContext.hpp:580
int n_links() const noexcept
Number of links.
Definition SimulationContext.hpp:2360
std::vector< transect::TransectData > transect_tables
Built transect geometry tables (indexed same as transects).
Definition SimulationContext.hpp:792