Skip to content

Commit c4f27dc

Browse files
authored
Merge branch 'develop' into improve_mg
2 parents cb9fce3 + 6338bff commit c4f27dc

69 files changed

Lines changed: 2771 additions & 2857 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Common/include/code_config.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ template<class T, class F> struct su2conditional<false, T, F> { using type = F;
6767
template<bool B, class T, class F>
6868
using su2conditional_t = typename su2conditional<B,T,F>::type;
6969

70+
/*! \brief Static cast "In" to "Out", in debug builds a dynamic cast is used. */
71+
template<class Out, class In>
72+
FORCEINLINE Out su2staticcast_p(In ptr) {
73+
static_assert(std::is_pointer<In>::value, "This expects a pointer");
74+
#ifndef NDEBUG
75+
return static_cast<Out>(ptr);
76+
#else
77+
return dynamic_cast<Out>(ptr);
78+
#endif
79+
}
80+
7081
/*--- Detect compilation with OpenMP. ---*/
7182
#if defined(_OPENMP)
7283
#define HAVE_OMP

SU2_CFD/include/drivers/CDiscAdjSinglezoneDriver.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ class CDiscAdjSinglezoneDriver : public CSinglezoneDriver {
112112
*/
113113
void SetAdj_ObjFunction(void);
114114

115-
/*!
116-
* \brief Print out the direct residuals.
117-
* \param[in] kind_recording - Type of recording (full list in ENUM_RECORDING, option_structure.hpp)
118-
*/
119-
void Print_DirectResidual(RECORDING kind_recording);
120-
121115
/*!
122116
* \brief Record the main computational path.
123117
*/

SU2_CFD/include/drivers/CDriver.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ class CDriver {
313313
*/
314314
virtual void Update() {}
315315

316+
/*!
317+
* \brief Print out the direct residuals.
318+
* \param[in] kind_recording - Type of recording (full list in ENUM_RECORDING, option_structure.hpp)
319+
*/
320+
void Print_DirectResidual(RECORDING kind_recording);
321+
316322
public:
317323

318324
/*!

SU2_CFD/include/limiters/CLimiterDetails.hpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,28 @@ struct CLimiterDetails
6464
/*!
6565
* \brief Common small functions used by limiters.
6666
*/
67-
namespace LimiterHelpers
67+
template<class Type = su2double>
68+
struct LimiterHelpers
6869
{
69-
inline passivedouble epsilon() {return std::numeric_limits<passivedouble>::epsilon();}
70+
FORCEINLINE static Type epsilon() {return std::numeric_limits<passivedouble>::epsilon();}
7071

71-
inline su2double venkatFunction(su2double proj, su2double delta, su2double eps2)
72+
FORCEINLINE static Type venkatFunction(const Type& proj, const Type& delta, const Type& eps2)
7273
{
73-
su2double y = delta*(delta+proj) + eps2;
74+
Type y = delta*(delta+proj) + eps2;
7475
return (y + delta*proj) / (y + 2*proj*proj);
7576
}
7677

77-
inline su2double raisedSine(su2double dist)
78+
FORCEINLINE static Type vanAlbadaFunction(const Type& proj, const Type& delta, const Type& eps)
7879
{
79-
su2double factor = 0.5*(1.0+dist+sin(PI_NUMBER*dist)/PI_NUMBER);
80+
return delta * (2*proj + delta) / (4*pow(proj, 2) + pow(delta, 2) + eps);
81+
}
82+
83+
FORCEINLINE static Type raisedSine(const Type& dist)
84+
{
85+
Type factor = 0.5*(1.0+dist+sin(PI_NUMBER*dist)/PI_NUMBER);
8086
return max(0.0, min(factor, 1.0));
8187
}
82-
}
88+
};
8389

8490

8591
/*!
@@ -94,7 +100,7 @@ struct CLimiterDetails<BARTH_JESPERSEN>
94100
* \brief Set a small epsilon to avoid divisions by 0.
95101
*/
96102
template<class... Ts>
97-
inline void preprocess(Ts&...) {eps2 = LimiterHelpers::epsilon();}
103+
inline void preprocess(Ts&...) {eps2 = LimiterHelpers<>::epsilon();}
98104

99105
/*!
100106
* \brief No geometric modification for this kind of limiter.
@@ -107,7 +113,7 @@ struct CLimiterDetails<BARTH_JESPERSEN>
107113
*/
108114
inline su2double limiterFunction(size_t, su2double proj, su2double delta) const
109115
{
110-
return LimiterHelpers::venkatFunction(proj, delta, eps2);
116+
return LimiterHelpers<>::venkatFunction(proj, delta, eps2);
111117
}
112118
};
113119

@@ -130,7 +136,7 @@ struct CLimiterDetails<VENKATAKRISHNAN>
130136
su2double L = config.GetRefElemLength();
131137
su2double K = config.GetVenkat_LimiterCoeff();
132138
su2double eps1 = fabs(L*K);
133-
eps2 = max(eps1*eps1*eps1, LimiterHelpers::epsilon());
139+
eps2 = max(eps1*eps1*eps1, LimiterHelpers<>::epsilon());
134140
}
135141

