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
69inline double limitSlope(double a, double b, Limiter lim) {
70 if (a * b <= 0.0) return 0.0; // extremum ⇒ no slope
71 switch (lim) {
72 case Limiter::VANLEER:
73 return 2.0 * a * b / (a + b);
74 case Limiter::SUPERBEE: {
75 const double s = (a > 0.0) ? 1.0 : -1.0;
76 return s * std::max(std::min(2.0 * std::fabs(a), std::fabs(b)),
77 std::min(std::fabs(a), 2.0 * std::fabs(b)));
78 }
79 case Limiter::MINMOD:
80 default:
81 return (std::fabs(a) < std::fabs(b)) ? a : b;
82 }
83}
84
97 const NetworkMeshData* mesh = nullptr;
99
100 // Scheme options (subset of FvOptions the kernels consume).
101 ScalarScheme scalar_scheme = ScalarScheme::MUSCL;
102 Limiter limiter = Limiter::MINMOD;
103 double dispersion = 0.0;
104 bool hllc = true;
105
112 const std::vector<double>* cell_dispersion = nullptr;
113
114 // Hydrodynamic face records of the current substep (read-only).
115 const std::vector<double>* f_mass = nullptr;
116 const std::vector<double>* f_sstar = nullptr;
117 const std::vector<openswmm::fv::kernels::FaceState>* f_state_l = nullptr;
118 const std::vector<openswmm::fv::kernels::FaceState>* f_state_r = nullptr;
119 const std::vector<openswmm::fv::kernels::FaceFlux>* f_flux = nullptr;
120
121 // Derived cell fields (read-only).
122 const std::vector<double>* cell_u = nullptr;
123 const std::vector<char>* cell_active = nullptr;
124 const std::vector<int>* active_faces = nullptr;
125
126 // Caller-owned outputs / scratch.
127 std::vector<double>* f_phi_l = nullptr;
128 std::vector<double>* f_phi_r = nullptr;
129 std::vector<double>* f_phi_flux = nullptr;
130 std::vector<double>* cell_slope = nullptr;
131 std::vector<double>* lo_flux = nullptr;
132 std::vector<double>* anti_flux = nullptr;
133 std::vector<double>* td = nullptr;
134 std::vector<double>* anew = nullptr;
135 std::vector<double>* rplus = nullptr;
136 std::vector<double>* rminus = nullptr;
137};
138
142void reconstructScalars(const SpeciesKernelView& v, double dt);
143
147void limitSpeciesFluxes(const SpeciesKernelView& v, int species, double dt);
148
153void dispersionSolve(const SpeciesKernelView& v, double dt);
154
155} // namespace openswmm::transport::fvkernels
156
157#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:52
void reconstructScalars(const SpeciesKernelView &v, double dt)
Definition SpeciesTransportKernels.cpp:43
void dispersionSolve(const SpeciesKernelView &v, double dt)
Definition SpeciesTransportKernels.cpp:359
double limitSlope(double a, double b, Limiter lim)
Definition SpeciesTransportKernels.hpp:69
void limitSpeciesFluxes(const SpeciesKernelView &v, int species, double dt)
Assemble the face species fluxes and limit them (Zalesak FCT).
Definition SpeciesTransportKernels.cpp:219
SoA mesh geometry and topology for the FV network solver.
Definition NetworkMeshData.hpp:176
Mutable solver state — the conserved variables and the node volumes.
Definition NetworkMeshData.hpp:489
Non-owning view over everything the species kernels read and write.
Definition SpeciesTransportKernels.hpp:96
double dispersion
Definition SpeciesTransportKernels.hpp:103
const std::vector< double > * cell_u
Q/A, dry-guarded.
Definition SpeciesTransportKernels.hpp:122
const std::vector< double > * f_sstar
HLLC contact speed.
Definition SpeciesTransportKernels.hpp:116
const std::vector< double > * f_mass
positivity-scaled mass flux
Definition SpeciesTransportKernels.hpp:115
std::vector< double > * cell_slope
Definition SpeciesTransportKernels.hpp:130
std::vector< double > * f_phi_l
[s*n_faces+f] reconstructed
Definition SpeciesTransportKernels.hpp:127
Limiter limiter
Definition SpeciesTransportKernels.hpp:102
std::vector< double > * f_phi_flux
[s*n_faces+f] limited flux
Definition SpeciesTransportKernels.hpp:129
const std::vector< openswmm::fv::kernels::FaceState > * f_state_r
Definition SpeciesTransportKernels.hpp:118
std::vector< double > * anew
Definition SpeciesTransportKernels.hpp:134
const std::vector< int > * active_faces
Definition SpeciesTransportKernels.hpp:124
std::vector< double > * lo_flux
Definition SpeciesTransportKernels.hpp:131
std::vector< double > * anti_flux
Definition SpeciesTransportKernels.hpp:132
const std::vector< openswmm::fv::kernels::FaceFlux > * f_flux
Definition SpeciesTransportKernels.hpp:119
bool hllc
Definition SpeciesTransportKernels.hpp:104
NetworkStateData * state
Definition SpeciesTransportKernels.hpp:98
std::vector< double > * rplus
Definition SpeciesTransportKernels.hpp:135
std::vector< double > * f_phi_r
face values
Definition SpeciesTransportKernels.hpp:128
const std::vector< openswmm::fv::kernels::FaceState > * f_state_l
Definition SpeciesTransportKernels.hpp:117
ScalarScheme scalar_scheme
Definition SpeciesTransportKernels.hpp:101
const NetworkMeshData * mesh
Definition SpeciesTransportKernels.hpp:97
std::vector< double > * td
Definition SpeciesTransportKernels.hpp:133
const std::vector< double > * cell_dispersion
Definition SpeciesTransportKernels.hpp:112
std::vector< double > * rminus
Definition SpeciesTransportKernels.hpp:136
const std::vector< char > * cell_active
Definition SpeciesTransportKernels.hpp:123