OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
InitialQualitySeeds.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
39
40#ifndef OPENSWMM_ENGINE_INITIAL_QUALITY_SEEDS_HPP
41#define OPENSWMM_ENGINE_INITIAL_QUALITY_SEEDS_HPP
42
45
46namespace openswmm::transport {
47
62inline double initialAgeSecondsFor(const SimulationContext& ctx, bool is_link, int idx,
63 double fallback) {
64 double v = fallback;
65 const auto& iq = ctx.initial_quality;
66 for (int r = 0; r < iq.count(); ++r) {
67 const auto ur = static_cast<std::size_t>(r);
68 if (iq.kind[ur] != InitialQualityData::kKindWaterAge)
69 continue;
70 if ((iq.is_link[ur] != 0) != is_link)
71 continue;
72 if (iq.elem_idx[ur] != idx)
73 continue;
74 v = iq.value[ur] * 3600.0; // hours -> seconds
75 }
76 return v;
77}
78
90inline double initialTempFor(const SimulationContext& ctx, bool is_link, int idx, double fallback) {
91 double v = fallback;
92 const auto& iq = ctx.initial_quality;
93 for (int r = 0; r < iq.count(); ++r) {
94 const auto ur = static_cast<std::size_t>(r);
95 if (iq.kind[ur] != InitialQualityData::kKindTemperature)
96 continue;
97 if ((iq.is_link[ur] != 0) != is_link)
98 continue;
99 if (iq.elem_idx[ur] != idx)
100 continue;
101 v = iq.value[ur];
102 }
103 return v;
104}
105
119 auto& ws = ctx.water_age_state;
120 if (ws.hotstart_loaded)
121 return;
122 const auto& iq = ctx.initial_quality;
123 for (int r = 0; r < iq.count(); ++r) {
124 const auto ur = static_cast<std::size_t>(r);
125 if (iq.kind[ur] != InitialQualityData::kKindWaterAge)
126 continue;
127 const int ei = iq.elem_idx[ur];
128 if (ei < 0)
129 continue;
130 auto& arr = iq.is_link[ur] ? ws.link_age : ws.node_age;
131 if (static_cast<std::size_t>(ei) < arr.size())
132 arr[static_cast<std::size_t>(ei)] = iq.value[ur] * 3600.0;
133 }
134}
135
148 auto& hs = ctx.heat_state;
149 const auto& iq = ctx.initial_quality;
150 for (int r = 0; r < iq.count(); ++r) {
151 const auto ur = static_cast<std::size_t>(r);
152 if (iq.kind[ur] != InitialQualityData::kKindTemperature)
153 continue;
154 const int ei = iq.elem_idx[ur];
155 if (ei < 0)
156 continue;
157 auto& arr = iq.is_link[ur] ? hs.link_temp : hs.node_temp;
158 if (static_cast<std::size_t>(ei) < arr.size())
159 arr[static_cast<std::size_t>(ei)] = iq.value[ur];
160 }
161}
162
163} // namespace openswmm::transport
164
165#endif // OPENSWMM_ENGINE_INITIAL_QUALITY_SEEDS_HPP
SoA store for [INITIAL_QUALITY] per-element initial concentrations.
The central, reentrant simulation context for the new engine.
Definition ExplicitFvSolver.hpp:53
double initialAgeSecondsFor(const SimulationContext &ctx, bool is_link, int idx, double fallback)
Per-element initial age (SECONDS) for one node/link, falling back to fallback (normally the INITIAL_S...
Definition InitialQualitySeeds.hpp:62
void applyInitialTempOverrides(SimulationContext &ctx)
Apply TEMPERATURE rows onto heat_state.node_temp/link_temp (degC). No-op on unsized arrays.
Definition InitialQualitySeeds.hpp:147
void applyInitialAgeOverrides(SimulationContext &ctx)
Apply WATER_AGE rows onto water_age_state.node_age/link_age (hours -> seconds). No-op when a hotstart...
Definition InitialQualitySeeds.hpp:118
double initialTempFor(const SimulationContext &ctx, bool is_link, int idx, double fallback)
Per-element initial temperature (degC) for one node/link, falling back to fallback (normally the INIT...
Definition InitialQualitySeeds.hpp:90
static constexpr int kKindWaterAge
Classified constituent kinds (see kind).
Definition InitialQualityData.hpp:49
static constexpr int kKindTemperature
TEMPERATURE (degC)
Definition InitialQualityData.hpp:50
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
WaterAgeState water_age_state
Definition SimulationContext.hpp:640
InitialQualityData initial_quality
Per-element initial quality rows from [INITIAL_QUALITY].
Definition SimulationContext.hpp:773
HeatState heat_state
Definition SimulationContext.hpp:656