OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
LidLayerSpeciesData.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
37
38#ifndef OPENSWMM_ENGINE_DATA_LIDLAYERSPECIESDATA_HPP
39#define OPENSWMM_ENGINE_DATA_LIDLAYERSPECIESDATA_HPP
40
41#include <cstddef>
42#include <vector>
43
44namespace openswmm {
45
52enum class LidLayer : int { SURFACE = 0, PAVEMENT = 1, SOIL = 2, STORAGE = 3, COUNT_ = 4 };
53
55enum class LidSpecies : int {
56 AGE = 0,
61};
62
72 int n_units = 0;
73 int n_species = 0;
74
77 std::vector<int> group_offset;
78
80 std::vector<double> value;
81
87 std::vector<double> vol_prev;
88
92 std::vector<double> drain_value;
93
98 std::vector<double> inflow_value;
99
100 static constexpr int kLayerCount = static_cast<int>(LidLayer::COUNT_);
101
106 bool active() const noexcept { return n_units > 0 && n_species > 0; }
107
117 std::size_t layer_index(int unit, LidLayer layer, int species) const noexcept {
118 return (static_cast<std::size_t>(unit) * kLayerCount + static_cast<std::size_t>(layer)) *
119 static_cast<std::size_t>(n_species) +
120 static_cast<std::size_t>(species);
121 }
122
136 void resize(int units, int species, const std::vector<int>& offsets) {
137 n_units = units;
138 n_species = species;
139 group_offset = offsets;
140 const auto n_layers =
141 static_cast<std::size_t>(units) * static_cast<std::size_t>(kLayerCount);
142 value.assign(n_layers * static_cast<std::size_t>(species), 0.0);
143 vol_prev.assign(n_layers, 0.0);
144 drain_value.assign(static_cast<std::size_t>(units) * static_cast<std::size_t>(species),
145 0.0);
146 inflow_value.assign(static_cast<std::size_t>(units) * static_cast<std::size_t>(species),
147 0.0);
148 }
149
162 void ensureSized(int units, int species, const std::vector<int>& offsets) {
163 const auto want = static_cast<std::size_t>(units) * static_cast<std::size_t>(kLayerCount) *
164 static_cast<std::size_t>(species);
165 if (n_units == units && n_species == species && value.size() == want)
166 return;
167 resize(units, species, offsets);
168 }
169
176 void clear() { *this = LidLayerSpeciesState{}; }
177};
178
179} // namespace openswmm
180
181#endif // OPENSWMM_ENGINE_DATA_LIDLAYERSPECIESDATA_HPP
Definition ExchangeLaw.hpp:60
LidLayer
Definition LidLayerSpeciesData.hpp:52
@ PAVEMENT
Definition LidLayerSpeciesData.hpp:52
@ SURFACE
Definition LidLayerSpeciesData.hpp:52
@ SOIL
Definition LidLayerSpeciesData.hpp:52
@ COUNT_
Definition LidLayerSpeciesData.hpp:52
@ STORAGE
Definition LidLayerSpeciesData.hpp:52
LidSpecies
Species rows carried on the LID layers.
Definition LidLayerSpeciesData.hpp:55
@ AGE
Definition LidLayerSpeciesData.hpp:56
@ TEMPERATURE
Definition LidLayerSpeciesData.hpp:59
@ COUNT_
Definition HeatData.hpp:80
Per-(unit, layer, species) state for every LID unit in the model.
Definition LidLayerSpeciesData.hpp:71
void resize(int units, int species, const std::vector< int > &offsets)
Replace LID layer state with a zeroed shape and copied group offsets.
Definition LidLayerSpeciesData.hpp:136
static constexpr int kLayerCount
Definition LidLayerSpeciesData.hpp:100
std::vector< int > group_offset
Definition LidLayerSpeciesData.hpp:77
int n_units
Definition LidLayerSpeciesData.hpp:72
std::vector< double > vol_prev
Definition LidLayerSpeciesData.hpp:87
int n_species
Definition LidLayerSpeciesData.hpp:73
bool active() const noexcept
Test whether both LID-unit and species counts are positive.
Definition LidLayerSpeciesData.hpp:106
std::vector< double > drain_value
Definition LidLayerSpeciesData.hpp:92
std::vector< double > value
[(unit * kLayerCount + layer) * n_species + species]
Definition LidLayerSpeciesData.hpp:80
void ensureSized(int units, int species, const std::vector< int > &offsets)
Resize LID state only when its main shape differs.
Definition LidLayerSpeciesData.hpp:162
std::vector< double > inflow_value
Definition LidLayerSpeciesData.hpp:98
std::size_t layer_index(int unit, LidLayer layer, int species) const noexcept
Calculate the flat unit/layer/species value index.
Definition LidLayerSpeciesData.hpp:117
void clear()
Release all LID layer species state and reset counts.
Definition LidLayerSpeciesData.hpp:176