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 {
55 SOIL = 2,
58};
59
61enum class LidSpecies : int {
62 AGE = 0,
67};
68
78 int n_units = 0;
79 int n_species = 0;
80
83 std::vector<int> group_offset;
84
86 std::vector<double> value;
87
93 std::vector<double> vol_prev;
94
98 std::vector<double> drain_value;
99
104 std::vector<double> inflow_value;
105
106 static constexpr int kLayerCount = static_cast<int>(LidLayer::COUNT_);
107
108 bool active() const noexcept { return n_units > 0 && n_species > 0; }
109
110 std::size_t layer_index(int unit, LidLayer layer, int species) const noexcept {
111 return (static_cast<std::size_t>(unit) * kLayerCount +
112 static_cast<std::size_t>(layer)) *
113 static_cast<std::size_t>(n_species) +
114 static_cast<std::size_t>(species);
115 }
116
123 void resize(int units, int species, const std::vector<int>& offsets) {
124 n_units = units;
125 n_species = species;
126 group_offset = offsets;
127 const auto n_layers = static_cast<std::size_t>(units) *
128 static_cast<std::size_t>(kLayerCount);
129 value.assign(n_layers * static_cast<std::size_t>(species), 0.0);
130 vol_prev.assign(n_layers, 0.0);
131 drain_value.assign(static_cast<std::size_t>(units) *
132 static_cast<std::size_t>(species), 0.0);
133 inflow_value.assign(static_cast<std::size_t>(units) *
134 static_cast<std::size_t>(species), 0.0);
135 }
136
152 void ensureSized(int units, int species, const std::vector<int>& offsets) {
153 const auto want = static_cast<std::size_t>(units) *
154 static_cast<std::size_t>(kLayerCount) *
155 static_cast<std::size_t>(species);
156 if (n_units == units && n_species == species && value.size() == want)
157 return;
158 resize(units, species, offsets);
159 }
160
161 void clear() { *this = LidLayerSpeciesState{}; }
162};
163
164} // namespace openswmm
165
166#endif // OPENSWMM_ENGINE_DATA_LIDLAYERSPECIESDATA_HPP
Definition NodeCoupling.cpp:16
LidLayer
Definition LidLayerSpeciesData.hpp:52
@ PAVEMENT
Definition LidLayerSpeciesData.hpp:54
@ SURFACE
Definition LidLayerSpeciesData.hpp:53
@ SOIL
Definition LidLayerSpeciesData.hpp:55
@ COUNT_
Definition LidLayerSpeciesData.hpp:57
@ STORAGE
Definition LidLayerSpeciesData.hpp:56
LidSpecies
Species rows carried on the LID layers.
Definition LidLayerSpeciesData.hpp:61
@ AGE
Definition LidLayerSpeciesData.hpp:62
@ TEMPERATURE
Definition LidLayerSpeciesData.hpp:65
@ COUNT_
Definition HeatData.hpp:80
Per-(unit, layer, species) state for every LID unit in the model.
Definition LidLayerSpeciesData.hpp:77
void resize(int units, int species, const std::vector< int > &offsets)
Definition LidLayerSpeciesData.hpp:123
static constexpr int kLayerCount
Definition LidLayerSpeciesData.hpp:106
std::vector< int > group_offset
Definition LidLayerSpeciesData.hpp:83
int n_units
Definition LidLayerSpeciesData.hpp:78
std::vector< double > vol_prev
Definition LidLayerSpeciesData.hpp:93
int n_species
Definition LidLayerSpeciesData.hpp:79
bool active() const noexcept
Definition LidLayerSpeciesData.hpp:108
std::vector< double > drain_value
Definition LidLayerSpeciesData.hpp:98
std::vector< double > value
[(unit * kLayerCount + layer) * n_species + species]
Definition LidLayerSpeciesData.hpp:86
void ensureSized(int units, int species, const std::vector< int > &offsets)
Size the block if it is not already the requested shape.
Definition LidLayerSpeciesData.hpp:152
std::vector< double > inflow_value
Definition LidLayerSpeciesData.hpp:104
std::size_t layer_index(int unit, LidLayer layer, int species) const noexcept
Definition LidLayerSpeciesData.hpp:110
void clear()
Definition LidLayerSpeciesData.hpp:161