31#include "../../../../Common/include/CConfig.hpp"
32#include "../../../../Common/include/containers/container_decorators.hpp"
34#include "../../variables/CFlowVariable.hpp"
41template <
class VariableType>
71 auto opt = common(config);
72 opt.boundedScalar = bounded;
74 opt.correctGradient =
true;
85 auto opt = common(config);
86 opt.boundedScalar = bounded;
97 auto opt = common(config);
98 opt.correctGradient =
true;
111 auto opt = common(config);
112 opt.correctGradient = correctGrad;
113 opt.convective =
false;
132template <
class Double,
size_t Size>
134 static constexpr size_t nVar = Size;
146template <
class Double,
class Derived,
class FlowIndices,
int nDim,
size_t nVar>
154 template <
class VariableType>
165 const Double proj_vector_ij =
dot(vector_ij, normal) / dist2_ij;
173 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) {
174 const auto grad_i = gatherVariables<nDim>(iPoint, side_i.
scalarNodes.GetGradient(), iVar);
175 const auto grad_j = gatherVariables<nDim>(jPoint, side_j.
scalarNodes.GetGradient(), iVar);
176 for (
int iDim = 0; iDim < nDim; ++iDim) avgGrad(iVar, iDim) = 0.5 * (grad_i(iDim) + grad_j(iDim));
180 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) {
183 const Double corr = (
dot(avgGrad[iVar], vector_ij) - phi_j + phi_i) / dist2_ij;
184 for (
int iDim = 0; iDim < nDim; ++iDim) avgGrad(iVar, iDim) -= corr * vector_ij(iDim);
189 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) projGrad(iVar) =
dot(avgGrad[iVar], normal);
193 Double proj_on_w_i = proj_vector_ij, proj_on_w_j = proj_vector_ij;
194 if constexpr (Derived::Conservative) {
195 proj_on_w_i = proj_vector_ij / rho.
i;
196 proj_on_w_j = proj_vector_ij / rho.
j;
199 const auto* self =
static_cast<const Derived*
>(
this);
200 const auto D = self->coefficients(idx, iPoint, side_i, jPoint, side_j, rho);
202 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) {
203 if constexpr (Derived::DiagonalDiffusion) {
204 res.
flux_i(iVar) -= D.i(iVar) * projGrad(iVar);
206 res.
jac_ii(iVar, iVar) += D.i(iVar) * proj_on_w_i;
207 if (!opt.
oneSided) res.
jac_ij(iVar, iVar) -= D.i(iVar) * proj_on_w_j;
210 res.
flux_j(iVar) += D.j(iVar) * projGrad(iVar);
212 res.
jac_ji(iVar, iVar) -= D.j(iVar) * proj_on_w_i;
213 res.
jac_jj(iVar, iVar) += D.j(iVar) * proj_on_w_j;
217 for (
size_t jVar = 0; jVar < res.
nVar; ++jVar) {
218 res.
flux_i(iVar) -= D.i(iVar, jVar) * projGrad(jVar);
220 res.
jac_ii(iVar, jVar) += D.i(iVar, jVar) * proj_on_w_i;
221 if (!opt.
oneSided) res.
jac_ij(iVar, jVar) -= D.i(iVar, jVar) * proj_on_w_j;
224 res.
flux_j(iVar) += D.j(iVar, jVar) * projGrad(jVar);
226 res.
jac_ji(iVar, jVar) -= D.j(iVar, jVar) * proj_on_w_i;
227 res.
jac_jj(iVar, jVar) += D.j(iVar, jVar) * proj_on_w_j;
237 self->coefficientJacobians(opt, D, projGrad, res);
240 self->extraDiffusionTerms(idx, opt, iPoint, side_i, jPoint, side_j, rho, normal, vector_ij, res);
246 template <
class... Ts>
253 template <
class... Ts>
263template <
class Double,
class Derived,
class FlowIndices,
int nDim,
size_t nVar>
282 template <
class VariableType,
size_t Size>
288 if constexpr (Derived::Conservative) {
293 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) {
294 const Double flux = w0 * phi.i.all(iVar) + w1 * phi.j.all(iVar);
300 res.
jac_ii(iVar, iVar) += a0;
302 res.
jac_ij(iVar, iVar) += a1;
303 res.
jac_ji(iVar, iVar) -= a0;
304 res.
jac_jj(iVar, iVar) -= a1;
315template <
class Double_,
class Derived,
class FlowIndices,
int nDim_,
size_t nVar_>
320 static constexpr int nDim = nDim_;
321 static constexpr size_t nVar = nVar_;
361 idx(
nDim, config.GetnSpecies()),
363 kappa(config.GetMUSCL_Kappa()),
366 limiterType(config.GetInnerIter() <= config.GetLimiterIter() ? config.GetKind_SlopeLimit() :
LIMITER::
NONE),
375 template <
class VariableType>
389 vector_ij = distanceVector<nDim>(iPoint, side_i.
coord, jPoint, side_j.
coord);
396 if (Derived::Conservative || Derived::DiffusionReadsDensity || opt.
boundedScalar) {
409 a0 = fmax(0.0, massFlux) / rho.i;
410 a1 = fmin(0.0, massFlux) / rho.j;
421 if constexpr (Derived::Conservative) {
434 rhoConv.
i = r.
i.all(0);
435 rhoConv.
j = r.
j.all(0);
442 for (
int iDim = 0; iDim <
nDim; ++iDim) vel_ij(iDim) = 0.5 * (u.
i.all(iDim) + u.
j.all(iDim));
445 const auto ug_i = gatherVariables<nDim>(iPoint, side_i.
gridVel);
448 const auto ug_j = opt.
oneSided ? ug_i : gatherVariables<nDim>(jPoint, side_j.
gridVel);
449 for (
int iDim = 0; iDim <
nDim; ++iDim) vel_ij(iDim) -= 0.5 * (ug_i(iDim) + ug_j(iDim));
453 a0 = fmax(0.0, q_ij);
454 a1 = fmin(0.0, q_ij);
461 for (
size_t iVar = 0; iVar < res.
nVar; ++iVar) {
468 reconstruct<nVar>(iPoint, jPoint, vector_ij, side_i.
scalarNodes.GetGradient_Reconstruction(),
478 static_cast<const Derived*
>(
this)->
finalizeFlux(
idx, opt, iPoint, side_i, jPoint, side_j, a0, a1, rhoConv, phi,
494 template <
class VariableType>
500 const auto res =
ComputeFlux(opt, iPoint, side_i, jPoint, side_j, normal, massFlux);
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
Diffusion of a transported scalar, driven by model-supplied coefficients.
Definition scalar_edge_flux.hpp:147
void diffusionTerms(const FlowIndices &idx, const ScalarFluxOptions &opt, Int iPoint, const EdgeSide< VariableType > &side_i, Int jPoint, const EdgeSide< VariableType > &side_j, const CPair< Double > &rho, const Vector< Double, nDim > &normal, const Vector< Double, nDim > &vector_ij, EdgeResidual< Double, nVar > &res) const
Definition scalar_edge_flux.hpp:155
void coefficientJacobians(Ts &&...) const
Contribution of the derivatives of the coefficients themselves.
Definition scalar_edge_flux.hpp:247
void extraDiffusionTerms(Ts &&...) const
Diffusion of a model that transports more than one gradient, of states it synthesises from its own co...
Definition scalar_edge_flux.hpp:254
typename CLaneTraits< Double >::Int Int
Definition scalar_edge_flux.hpp:149
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
bool GetDynamic_Grid(void) const
Get information about dynamic grids.
Definition CConfig.hpp:6276
bool GetMUSCL(void) const
Get if the upwind scheme used MUSCL or not.
Definition CConfig.hpp:4768
unsigned short GetKind_TimeIntScheme(void) const
Get the kind of time integration method.
Definition CConfig.hpp:4732
Class for defining the common variables of flow solvers.
Definition CFlowVariable.hpp:38
unsigned long GetnPrimVarGrad() const
Number of primitive variables that have a gradient/limiter column, from the start of the primitive ro...
Definition CFlowVariable.hpp:213
su2double GetPrimitive(unsigned long iPoint, unsigned long iVar) const final
Get a primitive variable.
Definition CFlowVariable.hpp:95
CMatrixView< su2double > GetGradient_Reconstruction(unsigned long iPoint) final
Get the array of the reconstruction variables gradient at a node.
Definition CFlowVariable.hpp:173
su2double GetLimiter_Primitive(unsigned long iPoint, unsigned long iVar) const final
Get the value of the primitive variables gradient.
Definition CFlowVariable.hpp:190
Class to represent a matrix (without owning the data, this just wraps a pointer).
Definition container_decorators.hpp:40
Class for holding and manipulating vectors needed by linear solvers.
Definition CSysVector.hpp:195
Upwind convection and diffusion of a transported scalar, accumulated into one residual,...
Definition scalar_edge_flux.hpp:316
EdgeResidual< Double, nVar > ComputeFlux(const ScalarFluxOptions &opt, Int iPoint, const EdgeSide< VariableType > &side_i, Int jPoint, const EdgeSide< VariableType > &side_j, const Vector< Double, nDim > &normal, const Double &massFlux) const
Definition scalar_edge_flux.hpp:376
CUpwScalarBase(const CConfig &config, size_t nEqn_=nVar_)
Constructor, inherited by the model with using Base::Base.
Definition scalar_edge_flux.hpp:359
static constexpr bool DiffusionReadsDensity
Whether the model's diffusion coefficients read the density, beyond the reading that Conservative alr...
Definition scalar_edge_flux.hpp:333
typename CLaneTraits< Double_ >::Int Int
Definition scalar_edge_flux.hpp:319
const bool musclFlow
Definition scalar_edge_flux.hpp:350
const su2double kappa
MUSCL reconstruction parameters, read from CConfig once per construction (i.e. once per nonlinear ite...
Definition scalar_edge_flux.hpp:348
const LIMITER limiterTypeFlow
Definition scalar_edge_flux.hpp:349
const size_t nEqn
Equations of the model, which a dynamic one gives to its base.
Definition scalar_edge_flux.hpp:339
const LIMITER limiterType
Definition scalar_edge_flux.hpp:349
Double_ Double
Definition scalar_edge_flux.hpp:318
const FlowIndices idx
Definition scalar_edge_flux.hpp:338
void ComputeFlux(const ScalarFluxOptions &opt, Int iEdge, Int iPoint, const EdgeSide< VariableType > &side_i, Int jPoint, const EdgeSide< VariableType > &side_j, const Vector< Double, nDim > &normal, const Double &massFlux, UpdateType updateType, Double updateMask, CSysVector< su2double > &vector, CSysVector< su2double > &vectorDiff, SparseMatrixType &matrix) const
Compute the flux of an edge and write it to the linear system.
Definition scalar_edge_flux.hpp:495
static constexpr size_t Size
Backing size, for the model to size the containers its coefficients() returns; nVar itself is Dynamic...
Definition scalar_edge_flux.hpp:327
const su2double umusclRamp
Definition scalar_edge_flux.hpp:348
const su2double kappaFlow
Definition scalar_edge_flux.hpp:348
static constexpr int nDim
Definition scalar_edge_flux.hpp:320
static constexpr size_t nVar
Definition scalar_edge_flux.hpp:321
Convective flux shared by every model whose transport equation has the shape flux(iVar) = a0 * w_i * ...
Definition scalar_edge_flux.hpp:264
void finalizeFlux(const FlowIndices &, const ScalarFluxOptions &opt, Int, const EdgeSide< VariableType > &, Int, const EdgeSide< VariableType > &, const Double &a0, const Double &a1, const CPair< Double > &rho, const CPair< CScalarValues< Double, Size > > &phi, EdgeResidual< Double, nVar > &res) const
Upwind convection of the transported variable, weighted by the density for a conservative model.
Definition scalar_edge_flux.hpp:283
typename CLaneTraits< Double >::Int Int
Definition scalar_edge_flux.hpp:266
CUpwScalarFlux(const CConfig &)
Definition scalar_edge_flux.hpp:268
#define FORCEINLINE
Definition code_config.hpp:44
passivedouble su2double
Definition code_config.hpp:181
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
void StartPreacc()
Starts a new preaccumulation section and sets the input variables.
Definition ad_structure.hpp:215
void EndPreacc()
Ends a preaccumulation section and computes the local Jacobi matrix of a code section using the varia...
Definition ad_structure.hpp:243
void SetPreaccIn(Ts &&... data)
Sets the scalar inputs of a preaccumulation section.
Definition ad_structure.hpp:186
UpdateType
Ways to update vectors and system matrices. COLORING is the typical i/j update, whereas for REDUCTION...
Definition util.hpp:44
constexpr size_t Dynamic
Equation count of a model whose value is only known at runtime.
Definition util.hpp:152
auto squaredNorm(ForwardIterator iterator) -> typename std::decay< decltype(*iterator)>::type
Squared norm.
Definition util.hpp:231
void reconstruct(typename CLaneTraits< Double >::Int iPoint, typename CLaneTraits< Double >::Int jPoint, const Vector< Double, nDim > &vector_ij, const Gradient_t &gradient, const Limiter_t &limiter, LIMITER limiterType, size_t iRow, CPair< VarType > &V, const CNonDeduced< Double > &kappa, const CNonDeduced< Double > &umusclRamp, size_t nVarGradRuntime=0)
Reconstruct a slice of nVarGrad variables starting at column iRow, dispatching on the limiter type; s...
Definition util.hpp:546
void updateLinearSystem(Int iEdge, Int iPoint, Int jPoint, bool implicit, UpdateType updateType, Double updateMask, const Vector< Double, nVar > &flux, const Matrix< Double, nVar, nVar > &jac_i, const Matrix< Double, nVar, nVar > &jac_j, CSysVector< su2double > &vector, SparseMatrixType &matrix)
Update the matrix and right-hand-side of a linear system with one conservative flux.
Definition util.hpp:571
void setPreaccOut(Vector< Double, Size > &x, size_t nVar)
Register the leading nVar entries of a static vector as preaccumulation outputs.
Definition util.hpp:380
auto dot(ForwardIterator iterator, const T *ptr) -> typename std::decay< decltype(*ptr)>::type
Dot product.
Definition util.hpp:203
Double gatherVariables(Int iPoint, const Container &vars, size_t iVar=0)
Gather a single variable, from column iVar (0 by default) of row iPoint of a 2D container,...
Definition util.hpp:277
@ NONE
Definition option_structure.hpp:282
@ EULER_IMPLICIT
Implicit Euler time integration definition.
Definition option_structure.hpp:1711
@ SPACE_UPWIND
Upwind convective numerical method.
Definition option_structure.hpp:633
LIMITER
Types of slope limiters.
Definition option_structure.hpp:1038
@ VAN_ALBADA_EDGE
Slope limiter using Van Albada method (edge formulation).
constexpr passivedouble EPS
Error scale.
Definition option_structure.hpp:100
Index type and lane count that go with a flux value type, the converse of CValueTraits,...
Definition util.hpp:107
Simple pair type for i/j variables.
Definition util.hpp:130
T i
Definition util.hpp:131
T j
Definition util.hpp:131
Thin wrapper giving a Vector the all(iVar) accessor the MUSCL reconstruction helpers expect (see CCom...
Definition scalar_edge_flux.hpp:133
Vector< Double, Size > all
Definition scalar_edge_flux.hpp:136
static constexpr size_t nVar
Only used as VarType::nVar when reconstruct's own nVarGrad_ default applies; every call site here pas...
Definition scalar_edge_flux.hpp:134
Residual of one edge, accumulated by the convective and the diffusive terms.
Definition util.hpp:169
Vector< Double, Size > flux_j
Definition util.hpp:176
Matrix< Double, Size, Size > jac_jj
Definition util.hpp:177
Matrix< Double, Size, Size > jac_ji
Definition util.hpp:177
const size_t nVar
Definition util.hpp:178
Vector< Double, Size > flux_i
Definition util.hpp:176
Matrix< Double, Size, Size > jac_ii
Definition util.hpp:177
Matrix< Double, Size, Size > jac_ij
Definition util.hpp:177
Locates the data of one endpoint of an edge.
Definition scalar_edge_flux.hpp:42
CMatrixView< const su2double > gridVel
Empty when the grid is static.
Definition scalar_edge_flux.hpp:46
CMatrixView< const su2double > coord
Point coordinates.
Definition scalar_edge_flux.hpp:45
const CFlowVariable * flowNodes
Flow variables, null for solid heat transfer.
Definition scalar_edge_flux.hpp:44
const VariableType & scalarNodes
Scalar solver variables.
Definition scalar_edge_flux.hpp:43
Loop invariant flags for a scalar edge flux, built once outside the edge loop so the compiler can uns...
Definition scalar_edge_flux.hpp:55
bool viscous
Whether the diffusion term contributes.
Definition scalar_edge_flux.hpp:62
bool implicit
Whether the Jacobians are assembled, and so computed.
Definition scalar_edge_flux.hpp:60
bool accurateJacobians
Definition scalar_edge_flux.hpp:59
bool muscl
Whether the convective scheme reconstructs.
Definition scalar_edge_flux.hpp:64
bool boundedScalar
Definition scalar_edge_flux.hpp:57
bool oneSided
Whether only the row of i is assembled.
Definition scalar_edge_flux.hpp:63
static ScalarFluxOptions BoundaryDiffusive(const CConfig &config, bool correctGrad)
Options of the diffusive pass of a fluid interface, which follows a convective pass over the donor ve...
Definition scalar_edge_flux.hpp:110
static ScalarFluxOptions BoundaryFull(const CConfig &config)
Options of a boundary that imposes both terms, which is the turbomachinery sites.
Definition scalar_edge_flux.hpp:96
bool dynamicGrid
Definition scalar_edge_flux.hpp:56
bool correctGradient
Definition scalar_edge_flux.hpp:58
static ScalarFluxOptions Interior(const CConfig &config, bool bounded, bool accurateJacobians=false)
Options of the interior edge loop: both terms, both rows, and reconstruction and gradient correction ...
Definition scalar_edge_flux.hpp:70
bool convective
Whether the convective scheme contributes.
Definition scalar_edge_flux.hpp:61
static ScalarFluxOptions BoundaryConvective(const CConfig &config, bool bounded)
Options of a boundary that imposes a convective flux alone, which is most of them: the diffusive term...
Definition scalar_edge_flux.hpp:84