OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SpeciesTransportKernels.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
45
46#ifndef OPENSWMM_ENGINE_TRANSPORT_FVKERNELS_SPECIES_TRANSPORT_KERNELS_HPP
47#define OPENSWMM_ENGINE_TRANSPORT_FVKERNELS_SPECIES_TRANSPORT_KERNELS_HPP
48
49#include <algorithm>
50#include <cmath>
51#include <vector>
52
56
58
60using openswmm::fv::NetworkMeshData;
61using openswmm::fv::NetworkStateData;
63
77inline double limitSlope(double a, double b, Limiter lim) {
78 if (a * b <= 0.0)
79 return 0.0; // extremum ⇒ no slope
80 switch (lim) {
81 case Limiter::VANLEER:
82 return 2.0 * a * b / (a + b);
83 case Limiter::SUPERBEE: {
84 const double s = (a > 0.0) ? 1.0 : -1.0;
85 return s * std::max(std::min(2.0 * std::fabs(a), std::fabs(b)),
86 std::min(std::fabs(a), 2.0 * std::fabs(b)));
87 }
88 case Limiter::MINMOD:
89 default:
90 return (std::fabs(a) < std::fabs(b)) ? a : b;
91 }
92}
93
104 const NetworkMeshData* mesh = nullptr;
106
107 // Scheme options (subset of FvOptions the kernels consume).
108 ScalarScheme scalar_scheme = ScalarScheme::MUSCL;
109 Limiter limiter = Limiter::MINMOD;
110 double dispersion = 0.0;
111 bool hllc = true;
112
119 const std::vector<double>* cell_dispersion = nullptr;
120
121 // Hydrodynamic face records of the current substep (read-only).
122 const std::vector<double>* f_mass = nullptr;
123 const std::vector<double>* f_sstar = nullptr;
124 const std::vector<openswmm::fv::kernels::FaceState>* f_state_l = nullptr;
125 const std::vector<openswmm::fv::kernels::FaceState>* f_state_r = nullptr;
126 const std::vector<openswmm::fv::kernels::FaceFlux>* f_flux = nullptr;
127
128 // Derived cell fields (read-only).
129 const std::vector<double>* cell_u = nullptr;
130 const std::vector<char>* cell_active = nullptr;
131 const std::vector<int>* active_faces = nullptr;
132
133 // Caller-owned outputs / scratch.
134 std::vector<double>* f_phi_l = nullptr;
135 std::vector<double>* f_phi_r = nullptr;
136 std::vector<double>* f_phi_flux = nullptr;
137 std::vector<double>* cell_slope = nullptr;
138 std::vector<double>* lo_flux = nullptr;
139 std::vector<double>* anti_flux = nullptr;
140 std::vector<double>* td = nullptr;
141 std::vector<double>* anew = nullptr;
142 std::vector<double>* rplus = nullptr;
143 std::vector<double>* rminus = nullptr;
144};
145
149void reconstructScalars(const SpeciesKernelView& v, double dt);
150
154void limitSpeciesFluxes(const SpeciesKernelView& v, int species, double dt);
155
160void dispersionSolve(const SpeciesKernelView& v, double dt);
161
162} // namespace openswmm::transport::fvkernels
163
164#endif // OPENSWMM_ENGINE_TRANSPORT_FVKERNELS_SPECIES_TRANSPORT_KERNELS_HPP
Single-source scalar kernels for the explicit FV 1D network solver.
Option struct for the explicit finite-volume 1D network solver.
SoA storage for the 1D finite-volume network mesh and its state.
ScalarScheme
Reconstruction used for the advected scalar field.
Definition FvOptions.hpp:68
Limiter
Slope limiter used by the second-order (MUSCL) reconstruction.
Definition FvOptions.hpp:61
Definition ExplicitFvSolver.hpp:53
void reconstructScalars(const SpeciesKernelView &v, double dt)
Build bounded face-native concentrations and conservative limited scalar fluxes for all rows.
Definition SpeciesTransportKernels.cpp:64
void dispersionSolve(const SpeciesKernelView &v, double dt)
Apply an implicit per-chain longitudinal dispersion solve to every native scalar row.
Definition SpeciesTransportKernels.cpp:419
double limitSlope(double a, double b, Limiter lim)
Slope limiters for the second-order scalar reconstruction. All three are TVD; superbee is the sharpes...
Definition SpeciesTransportKernels.hpp:77
void limitSpeciesFluxes(const SpeciesKernelView &v, int species, double dt)
Assemble the face species fluxes and limit them (Zalesak FCT).
Definition SpeciesTransportKernels.cpp:259
SoA mesh geometry and topology for the FV network solver.
Definition NetworkMeshData.hpp:123
Mutable solver state — the conserved variables and the node volumes.
Definition NetworkMeshData.hpp:519
Non-owning view over everything the species kernels read and write.
Definition SpeciesTransportKernels.hpp:103
double dispersion
Definition SpeciesTransportKernels.hpp:110
const std::vector< double > * cell_u
Q/A, dry-guarded.
Definition SpeciesTransportKernels.hpp:129
const std::vector< double > * f_sstar
HLLC contact speed.
Definition SpeciesTransportKernels.hpp:123
const std::vector< double > * f_mass
positivity-scaled mass flux
Definition SpeciesTransportKernels.hpp:122
std::vector< double > * cell_slope
Definition SpeciesTransportKernels.hpp:137
std::vector< double > * f_phi_l
[s*n_faces+f] reconstructed
Definition SpeciesTransportKernels.hpp:134
Limiter limiter
Definition SpeciesTransportKernels.hpp:109
std::vector< double > * f_phi_flux
[s*n_faces+f] limited flux
Definition SpeciesTransportKernels.hpp:136
const std::vector< openswmm::fv::kernels::FaceState > * f_state_r
Definition SpeciesTransportKernels.hpp:125
std::vector< double > * anew
Definition SpeciesTransportKernels.hpp:141
const std::vector< int > * active_faces
Definition SpeciesTransportKernels.hpp:131
std::vector< double > * lo_flux
Definition SpeciesTransportKernels.hpp:138
std::vector< double > * anti_flux
Definition SpeciesTransportKernels.hpp:139
const std::vector< openswmm::fv::kernels::FaceFlux > * f_flux
Definition SpeciesTransportKernels.hpp:126
bool hllc
Definition SpeciesTransportKernels.hpp:111
NetworkStateData * state
Definition SpeciesTransportKernels.hpp:105
std::vector< double > * rplus
Definition SpeciesTransportKernels.hpp:142
std::vector< double > * f_phi_r
face values
Definition SpeciesTransportKernels.hpp:135
const std::vector< openswmm::fv::kernels::FaceState > * f_state_l
Definition SpeciesTransportKernels.hpp:124
ScalarScheme scalar_scheme
Definition SpeciesTransportKernels.hpp:108
const NetworkMeshData * mesh
Definition SpeciesTransportKernels.hpp:104
std::vector< double > * td
Definition SpeciesTransportKernels.hpp:140
const std::vector< double > * cell_dispersion
Definition SpeciesTransportKernels.hpp:119
std::vector< double > * rminus
Definition SpeciesTransportKernels.hpp:143
const std::vector< char > * cell_active
Definition SpeciesTransportKernels.hpp:130