136142
/*!
@@ -144,7 +150,7 @@ struct CLimiterDetails<VENKATAKRISHNAN>
144150
*/
145151
inline su2double limiterFunction(size_t, su2double proj, su2double delta) const
146152
{
147-
return LimiterHelpers::venkatFunction(proj, delta, eps2);
153+
return LimiterHelpers<>::venkatFunction(proj, delta, eps2);
148154
}
149155
};
150156

@@ -229,7 +235,7 @@ struct CLimiterDetails<VENKATAKRISHNAN_WANG>
229235
for(size_t iVar = varBegin; iVar < varEnd; ++iVar)
230236
{
231237
su2double range = sharedMax(iVar) - sharedMin(iVar);
232-
eps2(iVar) = max(pow(K*range, 2), LimiterHelpers::epsilon());
238+
eps2(iVar) = max(pow(K*range, 2), LimiterHelpers<>::epsilon());
233239
}
234240
}
235241

@@ -245,7 +251,7 @@ struct CLimiterDetails<VENKATAKRISHNAN_WANG>
245251
inline su2double limiterFunction(size_t iVar, su2double proj, su2double delta) const
246252
{
247253
AD::SetPreaccIn(eps2(iVar));
248-
return LimiterHelpers::venkatFunction(proj, delta, eps2(iVar));
254+
return LimiterHelpers<>::venkatFunction(proj, delta, eps2(iVar));
249255
}
250256
};
251257

@@ -268,7 +274,7 @@ struct CLimiterDetails<SHARP_EDGES>
268274
su2double L = config.GetRefElemLength();
269275
su2double K = config.GetVenkat_LimiterCoeff();
270276
eps1 = fabs(L*K);
271-
eps2 = max(eps1*eps1*eps1, LimiterHelpers::epsilon());
277+
eps2 = max(eps1*eps1*eps1, LimiterHelpers<>::epsilon());
272278
}
273279

274280
/*!
@@ -278,15 +284,15 @@ struct CLimiterDetails<SHARP_EDGES>
278284
{
279285
AD::SetPreaccIn(geometry.nodes->GetSharpEdge_Distance(iPoint));
280286
su2double dist = geometry.nodes->GetSharpEdge_Distance(iPoint)/(sharpCoeff*eps1)-1.0;
281-
return LimiterHelpers::raisedSine(dist);
287+
return LimiterHelpers<>::raisedSine(dist);
282288
}
283289

284290
/*!
285291
* \brief Smooth function that disables limiting in smooth regions.
286292
*/
287293
inline su2double limiterFunction(size_t, su2double proj, su2double delta) const
288294
{
289-
return LimiterHelpers::venkatFunction(proj, delta, eps2);
295+
return LimiterHelpers<>::venkatFunction(proj, delta, eps2);
290296
}
291297
};
292298

@@ -309,7 +315,7 @@ struct CLimiterDetails<WALL_DISTANCE>
309315
su2double L = config.GetRefElemLength();
310316
su2double K = config.GetVenkat_LimiterCoeff();
311317
eps1 = fabs(L*K);
312-
eps2 = max(eps1*eps1*eps1, LimiterHelpers::epsilon());
318+
eps2 = max(eps1*eps1*eps1, LimiterHelpers<>::epsilon());
313319
}
314320

