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
53inline double initialAgeSecondsFor(const SimulationContext& ctx, bool is_link,
54 int idx, double fallback) {
55 double v = fallback;
56 const auto& iq = ctx.initial_quality;
57 for (int r = 0; r < iq.count(); ++r) {
58 const auto ur = static_cast<std::size_t>(r);
59 if (iq.kind[ur] != InitialQualityData::kKindWaterAge) continue;
60 if ((iq.is_link[ur] != 0) != is_link) continue;
61 if (iq.elem_idx[ur] != idx) continue;
62 v = iq.value[ur] * 3600.0; // hours -> seconds
63 }
64 return v;
65}
66
71inline double initialTempFor(const SimulationContext& ctx, bool is_link,
72 int idx, double fallback) {
73 double v = fallback;
74 const auto& iq = ctx.initial_quality;
75 for (int r = 0; r < iq.count(); ++r) {
76 const auto ur = static_cast<std::size_t>(r);
77 if (iq.kind[ur] != InitialQualityData::kKindTemperature) continue;
78 if ((iq.is_link[ur] != 0) != is_link) continue;
79 if (iq.elem_idx[ur] != idx) continue;
80 v = iq.value[ur];
81 }
82 return v;
83}
84
91 auto& ws = ctx.water_age_state;
92 if (ws.hotstart_loaded) return;
93 const auto& iq = ctx.initial_quality;
94 for (int r = 0; r < iq.count(); ++r) {
95 const auto ur = static_cast<std::size_t>(r);
96 if (iq.kind[ur] != InitialQualityData::kKindWaterAge) continue;
97 const int ei = iq.elem_idx[ur];
98 if (ei < 0) continue;
99 auto& arr = iq.is_link[ur] ? ws.link_age : ws.node_age;
100 if (static_cast<std::size_t>(ei) < arr.size())
101 arr[static_cast<std::size_t>(ei)] = iq.value[ur] * 3600.0;
102 }
103}
104
110 auto& hs = ctx.heat_state;
111 const auto& iq = ctx.initial_quality;
112 for (int r = 0; r < iq.count(); ++r) {
113 const auto ur = static_cast<std::size_t>(r);
114 if (iq.kind[ur] != InitialQualityData::kKindTemperature) continue;
115 const int ei = iq.elem_idx[ur];
116 if (ei < 0) continue;
117 auto& arr = iq.is_link[ur] ? hs.link_temp : hs.node_temp;
118 if (static_cast<std::size_t>(ei) < arr.size())
119 arr[static_cast<std::size_t>(ei)] = iq.value[ur];
120 }
121}
122
123} // namespace openswmm::transport
124
125#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:52
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:53
void applyInitialTempOverrides(SimulationContext &ctx)
Apply TEMPERATURE rows onto heat_state.node_temp/link_temp (degC). No-op on unsized arrays.
Definition InitialQualitySeeds.hpp:109
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:90
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:71
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:353
WaterAgeState water_age_state
Definition SimulationContext.hpp:573
InitialQualityData initial_quality
Per-element initial quality rows from [INITIAL_QUALITY].
Definition SimulationContext.hpp:688
HeatState heat_state
Definition SimulationContext.hpp:589