315321
/*!
@@ -319,14 +325,14 @@ struct CLimiterDetails<WALL_DISTANCE>
319325
{
320326
AD::SetPreaccIn(geometry.nodes->GetWall_Distance(iPoint));
321327
su2double dist = geometry.nodes->GetWall_Distance(iPoint)/(sharpCoeff*eps1)-1.0;
322-
return LimiterHelpers::raisedSine(dist);
328+
return LimiterHelpers<>::raisedSine(dist);
323329
}
324330

325331
/*!
326332
* \brief Smooth function that disables limiting in smooth regions.
327333
*/
328334
inline su2double limiterFunction(size_t, su2double proj, su2double delta) const
329335
{
330-
return LimiterHelpers::venkatFunction(proj, delta, eps2);
336+
return LimiterHelpers<>::venkatFunction(proj, delta, eps2);
331337
}
332338
};

SU2_CFD/include/numerics/CNumerics.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class CNumerics {
130130
*Psi_i, /*!< \brief Vector of adjoint variables at point i. */
131131
*Psi_j; /*!< \brief Vector of adjoint variables at point j. */
132132
const su2double
133-
*TurbVar_i, /*!< \brief Vector of turbulent variables at point i. */
134-
*TurbVar_j; /*!< \brief Vector of turbulent variables at point j. */
133+
*ScalarVar_i, /*!< \brief Vector of scalar variables at point i. */
134+
*ScalarVar_j; /*!< \brief Vector of scalar variables at point j. */
135135
const su2double
136136
*TransVar_i, /*!< \brief Vector of turbulent variables at point i. */
137137
*TransVar_j; /*!< \brief Vector of turbulent variables at point j. */
@@ -146,8 +146,8 @@ class CNumerics {
146146
PrimVar_Grad_j, /*!< \brief Gradient of primitive variables at point j. */
147147
PsiVar_Grad_i, /*!< \brief Gradient of adjoint variables at point i. */
148148
PsiVar_Grad_j, /*!< \brief Gradient of adjoint variables at point j. */
149-
TurbVar_Grad_i, /*!< \brief Gradient of turbulent variables at point i. */
150-
TurbVar_Grad_j, /*!< \brief Gradient of turbulent variables at point j. */
149+
ScalarVar_Grad_i, /*!< \brief Gradient of scalar variables at point i. */
150+
ScalarVar_Grad_j, /*!< \brief Gradient of scalar variables at point j. */
151151
TransVar_Grad_i, /*!< \brief Gradient of turbulent variables at point i. */
152152
TransVar_Grad_j, /*!< \brief Gradient of turbulent variables at point j. */
153153
TurbPsi_Grad_i, /*!< \brief Gradient of adjoint turbulent variables at point i. */
@@ -347,13 +347,13 @@ class CNumerics {
347347
}
348348

349349
/*!
350-
* \brief Set the value of the turbulent variable.
351-
* \param[in] val_turbvar_i - Value of the turbulent variable at point i.
352-
* \param[in] val_turbvar_j - Value of the turbulent variable at point j.
350+
* \brief Set the value of the scalar variable.
351+
* \param[in] val_scalarvar_i - Value of the scalar variable at point i.
352+
* \param[in] val_scalarvar_j - Value of the scalar variable at point j.
353353
*/
354-
inline void SetTurbVar(const su2double *val_turbvar_i, const su2double *val_turbvar_j) {
355-
TurbVar_i = val_turbvar_i;
356-
TurbVar_j = val_turbvar_j;
354+
inline void SetScalarVar(const su2double *val_scalarvar_i, const su2double *val_scalarvar_j) {
355+
ScalarVar_i = val_scalarvar_i;
356+
ScalarVar_j = val_scalarvar_j;
357357
}
358358

359359
/*!
@@ -367,14 +367,14 @@ class CNumerics {
367367
}
368368

369369
/*!
370-
* \brief Set the gradient of the turbulent variables.
371-
* \param[in] val_turbvar_grad_i - Gradient of the turbulent variable at point i.
372-
* \param[in] val_turbvar_grad_j - Gradient of the turbulent variable at point j.
370+
* \brief Set the gradient of the scalar variables.
371+
* \param[in] val_scalarvar_grad_i - Gradient of the scalar variable at point i.
372+
* \param[in] val_scalarvar_grad_j - Gradient of the scalar variable at point j.
373373
*/
374-
inline void SetTurbVarGradient(CMatrixView<const su2double> val_turbvar_grad_i,
375-
CMatrixView<const su2double> val_turbvar_grad_j) {
376-
TurbVar_Grad_i = val_turbvar_grad_i;
377-
TurbVar_Grad_j = val_turbvar_grad_j;
374+
inline void SetScalarVarGradient(CMatrixView<const su2double> val_scalarvar_grad_i,
375+
CMatrixView<const su2double> val_scalarvar_grad_j) {
376+
ScalarVar_Grad_i = val_scalarvar_grad_i;
377+
ScalarVar_Grad_j = val_scalarvar_grad_j;
378378
}
379379

380380
/*!
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*!
2+
* \file scalar_convection.hpp
3+
* \brief Delarations of numerics classes for discretization of
4+
* convective fluxes in scalar problems.
5+
* \author F. Palacios, T. Economon
6+
* \version 7.2.0 "Blackbird"
7+
*
8+
* SU2 Project Website: https://su2code.github.io
9+
*
10+
* The SU2 Project is maintained by the SU2 Foundation
11+
* (http://su2foundation.org)
12+
*
13+
* Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md)
14+
*
15+
* SU2 is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU Lesser General Public
17+
* License as published by the Free Software Foundation; either
18+
* version 2.1 of the License, or (at your option) any later version.
19+
*
20+
* SU2 is distributed in the hope that it will be useful,
21+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23+
* Lesser General Public License for more details.
24+
*
25+
* You should have received a copy of the GNU Lesser General Public
26+
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
29+
#pragma once
30+
31+
#include "../CNumerics.hpp"
32+
33+
/*!
34+
* \class CUpwScalar
35+
* \brief Template class for scalar upwind fluxes between nodes i and j.
36+
* \details This class serves as a template for the scalar upwinding residual
37+
* classes. The general structure of a scalar upwinding calculation is the
38+
* same for many different models, which leads to a lot of repeated code.
39+
* By using the template design pattern, these sections of repeated code are
40+
* moved to this shared base class, and the specifics of each model
41+
* are implemented by derived classes. In order to add a new residual
42+
* calculation for a convection residual, extend this class and implement
43+
* the pure virtual functions with model-specific behavior.
44+
* \ingroup ConvDiscr
45+
* \author C. Pederson, A. Bueno., and A. Campos.
46+
*/
47+
class CUpwScalar : public CNumerics {
48+
protected:
49+
su2double a0 = 0.0; /*!< \brief The maximum of the face-normal velocity and 0 */
50+
su2double a1 = 0.0; /*!< \brief The minimum of the face-normal velocity and 0 */
51+
su2double* Flux = nullptr; /*!< \brief Final result, diffusive flux/residual. */
52+
su2double** Jacobian_i = nullptr; /*!< \brief Flux Jacobian w.r.t. node i. */
53+
su2double** Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */
54+
55+
const bool implicit = false, incompressible = false, dynamic_grid = false;
56+
57+
/*!
58+
* \brief A pure virtual function; Adds any extra variables to AD
59+
*/
60+
virtual void ExtraADPreaccIn() = 0;
61+
62+
/*!
63+
* \brief Model-specific steps in the ComputeResidual method, derived classes
64+
* compute the Flux and its Jacobians via this method.
65+
* \param[in] config - Definition of the particular problem.
66+
*/
67+
virtual void FinishResidualCalc(const CConfig* config) = 0;
68+
69+
public:
70+
/*!
71+
* \brief Constructor of the class.
72+
* \param[in] val_nDim - Number of dimensions of the problem.
73+
* \param[in] val_nVar - Number of variables of the problem.
74+
* \param[in] config - Definition of the particular problem.
75+
*/
76+
CUpwScalar(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config);
77+
78+
/*!
79+
* \brief Destructor of the class.
80+
*/
81+
~CUpwScalar(void) override;
82+
83+
/*!
84+
* \brief Compute the scalar upwind flux between two nodes i and j.
85+
* \param[in] config - Definition of the particular problem.
86+
* \return A lightweight const-view (read-only) of the residual/flux and Jacobians.
87+
*/
88+
ResidualType<> ComputeResidual(const CConfig* config) override;
89+
};

0 commit comments

Comments
 (0)