From 944efc71206a98c5d37b194816c3b491d666144f Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 21 Jul 2021 17:20:14 +0200 Subject: [PATCH 01/48] Create CScalar and scalar_conv/diff/source layer and put it in front of CTurb-classes. --- .../numerics/scalar/scalar_convection.hpp | 151 +++ .../numerics/scalar/scalar_diffusion.hpp | 209 +++ .../numerics/scalar/scalar_sources.hpp | 417 ++++++ .../numerics/turbulent/turb_convection.hpp | 122 -- .../numerics/turbulent/turb_diffusion.hpp | 180 --- .../numerics/turbulent/turb_sources.hpp | 387 ------ SU2_CFD/include/solvers/CScalarSolver.hpp | 425 ++++++ SU2_CFD/include/solvers/CTurbSolver.hpp | 369 +----- SU2_CFD/include/variables/CScalarVariable.hpp | 90 ++ SU2_CFD/include/variables/CTurbVariable.hpp | 39 +- SU2_CFD/src/drivers/CDriver.cpp | 6 +- SU2_CFD/src/meson.build | 5 + .../src/numerics/scalar/scalar_convection.cpp | 145 +++ .../src/numerics/scalar/scalar_diffusion.cpp | 225 ++++ .../src/numerics/scalar/scalar_sources.cpp | 930 +++++++++++++ .../numerics/turbulent/turb_convection.cpp | 116 -- .../src/numerics/turbulent/turb_diffusion.cpp | 196 --- .../src/numerics/turbulent/turb_sources.cpp | 901 ------------- SU2_CFD/src/solvers/CScalarSolver.cpp | 1146 +++++++++++++++++ SU2_CFD/src/solvers/CTurbSolver.cpp | 1109 +--------------- SU2_CFD/src/variables/CScalarVariable.cpp | 66 + SU2_CFD/src/variables/CTurbVariable.cpp | 33 +- 22 files changed, 3819 insertions(+), 3448 deletions(-) create mode 100644 SU2_CFD/include/numerics/scalar/scalar_convection.hpp create mode 100644 SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp create mode 100644 SU2_CFD/include/numerics/scalar/scalar_sources.hpp create mode 100644 SU2_CFD/include/solvers/CScalarSolver.hpp create mode 100644 SU2_CFD/include/variables/CScalarVariable.hpp create mode 100644 SU2_CFD/src/numerics/scalar/scalar_convection.cpp create mode 100644 SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp create mode 100644 SU2_CFD/src/numerics/scalar/scalar_sources.cpp create mode 100644 SU2_CFD/src/solvers/CScalarSolver.cpp create mode 100644 SU2_CFD/src/variables/CScalarVariable.cpp diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp new file mode 100644 index 000000000000..9e2cea2032aa --- /dev/null +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -0,0 +1,151 @@ +/*! + * \file turb_convection.hpp + * \brief Delarations of numerics classes for discretization of + * convective fluxes in turbulence problems. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#pragma once + +#include "../CNumerics.hpp" + +/*! + * \class CUpwScalar + * \brief Template class for scalar upwind fluxes between nodes i and j. + * \details This class serves as a template for the scalar upwinding residual + * classes. The general structure of a scalar upwinding calculation is the + * same for many different models, which leads to a lot of repeated code. + * By using the template design pattern, these sections of repeated code are + * moved to this shared base class, and the specifics of each model + * are implemented by derived classes. In order to add a new residual + * calculation for a convection residual, extend this class and implement + * the pure virtual functions with model-specific behavior. + * \ingroup ConvDiscr + * \author C. Pederson, A. Bueno., and A. Campos. + */ +class CUpwScalar : public CNumerics { +protected: + su2double + a0 = 0.0, /*!< \brief The maximum of the face-normal velocity and 0 */ + a1 = 0.0, /*!< \brief The minimum of the face-normal velocity and 0 */ + *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ + **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ + **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + + const bool implicit = false, incompressible = false, dynamic_grid = false; + + /*! + * \brief A pure virtual function; Adds any extra variables to AD + */ + virtual void ExtraADPreaccIn() = 0; + + /*! + * \brief Model-specific steps in the ComputeResidual method, derived classes + * compute the Flux and its Jacobians via this method. + * \param[in] config - Definition of the particular problem. + */ + virtual void FinishResidualCalc(const CConfig* config) = 0; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CUpwScalar(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Destructor of the class. + */ + ~CUpwScalar(void) override; + + /*! + * \brief Compute the scalar upwind flux between two nodes i and j. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CUpwSca_TurbSA + * \brief Class for doing a scalar upwind solver for the Spalar-Allmaras turbulence model equations. + * \ingroup ConvDiscr + * \author A. Bueno. + */ +class CUpwSca_TurbSA final : public CUpwScalar { +private: + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn() override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CUpwSca_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + +}; + +/*! + * \class CUpwSca_TurbSST + * \brief Class for doing a scalar upwind solver for the Menter SST turbulence model equations. + * \ingroup ConvDiscr + * \author A. Campos. + */ +class CUpwSca_TurbSST final : public CUpwScalar { +private: + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn() override; + + /*! + * \brief SST specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CUpwSca_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + +}; diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp new file mode 100644 index 000000000000..fb07044dc044 --- /dev/null +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -0,0 +1,209 @@ +/*! + * \file turb_diffusion.hpp + * \brief Declarations of numerics classes for discretization of + * viscous fluxes in turbulence problems. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#pragma once + +#include "../CNumerics.hpp" + +/*! + * \class CAvgGrad_Scalar + * \brief Template class for computing viscous residual of scalar values + * \details This class serves as a template for the scalar viscous residual + * classes. The general structure of a viscous residual calculation is the + * same for many different models, which leads to a lot of repeated code. + * By using the template design pattern, these sections of repeated code are + * moved to a shared base class, and the specifics of each model + * are implemented by derived classes. In order to add a new residual + * calculation for a viscous residual, extend this class and implement + * the pure virtual functions with model-specific behavior. + * \ingroup ViscDiscr + * \author C. Pederson, A. Bueno, and F. Palacios + */ +class CAvgGrad_Scalar : public CNumerics { +protected: + su2double + *Proj_Mean_GradTurbVar_Normal = nullptr, /*!< \brief Mean_gradTurbVar DOT normal. */ + *Proj_Mean_GradTurbVar = nullptr, /*!< \brief Mean_gradTurbVar DOT normal, corrected if required. */ + proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ + *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ + **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ + **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + + const bool correct_gradient = false, implicit = false, incompressible = false; + + /*! + * \brief A pure virtual function; Adds any extra variables to AD + */ + virtual void ExtraADPreaccIn() = 0; + + /*! + * \brief Model-specific steps in the ComputeResidual method, derived classes + * should compute the Flux and Jacobians (i/j) inside this method. + * \param[in] config - Definition of the particular problem. + */ + virtual void FinishResidualCalc(const CConfig* config) = 0; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] correct_gradient - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, + bool correct_gradient, const CConfig* config); + + /*! + * \brief Destructor of the class. + */ + ~CAvgGrad_Scalar(void) override; + + /*! + * \brief Compute the viscous residual using an average of gradients without correction. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CAvgGrad_TurbSA + * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). + * \ingroup ViscDiscr + * \author A. Bueno. + */ +class CAvgGrad_TurbSA final : public CAvgGrad_Scalar { +private: + const su2double sigma = 2.0/3.0; + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config); +}; + +/*! + * \class CAvgGrad_TurbSA_Neg + * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). + * \ingroup ViscDiscr + * \author F. Palacios + */ +class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar { +private: + const su2double sigma = 2.0/3.0; + const su2double cn1 = 16.0; + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config); +}; + +/*! + * \class CAvgGrad_TurbSST + * \brief Class for computing viscous term using average of gradient with correction (Menter SST turbulence model). + * \ingroup ViscDiscr + * \author A. Bueno. + */ +class CAvgGrad_TurbSST final : public CAvgGrad_Scalar { +private: + const su2double + sigma_k1 = 0.0, /*!< \brief Constants for the viscous terms, k-w (1), k-eps (2)*/ + sigma_k2 = 0.0, + sigma_om1 = 0.0, + sigma_om2 = 0.0; + + su2double F1_i, F1_j; /*!< \brief Menter's first blending function */ + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SST specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] constants - Constants of the model. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSST(unsigned short val_nDim, unsigned short val_nVar, + const su2double* constants, bool correct_grad, const CConfig* config); + + /*! + * \brief Sets value of first blending function. + */ + void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { + F1_i = val_F1_i; F1_j = val_F1_j; + } + +}; diff --git a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp new file mode 100644 index 000000000000..2e0e2b8cb62a --- /dev/null +++ b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp @@ -0,0 +1,417 @@ +/*! + * \file turb_sources.hpp + * \brief Delarations of numerics classes for integration of source + * terms in turbulence problems. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#pragma once + +#include "../CNumerics.hpp" + +/*! + * \class CSourcePieceWise_TurbSA + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author A. Bueno. + */ +class CSourceBase_TurbSA : public CNumerics { +protected: + su2double cv1_3; + su2double k2; + su2double cb1; + su2double cw2; + su2double ct3; + su2double ct4; + su2double cw3_6; + su2double cb2_sigma; + su2double sigma; + su2double cb2; + su2double cw1; + su2double cr1; + + su2double Gamma_BC = 0.0; + su2double intermittency; + su2double Production, Destruction, CrossProduction; + + su2double Residual, *Jacobian_i; +private: + su2double Jacobian_Buffer; /// Static storage for the Jacobian (which needs to be pointer for return type). + +protected: + const bool incompressible = false, rotating_frame = false; + bool roughwall = false; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourceBase_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] intermittency_in - Value of the intermittency. + */ + inline void SetIntermittency(su2double intermittency_in) final { intermittency = intermittency_in; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_production - Value of the Production. + */ + inline void SetProduction(su2double val_production) final { Production = val_production; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_destruction - Value of the Destruction. + */ + inline void SetDestruction(su2double val_destruction) final { Destruction = val_destruction; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_crossproduction - Value of the CrossProduction. + */ + inline void SetCrossProduction(su2double val_crossproduction) final { CrossProduction = val_crossproduction; } + + /*! + * \brief ______________. + */ + inline su2double GetProduction(void) const final { return Production; } + + /*! + * \brief Get the intermittency for the BC trans. model. + * \return Value of the intermittency. + */ + inline su2double GetGammaBC(void) const final { return Gamma_BC; } + + /*! + * \brief ______________. + */ + inline su2double GetDestruction(void) const final { return Destruction; } + + /*! + * \brief ______________. + */ + inline su2double GetCrossProduction(void) const final { return CrossProduction; } +}; + + +/*! + * \class CSourcePieceWise_TurbSA + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author A. Bueno. + */ +class CSourcePieceWise_TurbSA final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + unsigned short iDim; + bool transition; + bool axisymmetric; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSA_COMP + * \brief Class for integrating the source terms of the Spalart-Allmaras CC modification turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_COMP final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double aux_cc, CompCorrection, c5; + unsigned short iDim, jDim; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSA_E + * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_E final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double Sbar; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_E(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; +}; + +/*! + * \class CSourcePieceWise_TurbSA_E_COMP + * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification with CC turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_E_COMP : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double Sbar; + su2double aux_cc, CompCorrection, c5; + unsigned short jDim; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; +}; + +/*! + * \class CSourcePieceWise_TurbSA_Neg + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author F. Palacios + */ +class CSourcePieceWise_TurbSA_Neg : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSST + * \brief Class for integrating the source terms of the Menter SST turbulence model equations. + * \ingroup SourceDiscr + * \author A. Campos. + */ +class CSourcePieceWise_TurbSST final : public CNumerics { +private: + su2double F1_i, + F1_j, + F2_i, + F2_j; + + su2double alfa_1, + alfa_2, + beta_1, + beta_2, + sigma_k_1, + sigma_k_2, + sigma_w_1, + sigma_w_2, + beta_star, + a1; + + su2double CDkw_i, CDkw_j; + + su2double kAmb, omegaAmb; + + su2double Residual[2], + *Jacobian_i[2] = {nullptr}, + Jacobian_Buffer[4] = {0.0}; /// Static storage for the Jacobian (which needs to be pointer for return type). + + bool incompressible; + bool sustaining_terms; + bool axisymmetric; + + /*! + * \brief A virtual member. Get strain magnitude based on perturbed reynolds stress matrix + * \param[in] turb_ke: turbulent kinetic energy of the node + */ + void SetPerturbedStrainMag(su2double turb_ke); + + /*! + * \brief Add contribution due to axisymmetric formulation to 2D residual + */ + inline void ResidualAxisymmetric(su2double alfa_blended, su2double zeta){ + + if (Coord_i[1] < EPS) return; + + su2double yinv, rhov, k, w; + su2double sigma_k_i, sigma_w_i; + su2double pk_axi, pw_axi, cdk_axi, cdw_axi; + + AD::SetPreaccIn(Coord_i[1]); + + yinv = 1.0/Coord_i[1]; + rhov = Density_i*V_i[2]; + k = TurbVar_i[0]; + w = TurbVar_i[1]; + + /*--- Compute blended constants ---*/ + sigma_k_i = F1_i*sigma_k_1+(1.0-F1_i)*sigma_k_2; + sigma_w_i = F1_i*sigma_w_1+(1.0-F1_i)*sigma_w_2; + + /*--- Production ---*/ + pk_axi = max(0.0,2.0/3.0*rhov*k*(2.0/zeta*(yinv*V_i[2]-PrimVar_Grad_i[2][1]-PrimVar_Grad_i[1][0])-1.0)); + pw_axi = alfa_blended*zeta/k*pk_axi; + + /*--- Convection-Diffusion ---*/ + cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*TurbVar_Grad_i[0][1]; + cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*TurbVar_Grad_i[1][1]; + + /*--- Add terms to the residuals ---*/ + Residual[0] += yinv*Volume*(pk_axi-cdk_axi); + Residual[1] += yinv*Volume*(pw_axi-cdw_axi); + + } + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const su2double* constants, + su2double val_kine_Inf, su2double val_omega_Inf, const CConfig* config); + + /*! + * \brief Set the value of the first blending function. + * \param[in] val_F1_i - Value of the first blending function at point i. + * \param[in] val_F1_j - Value of the first blending function at point j. + */ + inline void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { + F1_i = val_F1_i; + F1_j = val_F1_j; + } + + /*! + * \brief Set the value of the second blending function. + * \param[in] val_F2_i - Value of the second blending function at point i. + * \param[in] val_F2_j - Value of the second blending function at point j. + */ + inline void SetF2blending(su2double val_F2_i, su2double val_F2_j) override { + F2_i = val_F2_i; + F2_j = val_F2_j; + } + + /*! + * \brief Set the value of the cross diffusion for the SST model. + * \param[in] val_CDkw_i - Value of the cross diffusion at point i. + * \param[in] val_CDkw_j - Value of the cross diffusion at point j. + */ + inline void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) override { + CDkw_i = val_CDkw_i; + CDkw_j = val_CDkw_j; + } + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_convection.hpp b/SU2_CFD/include/numerics/turbulent/turb_convection.hpp index 9e2cea2032aa..ccb69c2cf75a 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_convection.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_convection.hpp @@ -27,125 +27,3 @@ */ #pragma once - -#include "../CNumerics.hpp" - -/*! - * \class CUpwScalar - * \brief Template class for scalar upwind fluxes between nodes i and j. - * \details This class serves as a template for the scalar upwinding residual - * classes. The general structure of a scalar upwinding calculation is the - * same for many different models, which leads to a lot of repeated code. - * By using the template design pattern, these sections of repeated code are - * moved to this shared base class, and the specifics of each model - * are implemented by derived classes. In order to add a new residual - * calculation for a convection residual, extend this class and implement - * the pure virtual functions with model-specific behavior. - * \ingroup ConvDiscr - * \author C. Pederson, A. Bueno., and A. Campos. - */ -class CUpwScalar : public CNumerics { -protected: - su2double - a0 = 0.0, /*!< \brief The maximum of the face-normal velocity and 0 */ - a1 = 0.0, /*!< \brief The minimum of the face-normal velocity and 0 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ - - const bool implicit = false, incompressible = false, dynamic_grid = false; - - /*! - * \brief A pure virtual function; Adds any extra variables to AD - */ - virtual void ExtraADPreaccIn() = 0; - - /*! - * \brief Model-specific steps in the ComputeResidual method, derived classes - * compute the Flux and its Jacobians via this method. - * \param[in] config - Definition of the particular problem. - */ - virtual void FinishResidualCalc(const CConfig* config) = 0; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CUpwScalar(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Destructor of the class. - */ - ~CUpwScalar(void) override; - - /*! - * \brief Compute the scalar upwind flux between two nodes i and j. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CUpwSca_TurbSA - * \brief Class for doing a scalar upwind solver for the Spalar-Allmaras turbulence model equations. - * \ingroup ConvDiscr - * \author A. Bueno. - */ -class CUpwSca_TurbSA final : public CUpwScalar { -private: - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn() override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CUpwSca_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - -}; - -/*! - * \class CUpwSca_TurbSST - * \brief Class for doing a scalar upwind solver for the Menter SST turbulence model equations. - * \ingroup ConvDiscr - * \author A. Campos. - */ -class CUpwSca_TurbSST final : public CUpwScalar { -private: - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn() override; - - /*! - * \brief SST specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CUpwSca_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - -}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp index fb07044dc044..d0fbecdb8a06 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp @@ -27,183 +27,3 @@ */ #pragma once - -#include "../CNumerics.hpp" - -/*! - * \class CAvgGrad_Scalar - * \brief Template class for computing viscous residual of scalar values - * \details This class serves as a template for the scalar viscous residual - * classes. The general structure of a viscous residual calculation is the - * same for many different models, which leads to a lot of repeated code. - * By using the template design pattern, these sections of repeated code are - * moved to a shared base class, and the specifics of each model - * are implemented by derived classes. In order to add a new residual - * calculation for a viscous residual, extend this class and implement - * the pure virtual functions with model-specific behavior. - * \ingroup ViscDiscr - * \author C. Pederson, A. Bueno, and F. Palacios - */ -class CAvgGrad_Scalar : public CNumerics { -protected: - su2double - *Proj_Mean_GradTurbVar_Normal = nullptr, /*!< \brief Mean_gradTurbVar DOT normal. */ - *Proj_Mean_GradTurbVar = nullptr, /*!< \brief Mean_gradTurbVar DOT normal, corrected if required. */ - proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ - - const bool correct_gradient = false, implicit = false, incompressible = false; - - /*! - * \brief A pure virtual function; Adds any extra variables to AD - */ - virtual void ExtraADPreaccIn() = 0; - - /*! - * \brief Model-specific steps in the ComputeResidual method, derived classes - * should compute the Flux and Jacobians (i/j) inside this method. - * \param[in] config - Definition of the particular problem. - */ - virtual void FinishResidualCalc(const CConfig* config) = 0; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] correct_gradient - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, - bool correct_gradient, const CConfig* config); - - /*! - * \brief Destructor of the class. - */ - ~CAvgGrad_Scalar(void) override; - - /*! - * \brief Compute the viscous residual using an average of gradients without correction. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CAvgGrad_TurbSA - * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). - * \ingroup ViscDiscr - * \author A. Bueno. - */ -class CAvgGrad_TurbSA final : public CAvgGrad_Scalar { -private: - const su2double sigma = 2.0/3.0; - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config); -}; - -/*! - * \class CAvgGrad_TurbSA_Neg - * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). - * \ingroup ViscDiscr - * \author F. Palacios - */ -class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar { -private: - const su2double sigma = 2.0/3.0; - const su2double cn1 = 16.0; - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config); -}; - -/*! - * \class CAvgGrad_TurbSST - * \brief Class for computing viscous term using average of gradient with correction (Menter SST turbulence model). - * \ingroup ViscDiscr - * \author A. Bueno. - */ -class CAvgGrad_TurbSST final : public CAvgGrad_Scalar { -private: - const su2double - sigma_k1 = 0.0, /*!< \brief Constants for the viscous terms, k-w (1), k-eps (2)*/ - sigma_k2 = 0.0, - sigma_om1 = 0.0, - sigma_om2 = 0.0; - - su2double F1_i, F1_j; /*!< \brief Menter's first blending function */ - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SST specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] constants - Constants of the model. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSST(unsigned short val_nDim, unsigned short val_nVar, - const su2double* constants, bool correct_grad, const CConfig* config); - - /*! - * \brief Sets value of first blending function. - */ - void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { - F1_i = val_F1_i; F1_j = val_F1_j; - } - -}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp index 2e0e2b8cb62a..12a459436c89 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp @@ -28,390 +28,3 @@ #pragma once -#include "../CNumerics.hpp" - -/*! - * \class CSourcePieceWise_TurbSA - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author A. Bueno. - */ -class CSourceBase_TurbSA : public CNumerics { -protected: - su2double cv1_3; - su2double k2; - su2double cb1; - su2double cw2; - su2double ct3; - su2double ct4; - su2double cw3_6; - su2double cb2_sigma; - su2double sigma; - su2double cb2; - su2double cw1; - su2double cr1; - - su2double Gamma_BC = 0.0; - su2double intermittency; - su2double Production, Destruction, CrossProduction; - - su2double Residual, *Jacobian_i; -private: - su2double Jacobian_Buffer; /// Static storage for the Jacobian (which needs to be pointer for return type). - -protected: - const bool incompressible = false, rotating_frame = false; - bool roughwall = false; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourceBase_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] intermittency_in - Value of the intermittency. - */ - inline void SetIntermittency(su2double intermittency_in) final { intermittency = intermittency_in; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_production - Value of the Production. - */ - inline void SetProduction(su2double val_production) final { Production = val_production; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_destruction - Value of the Destruction. - */ - inline void SetDestruction(su2double val_destruction) final { Destruction = val_destruction; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_crossproduction - Value of the CrossProduction. - */ - inline void SetCrossProduction(su2double val_crossproduction) final { CrossProduction = val_crossproduction; } - - /*! - * \brief ______________. - */ - inline su2double GetProduction(void) const final { return Production; } - - /*! - * \brief Get the intermittency for the BC trans. model. - * \return Value of the intermittency. - */ - inline su2double GetGammaBC(void) const final { return Gamma_BC; } - - /*! - * \brief ______________. - */ - inline su2double GetDestruction(void) const final { return Destruction; } - - /*! - * \brief ______________. - */ - inline su2double GetCrossProduction(void) const final { return CrossProduction; } -}; - - -/*! - * \class CSourcePieceWise_TurbSA - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author A. Bueno. - */ -class CSourcePieceWise_TurbSA final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - unsigned short iDim; - bool transition; - bool axisymmetric; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSA_COMP - * \brief Class for integrating the source terms of the Spalart-Allmaras CC modification turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_COMP final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double aux_cc, CompCorrection, c5; - unsigned short iDim, jDim; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSA_E - * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_E final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double Sbar; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_E(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; -}; - -/*! - * \class CSourcePieceWise_TurbSA_E_COMP - * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification with CC turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_E_COMP : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double Sbar; - su2double aux_cc, CompCorrection, c5; - unsigned short jDim; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; -}; - -/*! - * \class CSourcePieceWise_TurbSA_Neg - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author F. Palacios - */ -class CSourcePieceWise_TurbSA_Neg : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSST - * \brief Class for integrating the source terms of the Menter SST turbulence model equations. - * \ingroup SourceDiscr - * \author A. Campos. - */ -class CSourcePieceWise_TurbSST final : public CNumerics { -private: - su2double F1_i, - F1_j, - F2_i, - F2_j; - - su2double alfa_1, - alfa_2, - beta_1, - beta_2, - sigma_k_1, - sigma_k_2, - sigma_w_1, - sigma_w_2, - beta_star, - a1; - - su2double CDkw_i, CDkw_j; - - su2double kAmb, omegaAmb; - - su2double Residual[2], - *Jacobian_i[2] = {nullptr}, - Jacobian_Buffer[4] = {0.0}; /// Static storage for the Jacobian (which needs to be pointer for return type). - - bool incompressible; - bool sustaining_terms; - bool axisymmetric; - - /*! - * \brief A virtual member. Get strain magnitude based on perturbed reynolds stress matrix - * \param[in] turb_ke: turbulent kinetic energy of the node - */ - void SetPerturbedStrainMag(su2double turb_ke); - - /*! - * \brief Add contribution due to axisymmetric formulation to 2D residual - */ - inline void ResidualAxisymmetric(su2double alfa_blended, su2double zeta){ - - if (Coord_i[1] < EPS) return; - - su2double yinv, rhov, k, w; - su2double sigma_k_i, sigma_w_i; - su2double pk_axi, pw_axi, cdk_axi, cdw_axi; - - AD::SetPreaccIn(Coord_i[1]); - - yinv = 1.0/Coord_i[1]; - rhov = Density_i*V_i[2]; - k = TurbVar_i[0]; - w = TurbVar_i[1]; - - /*--- Compute blended constants ---*/ - sigma_k_i = F1_i*sigma_k_1+(1.0-F1_i)*sigma_k_2; - sigma_w_i = F1_i*sigma_w_1+(1.0-F1_i)*sigma_w_2; - - /*--- Production ---*/ - pk_axi = max(0.0,2.0/3.0*rhov*k*(2.0/zeta*(yinv*V_i[2]-PrimVar_Grad_i[2][1]-PrimVar_Grad_i[1][0])-1.0)); - pw_axi = alfa_blended*zeta/k*pk_axi; - - /*--- Convection-Diffusion ---*/ - cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*TurbVar_Grad_i[0][1]; - cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*TurbVar_Grad_i[1][1]; - - /*--- Add terms to the residuals ---*/ - Residual[0] += yinv*Volume*(pk_axi-cdk_axi); - Residual[1] += yinv*Volume*(pw_axi-cdw_axi); - - } - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const su2double* constants, - su2double val_kine_Inf, su2double val_omega_Inf, const CConfig* config); - - /*! - * \brief Set the value of the first blending function. - * \param[in] val_F1_i - Value of the first blending function at point i. - * \param[in] val_F1_j - Value of the first blending function at point j. - */ - inline void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { - F1_i = val_F1_i; - F1_j = val_F1_j; - } - - /*! - * \brief Set the value of the second blending function. - * \param[in] val_F2_i - Value of the second blending function at point i. - * \param[in] val_F2_j - Value of the second blending function at point j. - */ - inline void SetF2blending(su2double val_F2_i, su2double val_F2_j) override { - F2_i = val_F2_i; - F2_j = val_F2_j; - } - - /*! - * \brief Set the value of the cross diffusion for the SST model. - * \param[in] val_CDkw_i - Value of the cross diffusion at point i. - * \param[in] val_CDkw_j - Value of the cross diffusion at point j. - */ - inline void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) override { - CDkw_i = val_CDkw_i; - CDkw_j = val_CDkw_j; - } - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp new file mode 100644 index 000000000000..d60bdbac89d5 --- /dev/null +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -0,0 +1,425 @@ +/*! + * \file CScalarSolver.hpp + * \brief Headers of the CScalarSolver class + * \author A. Bueno. + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#pragma once + +#include "CSolver.hpp" +#include "../variables/CScalarVariable.hpp" +#include "../../../Common/include/parallelization/omp_structure.hpp" + +/*! + * \class CScalarSolver + * \brief Main class for defining the turbulence model solver. + * \ingroup Turbulence_Model + * \author A. Bueno. + */ +class CScalarSolver : public CSolver { +protected: + enum : size_t {MAXNDIM = 3}; /*!< \brief Max number of space dimensions, used in some static arrays. */ + enum : size_t {MAXNVAR = 2}; /*!< \brief Max number of variables, used in some static arrays. */ + enum : size_t {MAXNVARFLOW = 12}; /*!< \brief Max number of flow variables, used in some static arrays. */ + + enum : size_t {OMP_MAX_SIZE = 512}; /*!< \brief Max chunk size for light point loops. */ + enum : size_t {OMP_MIN_SIZE = 32}; /*!< \brief Min chunk size for edge loops (max is color group size). */ + + unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ + + su2double + lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ + upperlimit[MAXNVAR] = {0.0}, /*!< \brief contains upper limits for turbulence variables. */ + Gamma, /*!< \brief Fluid's Gamma constant (ratio of specific heats). */ + Gamma_Minus_One; /*!< \brief Fluids's Gamma - 1.0 . */ + vector Inlet_TurbVars; /*!< \brief Turbulence variables at inlet profiles */ + + su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ + + /*--- Sliding meshes variables. ---*/ + + vector > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone) + vector > SlidingStateNodes; + + /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ + +#ifdef HAVE_OMP + vector > EdgeColoring; /*!< \brief Edge colors. */ + bool ReducerStrategy = false; /*!< \brief If the reducer strategy is in use. */ +#else + array,1> EdgeColoring; + /*--- Never use the reducer strategy if compiling for MPI-only. ---*/ + static constexpr bool ReducerStrategy = false; +#endif + + /*--- Edge fluxes for reducer strategy (see the notes in CEulerSolver.hpp). ---*/ + CSysVector EdgeFluxes; /*!< \brief Flux across each edge. */ + + /*! + * \brief The highest level in the variable hierarchy this solver can safely use. + */ + CScalarVariable* nodes = nullptr; + + /*! + * \brief Return nodes to allow CSolver::base_nodes to be set. + */ + inline CVariable* GetBaseClassPointerToNodes() final { return nodes; } + +private: //changed from private in CTurbSolver.hpp + + /*! + * \brief Compute the viscous flux for the turbulent equation at a particular edge. + * \param[in] iEdge - Edge for which we want to compute the flux + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + */ + void Viscous_Residual(unsigned long iEdge, + CGeometry *geometry, + CSolver **solver_container, + CNumerics *numerics, + CConfig *config); + using CSolver::Viscous_Residual; /*--- Silence warning ---*/ + + /*! + * \brief Sum the edge fluxes for each cell to populate the residual vector, only used on coarse grids. + * \param[in] geometry - Geometrical definition of the problem. + */ + void SumEdgeFluxes(CGeometry* geometry); + + /*! + * \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over + * a nonlinear iteration for stability. + * \param[in] config - Definition of the particular problem. + */ + void ComputeUnderRelaxationFactor(const CConfig *config); + +public: + + /*! + * \brief Constructor of the class. + */ + CScalarSolver(void); + + /*! + * \brief Destructor of the class. + */ + ~CScalarSolver(void) override; + + /*! + * \brief Constructor of the class. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] config - Definition of the particular problem. + */ + CScalarSolver(CGeometry* geometry, CConfig *config); + + /*! + * \brief Compute the spatial integration using a upwind scheme. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics_container - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] iMesh - Index of the mesh in multigrid computations. + */ + void Upwind_Residual(CGeometry *geometry, + CSolver **solver_container, + CNumerics **numerics_container, + CConfig *config, + unsigned short iMesh) override; + + /*! + * \brief Impose the Symmetry Plane boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] conv_numerics - Description of the numerical method. + * \param[in] visc_numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Sym_Plane(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) override; + + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] conv_numerics - Description of the numerical method. + * \param[in] visc_numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Euler_Wall(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) override; + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Riemann(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_TurboRiemann(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Giles(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose a periodic boundary condition by summing contributions from the complete control volume. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + */ + void BC_Periodic(CGeometry *geometry, + CSolver **solver_container, + CNumerics *numerics, + CConfig *config) final; + + /*! + * \brief Impose the fluid interface boundary condition using tranfer data. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] conv_numerics - Description of the numerical method. + * \param[in] visc_numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + */ + void BC_Fluid_Interface(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config) final; + + /*! + * \brief Set the solution using the Freestream values. + * \param[in] config - Definition of the particular problem. + */ + inline void SetFreeStream_Solution(const CConfig *config) final { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++){ + nodes->SetSolution(iPoint, Solution_Inf); + } + END_SU2_OMP_FOR + } + + /*! + * \brief Impose fixed values to turbulence quantities. + * \details Turbulence quantities are set to far-field values in an upstream half-plane + * in order to keep them from decaying. + */ + void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) final; + + /*! + * \brief Prepare an implicit iteration. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] config - Definition of the particular problem. + */ + void PrepareImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; + + /*! + * \brief Complete an implicit iteration. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] config - Definition of the particular problem. + */ + void CompleteImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; + + /*! + * \brief Update the solution using an implicit solver. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] config - Definition of the particular problem. + */ + void ImplicitEuler_Iteration(CGeometry *geometry, + CSolver **solver_container, + CConfig *config) override; + + /*! + * \brief Set the total residual adding the term that comes from the Dual Time-Stepping Strategy. + * \param[in] geometry - Geometric definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] config - Definition of the particular problem. + * \param[in] iRKStep - Current step of the Runge-Kutta iteration. + * \param[in] iMesh - Index of the mesh in multigrid computations. + * \param[in] RunTime_EqSystem - System of equations which is going to be solved. + */ + void SetResidual_DualTime(CGeometry *geometry, + CSolver **solver_container, + CConfig *config, + unsigned short iRKStep, + unsigned short iMesh, + unsigned short RunTime_EqSystem) final; + + /*! + * \brief Load a solution from a restart file. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver - Container vector with all of the solvers. + * \param[in] config - Definition of the particular problem. + * \param[in] val_iter - Current external iteration number. + * \param[in] val_update_geo - Flag for updating coords and grid velocity. + */ + void LoadRestart(CGeometry **geometry, + CSolver ***solver, + CConfig *config, + int val_iter, + bool val_update_geo) final; + + /*! + * \brief Get the outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] val_state - requested state component + * \param[in] donor_index- index of the donor node to get + */ + inline su2double GetSlidingState(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_state, + unsigned long donor_index) const final { + return SlidingState[val_marker][val_vertex][val_state][donor_index]; + } + + /*! + * \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it. That number is stored in SlidingStateNodes[val_marker][val_vertex]. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + */ + inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) final { + int iVar; + + for( iVar = 0; iVar < nVar+1; iVar++){ + if( SlidingState[val_marker][val_vertex][iVar] != nullptr ) + delete [] SlidingState[val_marker][val_vertex][iVar]; + } + + for( iVar = 0; iVar < nVar+1; iVar++) + SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ]; + } + + + /*! + * \brief Set the outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] val_state - requested state component + * \param[in] donor_index - index of the donor node to set + * \param[in] component - set value + */ + inline void SetSlidingState(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_state, + unsigned long donor_index, + su2double component) final { + SlidingState[val_marker][val_vertex][val_state][donor_index] = component; + } + + + /*! + * \brief Set the number of outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] value - number of outer states + */ + inline void SetnSlidingStates(unsigned short val_marker, + unsigned long val_vertex, + int value) final { SlidingStateNodes[val_marker][val_vertex] = value; } + + /*! + * \brief Get the number of outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + */ + inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const final { + return SlidingStateNodes[val_marker][val_vertex]; + } + + /*! + * \brief Set custom turbulence variables at the vertex of an inlet. + * \param[in] iMarker - Marker identifier. + * \param[in] iVertex - Vertex identifier. + * \param[in] iDim - Index of the turbulence variable (i.e. k is 0 in SST) + * \param[in] val_turb_var - Value of the turbulence variable to be used. + */ + inline void SetInlet_TurbVar(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_dim, + su2double val_turb_var) final { + /*--- Since this call can be accessed indirectly using python, do some error + * checking to prevent segmentation faults ---*/ + if (val_marker >= nMarker) + SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION); + else if (val_vertex >= nVertex[val_marker]) + SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION); + else if (val_dim >= nVar) + SU2_MPI::Error("Out-of-bounds index used for inlet turbulence variable.", CURRENT_FUNCTION); + else + Inlet_TurbVars[val_marker][val_vertex][val_dim] = val_turb_var; + } + + /*! + * \brief SA and SST support OpenMP+MPI. + */ + inline bool GetHasHybridParallel() const override { return true; } + +}; diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index 9e032a659f8f..d9623d67cea9 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -27,7 +27,7 @@ #pragma once -#include "CSolver.hpp" +#include "CScalarSolver.hpp" #include "../variables/CTurbVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" @@ -37,85 +37,7 @@ * \ingroup Turbulence_Model * \author A. Bueno. */ -class CTurbSolver : public CSolver { -protected: - enum : size_t {MAXNDIM = 3}; /*!< \brief Max number of space dimensions, used in some static arrays. */ - enum : size_t {MAXNVAR = 2}; /*!< \brief Max number of variables, used in some static arrays. */ - enum : size_t {MAXNVARFLOW = 12}; /*!< \brief Max number of flow variables, used in some static arrays. */ - - enum : size_t {OMP_MAX_SIZE = 512}; /*!< \brief Max chunk size for light point loops. */ - enum : size_t {OMP_MIN_SIZE = 32}; /*!< \brief Min chunk size for edge loops (max is color group size). */ - - unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - - su2double - lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ - upperlimit[MAXNVAR] = {0.0}, /*!< \brief contains upper limits for turbulence variables. */ - Gamma, /*!< \brief Fluid's Gamma constant (ratio of specific heats). */ - Gamma_Minus_One; /*!< \brief Fluids's Gamma - 1.0 . */ - vector Inlet_TurbVars; /*!< \brief Turbulence variables at inlet profiles */ - - su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ - - /*--- Sliding meshes variables. ---*/ - - vector > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone) - vector > SlidingStateNodes; - - /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ - -#ifdef HAVE_OMP - vector > EdgeColoring; /*!< \brief Edge colors. */ - bool ReducerStrategy = false; /*!< \brief If the reducer strategy is in use. */ -#else - array,1> EdgeColoring; - /*--- Never use the reducer strategy if compiling for MPI-only. ---*/ - static constexpr bool ReducerStrategy = false; -#endif - - /*--- Edge fluxes for reducer strategy (see the notes in CEulerSolver.hpp). ---*/ - CSysVector EdgeFluxes; /*!< \brief Flux across each edge. */ - - /*! - * \brief The highest level in the variable hierarchy this solver can safely use. - */ - CTurbVariable* nodes = nullptr; - - /*! - * \brief Return nodes to allow CSolver::base_nodes to be set. - */ - inline CVariable* GetBaseClassPointerToNodes() final { return nodes; } - -private: - - /*! - * \brief Compute the viscous flux for the turbulent equation at a particular edge. - * \param[in] iEdge - Edge for which we want to compute the flux - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - */ - void Viscous_Residual(unsigned long iEdge, - CGeometry *geometry, - CSolver **solver_container, - CNumerics *numerics, - CConfig *config); - using CSolver::Viscous_Residual; /*--- Silence warning ---*/ - - /*! - * \brief Sum the edge fluxes for each cell to populate the residual vector, only used on coarse grids. - * \param[in] geometry - Geometrical definition of the problem. - */ - void SumEdgeFluxes(CGeometry* geometry); - - /*! - * \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over - * a nonlinear iteration for stability. - * \param[in] config - Definition of the particular problem. - */ - void ComputeUnderRelaxationFactor(const CConfig *config); - +class CTurbSolver : public CScalarSolver { public: /*! @@ -135,291 +57,4 @@ class CTurbSolver : public CSolver { */ CTurbSolver(CGeometry* geometry, CConfig *config); - /*! - * \brief Compute the spatial integration using a upwind scheme. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics_container - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] iMesh - Index of the mesh in multigrid computations. - */ - void Upwind_Residual(CGeometry *geometry, - CSolver **solver_container, - CNumerics **numerics_container, - CConfig *config, - unsigned short iMesh) override; - - /*! - * \brief Impose the Symmetry Plane boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] conv_numerics - Description of the numerical method. - * \param[in] visc_numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Sym_Plane(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override; - - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] conv_numerics - Description of the numerical method. - * \param[in] visc_numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Euler_Wall(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override; - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Riemann(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) final; - - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_TurboRiemann(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) final; - - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Giles(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) final; - - /*! - * \brief Impose a periodic boundary condition by summing contributions from the complete control volume. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - */ - void BC_Periodic(CGeometry *geometry, - CSolver **solver_container, - CNumerics *numerics, - CConfig *config) final; - - /*! - * \brief Impose the fluid interface boundary condition using tranfer data. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] conv_numerics - Description of the numerical method. - * \param[in] visc_numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - */ - void BC_Fluid_Interface(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config) final; - - /*! - * \brief Set the solution using the Freestream values. - * \param[in] config - Definition of the particular problem. - */ - inline void SetFreeStream_Solution(const CConfig *config) final { - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++){ - nodes->SetSolution(iPoint, Solution_Inf); - } - END_SU2_OMP_FOR - } - - /*! - * \brief Impose fixed values to turbulence quantities. - * \details Turbulence quantities are set to far-field values in an upstream half-plane - * in order to keep them from decaying. - */ - void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) final; - - /*! - * \brief Prepare an implicit iteration. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] config - Definition of the particular problem. - */ - void PrepareImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; - - /*! - * \brief Complete an implicit iteration. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] config - Definition of the particular problem. - */ - void CompleteImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; - - /*! - * \brief Update the solution using an implicit solver. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] config - Definition of the particular problem. - */ - void ImplicitEuler_Iteration(CGeometry *geometry, - CSolver **solver_container, - CConfig *config) override; - - /*! - * \brief Set the total residual adding the term that comes from the Dual Time-Stepping Strategy. - * \param[in] geometry - Geometric definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] config - Definition of the particular problem. - * \param[in] iRKStep - Current step of the Runge-Kutta iteration. - * \param[in] iMesh - Index of the mesh in multigrid computations. - * \param[in] RunTime_EqSystem - System of equations which is going to be solved. - */ - void SetResidual_DualTime(CGeometry *geometry, - CSolver **solver_container, - CConfig *config, - unsigned short iRKStep, - unsigned short iMesh, - unsigned short RunTime_EqSystem) final; - - /*! - * \brief Load a solution from a restart file. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver - Container vector with all of the solvers. - * \param[in] config - Definition of the particular problem. - * \param[in] val_iter - Current external iteration number. - * \param[in] val_update_geo - Flag for updating coords and grid velocity. - */ - void LoadRestart(CGeometry **geometry, - CSolver ***solver, - CConfig *config, - int val_iter, - bool val_update_geo) final; - - /*! - * \brief Get the outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] val_state - requested state component - * \param[in] donor_index- index of the donor node to get - */ - inline su2double GetSlidingState(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_state, - unsigned long donor_index) const final { - return SlidingState[val_marker][val_vertex][val_state][donor_index]; - } - - /*! - * \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it. That number is stored in SlidingStateNodes[val_marker][val_vertex]. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - */ - inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) final { - int iVar; - - for( iVar = 0; iVar < nVar+1; iVar++){ - if( SlidingState[val_marker][val_vertex][iVar] != nullptr ) - delete [] SlidingState[val_marker][val_vertex][iVar]; - } - - for( iVar = 0; iVar < nVar+1; iVar++) - SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ]; - } - - - /*! - * \brief Set the outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] val_state - requested state component - * \param[in] donor_index - index of the donor node to set - * \param[in] component - set value - */ - inline void SetSlidingState(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_state, - unsigned long donor_index, - su2double component) final { - SlidingState[val_marker][val_vertex][val_state][donor_index] = component; - } - - - /*! - * \brief Set the number of outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] value - number of outer states - */ - inline void SetnSlidingStates(unsigned short val_marker, - unsigned long val_vertex, - int value) final { SlidingStateNodes[val_marker][val_vertex] = value; } - - /*! - * \brief Get the number of outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - */ - inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const final { - return SlidingStateNodes[val_marker][val_vertex]; - } - - /*! - * \brief Set custom turbulence variables at the vertex of an inlet. - * \param[in] iMarker - Marker identifier. - * \param[in] iVertex - Vertex identifier. - * \param[in] iDim - Index of the turbulence variable (i.e. k is 0 in SST) - * \param[in] val_turb_var - Value of the turbulence variable to be used. - */ - inline void SetInlet_TurbVar(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_dim, - su2double val_turb_var) final { - /*--- Since this call can be accessed indirectly using python, do some error - * checking to prevent segmentation faults ---*/ - if (val_marker >= nMarker) - SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION); - else if (val_vertex >= nVertex[val_marker]) - SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION); - else if (val_dim >= nVar) - SU2_MPI::Error("Out-of-bounds index used for inlet turbulence variable.", CURRENT_FUNCTION); - else - Inlet_TurbVars[val_marker][val_vertex][val_dim] = val_turb_var; - } - - /*! - * \brief SA and SST support OpenMP+MPI. - */ - inline bool GetHasHybridParallel() const override { return true; } - }; diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp new file mode 100644 index 000000000000..2542ab2733cd --- /dev/null +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -0,0 +1,90 @@ +/*! + * \file CScalarVariable.hpp + * \brief Base class for defining the variables of the turbulence model. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#pragma once + +#include "CVariable.hpp" + +/*! + * \class CScalarVariable + * \brief Base class for defining the variables of the turbulence model. + * \ingroup Turbulence_Model + * \author A. Bueno. + */ +class CScalarVariable : public CVariable { +protected: + VectorType muT; /*!< \brief Eddy viscosity. */ + MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ + + CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */ + CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ + +public: + /*! + * \brief Constructor of the class. + * \param[in] npoint - Number of points/nodes/vertices in the domain. + * \param[in] ndim - Number of dimensions of the problem. + * \param[in] nvar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config); + + /*! + * \brief Destructor of the class. + */ + ~CScalarVariable() override = default; + + /*! + * \brief Get the value of the eddy viscosity. + * \param[in] iPoint - Point index. + * \return the value of the eddy viscosity. + */ + inline su2double GetmuT(unsigned long iPoint) const final { return muT(iPoint); } + + /*! + * \brief Set the value of the eddy viscosity. + * \param[in] iPoint - Point index. + * \param[in] val_muT - Value of the eddy viscosity. + */ + inline void SetmuT(unsigned long iPoint, su2double val_muT) final { muT(iPoint) = val_muT; } + + /*! + * \brief Get the array of the reconstruction variables gradient at a node. + * \param[in] iPoint - Index of the current node. + * \return Array of the reconstruction variables gradient at a node. + */ + inline CMatrixView GetGradient_Reconstruction(unsigned long iPoint) final { return Gradient_Reconstruction[iPoint]; } + + /*! + * \brief Get the reconstruction gradient for primitive variable at all points. + * \return Reference to variable reconstruction gradient. + */ + inline CVectorOfMatrix& GetGradient_Reconstruction() final { return Gradient_Reconstruction; } + inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; } + +}; + diff --git a/SU2_CFD/include/variables/CTurbVariable.hpp b/SU2_CFD/include/variables/CTurbVariable.hpp index 010c34148814..a640de8495da 100644 --- a/SU2_CFD/include/variables/CTurbVariable.hpp +++ b/SU2_CFD/include/variables/CTurbVariable.hpp @@ -27,7 +27,7 @@ #pragma once -#include "CVariable.hpp" +#include "CScalarVariable.hpp" /*! * \class CTurbVariable @@ -35,14 +35,7 @@ * \ingroup Turbulence_Model * \author A. Bueno. */ -class CTurbVariable : public CVariable { -protected: - VectorType muT; /*!< \brief Eddy viscosity. */ - MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ - - CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */ - CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ - +class CTurbVariable : public CScalarVariable { public: /*! * \brief Constructor of the class. @@ -58,33 +51,5 @@ class CTurbVariable : public CVariable { */ ~CTurbVariable() override = default; - /*! - * \brief Get the value of the eddy viscosity. - * \param[in] iPoint - Point index. - * \return the value of the eddy viscosity. - */ - inline su2double GetmuT(unsigned long iPoint) const final { return muT(iPoint); } - - /*! - * \brief Set the value of the eddy viscosity. - * \param[in] iPoint - Point index. - * \param[in] val_muT - Value of the eddy viscosity. - */ - inline void SetmuT(unsigned long iPoint, su2double val_muT) final { muT(iPoint) = val_muT; } - - /*! - * \brief Get the array of the reconstruction variables gradient at a node. - * \param[in] iPoint - Index of the current node. - * \return Array of the reconstruction variables gradient at a node. - */ - inline CMatrixView GetGradient_Reconstruction(unsigned long iPoint) final { return Gradient_Reconstruction[iPoint]; } - - /*! - * \brief Get the reconstruction gradient for primitive variable at all points. - * \return Reference to variable reconstruction gradient. - */ - inline CVectorOfMatrix& GetGradient_Reconstruction() final { return Gradient_Reconstruction; } - inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; } - }; diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 0b40964ac3ac..4e577958dc91 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -75,9 +75,9 @@ #include "../../include/numerics/continuous_adjoint/adj_convection.hpp" #include "../../include/numerics/continuous_adjoint/adj_diffusion.hpp" #include "../../include/numerics/continuous_adjoint/adj_sources.hpp" -#include "../../include/numerics/turbulent/turb_convection.hpp" -#include "../../include/numerics/turbulent/turb_diffusion.hpp" -#include "../../include/numerics/turbulent/turb_sources.hpp" +#include "../../include/numerics/scalar/scalar_convection.hpp" +#include "../../include/numerics/scalar/scalar_diffusion.hpp" +#include "../../include/numerics/scalar/scalar_sources.hpp" #include "../../include/numerics/elasticity/CFEAElasticity.hpp" #include "../../include/numerics/elasticity/CFEALinearElasticity.hpp" #include "../../include/numerics/elasticity/CFEANonlinearElasticity.hpp" diff --git a/SU2_CFD/src/meson.build b/SU2_CFD/src/meson.build index 736100a1b812..5327a5b831a7 100644 --- a/SU2_CFD/src/meson.build +++ b/SU2_CFD/src/meson.build @@ -54,6 +54,7 @@ su2_cfd_src += files(['variables/CIncNSVariable.cpp', 'variables/CAdjEulerVariable.cpp', 'variables/CHeatVariable.cpp', 'variables/CTurbVariable.cpp', + 'variables/CScalarVariable.cpp', 'variables/CAdjNSVariable.cpp', 'variables/CBaselineVariable.cpp', 'variables/CDiscAdjFEABoundVariable.cpp', @@ -101,6 +102,7 @@ su2_cfd_src += files(['solvers/CSolverFactory.cpp', 'solvers/CSolver.cpp', 'solvers/CTemplateSolver.cpp', 'solvers/CTransLMSolver.cpp', + 'solvers/CScalarSolver.cpp', 'solvers/CTurbSolver.cpp', 'solvers/CTurbSASolver.cpp', 'solvers/CTurbSSTSolver.cpp']) @@ -131,6 +133,9 @@ su2_cfd_src += files(['numerics/CNumerics.cpp', 'numerics/continuous_adjoint/adj_convection.cpp', 'numerics/continuous_adjoint/adj_diffusion.cpp', 'numerics/continuous_adjoint/adj_sources.cpp', + 'numerics/scalar/scalar_convection.cpp', + 'numerics/scalar/scalar_diffusion.cpp', + 'numerics/scalar/scalar_sources.cpp', 'numerics/turbulent/turb_convection.cpp', 'numerics/turbulent/turb_diffusion.cpp', 'numerics/turbulent/turb_sources.cpp', diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp new file mode 100644 index 000000000000..5c7bbb6820bb --- /dev/null +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -0,0 +1,145 @@ +/*! + * \file turb_convection.cpp + * \brief Implementation of numerics classes to compute convective + * fluxes in turbulence problems. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#include "../../../include/numerics/scalar/scalar_convection.hpp" + +CUpwScalar::CUpwScalar(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config), + implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), + dynamic_grid(config->GetDynamic_Grid()) +{ + Flux = new su2double [nVar]; + Jacobian_i = new su2double* [nVar]; + Jacobian_j = new su2double* [nVar]; + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + Jacobian_i[iVar] = new su2double [nVar]; + Jacobian_j[iVar] = new su2double [nVar]; + } +} + +CUpwScalar::~CUpwScalar(void) { + + delete [] Flux; + if (Jacobian_i != nullptr) { + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + delete [] Jacobian_i[iVar]; + delete [] Jacobian_j[iVar]; + } + delete [] Jacobian_i; + delete [] Jacobian_j; + } +} + +CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { + + unsigned short iDim; + + AD::StartPreacc(); + AD::SetPreaccIn(Normal, nDim); + AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j, nVar); + if (dynamic_grid) { + AD::SetPreaccIn(GridVel_i, nDim); AD::SetPreaccIn(GridVel_j, nDim); + } + + ExtraADPreaccIn(); + + Density_i = V_i[nDim+2]; + Density_j = V_j[nDim+2]; + + su2double q_ij = 0.0; + if (dynamic_grid) { + for (iDim = 0; iDim < nDim; iDim++) { + su2double Velocity_i = V_i[iDim+1] - GridVel_i[iDim]; + su2double Velocity_j = V_j[iDim+1] - GridVel_j[iDim]; + q_ij += 0.5*(Velocity_i+Velocity_j)*Normal[iDim]; + } + } + else { + for (iDim = 0; iDim < nDim; iDim++) { + q_ij += 0.5*(V_i[iDim+1]+V_j[iDim+1])*Normal[iDim]; + } + } + + a0 = 0.5*(q_ij+fabs(q_ij)); + a1 = 0.5*(q_ij-fabs(q_ij)); + + FinishResidualCalc(config); + + AD::SetPreaccOut(Flux, nVar); + AD::EndPreacc(); + + return ResidualType<>(Flux, Jacobian_i, Jacobian_j); + +} + +CUpwSca_TurbSA::CUpwSca_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CUpwScalar(val_nDim, val_nVar, config) { } + +void CUpwSca_TurbSA::ExtraADPreaccIn() { + AD::SetPreaccIn(V_i, nDim+1); + AD::SetPreaccIn(V_j, nDim+1); +} + +void CUpwSca_TurbSA::FinishResidualCalc(const CConfig* config) { + + Flux[0] = a0*TurbVar_i[0]+a1*TurbVar_j[0]; + + if (implicit) { + Jacobian_i[0][0] = a0; + Jacobian_j[0][0] = a1; + } +} + +CUpwSca_TurbSST::CUpwSca_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CUpwScalar(val_nDim, val_nVar, config) { } + +void CUpwSca_TurbSST::ExtraADPreaccIn() { + AD::SetPreaccIn(V_i, nDim+3); + AD::SetPreaccIn(V_j, nDim+3); +} + +void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { + + Flux[0] = a0*Density_i*TurbVar_i[0]+a1*Density_j*TurbVar_j[0]; + Flux[1] = a0*Density_i*TurbVar_i[1]+a1*Density_j*TurbVar_j[1]; + + if (implicit) { + Jacobian_i[0][0] = a0; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = a0; + + Jacobian_j[0][0] = a1; Jacobian_j[0][1] = 0.0; + Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = a1; + } +} diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp new file mode 100644 index 000000000000..a9ea198137b5 --- /dev/null +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -0,0 +1,225 @@ +/*! + * \file turb_diffusion.cpp + * \brief Implementation of numerics classes to compute viscous + * fluxes in turbulence problems. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#include "../../../include/numerics/scalar/scalar_diffusion.hpp" + +CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, + unsigned short val_nVar, + bool correct_grad, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config), + correct_gradient(correct_grad), + implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) +{ + Proj_Mean_GradTurbVar_Normal = new su2double [nVar] (); + Proj_Mean_GradTurbVar = new su2double [nVar] (); + + Flux = new su2double [nVar] (); + Jacobian_i = new su2double* [nVar]; + Jacobian_j = new su2double* [nVar]; + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + Jacobian_i[iVar] = new su2double [nVar] (); + Jacobian_j[iVar] = new su2double [nVar] (); + } +} + +CAvgGrad_Scalar::~CAvgGrad_Scalar(void) { + + delete [] Proj_Mean_GradTurbVar_Normal; + delete [] Proj_Mean_GradTurbVar; + + delete [] Flux; + if (Jacobian_i != nullptr) { + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + delete [] Jacobian_i[iVar]; + delete [] Jacobian_j[iVar]; + } + delete [] Jacobian_i; + delete [] Jacobian_j; + } +} + +CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config) { + + AD::StartPreacc(); + AD::SetPreaccIn(Coord_i, nDim); AD::SetPreaccIn(Coord_j, nDim); + AD::SetPreaccIn(Normal, nDim); + AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); + AD::SetPreaccIn(TurbVar_Grad_j, nVar, nDim); + if (correct_gradient) { + AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j ,nVar); + } + ExtraADPreaccIn(); + + if (incompressible) { + AD::SetPreaccIn(V_i, nDim+6); AD::SetPreaccIn(V_j, nDim+6); + + Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; Laminar_Viscosity_j = V_j[nDim+4]; + Eddy_Viscosity_i = V_i[nDim+5]; Eddy_Viscosity_j = V_j[nDim+5]; + } + else { + AD::SetPreaccIn(V_i, nDim+7); AD::SetPreaccIn(V_j, nDim+7); + + Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; Laminar_Viscosity_j = V_j[nDim+5]; + Eddy_Viscosity_i = V_i[nDim+6]; Eddy_Viscosity_j = V_j[nDim+6]; + } + + proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, TurbVar_Grad_i, + TurbVar_Grad_j, correct_gradient, TurbVar_i, TurbVar_j, + Proj_Mean_GradTurbVar_Normal, Proj_Mean_GradTurbVar); + FinishResidualCalc(config); + + AD::SetPreaccOut(Flux, nVar); + AD::EndPreacc(); + + return ResidualType<>(Flux, Jacobian_i, Jacobian_j); + +} + +CAvgGrad_TurbSA::CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } + +void CAvgGrad_TurbSA::ExtraADPreaccIn() { } + +void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { + + /*--- Compute mean effective viscosity ---*/ + + su2double nu_i = Laminar_Viscosity_i/Density_i; + su2double nu_j = Laminar_Viscosity_j/Density_j; + su2double nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); + + Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + + if (implicit) { + Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + } + +} + +CAvgGrad_TurbSA_Neg::CAvgGrad_TurbSA_Neg(unsigned short val_nDim, + unsigned short val_nVar, + bool correct_grad, + const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } + +void CAvgGrad_TurbSA_Neg::ExtraADPreaccIn() { } + +void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { + + /*--- Compute mean effective viscosity ---*/ + + su2double nu_i = Laminar_Viscosity_i/Density_i; + su2double nu_j = Laminar_Viscosity_j/Density_j; + + su2double nu_ij = 0.5*(nu_i+nu_j); + su2double nu_tilde_ij = 0.5*(TurbVar_i[0]+TurbVar_j[0]); + + su2double nu_e; + + if (nu_tilde_ij > 0.0) { + nu_e = nu_ij + nu_tilde_ij; + } + else { + su2double Xi = nu_tilde_ij/nu_ij; + su2double fn = (cn1 + Xi*Xi*Xi)/(cn1 - Xi*Xi*Xi); + nu_e = nu_ij + fn*nu_tilde_ij; + } + + Flux[0] = nu_e*Proj_Mean_GradTurbVar_Normal[0]/sigma; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + + if (implicit) { + Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + } + +} + +CAvgGrad_TurbSST::CAvgGrad_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const su2double *constants, + bool correct_grad, + const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config), + sigma_k1(constants[0]), + sigma_k2(constants[1]), + sigma_om1(constants[2]), + sigma_om2(constants[3]) { + +} + +void CAvgGrad_TurbSST::ExtraADPreaccIn() { + AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F1_j); +} + +void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { + + su2double sigma_kine_i, sigma_kine_j, sigma_omega_i, sigma_omega_j; + su2double diff_i_kine, diff_i_omega, diff_j_kine, diff_j_omega; + + /*--- Compute the blended constant for the viscous terms ---*/ + sigma_kine_i = F1_i*sigma_k1 + (1.0 - F1_i)*sigma_k2; + sigma_kine_j = F1_j*sigma_k1 + (1.0 - F1_j)*sigma_k2; + sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2; + sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2; + + /*--- Compute mean effective viscosity ---*/ + diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i; + diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j; + diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i; + diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j; + + su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine); + su2double diff_omega = 0.5*(diff_i_omega + diff_j_omega); + + Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; + Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + if (implicit) { + su2double proj_on_rho = proj_vector_ij/Density_i; + + Jacobian_i[0][0] = -diff_kine*proj_on_rho; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = -diff_omega*proj_on_rho; + + proj_on_rho = proj_vector_ij/Density_j; + + Jacobian_j[0][0] = diff_kine*proj_on_rho; Jacobian_j[0][1] = 0.0; + Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = diff_omega*proj_on_rho; + } + +} diff --git a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp new file mode 100644 index 000000000000..f12b76d3140d --- /dev/null +++ b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp @@ -0,0 +1,930 @@ +/*! + * \file turb_sources.cpp + * \brief Implementation of numerics classes for integration of + * turbulence source-terms. + * \author F. Palacios, T. Economon + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#include "../../../include/numerics/scalar/scalar_sources.hpp" + +CSourceBase_TurbSA::CSourceBase_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), + rotating_frame(config->GetRotating_Frame()) +{ + /*--- Spalart-Allmaras closure constants ---*/ + + cv1_3 = pow(7.1, 3.0); + k2 = pow(0.41, 2.0); + cb1 = 0.1355; + cw2 = 0.3; + ct3 = 1.2; + ct4 = 0.5; + cw3_6 = pow(2.0, 6.0); + sigma = 2./3.; + cb2 = 0.622; + cb2_sigma = cb2/sigma; + cw1 = cb1/k2+(1.0+cb2)/sigma; + cr1 = 0.5; + + /*--- Setup the Jacobian pointer, we need to return su2double** but + * we know the Jacobian is 1x1 so we use this "trick" to avoid + * having to dynamically allocate. ---*/ + + Jacobian_i = &Jacobian_Buffer; + +} + +CSourcePieceWise_TurbSA::CSourcePieceWise_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { + + transition = (config->GetKind_Trans_Model() == BC); +} + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig* config) { + +// AD::StartPreacc(); +// AD::SetPreaccIn(V_i, nDim+6); +// AD::SetPreaccIn(Vorticity_i, nDim); +// AD::SetPreaccIn(StrainMag_i); +// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + // Set the boolean here depending on whether the point is closest to a rough wall or not. + roughwall = (roughness_i > 0.0); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + + /*--- Modified values for roughness ---*/ + /*--- Ref: Aupoix, B. and Spalart, P. R., "Extensions of the Spalart-Allmaras Turbulence Model to Account for Wall Roughness," + * International Journal of Heat and Fluid Flow, Vol. 24, 2003, pp. 454-462. ---*/ + /* --- See https://turbmodels.larc.nasa.gov/spalart.html#sarough for detailed explanation. ---*/ + + Ji = TurbVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + + /*--- Using a modified relation so as to not change the Shat that depends on fv2. ---*/ + fv2 = 1.0 - TurbVar_i[0]/(nu+TurbVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper + + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + +// Original SA model +// Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; + + if (transition) { + + /*--- BC model constants (2020 revision). ---*/ + const su2double chi_1 = 0.002; + const su2double chi_2 = 50.0; + + /*--- turbulence intensity is u'/U so we multiply by 100 to get percentage ---*/ + su2double tu = 100.0 * config->GetTurbulenceIntensity_FreeStream(); + + su2double nu_t = (TurbVar_i[0]*fv1); //S-A variable + + su2double re_v = ((Density_i*pow(dist_i,2.))/(Laminar_Viscosity_i))*Omega; + su2double re_theta = re_v/2.193; + su2double re_theta_t = (803.73 * pow((tu + 0.6067),-1.027)); //MENTER correlation + //re_theta_t = 163.0 + exp(6.91-tu); //ABU-GHANNAM & SHAW correlation + + su2double term1 = sqrt(max(re_theta-re_theta_t,0.)/(chi_1*re_theta_t)); + su2double term2 = sqrt(max((nu_t*chi_2)/nu,0.)); + su2double term_exponential = (term1 + term2); + + Gamma_BC = 1.0 - exp(-term_exponential); + + Production = Gamma_BC*cb1*Shat*TurbVar_i[0]*Volume; + } + else { + Production = cb1*Shat*TurbVar_i[0]*Volume; + } + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + +// Original SA model +// Destruction = (cw1*fw-cb1*ft2/k2)*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; + + if (transition) { + Jacobian_i[0] += Gamma_BC*cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + } + else { + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + } + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + if (r == 10.0) dr = 0.0; + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + +// AD::SetPreaccOut(Residual); +// AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_COMP::CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config), c5(3.5) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CConfig* config) { + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Compressibility Correction term ---*/ + Pressure_i = V_i[nDim+1]; + SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); + aux_cc=0; + for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_E::CSourcePieceWise_TurbSA_E(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConfig* config) { + + unsigned short iDim, jDim; + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /* + From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html + This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: + Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. + In this modificaton Omega is replaced by Strain Rate + */ + + /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ + + Sbar = 0.0; + for(iDim=0;iDim 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + //Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); + + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r=tanh(r)/tanh(1.0); + + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + + // AD::SetPreaccOut(Residual); + // AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_E_COMP::CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const CConfig* config) { + + unsigned short iDim; + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /* + From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html + This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: + Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. + In this modificaton Omega is replaced by Strain Rate + */ + + /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ + + Sbar = 0.0; + for(iDim=0;iDim 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); + + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r=tanh(r)/tanh(1.0); + + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Compressibility Correction term ---*/ + Pressure_i = V_i[nDim+1]; + SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); + aux_cc=0; + for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_Neg::CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CConfig* config) { + + unsigned short iDim; + +// AD::StartPreacc(); +// AD::SetPreaccIn(V_i, nDim+6); +// AD::SetPreaccIn(Vorticity_i, nDim); +// AD::SetPreaccIn(StrainMag_i); +// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + if (TurbVar_i[0] > 0.0) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + // Original SA model + // Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + if (r == 10.0) dr = 0.0; + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + + else { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + + /*--- Production term ---*/; + + Production = cb1*(1.0-ct3)*Omega*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + Destruction = cw1*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production + Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + Jacobian_i[0] += cb1*(1.0-ct3)*Omega*Volume; + + /*--- Implicit part, destruction term ---*/ + + Jacobian_i[0] += 2.0*cw1*TurbVar_i[0]/dist_i_2*Volume; + + } + + } + +// AD::SetPreaccOut(Residual); +// AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSST::CSourcePieceWise_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const su2double *constants, + su2double val_kine_Inf, + su2double val_omega_Inf, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config) { + + incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + sustaining_terms = (config->GetKind_Turb_Model() == SST_SUST); + axisymmetric = config->GetAxisymmetric(); + + /*--- Closure constants ---*/ + sigma_k_1 = constants[0]; + sigma_k_2 = constants[1]; + sigma_w_1 = constants[2]; + sigma_w_2 = constants[3]; + beta_1 = constants[4]; + beta_2 = constants[5]; + beta_star = constants[6]; + a1 = constants[7]; + alfa_1 = constants[8]; + alfa_2 = constants[9]; + + /*--- Set the ambient values of k and omega to the free stream values. ---*/ + kAmb = val_kine_Inf; + omegaAmb = val_omega_Inf; + + /*--- "Allocate" the Jacobian using the static buffer. ---*/ + Jacobian_i[0] = Jacobian_Buffer; + Jacobian_i[1] = Jacobian_Buffer+2; + +} + +CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfig* config) { + + AD::StartPreacc(); + AD::SetPreaccIn(StrainMag_i); + AD::SetPreaccIn(TurbVar_i, nVar); + AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); + AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); + AD::SetPreaccIn(PrimVar_Grad_i, nDim+1, nDim); + AD::SetPreaccIn(Vorticity_i, 3); + + unsigned short iDim; + su2double alfa_blended, beta_blended; + su2double diverg, pk, pw, zeta; + su2double VorticityMag = sqrt(Vorticity_i[0]*Vorticity_i[0] + + Vorticity_i[1]*Vorticity_i[1] + + Vorticity_i[2]*Vorticity_i[2]); + + if (incompressible) { + AD::SetPreaccIn(V_i, nDim+6); + + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + Eddy_Viscosity_i = V_i[nDim+5]; + } + else { + AD::SetPreaccIn(V_i, nDim+7); + + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + Eddy_Viscosity_i = V_i[nDim+6]; + } + + Residual[0] = 0.0; Residual[1] = 0.0; + Jacobian_i[0][0] = 0.0; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = 0.0; + + /*--- Computation of blended constants for the source terms---*/ + + alfa_blended = F1_i*alfa_1 + (1.0 - F1_i)*alfa_2; + beta_blended = F1_i*beta_1 + (1.0 - F1_i)*beta_2; + + if (dist_i > 1e-10) { + + /*--- Production ---*/ + + diverg = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + diverg += PrimVar_Grad_i[iDim+1][iDim]; + + /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ + + if (using_uq){ + ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, + PrimVar_Grad_i+1, Density_i, Eddy_Viscosity_i, + TurbVar_i[0], MeanPerturbedRSM); + SetPerturbedStrainMag(TurbVar_i[0]); + pk = Eddy_Viscosity_i*PerturbedStrainMag*PerturbedStrainMag + - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + } + else { + pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + } + + pk = min(pk,20.0*beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]); + pk = max(pk,0.0); + + zeta = max(TurbVar_i[1], VorticityMag*F2_i/a1); + + /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ + + if (using_uq){ + pw = PerturbedStrainMag * PerturbedStrainMag - 2.0/3.0*zeta*diverg; + } + else { + pw = StrainMag_i*StrainMag_i - 2.0/3.0*zeta*diverg; + } + pw = alfa_blended*Density_i*max(pw,0.0); + + /*--- Sustaining terms, if desired. Note that if the production terms are + larger equal than the sustaining terms, the original formulation is + obtained again. This is in contrast to the version in literature + where the sustaining terms are simply added. This latter approach could + lead to problems for very big values of the free-stream turbulence + intensity. ---*/ + + if ( sustaining_terms ) { + const su2double sust_k = beta_star*Density_i*kAmb*omegaAmb; + const su2double sust_w = beta_blended*Density_i*omegaAmb*omegaAmb; + + pk = max(pk, sust_k); + pw = max(pw, sust_w); + } + + /*--- Add the production terms to the residuals. ---*/ + + Residual[0] += pk*Volume; + Residual[1] += pw*Volume; + + /*--- Dissipation ---*/ + + Residual[0] -= beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]*Volume; + Residual[1] -= beta_blended*Density_i*TurbVar_i[1]*TurbVar_i[1]*Volume; + + /*--- Cross diffusion ---*/ + + Residual[1] += (1.0 - F1_i)*CDkw_i*Volume; + + /*--- Contribution due to 2D axisymmetric formulation ---*/ + + if (axisymmetric) ResidualAxisymmetric(alfa_blended,zeta); + + /*--- Implicit part ---*/ + + Jacobian_i[0][0] = -beta_star*TurbVar_i[1]*Volume; + Jacobian_i[0][1] = -beta_star*TurbVar_i[0]*Volume; + Jacobian_i[1][0] = 0.0; + Jacobian_i[1][1] = -2.0*beta_blended*TurbVar_i[1]*Volume; + } + + AD::SetPreaccOut(Residual, nVar); + AD::EndPreacc(); + + return ResidualType<>(Residual, Jacobian_i, nullptr); + +} + +void CSourcePieceWise_TurbSST::SetPerturbedStrainMag(su2double turb_ke){ + + /*--- Compute norm of perturbed strain rate tensor. ---*/ + + PerturbedStrainMag = 0; + for (unsigned short iDim = 0; iDim < nDim; iDim++){ + for (unsigned short jDim = 0; jDim < nDim; jDim++){ + su2double StrainRate_ij = MeanPerturbedRSM[iDim][jDim] - TWO3 * turb_ke * delta[iDim][jDim]; + StrainRate_ij = - StrainRate_ij * Density_i / (2 * Eddy_Viscosity_i); + + PerturbedStrainMag += pow(StrainRate_ij, 2.0); + } + } + PerturbedStrainMag = sqrt(2.0*PerturbedStrainMag); + +} diff --git a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp index a73a2dfd8b58..086eae2d6dee 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp @@ -27,119 +27,3 @@ */ #include "../../../include/numerics/turbulent/turb_convection.hpp" - -CUpwScalar::CUpwScalar(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), - dynamic_grid(config->GetDynamic_Grid()) -{ - Flux = new su2double [nVar]; - Jacobian_i = new su2double* [nVar]; - Jacobian_j = new su2double* [nVar]; - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - Jacobian_i[iVar] = new su2double [nVar]; - Jacobian_j[iVar] = new su2double [nVar]; - } -} - -CUpwScalar::~CUpwScalar(void) { - - delete [] Flux; - if (Jacobian_i != nullptr) { - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - delete [] Jacobian_i[iVar]; - delete [] Jacobian_j[iVar]; - } - delete [] Jacobian_i; - delete [] Jacobian_j; - } -} - -CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { - - unsigned short iDim; - - AD::StartPreacc(); - AD::SetPreaccIn(Normal, nDim); - AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j, nVar); - if (dynamic_grid) { - AD::SetPreaccIn(GridVel_i, nDim); AD::SetPreaccIn(GridVel_j, nDim); - } - - ExtraADPreaccIn(); - - Density_i = V_i[nDim+2]; - Density_j = V_j[nDim+2]; - - su2double q_ij = 0.0; - if (dynamic_grid) { - for (iDim = 0; iDim < nDim; iDim++) { - su2double Velocity_i = V_i[iDim+1] - GridVel_i[iDim]; - su2double Velocity_j = V_j[iDim+1] - GridVel_j[iDim]; - q_ij += 0.5*(Velocity_i+Velocity_j)*Normal[iDim]; - } - } - else { - for (iDim = 0; iDim < nDim; iDim++) { - q_ij += 0.5*(V_i[iDim+1]+V_j[iDim+1])*Normal[iDim]; - } - } - - a0 = 0.5*(q_ij+fabs(q_ij)); - a1 = 0.5*(q_ij-fabs(q_ij)); - - FinishResidualCalc(config); - - AD::SetPreaccOut(Flux, nVar); - AD::EndPreacc(); - - return ResidualType<>(Flux, Jacobian_i, Jacobian_j); - -} - -CUpwSca_TurbSA::CUpwSca_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CUpwScalar(val_nDim, val_nVar, config) { } - -void CUpwSca_TurbSA::ExtraADPreaccIn() { - AD::SetPreaccIn(V_i, nDim+1); - AD::SetPreaccIn(V_j, nDim+1); -} - -void CUpwSca_TurbSA::FinishResidualCalc(const CConfig* config) { - - Flux[0] = a0*TurbVar_i[0]+a1*TurbVar_j[0]; - - if (implicit) { - Jacobian_i[0][0] = a0; - Jacobian_j[0][0] = a1; - } -} - -CUpwSca_TurbSST::CUpwSca_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CUpwScalar(val_nDim, val_nVar, config) { } - -void CUpwSca_TurbSST::ExtraADPreaccIn() { - AD::SetPreaccIn(V_i, nDim+3); - AD::SetPreaccIn(V_j, nDim+3); -} - -void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { - - Flux[0] = a0*Density_i*TurbVar_i[0]+a1*Density_j*TurbVar_j[0]; - Flux[1] = a0*Density_i*TurbVar_i[1]+a1*Density_j*TurbVar_j[1]; - - if (implicit) { - Jacobian_i[0][0] = a0; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = a0; - - Jacobian_j[0][0] = a1; Jacobian_j[0][1] = 0.0; - Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = a1; - } -} diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index aa97f45bb142..79792323f32e 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -27,199 +27,3 @@ */ #include "../../../include/numerics/turbulent/turb_diffusion.hpp" - -CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, - unsigned short val_nVar, - bool correct_grad, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - correct_gradient(correct_grad), - implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) -{ - Proj_Mean_GradTurbVar_Normal = new su2double [nVar] (); - Proj_Mean_GradTurbVar = new su2double [nVar] (); - - Flux = new su2double [nVar] (); - Jacobian_i = new su2double* [nVar]; - Jacobian_j = new su2double* [nVar]; - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - Jacobian_i[iVar] = new su2double [nVar] (); - Jacobian_j[iVar] = new su2double [nVar] (); - } -} - -CAvgGrad_Scalar::~CAvgGrad_Scalar(void) { - - delete [] Proj_Mean_GradTurbVar_Normal; - delete [] Proj_Mean_GradTurbVar; - - delete [] Flux; - if (Jacobian_i != nullptr) { - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - delete [] Jacobian_i[iVar]; - delete [] Jacobian_j[iVar]; - } - delete [] Jacobian_i; - delete [] Jacobian_j; - } -} - -CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config) { - - AD::StartPreacc(); - AD::SetPreaccIn(Coord_i, nDim); AD::SetPreaccIn(Coord_j, nDim); - AD::SetPreaccIn(Normal, nDim); - AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); - AD::SetPreaccIn(TurbVar_Grad_j, nVar, nDim); - if (correct_gradient) { - AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j ,nVar); - } - ExtraADPreaccIn(); - - if (incompressible) { - AD::SetPreaccIn(V_i, nDim+6); AD::SetPreaccIn(V_j, nDim+6); - - Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; Laminar_Viscosity_j = V_j[nDim+4]; - Eddy_Viscosity_i = V_i[nDim+5]; Eddy_Viscosity_j = V_j[nDim+5]; - } - else { - AD::SetPreaccIn(V_i, nDim+7); AD::SetPreaccIn(V_j, nDim+7); - - Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; Laminar_Viscosity_j = V_j[nDim+5]; - Eddy_Viscosity_i = V_i[nDim+6]; Eddy_Viscosity_j = V_j[nDim+6]; - } - - proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, TurbVar_Grad_i, - TurbVar_Grad_j, correct_gradient, TurbVar_i, TurbVar_j, - Proj_Mean_GradTurbVar_Normal, Proj_Mean_GradTurbVar); - FinishResidualCalc(config); - - AD::SetPreaccOut(Flux, nVar); - AD::EndPreacc(); - - return ResidualType<>(Flux, Jacobian_i, Jacobian_j); - -} - -CAvgGrad_TurbSA::CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } - -void CAvgGrad_TurbSA::ExtraADPreaccIn() { } - -void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { - - /*--- Compute mean effective viscosity ---*/ - - su2double nu_i = Laminar_Viscosity_i/Density_i; - su2double nu_j = Laminar_Viscosity_j/Density_j; - su2double nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); - - Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - - if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; - } - -} - -CAvgGrad_TurbSA_Neg::CAvgGrad_TurbSA_Neg(unsigned short val_nDim, - unsigned short val_nVar, - bool correct_grad, - const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } - -void CAvgGrad_TurbSA_Neg::ExtraADPreaccIn() { } - -void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { - - /*--- Compute mean effective viscosity ---*/ - - su2double nu_i = Laminar_Viscosity_i/Density_i; - su2double nu_j = Laminar_Viscosity_j/Density_j; - - su2double nu_ij = 0.5*(nu_i+nu_j); - su2double nu_tilde_ij = 0.5*(TurbVar_i[0]+TurbVar_j[0]); - - su2double nu_e; - - if (nu_tilde_ij > 0.0) { - nu_e = nu_ij + nu_tilde_ij; - } - else { - su2double Xi = nu_tilde_ij/nu_ij; - su2double fn = (cn1 + Xi*Xi*Xi)/(cn1 - Xi*Xi*Xi); - nu_e = nu_ij + fn*nu_tilde_ij; - } - - Flux[0] = nu_e*Proj_Mean_GradTurbVar_Normal[0]/sigma; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - - if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; - } - -} - -CAvgGrad_TurbSST::CAvgGrad_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const su2double *constants, - bool correct_grad, - const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config), - sigma_k1(constants[0]), - sigma_k2(constants[1]), - sigma_om1(constants[2]), - sigma_om2(constants[3]) { - -} - -void CAvgGrad_TurbSST::ExtraADPreaccIn() { - AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F1_j); -} - -void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { - - su2double sigma_kine_i, sigma_kine_j, sigma_omega_i, sigma_omega_j; - su2double diff_i_kine, diff_i_omega, diff_j_kine, diff_j_omega; - - /*--- Compute the blended constant for the viscous terms ---*/ - sigma_kine_i = F1_i*sigma_k1 + (1.0 - F1_i)*sigma_k2; - sigma_kine_j = F1_j*sigma_k1 + (1.0 - F1_j)*sigma_k2; - sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2; - sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2; - - /*--- Compute mean effective viscosity ---*/ - diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i; - diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j; - diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i; - diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j; - - su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine); - su2double diff_omega = 0.5*(diff_i_omega + diff_j_omega); - - Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; - Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - if (implicit) { - su2double proj_on_rho = proj_vector_ij/Density_i; - - Jacobian_i[0][0] = -diff_kine*proj_on_rho; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = -diff_omega*proj_on_rho; - - proj_on_rho = proj_vector_ij/Density_j; - - Jacobian_j[0][0] = diff_kine*proj_on_rho; Jacobian_j[0][1] = 0.0; - Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = diff_omega*proj_on_rho; - } - -} diff --git a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp index a4d4d49e663e..39bb5e934cdd 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp @@ -27,904 +27,3 @@ */ #include "../../../include/numerics/turbulent/turb_sources.hpp" - -CSourceBase_TurbSA::CSourceBase_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), - rotating_frame(config->GetRotating_Frame()) -{ - /*--- Spalart-Allmaras closure constants ---*/ - - cv1_3 = pow(7.1, 3.0); - k2 = pow(0.41, 2.0); - cb1 = 0.1355; - cw2 = 0.3; - ct3 = 1.2; - ct4 = 0.5; - cw3_6 = pow(2.0, 6.0); - sigma = 2./3.; - cb2 = 0.622; - cb2_sigma = cb2/sigma; - cw1 = cb1/k2+(1.0+cb2)/sigma; - cr1 = 0.5; - - /*--- Setup the Jacobian pointer, we need to return su2double** but - * we know the Jacobian is 1x1 so we use this "trick" to avoid - * having to dynamically allocate. ---*/ - - Jacobian_i = &Jacobian_Buffer; - -} - -CSourcePieceWise_TurbSA::CSourcePieceWise_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { - - transition = (config->GetKind_Trans_Model() == BC); -} - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig* config) { - -// AD::StartPreacc(); -// AD::SetPreaccIn(V_i, nDim+6); -// AD::SetPreaccIn(Vorticity_i, nDim); -// AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); -// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - // Set the boolean here depending on whether the point is closest to a rough wall or not. - roughwall = (roughness_i > 0.0); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - - /*--- Modified values for roughness ---*/ - /*--- Ref: Aupoix, B. and Spalart, P. R., "Extensions of the Spalart-Allmaras Turbulence Model to Account for Wall Roughness," - * International Journal of Heat and Fluid Flow, Vol. 24, 2003, pp. 454-462. ---*/ - /* --- See https://turbmodels.larc.nasa.gov/spalart.html#sarough for detailed explanation. ---*/ - - Ji = TurbVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - - /*--- Using a modified relation so as to not change the Shat that depends on fv2. ---*/ - fv2 = 1.0 - TurbVar_i[0]/(nu+TurbVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper - - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - -// Original SA model -// Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; - - if (transition) { - - /*--- BC model constants (2020 revision). ---*/ - const su2double chi_1 = 0.002; - const su2double chi_2 = 50.0; - - /*--- turbulence intensity is u'/U so we multiply by 100 to get percentage ---*/ - su2double tu = 100.0 * config->GetTurbulenceIntensity_FreeStream(); - - su2double nu_t = (TurbVar_i[0]*fv1); //S-A variable - - su2double re_v = ((Density_i*pow(dist_i,2.))/(Laminar_Viscosity_i))*Omega; - su2double re_theta = re_v/2.193; - su2double re_theta_t = (803.73 * pow((tu + 0.6067),-1.027)); //MENTER correlation - //re_theta_t = 163.0 + exp(6.91-tu); //ABU-GHANNAM & SHAW correlation - - su2double term1 = sqrt(max(re_theta-re_theta_t,0.)/(chi_1*re_theta_t)); - su2double term2 = sqrt(max((nu_t*chi_2)/nu,0.)); - su2double term_exponential = (term1 + term2); - - Gamma_BC = 1.0 - exp(-term_exponential); - - Production = Gamma_BC*cb1*Shat*TurbVar_i[0]*Volume; - } - else { - Production = cb1*Shat*TurbVar_i[0]*Volume; - } - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - -// Original SA model -// Destruction = (cw1*fw-cb1*ft2/k2)*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - - if (transition) { - Jacobian_i[0] += Gamma_BC*cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - } - else { - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - } - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - if (r == 10.0) dr = 0.0; - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - -// AD::SetPreaccOut(Residual); -// AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_COMP::CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config), c5(3.5) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CConfig* config) { - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Compressibility Correction term ---*/ - Pressure_i = V_i[nDim+1]; - SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); - aux_cc=0; - for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_E::CSourcePieceWise_TurbSA_E(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConfig* config) { - - unsigned short iDim, jDim; - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /* - From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html - This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: - Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. - In this modificaton Omega is replaced by Strain Rate - */ - - /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ - - Sbar = 0.0; - for(iDim=0;iDim 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - //Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); - - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - r=tanh(r)/tanh(1.0); - - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - - // AD::SetPreaccOut(Residual); - // AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_E_COMP::CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const CConfig* config) { - - unsigned short iDim; - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /* - From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html - This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: - Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. - In this modificaton Omega is replaced by Strain Rate - */ - - /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ - - Sbar = 0.0; - for(iDim=0;iDim 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); - - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - r=tanh(r)/tanh(1.0); - - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Compressibility Correction term ---*/ - Pressure_i = V_i[nDim+1]; - SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); - aux_cc=0; - for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_Neg::CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CConfig* config) { - - unsigned short iDim; - -// AD::StartPreacc(); -// AD::SetPreaccIn(V_i, nDim+6); -// AD::SetPreaccIn(Vorticity_i, nDim); -// AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); -// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - if (TurbVar_i[0] > 0.0) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - // Original SA model - // Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - if (r == 10.0) dr = 0.0; - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - - else { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - - /*--- Production term ---*/; - - Production = cb1*(1.0-ct3)*Omega*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - Destruction = cw1*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production + Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - Jacobian_i[0] += cb1*(1.0-ct3)*Omega*Volume; - - /*--- Implicit part, destruction term ---*/ - - Jacobian_i[0] += 2.0*cw1*TurbVar_i[0]/dist_i_2*Volume; - - } - - } - -// AD::SetPreaccOut(Residual); -// AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSST::CSourcePieceWise_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const su2double *constants, - su2double val_kine_Inf, - su2double val_omega_Inf, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config) { - - incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - sustaining_terms = (config->GetKind_Turb_Model() == SST_SUST); - axisymmetric = config->GetAxisymmetric(); - - /*--- Closure constants ---*/ - sigma_k_1 = constants[0]; - sigma_k_2 = constants[1]; - sigma_w_1 = constants[2]; - sigma_w_2 = constants[3]; - beta_1 = constants[4]; - beta_2 = constants[5]; - beta_star = constants[6]; - a1 = constants[7]; - alfa_1 = constants[8]; - alfa_2 = constants[9]; - - /*--- Set the ambient values of k and omega to the free stream values. ---*/ - kAmb = val_kine_Inf; - omegaAmb = val_omega_Inf; - - /*--- "Allocate" the Jacobian using the static buffer. ---*/ - Jacobian_i[0] = Jacobian_Buffer; - Jacobian_i[1] = Jacobian_Buffer+2; - -} - -CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfig* config) { - - AD::StartPreacc(); - AD::SetPreaccIn(StrainMag_i); - AD::SetPreaccIn(TurbVar_i, nVar); - AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); - AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); - AD::SetPreaccIn(PrimVar_Grad_i, nDim+1, nDim); - AD::SetPreaccIn(Vorticity_i, 3); - - unsigned short iDim; - su2double alfa_blended, beta_blended; - su2double diverg, pk, pw, zeta; - su2double VorticityMag = sqrt(Vorticity_i[0]*Vorticity_i[0] + - Vorticity_i[1]*Vorticity_i[1] + - Vorticity_i[2]*Vorticity_i[2]); - - if (incompressible) { - AD::SetPreaccIn(V_i, nDim+6); - - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - Eddy_Viscosity_i = V_i[nDim+5]; - } - else { - AD::SetPreaccIn(V_i, nDim+7); - - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - Eddy_Viscosity_i = V_i[nDim+6]; - } - - Residual[0] = 0.0; Residual[1] = 0.0; - Jacobian_i[0][0] = 0.0; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = 0.0; - - /*--- Computation of blended constants for the source terms---*/ - - alfa_blended = F1_i*alfa_1 + (1.0 - F1_i)*alfa_2; - beta_blended = F1_i*beta_1 + (1.0 - F1_i)*beta_2; - - if (dist_i > 1e-10) { - - /*--- Production ---*/ - - diverg = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - diverg += PrimVar_Grad_i[iDim+1][iDim]; - - /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ - - if (using_uq){ - ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, - PrimVar_Grad_i+1, Density_i, Eddy_Viscosity_i, - TurbVar_i[0], MeanPerturbedRSM); - SetPerturbedStrainMag(TurbVar_i[0]); - pk = Eddy_Viscosity_i*PerturbedStrainMag*PerturbedStrainMag - - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; - } - else { - pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; - } - - pk = min(pk,20.0*beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]); - pk = max(pk,0.0); - - zeta = max(TurbVar_i[1], VorticityMag*F2_i/a1); - - /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ - - if (using_uq){ - pw = PerturbedStrainMag * PerturbedStrainMag - 2.0/3.0*zeta*diverg; - } - else { - pw = StrainMag_i*StrainMag_i - 2.0/3.0*zeta*diverg; - } - pw = alfa_blended*Density_i*max(pw,0.0); - - /*--- Sustaining terms, if desired. Note that if the production terms are - larger equal than the sustaining terms, the original formulation is - obtained again. This is in contrast to the version in literature - where the sustaining terms are simply added. This latter approach could - lead to problems for very big values of the free-stream turbulence - intensity. ---*/ - - if ( sustaining_terms ) { - const su2double sust_k = beta_star*Density_i*kAmb*omegaAmb; - const su2double sust_w = beta_blended*Density_i*omegaAmb*omegaAmb; - - pk = max(pk, sust_k); - pw = max(pw, sust_w); - } - - /*--- Add the production terms to the residuals. ---*/ - - Residual[0] += pk*Volume; - Residual[1] += pw*Volume; - - /*--- Dissipation ---*/ - - Residual[0] -= beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]*Volume; - Residual[1] -= beta_blended*Density_i*TurbVar_i[1]*TurbVar_i[1]*Volume; - - /*--- Cross diffusion ---*/ - - Residual[1] += (1.0 - F1_i)*CDkw_i*Volume; - - /*--- Contribution due to 2D axisymmetric formulation ---*/ - - if (axisymmetric) ResidualAxisymmetric(alfa_blended,zeta); - - /*--- Implicit part ---*/ - - Jacobian_i[0][0] = -beta_star*TurbVar_i[1]*Volume; - Jacobian_i[0][1] = -beta_star*TurbVar_i[0]*Volume; - Jacobian_i[1][0] = 0.0; - Jacobian_i[1][1] = -2.0*beta_blended*TurbVar_i[1]*Volume; - } - - AD::SetPreaccOut(Residual, nVar); - AD::EndPreacc(); - - return ResidualType<>(Residual, Jacobian_i, nullptr); - -} - -void CSourcePieceWise_TurbSST::SetPerturbedStrainMag(su2double turb_ke){ - - /*--- Compute norm of perturbed strain rate tensor. ---*/ - - PerturbedStrainMag = 0; - for (unsigned short iDim = 0; iDim < nDim; iDim++){ - for (unsigned short jDim = 0; jDim < nDim; jDim++){ - su2double StrainRate_ij = MeanPerturbedRSM[iDim][jDim] - TWO3 * turb_ke * delta[iDim][jDim]; - StrainRate_ij = - StrainRate_ij * Density_i / (2 * Eddy_Viscosity_i); - - PerturbedStrainMag += pow(StrainRate_ij, 2.0); - } - } - PerturbedStrainMag = sqrt(2.0*PerturbedStrainMag); - -} diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp new file mode 100644 index 000000000000..0fd7f21c6c0b --- /dev/null +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -0,0 +1,1146 @@ +/*! + * \file CScalarSolver.cpp + * \brief Main subrotuines of CScalarSolver class + * \author F. Palacios, A. Bueno + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + +#include "../../include/solvers/CScalarSolver.hpp" +#include "../../../Common/include/parallelization/omp_structure.hpp" +#include "../../../Common/include/toolboxes/geometry_toolbox.hpp" + + +CScalarSolver::CScalarSolver(void) : CSolver() { } + +CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { + + Gamma = config->GetGamma(); + Gamma_Minus_One = Gamma - 1.0; + + nMarker = config->GetnMarker_All(); + + /*--- Store the number of vertices on each marker for deallocation later ---*/ + nVertex.resize(nMarker); + for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) + nVertex[iMarker] = geometry->nVertex[iMarker]; + + /* A grid is defined as dynamic if there's rigid grid movement or grid deformation AND the problem is time domain */ + dynamic_grid = config->GetDynamic_Grid(); + +#ifdef HAVE_OMP + /*--- Get the edge coloring, see notes in CEulerSolver's constructor. ---*/ + su2double parallelEff = 1.0; + const auto& coloring = geometry->GetEdgeColoring(¶llelEff); + + ReducerStrategy = parallelEff < COLORING_EFF_THRESH; + + if (ReducerStrategy && (coloring.getOuterSize()>1)) + geometry->SetNaturalEdgeColoring(); + + if (!coloring.empty()) { + auto groupSize = ReducerStrategy? 1ul : geometry->GetEdgeColorGroupSize(); + auto nColor = coloring.getOuterSize(); + EdgeColoring.reserve(nColor); + + for(auto iColor = 0ul; iColor < nColor; ++iColor) + EdgeColoring.emplace_back(coloring.innerIdx(iColor), coloring.getNumNonZeros(iColor), groupSize); + } + + nPoint = geometry->GetnPoint(); + omp_chunk_size = computeStaticChunkSize(nPoint, omp_get_max_threads(), OMP_MAX_SIZE); +#else + EdgeColoring[0] = DummyGridColor<>(geometry->GetnEdge()); +#endif +} + +CScalarSolver::~CScalarSolver(void) { + + for (auto& mat : SlidingState) { + for (auto ptr : mat) delete [] ptr; + } + + delete nodes; + +} + +void CScalarSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_container, + CNumerics **numerics_container, CConfig *config, unsigned short iMesh) { + + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + const bool muscl = config->GetMUSCL_Turb(); + const bool limiter = (config->GetKind_SlopeLimit_Turb() != NO_LIMITER); + + /*--- Only reconstruct flow variables if MUSCL is on for flow (requires upwind) and turbulence. ---*/ + const bool musclFlow = config->GetMUSCL_Flow() && muscl && + (config->GetKind_ConvNumScheme_Flow() == SPACE_UPWIND); + /*--- Only consider flow limiters for cell-based limiters, edge-based would need to be recomputed. ---*/ + const bool limiterFlow = (config->GetKind_SlopeLimit_Flow() != NO_LIMITER) && + (config->GetKind_SlopeLimit_Flow() != VAN_ALBADA_EDGE); + + CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); + + /*--- Pick one numerics object per thread. ---*/ + CNumerics* numerics = numerics_container[CONV_TERM + omp_get_thread_num()*MAX_TERMS]; + + /*--- Static arrays of MUSCL-reconstructed flow primitives and turbulence variables (thread safety). ---*/ + su2double solution_i[MAXNVAR] = {0.0}, flowPrimVar_i[MAXNVARFLOW] = {0.0}; + su2double solution_j[MAXNVAR] = {0.0}, flowPrimVar_j[MAXNVARFLOW] = {0.0}; + + /*--- Loop over edge colors. ---*/ + for (auto color : EdgeColoring) + { + /*--- Chunk size is at least OMP_MIN_SIZE and a multiple of the color group size. ---*/ + SU2_OMP_FOR_DYN(nextMultiple(OMP_MIN_SIZE, color.groupSize)) + for(auto k = 0ul; k < color.size; ++k) { + + auto iEdge = color.indices[k]; + + unsigned short iDim, iVar; + + /*--- Points in edge and normal vectors ---*/ + + auto iPoint = geometry->edges->GetNode(iEdge,0); + auto jPoint = geometry->edges->GetNode(iEdge,1); + + numerics->SetNormal(geometry->edges->GetNormal(iEdge)); + + /*--- Primitive variables w/o reconstruction ---*/ + + const auto V_i = flowNodes->GetPrimitive(iPoint); + const auto V_j = flowNodes->GetPrimitive(jPoint); + numerics->SetPrimitive(V_i, V_j); + + /*--- Turbulent variables w/o reconstruction ---*/ + + const auto Turb_i = nodes->GetSolution(iPoint); + const auto Turb_j = nodes->GetSolution(jPoint); + numerics->SetTurbVar(Turb_i, Turb_j); + + /*--- Grid Movement ---*/ + + if (dynamic_grid) + numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), + geometry->nodes->GetGridVel(jPoint)); + + if (muscl || musclFlow) { + const su2double *Limiter_i = nullptr, *Limiter_j = nullptr; + + const auto Coord_i = geometry->nodes->GetCoord(iPoint); + const auto Coord_j = geometry->nodes->GetCoord(jPoint); + + su2double Vector_ij[MAXNDIM] = {0.0}; + for (iDim = 0; iDim < nDim; iDim++) { + Vector_ij[iDim] = 0.5*(Coord_j[iDim] - Coord_i[iDim]); + } + + if (musclFlow) { + /*--- Reconstruct mean flow primitive variables. ---*/ + + auto Gradient_i = flowNodes->GetGradient_Reconstruction(iPoint); + auto Gradient_j = flowNodes->GetGradient_Reconstruction(jPoint); + + if (limiterFlow) { + Limiter_i = flowNodes->GetLimiter_Primitive(iPoint); + Limiter_j = flowNodes->GetLimiter_Primitive(jPoint); + } + + for (iVar = 0; iVar < solver_container[FLOW_SOL]->GetnPrimVarGrad(); iVar++) { + su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; + for (iDim = 0; iDim < nDim; iDim++) { + Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; + Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; + } + if (limiterFlow) { + Project_Grad_i *= Limiter_i[iVar]; + Project_Grad_j *= Limiter_j[iVar]; + } + flowPrimVar_i[iVar] = V_i[iVar] + Project_Grad_i; + flowPrimVar_j[iVar] = V_j[iVar] + Project_Grad_j; + } + + numerics->SetPrimitive(flowPrimVar_i, flowPrimVar_j); + } + + if (muscl) { + /*--- Reconstruct turbulence variables. ---*/ + + auto Gradient_i = nodes->GetGradient_Reconstruction(iPoint); + auto Gradient_j = nodes->GetGradient_Reconstruction(jPoint); + + if (limiter) { + Limiter_i = nodes->GetLimiter(iPoint); + Limiter_j = nodes->GetLimiter(jPoint); + } + + for (iVar = 0; iVar < nVar; iVar++) { + su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; + for (iDim = 0; iDim < nDim; iDim++) { + Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; + Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; + } + if (limiter) { + Project_Grad_i *= Limiter_i[iVar]; + Project_Grad_j *= Limiter_j[iVar]; + } + solution_i[iVar] = Turb_i[iVar] + Project_Grad_i; + solution_j[iVar] = Turb_j[iVar] + Project_Grad_j; + } + + numerics->SetTurbVar(solution_i, solution_j); + } + } + + /*--- Update convective residual value ---*/ + + auto residual = numerics->ComputeResidual(config); + + if (ReducerStrategy) { + EdgeFluxes.SetBlock(iEdge, residual); + if (implicit) Jacobian.SetBlocks(iEdge, residual.jacobian_i, residual.jacobian_j); + } + else { + LinSysRes.AddBlock(iPoint, residual); + LinSysRes.SubtractBlock(jPoint, residual); + if (implicit) Jacobian.UpdateBlocks(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); + } + + /*--- Viscous contribution. ---*/ + + Viscous_Residual(iEdge, geometry, solver_container, + numerics_container[VISC_TERM + omp_get_thread_num()*MAX_TERMS], config); + } + END_SU2_OMP_FOR + } // end color loop + + if (ReducerStrategy) { + SumEdgeFluxes(geometry); + if (implicit) Jacobian.SetDiagonalAsColumnSum(); + } +} + +void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, CSolver **solver_container, + CNumerics *numerics, CConfig *config) { + + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); + + /*--- Points in edge ---*/ + + auto iPoint = geometry->edges->GetNode(iEdge,0); + auto jPoint = geometry->edges->GetNode(iEdge,1); + + /*--- Points coordinates, and normal vector ---*/ + + numerics->SetCoord(geometry->nodes->GetCoord(iPoint), + geometry->nodes->GetCoord(jPoint)); + numerics->SetNormal(geometry->edges->GetNormal(iEdge)); + + /*--- Conservative variables w/o reconstruction ---*/ + + numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), + flowNodes->GetPrimitive(jPoint)); + + /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ + + numerics->SetTurbVar(nodes->GetSolution(iPoint), + nodes->GetSolution(jPoint)); + numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), + nodes->GetGradient(jPoint)); + + /*--- Menter's first blending function (only SST)---*/ + if ((config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST)) + numerics->SetF1blending(nodes->GetF1blending(iPoint), + nodes->GetF1blending(jPoint)); + + /*--- Roughness heights. ---*/ + if (config->GetKind_Turb_Model() == SA) + numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), + geometry->nodes->GetRoughnessHeight(jPoint)); + + /*--- Compute residual, and Jacobians ---*/ + + auto residual = numerics->ComputeResidual(config); + + if (ReducerStrategy) { + EdgeFluxes.SubtractBlock(iEdge, residual); + if (implicit) Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j); + } + else { + LinSysRes.SubtractBlock(iPoint, residual); + LinSysRes.AddBlock(jPoint, residual); + if (implicit) Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); + } +} + +void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { + + LinSysRes.SetBlock_Zero(iPoint); + + for (auto iEdge : geometry->nodes->GetEdges(iPoint)) { + if (iPoint == geometry->edges->GetNode(iEdge,0)) + LinSysRes.AddBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); + else + LinSysRes.SubtractBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); + } + } + END_SU2_OMP_FOR + +} + +void CScalarSolver::BC_Sym_Plane(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) { + + /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ + +} + +void CScalarSolver::BC_Euler_Wall(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) { + + /*--- Convective fluxes across euler wall are equal to zero. ---*/ + +} + +void CScalarSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Riemann(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: + BC_Inlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case STATIC_PRESSURE: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } +} + +void CScalarSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Riemann(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case STATIC_PRESSURE: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } +} + + +void CScalarSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Giles(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT:case TOTAL_CONDITIONS_PT_1D: case DENSITY_VELOCITY: + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case MIXING_IN: + if (config->GetBoolTurbMixingPlane()){ + BC_Inlet_MixingPlane(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + } + else{ + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + } + break; + + case STATIC_PRESSURE: case MIXING_OUT: case STATIC_PRESSURE_1D: case RADIAL_EQUILIBRIUM: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } +} + +void CScalarSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, + CNumerics *numerics, CConfig *config) { + + /*--- Complete residuals for periodic boundary conditions. We loop over + the periodic BCs in matching pairs so that, in the event that there are + adjacent periodic markers, the repeated points will have their residuals + accumulated corectly during the communications. For implicit calculations + the Jacobians and linear system are also correctly adjusted here. ---*/ + + for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { + InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); + CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); + } + +} + +void CScalarSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, + CNumerics *visc_numerics, CConfig *config) { + + const bool sst = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); + const auto nPrimVar = solver_container[FLOW_SOL]->GetnPrimVar(); + su2double *PrimVar_j = new su2double[nPrimVar]; + su2double solution_j[MAXNVAR] = {0.0}; + + for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { + + if (config->GetMarker_All_KindBC(iMarker) != FLUID_INTERFACE) continue; + + SU2_OMP_FOR_STAT(OMP_MIN_SIZE) + for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) { + + const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); + + if (!geometry->nodes->GetDomain(iPoint)) continue; + + const auto Point_Normal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor(); + const auto nDonorVertex = GetnSlidingStates(iMarker,iVertex); + + su2double Normal[MAXNDIM] = {0.0}; + for (auto iDim = 0u; iDim < nDim; iDim++) + Normal[iDim] = -geometry->vertex[iMarker][iVertex]->GetNormal()[iDim]; + + su2double* PrimVar_i = solver_container[FLOW_SOL]->GetNodes()->GetPrimitive(iPoint); + + auto Jacobian_i = Jacobian.GetBlock(iPoint,iPoint); + + /*--- Loop over the nDonorVertexes and compute the averaged flux ---*/ + + for (auto jVertex = 0; jVertex < nDonorVertex; jVertex++) { + + for (auto iVar = 0u; iVar < nPrimVar; iVar++) + PrimVar_j[iVar] = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, iVar, jVertex); + + /*--- Get the weight computed in the interpolator class for the j-th donor vertex ---*/ + + const su2double weight = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, nPrimVar, jVertex); + + /*--- Set primitive variables ---*/ + + conv_numerics->SetPrimitive( PrimVar_i, PrimVar_j ); + + /*--- Set the turbulent variable states ---*/ + + for (auto iVar = 0u; iVar < nVar; ++iVar) + solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex); + + conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + + /*--- Set the normal vector ---*/ + + conv_numerics->SetNormal(Normal); + + if (dynamic_grid) + conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(iPoint)); + + auto residual = conv_numerics->ComputeResidual(config); + + /*--- Accumulate the residuals to compute the average ---*/ + + for (auto iVar = 0u; iVar < nVar; iVar++) { + LinSysRes(iPoint,iVar) += weight*residual[iVar]; + for (auto jVar = 0u; jVar < nVar; jVar++) + Jacobian_i[iVar*nVar+jVar] += SU2_TYPE::GetValue(weight*residual.jacobian_i[iVar][jVar]); + } + } + + /*--- Set the normal vector and the coordinates ---*/ + + visc_numerics->SetNormal(Normal); + su2double Coord_Reflected[MAXNDIM]; + GeometryToolbox::PointPointReflect(nDim, geometry->nodes->GetCoord(Point_Normal), + geometry->nodes->GetCoord(iPoint), Coord_Reflected); + visc_numerics->SetCoord(geometry->nodes->GetCoord(iPoint), Coord_Reflected); + + /*--- Primitive variables ---*/ + + visc_numerics->SetPrimitive(PrimVar_i, PrimVar_j); + + /*--- Turbulent variables and their gradients ---*/ + + visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); + + /*--- Menter's first blending function ---*/ + + if(sst) visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); + + /*--- Compute and update residual ---*/ + + auto residual = visc_numerics->ComputeResidual(config); + + LinSysRes.SubtractBlock(iPoint, residual); + + /*--- Jacobian contribution for implicit integration ---*/ + + Jacobian.SubtractBlock2Diag(iPoint, residual.jacobian_i); + + } + END_SU2_OMP_FOR + } + + delete [] PrimVar_j; + +} + +void CScalarSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config){ + + /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ + if(config->GetTurb_Fixed_Values()){ + + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + + /*--- Form normalized far-field velocity ---*/ + const su2double* velocity_inf = config->GetVelocity_FreeStreamND(); + su2double velmag_inf = GeometryToolbox::Norm(nDim, velocity_inf); + if(velmag_inf==0) + SU2_MPI::Error("Far-field velocity is zero, cannot fix turbulence quantities to inflow values.", CURRENT_FUNCTION); + su2double unit_velocity_inf[MAXNDIM]; + for(unsigned short iDim=0; iDimnodes->GetCoord(iPoint), unit_velocity_inf) + < config->GetTurb_Fixed_Values_MaxScalarProd() ) { + /*--- Set the solution values and zero the residual ---*/ + nodes->SetSolution_Old(iPoint, Solution_Inf); + nodes->SetSolution(iPoint, Solution_Inf); + LinSysRes.SetBlock_Zero(iPoint); + if (implicit) { + /*--- Change rows of the Jacobian (includes 1 in the diagonal) ---*/ + for(unsigned long iVar=0; iVarGetNodes(); + + /*--- Set shared residual variables to 0 and declare + * local ones for current thread to work on. ---*/ + + SetResToZero(); + + su2double resMax[MAXNVAR] = {0.0}, resRMS[MAXNVAR] = {0.0}; + const su2double* coordMax[MAXNVAR] = {nullptr}; + unsigned long idxMax[MAXNVAR] = {0}; + + /*--- Build implicit system ---*/ + + SU2_OMP_FOR_(schedule(static,omp_chunk_size) SU2_NOWAIT) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + + /// TODO: This could be the SetTime_Step of this solver. + su2double dt = nodes->GetLocalCFL(iPoint) / flowNodes->GetLocalCFL(iPoint) * flowNodes->GetDelta_Time(iPoint); + nodes->SetDelta_Time(iPoint, dt); + + /*--- Modify matrix diagonal to improve diagonal dominance. ---*/ + + if (dt != 0.0) { + su2double Vol = geometry->nodes->GetVolume(iPoint) + geometry->nodes->GetPeriodicVolume(iPoint); + Jacobian.AddVal2Diag(iPoint, Vol / dt); + } + else { + Jacobian.SetVal2Diag(iPoint, 1.0); + LinSysRes.SetBlock_Zero(iPoint); + } + + /*--- Right hand side of the system (-Residual) and initial guess (x = 0) ---*/ + + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + unsigned long total_index = iPoint*nVar + iVar; + LinSysRes[total_index] = -LinSysRes[total_index]; + LinSysSol[total_index] = 0.0; + + su2double Res = fabs(LinSysRes[total_index]); + resRMS[iVar] += Res*Res; + if (Res > resMax[iVar]) { + resMax[iVar] = Res; + idxMax[iVar] = iPoint; + coordMax[iVar] = geometry->nodes->GetCoord(iPoint); + } + } + } + END_SU2_OMP_FOR + SU2_OMP_CRITICAL + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + Residual_RMS[iVar] += resRMS[iVar]; + AddRes_Max(iVar, resMax[iVar], geometry->nodes->GetGlobalIndex(idxMax[iVar]), coordMax[iVar]); + } + END_SU2_OMP_CRITICAL + SU2_OMP_BARRIER + + /*--- Compute the root mean square residual ---*/ + SetResidual_RMS(geometry, config); +} + +void CScalarSolver::CompleteImplicitIteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { + + const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); + + const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); + + ComputeUnderRelaxationFactor(config); + + /*--- Update solution (system written in terms of increments) ---*/ + + if (!adjoint) { + + /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ + + switch (config->GetKind_Turb_Model()) { + + case SA: case SA_E: case SA_COMP: case SA_E_COMP: case SA_NEG: + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + nodes->AddSolution(iPoint, 0, nodes->GetUnderRelaxation(iPoint)*LinSysSol[iPoint]); + } + END_SU2_OMP_FOR + break; + + case SST: case SST_SUST: + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + + su2double density = flowNodes->GetDensity(iPoint); + su2double density_old = density; + + if (compressible) + density_old = flowNodes->GetSolution_Old(iPoint,0); + + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + nodes->AddConservativeSolution(iPoint, iVar, + nodes->GetUnderRelaxation(iPoint)*LinSysSol(iPoint,iVar), + density, density_old, lowerlimit[iVar], upperlimit[iVar]); + } + } + END_SU2_OMP_FOR + break; + + } + } + + for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { + InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); + CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); + } + + InitiateComms(geometry, config, SOLUTION_EDDY); + CompleteComms(geometry, config, SOLUTION_EDDY); + +} + +void CScalarSolver::ImplicitEuler_Iteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { + + PrepareImplicitIteration(geometry, solver_container, config); + + /*--- Solve or smooth the linear system. ---*/ + + SU2_OMP_FOR_(schedule(static,OMP_MIN_SIZE) SU2_NOWAIT) + for (unsigned long iPoint = nPointDomain; iPoint < nPoint; iPoint++) { + LinSysRes.SetBlock_Zero(iPoint); + LinSysSol.SetBlock_Zero(iPoint); + } + END_SU2_OMP_FOR + + auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config); + + SU2_OMP_MASTER { + SetIterLinSolver(iter); + SetResLinSolver(System.GetResidual()); + } + END_SU2_OMP_MASTER + SU2_OMP_BARRIER + + CompleteImplicitIteration(geometry, solver_container, config); + +} + +void CScalarSolver::ComputeUnderRelaxationFactor(const CConfig *config) { + + /* Only apply the turbulent under-relaxation to the SA variants. The + SA_NEG model is more robust due to allowing for negative nu_tilde, + so the under-relaxation is not applied to that variant. */ + + bool sa_model = ((config->GetKind_Turb_Model() == SA) || + (config->GetKind_Turb_Model() == SA_E) || + (config->GetKind_Turb_Model() == SA_COMP) || + (config->GetKind_Turb_Model() == SA_E_COMP)); + + /* Loop over the solution update given by relaxing the linear + system for this nonlinear iteration. */ + + su2double localUnderRelaxation = 1.00; + const su2double allowableRatio = 0.99; + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + + localUnderRelaxation = 1.0; + if (sa_model) { + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + + /* We impose a limit on the maximum percentage that the + turbulence variables can change over a nonlinear iteration. */ + + const unsigned long index = iPoint * nVar + iVar; + su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); + if (ratio > allowableRatio) { + localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); + } + + } + } + + /* Threshold the relaxation factor in the event that there is + a very small value. This helps avoid catastrophic crashes due + to non-realizable states by canceling the update. */ + + if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0; + + /* Store the under-relaxation factor for this point. */ + + nodes->SetUnderRelaxation(iPoint, localUnderRelaxation); + + } + END_SU2_OMP_FOR + +} + +void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_container, CConfig *config, + unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { + + const bool sst_model = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST); + const bool second_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND); + const bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + + /*--- Flow solution, needed to get density. ---*/ + + CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); + + /*--- Store the physical time step ---*/ + + const su2double TimeStep = config->GetDelta_UnstTimeND(); + + /*--- Local variables ---*/ + + unsigned short iVar, iMarker, iDim, iNeigh; + unsigned long iPoint, jPoint, iVertex, iEdge; + + const su2double *U_time_nM1 = nullptr, *U_time_n = nullptr, *U_time_nP1 = nullptr; + su2double Volume_nM1, Volume_nP1; + su2double Density_nM1, Density_n, Density_nP1; + const su2double *Normal = nullptr, *GridVel_i = nullptr, *GridVel_j = nullptr; + su2double Residual_GCL; + + /*--- Compute the dual time-stepping source term for static meshes ---*/ + + if (!dynamic_grid) { + + /*--- Loop over all nodes (excluding halos) ---*/ + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (iPoint = 0; iPoint < nPointDomain; iPoint++) { + + /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that + we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, + previous solutions that are stored in memory. ---*/ + + U_time_nM1 = nodes->GetSolution_time_n1(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); + U_time_nP1 = nodes->GetSolution(iPoint); + + /*--- CV volume at time n+1. As we are on a static mesh, the volume + of the CV will remained fixed for all time steps. ---*/ + + Volume_nP1 = geometry->nodes->GetVolume(iPoint); + + /*--- Compute the dual time-stepping source term based on the chosen + time discretization scheme (1st- or 2nd-order).---*/ + + if (sst_model) { + + /*--- If this is the SST model, we need to multiply by the density + in order to get the conservative variables ---*/ + if (incompressible){ + /*--- This is temporary and only valid for constant-density problems: + density could also be temperature dependent, but as it is not a part + of the solution vector it's neither stored for previous time steps + nor updated with the solution at the end of each iteration. */ + Density_nM1 = flowNodes->GetDensity(iPoint); + Density_n = flowNodes->GetDensity(iPoint); + Density_nP1 = flowNodes->GetDensity(iPoint); + } + else{ + Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; + Density_n = flowNodes->GetSolution_time_n(iPoint,0); + Density_nP1 = flowNodes->GetSolution(iPoint,0); + } + + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) + LinSysRes(iPoint,iVar) += ( Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*Volume_nP1 / TimeStep; + if (second_order) + LinSysRes(iPoint,iVar) += ( 3.0*Density_nP1*U_time_nP1[iVar] - 4.0*Density_n*U_time_n[iVar] + +1.0*Density_nM1*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); + } + + } else { + + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) + LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*Volume_nP1 / TimeStep; + if (second_order) + LinSysRes(iPoint,iVar) += ( 3.0*U_time_nP1[iVar] - 4.0*U_time_n[iVar] + +1.0*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); + } + } + + /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ + if (implicit) { + if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); + if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); + } + + } + END_SU2_OMP_FOR + + } else { + + /*--- For unsteady flows on dynamic meshes (rigidly transforming or + dynamically deforming), the Geometric Conservation Law (GCL) should be + satisfied in conjunction with the ALE formulation of the governing + equations. The GCL prevents accuracy issues caused by grid motion, i.e. + a uniform free-stream should be preserved through a moving grid. First, + we will loop over the edges and boundaries to compute the GCL component + of the dual time source term that depends on grid velocities. ---*/ + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (iPoint = 0; iPoint < nPointDomain; ++iPoint) { + + GridVel_i = geometry->nodes->GetGridVel(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); + Density_n = 1.0; + + if (sst_model) { + if (incompressible) + Density_n = flowNodes->GetDensity(iPoint); // Temporary fix + else + Density_n = flowNodes->GetSolution_time_n(iPoint,0); + } + + for (iNeigh = 0; iNeigh < geometry->nodes->GetnPoint(iPoint); iNeigh++) { + + iEdge = geometry->nodes->GetEdge(iPoint, iNeigh); + Normal = geometry->edges->GetNormal(iEdge); + + jPoint = geometry->nodes->GetPoint(iPoint, iNeigh); + GridVel_j = geometry->nodes->GetGridVel(jPoint); + + /*--- Determine whether to consider the normal outward or inward. ---*/ + su2double dir = (iPoint < jPoint)? 0.5 : -0.5; + + Residual_GCL = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + Residual_GCL += dir*(GridVel_i[iDim]+GridVel_j[iDim])*Normal[iDim]; + + Residual_GCL *= Density_n; + + for (iVar = 0; iVar < nVar; iVar++) + LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; + } + } + END_SU2_OMP_FOR + + /*--- Loop over the boundary edges ---*/ + + for (iMarker = 0; iMarker < geometry->GetnMarker(); iMarker++) { + if ((config->GetMarker_All_KindBC(iMarker) != INTERNAL_BOUNDARY) && + (config->GetMarker_All_KindBC(iMarker) != PERIODIC_BOUNDARY)) { + + SU2_OMP_FOR_STAT(OMP_MIN_SIZE) + for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) { + + /*--- Get the index for node i plus the boundary face normal ---*/ + + iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); + Normal = geometry->vertex[iMarker][iVertex]->GetNormal(); + + /*--- Grid velocities stored at boundary node i ---*/ + + GridVel_i = geometry->nodes->GetGridVel(iPoint); + + /*--- Compute the GCL term by dotting the grid velocity with the face + normal. The normal is negated to match the boundary convention. ---*/ + + Residual_GCL = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + Residual_GCL -= 0.5*(GridVel_i[iDim]+GridVel_i[iDim])*Normal[iDim]; + + /*--- Compute the GCL component of the source term for node i ---*/ + + U_time_n = nodes->GetSolution_time_n(iPoint); + + /*--- Multiply by density at node i for the SST model ---*/ + + if (sst_model) { + if (incompressible) + Density_n = flowNodes->GetDensity(iPoint); // Temporary fix + else + Density_n = flowNodes->GetSolution_time_n(iPoint,0); + + for (iVar = 0; iVar < nVar; iVar++) + LinSysRes(iPoint,iVar) += Density_n*U_time_n[iVar]*Residual_GCL; + } + else { + for (iVar = 0; iVar < nVar; iVar++) + LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; + } + + } + END_SU2_OMP_FOR + } + } + + /*--- Loop over all nodes (excluding halos) to compute the remainder + of the dual time-stepping source term. ---*/ + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (iPoint = 0; iPoint < nPointDomain; iPoint++) { + + /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that + we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, + previous solutions that are stored in memory. ---*/ + + U_time_nM1 = nodes->GetSolution_time_n1(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); + U_time_nP1 = nodes->GetSolution(iPoint); + + /*--- CV volume at time n-1 and n+1. In the case of dynamically deforming + grids, the volumes will change. On rigidly transforming grids, the + volumes will remain constant. ---*/ + + Volume_nM1 = geometry->nodes->GetVolume_nM1(iPoint); + Volume_nP1 = geometry->nodes->GetVolume(iPoint); + + /*--- Compute the dual time-stepping source residual. Due to the + introduction of the GCL term above, the remainder of the source residual + due to the time discretization has a new form.---*/ + + if (sst_model) { + + /*--- If this is the SST model, we need to multiply by the density + in order to get the conservative variables ---*/ + if (incompressible) { + /*--- This is temporary and only valid for constant-density problems: + density could also be temperature dependent, but as it is not a part + of the solution vector it's neither stored for previous time steps + nor updated with the solution at the end of each iteration. */ + Density_nM1 = flowNodes->GetDensity(iPoint); + Density_n = flowNodes->GetDensity(iPoint); + Density_nP1 = flowNodes->GetDensity(iPoint); + } + else { + Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; + Density_n = flowNodes->GetSolution_time_n(iPoint,0); + Density_nP1 = flowNodes->GetSolution(iPoint,0); + } + + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) + LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(Volume_nP1/TimeStep); + if (second_order) + LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) + + (Density_nM1*U_time_nM1[iVar] - Density_n*U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); + } + + } else { + + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) + LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(Volume_nP1/TimeStep); + if (second_order) + LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) + + (U_time_nM1[iVar] - U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); + } + } + + /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ + if (implicit) { + if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); + if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); + } + } + END_SU2_OMP_FOR + + } // end dynamic grid + +} + + +void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) { + + /*--- Restart the solution from file information ---*/ + + unsigned short iVar, iMesh; + unsigned long iPoint, index, iChildren, Point_Fine; + su2double Area_Children, Area_Parent; + const su2double *Solution_Fine = nullptr; + + string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter); + + /*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/ + SU2_OMP_MASTER + { + + /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ + + if (config->GetRead_Binary_Restart()) { + Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); + } else { + Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); + } + + /*--- Skip flow variables ---*/ + + unsigned short skipVars = 0; + + if (nDim == 2) skipVars += 6; + if (nDim == 3) skipVars += 8; + + /*--- Adjust the number of solution variables in the incompressible + restart. We always carry a space in nVar for the energy equation in the + mean flow solver, but we only write it to the restart if it is active. + Therefore, we must reduce skipVars here if energy is inactive so that + the turbulent variables are read correctly. ---*/ + + bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + bool energy = config->GetEnergy_Equation(); + bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); + + if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; + + /*--- Load data from the restart into correct containers. ---*/ + + unsigned long counter = 0, iPoint_Global = 0; + for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { + + + /*--- Retrieve local index. If this node from the restart file lives + on the current processor, we will load and instantiate the vars. ---*/ + + auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); + + if (iPoint_Local > -1) { + + /*--- We need to store this point's data, so jump to the correct + offset in the buffer of data from the restart file and load it. ---*/ + + index = counter*Restart_Vars[1] + skipVars; + for (iVar = 0; iVar < nVar; ++iVar) + nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]); + + /*--- Increment the overall counter for how many points have been loaded. ---*/ + counter++; + } + + } + + /*--- Detect a wrong solution file ---*/ + + if (counter != nPointDomain) { + SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + + string("It could be empty lines at the end of the file."), CURRENT_FUNCTION); + } + + } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. + END_SU2_OMP_MASTER + SU2_OMP_BARRIER + + /*--- MPI solution and compute the eddy viscosity ---*/ + + solver[MESH_0][TURB_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION); + solver[MESH_0][TURB_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION); + + solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, RUNTIME_FLOW_SYS, false); + solver[MESH_0][TURB_SOL]->Postprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0); + + /*--- Interpolate the solution down to the coarse multigrid levels ---*/ + + for (iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (iPoint = 0; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) { + Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint); + su2double Solution_Coarse[MAXNVAR] = {0.0}; + for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) { + Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren); + Area_Children = geometry[iMesh-1]->nodes->GetVolume(Point_Fine); + Solution_Fine = solver[iMesh-1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); + for (iVar = 0; iVar < nVar; iVar++) { + Solution_Coarse[iVar] += Solution_Fine[iVar]*Area_Children/Area_Parent; + } + } + solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint,Solution_Coarse); + } + END_SU2_OMP_FOR + + solver[iMesh][TURB_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION); + solver[iMesh][TURB_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION); + + solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, false); + solver[iMesh][TURB_SOL]->Postprocessing(geometry[iMesh], solver[iMesh], config, iMesh); + } + + /*--- Go back to single threaded execution. ---*/ + SU2_OMP_MASTER + { + /*--- Delete the class memory that is used to load the restart. ---*/ + + delete [] Restart_Vars; Restart_Vars = nullptr; + delete [] Restart_Data; Restart_Data = nullptr; + + } + END_SU2_OMP_MASTER + SU2_OMP_BARRIER + +} diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index 64ea6dcf5259..8685aa533e46 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -30,1117 +30,12 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CTurbSolver::CTurbSolver(void) : CSolver() { } +CTurbSolver::CTurbSolver(void) : CScalarSolver() { } -CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config) : CSolver() { +CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config) : CScalarSolver(geometry, config) { - Gamma = config->GetGamma(); - Gamma_Minus_One = Gamma - 1.0; - - nMarker = config->GetnMarker_All(); - - /*--- Store the number of vertices on each marker for deallocation later ---*/ - nVertex.resize(nMarker); - for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) - nVertex[iMarker] = geometry->nVertex[iMarker]; - - /* A grid is defined as dynamic if there's rigid grid movement or grid deformation AND the problem is time domain */ - dynamic_grid = config->GetDynamic_Grid(); - -#ifdef HAVE_OMP - /*--- Get the edge coloring, see notes in CEulerSolver's constructor. ---*/ - su2double parallelEff = 1.0; - const auto& coloring = geometry->GetEdgeColoring(¶llelEff); - - ReducerStrategy = parallelEff < COLORING_EFF_THRESH; - - if (ReducerStrategy && (coloring.getOuterSize()>1)) - geometry->SetNaturalEdgeColoring(); - - if (!coloring.empty()) { - auto groupSize = ReducerStrategy? 1ul : geometry->GetEdgeColorGroupSize(); - auto nColor = coloring.getOuterSize(); - EdgeColoring.reserve(nColor); - - for(auto iColor = 0ul; iColor < nColor; ++iColor) - EdgeColoring.emplace_back(coloring.innerIdx(iColor), coloring.getNumNonZeros(iColor), groupSize); - } - - nPoint = geometry->GetnPoint(); - omp_chunk_size = computeStaticChunkSize(nPoint, omp_get_max_threads(), OMP_MAX_SIZE); -#else - EdgeColoring[0] = DummyGridColor<>(geometry->GetnEdge()); -#endif } CTurbSolver::~CTurbSolver(void) { - for (auto& mat : SlidingState) { - for (auto ptr : mat) delete [] ptr; - } - - delete nodes; - -} - -void CTurbSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_container, - CNumerics **numerics_container, CConfig *config, unsigned short iMesh) { - - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - const bool muscl = config->GetMUSCL_Turb(); - const bool limiter = (config->GetKind_SlopeLimit_Turb() != NO_LIMITER); - - /*--- Only reconstruct flow variables if MUSCL is on for flow (requires upwind) and turbulence. ---*/ - const bool musclFlow = config->GetMUSCL_Flow() && muscl && - (config->GetKind_ConvNumScheme_Flow() == SPACE_UPWIND); - /*--- Only consider flow limiters for cell-based limiters, edge-based would need to be recomputed. ---*/ - const bool limiterFlow = (config->GetKind_SlopeLimit_Flow() != NO_LIMITER) && - (config->GetKind_SlopeLimit_Flow() != VAN_ALBADA_EDGE); - - CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); - - /*--- Pick one numerics object per thread. ---*/ - CNumerics* numerics = numerics_container[CONV_TERM + omp_get_thread_num()*MAX_TERMS]; - - /*--- Static arrays of MUSCL-reconstructed flow primitives and turbulence variables (thread safety). ---*/ - su2double solution_i[MAXNVAR] = {0.0}, flowPrimVar_i[MAXNVARFLOW] = {0.0}; - su2double solution_j[MAXNVAR] = {0.0}, flowPrimVar_j[MAXNVARFLOW] = {0.0}; - - /*--- Loop over edge colors. ---*/ - for (auto color : EdgeColoring) - { - /*--- Chunk size is at least OMP_MIN_SIZE and a multiple of the color group size. ---*/ - SU2_OMP_FOR_DYN(nextMultiple(OMP_MIN_SIZE, color.groupSize)) - for(auto k = 0ul; k < color.size; ++k) { - - auto iEdge = color.indices[k]; - - unsigned short iDim, iVar; - - /*--- Points in edge and normal vectors ---*/ - - auto iPoint = geometry->edges->GetNode(iEdge,0); - auto jPoint = geometry->edges->GetNode(iEdge,1); - - numerics->SetNormal(geometry->edges->GetNormal(iEdge)); - - /*--- Primitive variables w/o reconstruction ---*/ - - const auto V_i = flowNodes->GetPrimitive(iPoint); - const auto V_j = flowNodes->GetPrimitive(jPoint); - numerics->SetPrimitive(V_i, V_j); - - /*--- Turbulent variables w/o reconstruction ---*/ - - const auto Turb_i = nodes->GetSolution(iPoint); - const auto Turb_j = nodes->GetSolution(jPoint); - numerics->SetTurbVar(Turb_i, Turb_j); - - /*--- Grid Movement ---*/ - - if (dynamic_grid) - numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), - geometry->nodes->GetGridVel(jPoint)); - - if (muscl || musclFlow) { - const su2double *Limiter_i = nullptr, *Limiter_j = nullptr; - - const auto Coord_i = geometry->nodes->GetCoord(iPoint); - const auto Coord_j = geometry->nodes->GetCoord(jPoint); - - su2double Vector_ij[MAXNDIM] = {0.0}; - for (iDim = 0; iDim < nDim; iDim++) { - Vector_ij[iDim] = 0.5*(Coord_j[iDim] - Coord_i[iDim]); - } - - if (musclFlow) { - /*--- Reconstruct mean flow primitive variables. ---*/ - - auto Gradient_i = flowNodes->GetGradient_Reconstruction(iPoint); - auto Gradient_j = flowNodes->GetGradient_Reconstruction(jPoint); - - if (limiterFlow) { - Limiter_i = flowNodes->GetLimiter_Primitive(iPoint); - Limiter_j = flowNodes->GetLimiter_Primitive(jPoint); - } - - for (iVar = 0; iVar < solver_container[FLOW_SOL]->GetnPrimVarGrad(); iVar++) { - su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; - for (iDim = 0; iDim < nDim; iDim++) { - Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; - Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; - } - if (limiterFlow) { - Project_Grad_i *= Limiter_i[iVar]; - Project_Grad_j *= Limiter_j[iVar]; - } - flowPrimVar_i[iVar] = V_i[iVar] + Project_Grad_i; - flowPrimVar_j[iVar] = V_j[iVar] + Project_Grad_j; - } - - numerics->SetPrimitive(flowPrimVar_i, flowPrimVar_j); - } - - if (muscl) { - /*--- Reconstruct turbulence variables. ---*/ - - auto Gradient_i = nodes->GetGradient_Reconstruction(iPoint); - auto Gradient_j = nodes->GetGradient_Reconstruction(jPoint); - - if (limiter) { - Limiter_i = nodes->GetLimiter(iPoint); - Limiter_j = nodes->GetLimiter(jPoint); - } - - for (iVar = 0; iVar < nVar; iVar++) { - su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; - for (iDim = 0; iDim < nDim; iDim++) { - Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; - Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; - } - if (limiter) { - Project_Grad_i *= Limiter_i[iVar]; - Project_Grad_j *= Limiter_j[iVar]; - } - solution_i[iVar] = Turb_i[iVar] + Project_Grad_i; - solution_j[iVar] = Turb_j[iVar] + Project_Grad_j; - } - - numerics->SetTurbVar(solution_i, solution_j); - } - } - - /*--- Update convective residual value ---*/ - - auto residual = numerics->ComputeResidual(config); - - if (ReducerStrategy) { - EdgeFluxes.SetBlock(iEdge, residual); - if (implicit) Jacobian.SetBlocks(iEdge, residual.jacobian_i, residual.jacobian_j); - } - else { - LinSysRes.AddBlock(iPoint, residual); - LinSysRes.SubtractBlock(jPoint, residual); - if (implicit) Jacobian.UpdateBlocks(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); - } - - /*--- Viscous contribution. ---*/ - - Viscous_Residual(iEdge, geometry, solver_container, - numerics_container[VISC_TERM + omp_get_thread_num()*MAX_TERMS], config); - } - END_SU2_OMP_FOR - } // end color loop - - if (ReducerStrategy) { - SumEdgeFluxes(geometry); - if (implicit) Jacobian.SetDiagonalAsColumnSum(); - } -} - -void CTurbSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, CSolver **solver_container, - CNumerics *numerics, CConfig *config) { - - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); - - /*--- Points in edge ---*/ - - auto iPoint = geometry->edges->GetNode(iEdge,0); - auto jPoint = geometry->edges->GetNode(iEdge,1); - - /*--- Points coordinates, and normal vector ---*/ - - numerics->SetCoord(geometry->nodes->GetCoord(iPoint), - geometry->nodes->GetCoord(jPoint)); - numerics->SetNormal(geometry->edges->GetNormal(iEdge)); - - /*--- Conservative variables w/o reconstruction ---*/ - - numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), - flowNodes->GetPrimitive(jPoint)); - - /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - - numerics->SetTurbVar(nodes->GetSolution(iPoint), - nodes->GetSolution(jPoint)); - numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), - nodes->GetGradient(jPoint)); - - /*--- Menter's first blending function (only SST)---*/ - if ((config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST)) - numerics->SetF1blending(nodes->GetF1blending(iPoint), - nodes->GetF1blending(jPoint)); - - /*--- Roughness heights. ---*/ - if (config->GetKind_Turb_Model() == SA) - numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), - geometry->nodes->GetRoughnessHeight(jPoint)); - - /*--- Compute residual, and Jacobians ---*/ - - auto residual = numerics->ComputeResidual(config); - - if (ReducerStrategy) { - EdgeFluxes.SubtractBlock(iEdge, residual); - if (implicit) Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j); - } - else { - LinSysRes.SubtractBlock(iPoint, residual); - LinSysRes.AddBlock(jPoint, residual); - if (implicit) Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); - } -} - -void CTurbSolver::SumEdgeFluxes(CGeometry* geometry) { - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { - - LinSysRes.SetBlock_Zero(iPoint); - - for (auto iEdge : geometry->nodes->GetEdges(iPoint)) { - if (iPoint == geometry->edges->GetNode(iEdge,0)) - LinSysRes.AddBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); - else - LinSysRes.SubtractBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); - } - } - END_SU2_OMP_FOR - -} - -void CTurbSolver::BC_Sym_Plane(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) { - - /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ - -} - -void CTurbSolver::BC_Euler_Wall(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) { - - /*--- Convective fluxes across euler wall are equal to zero. ---*/ - -} - -void CTurbSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Riemann(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: - BC_Inlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case STATIC_PRESSURE: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - -void CTurbSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Riemann(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case STATIC_PRESSURE: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - - -void CTurbSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Giles(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT:case TOTAL_CONDITIONS_PT_1D: case DENSITY_VELOCITY: - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case MIXING_IN: - if (config->GetBoolTurbMixingPlane()){ - BC_Inlet_MixingPlane(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - } - else{ - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - } - break; - - case STATIC_PRESSURE: case MIXING_OUT: case STATIC_PRESSURE_1D: case RADIAL_EQUILIBRIUM: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - -void CTurbSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, - CNumerics *numerics, CConfig *config) { - - /*--- Complete residuals for periodic boundary conditions. We loop over - the periodic BCs in matching pairs so that, in the event that there are - adjacent periodic markers, the repeated points will have their residuals - accumulated corectly during the communications. For implicit calculations - the Jacobians and linear system are also correctly adjusted here. ---*/ - - for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { - InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); - CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); - } - -} - -void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, - CNumerics *visc_numerics, CConfig *config) { - - const bool sst = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); - const auto nPrimVar = solver_container[FLOW_SOL]->GetnPrimVar(); - su2double *PrimVar_j = new su2double[nPrimVar]; - su2double solution_j[MAXNVAR] = {0.0}; - - for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { - - if (config->GetMarker_All_KindBC(iMarker) != FLUID_INTERFACE) continue; - - SU2_OMP_FOR_STAT(OMP_MIN_SIZE) - for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) { - - const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); - - if (!geometry->nodes->GetDomain(iPoint)) continue; - - const auto Point_Normal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor(); - const auto nDonorVertex = GetnSlidingStates(iMarker,iVertex); - - su2double Normal[MAXNDIM] = {0.0}; - for (auto iDim = 0u; iDim < nDim; iDim++) - Normal[iDim] = -geometry->vertex[iMarker][iVertex]->GetNormal()[iDim]; - - su2double* PrimVar_i = solver_container[FLOW_SOL]->GetNodes()->GetPrimitive(iPoint); - - auto Jacobian_i = Jacobian.GetBlock(iPoint,iPoint); - - /*--- Loop over the nDonorVertexes and compute the averaged flux ---*/ - - for (auto jVertex = 0; jVertex < nDonorVertex; jVertex++) { - - for (auto iVar = 0u; iVar < nPrimVar; iVar++) - PrimVar_j[iVar] = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, iVar, jVertex); - - /*--- Get the weight computed in the interpolator class for the j-th donor vertex ---*/ - - const su2double weight = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, nPrimVar, jVertex); - - /*--- Set primitive variables ---*/ - - conv_numerics->SetPrimitive( PrimVar_i, PrimVar_j ); - - /*--- Set the turbulent variable states ---*/ - - for (auto iVar = 0u; iVar < nVar; ++iVar) - solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex); - - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - - /*--- Set the normal vector ---*/ - - conv_numerics->SetNormal(Normal); - - if (dynamic_grid) - conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(iPoint)); - - auto residual = conv_numerics->ComputeResidual(config); - - /*--- Accumulate the residuals to compute the average ---*/ - - for (auto iVar = 0u; iVar < nVar; iVar++) { - LinSysRes(iPoint,iVar) += weight*residual[iVar]; - for (auto jVar = 0u; jVar < nVar; jVar++) - Jacobian_i[iVar*nVar+jVar] += SU2_TYPE::GetValue(weight*residual.jacobian_i[iVar][jVar]); - } - } - - /*--- Set the normal vector and the coordinates ---*/ - - visc_numerics->SetNormal(Normal); - su2double Coord_Reflected[MAXNDIM]; - GeometryToolbox::PointPointReflect(nDim, geometry->nodes->GetCoord(Point_Normal), - geometry->nodes->GetCoord(iPoint), Coord_Reflected); - visc_numerics->SetCoord(geometry->nodes->GetCoord(iPoint), Coord_Reflected); - - /*--- Primitive variables ---*/ - - visc_numerics->SetPrimitive(PrimVar_i, PrimVar_j); - - /*--- Turbulent variables and their gradients ---*/ - - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); - - /*--- Menter's first blending function ---*/ - - if(sst) visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); - - /*--- Compute and update residual ---*/ - - auto residual = visc_numerics->ComputeResidual(config); - - LinSysRes.SubtractBlock(iPoint, residual); - - /*--- Jacobian contribution for implicit integration ---*/ - - Jacobian.SubtractBlock2Diag(iPoint, residual.jacobian_i); - - } - END_SU2_OMP_FOR - } - - delete [] PrimVar_j; - -} - -void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config){ - - /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ - if(config->GetTurb_Fixed_Values()){ - - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - - /*--- Form normalized far-field velocity ---*/ - const su2double* velocity_inf = config->GetVelocity_FreeStreamND(); - su2double velmag_inf = GeometryToolbox::Norm(nDim, velocity_inf); - if(velmag_inf==0) - SU2_MPI::Error("Far-field velocity is zero, cannot fix turbulence quantities to inflow values.", CURRENT_FUNCTION); - su2double unit_velocity_inf[MAXNDIM]; - for(unsigned short iDim=0; iDimnodes->GetCoord(iPoint), unit_velocity_inf) - < config->GetTurb_Fixed_Values_MaxScalarProd() ) { - /*--- Set the solution values and zero the residual ---*/ - nodes->SetSolution_Old(iPoint, Solution_Inf); - nodes->SetSolution(iPoint, Solution_Inf); - LinSysRes.SetBlock_Zero(iPoint); - if (implicit) { - /*--- Change rows of the Jacobian (includes 1 in the diagonal) ---*/ - for(unsigned long iVar=0; iVarGetNodes(); - - /*--- Set shared residual variables to 0 and declare - * local ones for current thread to work on. ---*/ - - SetResToZero(); - - su2double resMax[MAXNVAR] = {0.0}, resRMS[MAXNVAR] = {0.0}; - const su2double* coordMax[MAXNVAR] = {nullptr}; - unsigned long idxMax[MAXNVAR] = {0}; - - /*--- Build implicit system ---*/ - - SU2_OMP_FOR_(schedule(static,omp_chunk_size) SU2_NOWAIT) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - - /// TODO: This could be the SetTime_Step of this solver. - su2double dt = nodes->GetLocalCFL(iPoint) / flowNodes->GetLocalCFL(iPoint) * flowNodes->GetDelta_Time(iPoint); - nodes->SetDelta_Time(iPoint, dt); - - /*--- Modify matrix diagonal to improve diagonal dominance. ---*/ - - if (dt != 0.0) { - su2double Vol = geometry->nodes->GetVolume(iPoint) + geometry->nodes->GetPeriodicVolume(iPoint); - Jacobian.AddVal2Diag(iPoint, Vol / dt); - } - else { - Jacobian.SetVal2Diag(iPoint, 1.0); - LinSysRes.SetBlock_Zero(iPoint); - } - - /*--- Right hand side of the system (-Residual) and initial guess (x = 0) ---*/ - - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - unsigned long total_index = iPoint*nVar + iVar; - LinSysRes[total_index] = -LinSysRes[total_index]; - LinSysSol[total_index] = 0.0; - - su2double Res = fabs(LinSysRes[total_index]); - resRMS[iVar] += Res*Res; - if (Res > resMax[iVar]) { - resMax[iVar] = Res; - idxMax[iVar] = iPoint; - coordMax[iVar] = geometry->nodes->GetCoord(iPoint); - } - } - } - END_SU2_OMP_FOR - SU2_OMP_CRITICAL - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - Residual_RMS[iVar] += resRMS[iVar]; - AddRes_Max(iVar, resMax[iVar], geometry->nodes->GetGlobalIndex(idxMax[iVar]), coordMax[iVar]); - } - END_SU2_OMP_CRITICAL - SU2_OMP_BARRIER - - /*--- Compute the root mean square residual ---*/ - SetResidual_RMS(geometry, config); -} - -void CTurbSolver::CompleteImplicitIteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { - - const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); - - const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); - - ComputeUnderRelaxationFactor(config); - - /*--- Update solution (system written in terms of increments) ---*/ - - if (!adjoint) { - - /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ - - switch (config->GetKind_Turb_Model()) { - - case SA: case SA_E: case SA_COMP: case SA_E_COMP: case SA_NEG: - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - nodes->AddSolution(iPoint, 0, nodes->GetUnderRelaxation(iPoint)*LinSysSol[iPoint]); - } - END_SU2_OMP_FOR - break; - - case SST: case SST_SUST: - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - - su2double density = flowNodes->GetDensity(iPoint); - su2double density_old = density; - - if (compressible) - density_old = flowNodes->GetSolution_Old(iPoint,0); - - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - nodes->AddConservativeSolution(iPoint, iVar, - nodes->GetUnderRelaxation(iPoint)*LinSysSol(iPoint,iVar), - density, density_old, lowerlimit[iVar], upperlimit[iVar]); - } - } - END_SU2_OMP_FOR - break; - - } - } - - for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { - InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); - CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); - } - - InitiateComms(geometry, config, SOLUTION_EDDY); - CompleteComms(geometry, config, SOLUTION_EDDY); - -} - -void CTurbSolver::ImplicitEuler_Iteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { - - PrepareImplicitIteration(geometry, solver_container, config); - - /*--- Solve or smooth the linear system. ---*/ - - SU2_OMP_FOR_(schedule(static,OMP_MIN_SIZE) SU2_NOWAIT) - for (unsigned long iPoint = nPointDomain; iPoint < nPoint; iPoint++) { - LinSysRes.SetBlock_Zero(iPoint); - LinSysSol.SetBlock_Zero(iPoint); - } - END_SU2_OMP_FOR - - auto iter = System.Solve(Jacobian, LinSysRes, LinSysSol, geometry, config); - - SU2_OMP_MASTER { - SetIterLinSolver(iter); - SetResLinSolver(System.GetResidual()); - } - END_SU2_OMP_MASTER - SU2_OMP_BARRIER - - CompleteImplicitIteration(geometry, solver_container, config); - -} - -void CTurbSolver::ComputeUnderRelaxationFactor(const CConfig *config) { - - /* Only apply the turbulent under-relaxation to the SA variants. The - SA_NEG model is more robust due to allowing for negative nu_tilde, - so the under-relaxation is not applied to that variant. */ - - bool sa_model = ((config->GetKind_Turb_Model() == SA) || - (config->GetKind_Turb_Model() == SA_E) || - (config->GetKind_Turb_Model() == SA_COMP) || - (config->GetKind_Turb_Model() == SA_E_COMP)); - - /* Loop over the solution update given by relaxing the linear - system for this nonlinear iteration. */ - - su2double localUnderRelaxation = 1.00; - const su2double allowableRatio = 0.99; - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - - localUnderRelaxation = 1.0; - if (sa_model) { - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - - /* We impose a limit on the maximum percentage that the - turbulence variables can change over a nonlinear iteration. */ - - const unsigned long index = iPoint * nVar + iVar; - su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); - if (ratio > allowableRatio) { - localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); - } - - } - } - - /* Threshold the relaxation factor in the event that there is - a very small value. This helps avoid catastrophic crashes due - to non-realizable states by canceling the update. */ - - if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0; - - /* Store the under-relaxation factor for this point. */ - - nodes->SetUnderRelaxation(iPoint, localUnderRelaxation); - - } - END_SU2_OMP_FOR - -} - -void CTurbSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_container, CConfig *config, - unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { - - const bool sst_model = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST); - const bool second_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND); - const bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - - /*--- Flow solution, needed to get density. ---*/ - - CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); - - /*--- Store the physical time step ---*/ - - const su2double TimeStep = config->GetDelta_UnstTimeND(); - - /*--- Local variables ---*/ - - unsigned short iVar, iMarker, iDim, iNeigh; - unsigned long iPoint, jPoint, iVertex, iEdge; - - const su2double *U_time_nM1 = nullptr, *U_time_n = nullptr, *U_time_nP1 = nullptr; - su2double Volume_nM1, Volume_nP1; - su2double Density_nM1, Density_n, Density_nP1; - const su2double *Normal = nullptr, *GridVel_i = nullptr, *GridVel_j = nullptr; - su2double Residual_GCL; - - /*--- Compute the dual time-stepping source term for static meshes ---*/ - - if (!dynamic_grid) { - - /*--- Loop over all nodes (excluding halos) ---*/ - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (iPoint = 0; iPoint < nPointDomain; iPoint++) { - - /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that - we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, - previous solutions that are stored in memory. ---*/ - - U_time_nM1 = nodes->GetSolution_time_n1(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); - U_time_nP1 = nodes->GetSolution(iPoint); - - /*--- CV volume at time n+1. As we are on a static mesh, the volume - of the CV will remained fixed for all time steps. ---*/ - - Volume_nP1 = geometry->nodes->GetVolume(iPoint); - - /*--- Compute the dual time-stepping source term based on the chosen - time discretization scheme (1st- or 2nd-order).---*/ - - if (sst_model) { - - /*--- If this is the SST model, we need to multiply by the density - in order to get the conservative variables ---*/ - if (incompressible){ - /*--- This is temporary and only valid for constant-density problems: - density could also be temperature dependent, but as it is not a part - of the solution vector it's neither stored for previous time steps - nor updated with the solution at the end of each iteration. */ - Density_nM1 = flowNodes->GetDensity(iPoint); - Density_n = flowNodes->GetDensity(iPoint); - Density_nP1 = flowNodes->GetDensity(iPoint); - } - else{ - Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - Density_nP1 = flowNodes->GetSolution(iPoint,0); - } - - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += ( Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*Volume_nP1 / TimeStep; - if (second_order) - LinSysRes(iPoint,iVar) += ( 3.0*Density_nP1*U_time_nP1[iVar] - 4.0*Density_n*U_time_n[iVar] - +1.0*Density_nM1*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); - } - - } else { - - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*Volume_nP1 / TimeStep; - if (second_order) - LinSysRes(iPoint,iVar) += ( 3.0*U_time_nP1[iVar] - 4.0*U_time_n[iVar] - +1.0*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); - } - } - - /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ - if (implicit) { - if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); - if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); - } - - } - END_SU2_OMP_FOR - - } else { - - /*--- For unsteady flows on dynamic meshes (rigidly transforming or - dynamically deforming), the Geometric Conservation Law (GCL) should be - satisfied in conjunction with the ALE formulation of the governing - equations. The GCL prevents accuracy issues caused by grid motion, i.e. - a uniform free-stream should be preserved through a moving grid. First, - we will loop over the edges and boundaries to compute the GCL component - of the dual time source term that depends on grid velocities. ---*/ - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (iPoint = 0; iPoint < nPointDomain; ++iPoint) { - - GridVel_i = geometry->nodes->GetGridVel(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); - Density_n = 1.0; - - if (sst_model) { - if (incompressible) - Density_n = flowNodes->GetDensity(iPoint); // Temporary fix - else - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - } - - for (iNeigh = 0; iNeigh < geometry->nodes->GetnPoint(iPoint); iNeigh++) { - - iEdge = geometry->nodes->GetEdge(iPoint, iNeigh); - Normal = geometry->edges->GetNormal(iEdge); - - jPoint = geometry->nodes->GetPoint(iPoint, iNeigh); - GridVel_j = geometry->nodes->GetGridVel(jPoint); - - /*--- Determine whether to consider the normal outward or inward. ---*/ - su2double dir = (iPoint < jPoint)? 0.5 : -0.5; - - Residual_GCL = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - Residual_GCL += dir*(GridVel_i[iDim]+GridVel_j[iDim])*Normal[iDim]; - - Residual_GCL *= Density_n; - - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; - } - } - END_SU2_OMP_FOR - - /*--- Loop over the boundary edges ---*/ - - for (iMarker = 0; iMarker < geometry->GetnMarker(); iMarker++) { - if ((config->GetMarker_All_KindBC(iMarker) != INTERNAL_BOUNDARY) && - (config->GetMarker_All_KindBC(iMarker) != PERIODIC_BOUNDARY)) { - - SU2_OMP_FOR_STAT(OMP_MIN_SIZE) - for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) { - - /*--- Get the index for node i plus the boundary face normal ---*/ - - iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); - Normal = geometry->vertex[iMarker][iVertex]->GetNormal(); - - /*--- Grid velocities stored at boundary node i ---*/ - - GridVel_i = geometry->nodes->GetGridVel(iPoint); - - /*--- Compute the GCL term by dotting the grid velocity with the face - normal. The normal is negated to match the boundary convention. ---*/ - - Residual_GCL = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - Residual_GCL -= 0.5*(GridVel_i[iDim]+GridVel_i[iDim])*Normal[iDim]; - - /*--- Compute the GCL component of the source term for node i ---*/ - - U_time_n = nodes->GetSolution_time_n(iPoint); - - /*--- Multiply by density at node i for the SST model ---*/ - - if (sst_model) { - if (incompressible) - Density_n = flowNodes->GetDensity(iPoint); // Temporary fix - else - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += Density_n*U_time_n[iVar]*Residual_GCL; - } - else { - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; - } - - } - END_SU2_OMP_FOR - } - } - - /*--- Loop over all nodes (excluding halos) to compute the remainder - of the dual time-stepping source term. ---*/ - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (iPoint = 0; iPoint < nPointDomain; iPoint++) { - - /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that - we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, - previous solutions that are stored in memory. ---*/ - - U_time_nM1 = nodes->GetSolution_time_n1(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); - U_time_nP1 = nodes->GetSolution(iPoint); - - /*--- CV volume at time n-1 and n+1. In the case of dynamically deforming - grids, the volumes will change. On rigidly transforming grids, the - volumes will remain constant. ---*/ - - Volume_nM1 = geometry->nodes->GetVolume_nM1(iPoint); - Volume_nP1 = geometry->nodes->GetVolume(iPoint); - - /*--- Compute the dual time-stepping source residual. Due to the - introduction of the GCL term above, the remainder of the source residual - due to the time discretization has a new form.---*/ - - if (sst_model) { - - /*--- If this is the SST model, we need to multiply by the density - in order to get the conservative variables ---*/ - if (incompressible) { - /*--- This is temporary and only valid for constant-density problems: - density could also be temperature dependent, but as it is not a part - of the solution vector it's neither stored for previous time steps - nor updated with the solution at the end of each iteration. */ - Density_nM1 = flowNodes->GetDensity(iPoint); - Density_n = flowNodes->GetDensity(iPoint); - Density_nP1 = flowNodes->GetDensity(iPoint); - } - else { - Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - Density_nP1 = flowNodes->GetSolution(iPoint,0); - } - - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(Volume_nP1/TimeStep); - if (second_order) - LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) - + (Density_nM1*U_time_nM1[iVar] - Density_n*U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); - } - - } else { - - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(Volume_nP1/TimeStep); - if (second_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) - + (U_time_nM1[iVar] - U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); - } - } - - /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ - if (implicit) { - if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); - if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); - } - } - END_SU2_OMP_FOR - - } // end dynamic grid - -} - - -void CTurbSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) { - - /*--- Restart the solution from file information ---*/ - - unsigned short iVar, iMesh; - unsigned long iPoint, index, iChildren, Point_Fine; - su2double Area_Children, Area_Parent; - const su2double *Solution_Fine = nullptr; - - string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter); - - /*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/ - SU2_OMP_MASTER - { - - /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ - - if (config->GetRead_Binary_Restart()) { - Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); - } else { - Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); - } - - /*--- Skip flow variables ---*/ - - unsigned short skipVars = 0; - - if (nDim == 2) skipVars += 6; - if (nDim == 3) skipVars += 8; - - /*--- Adjust the number of solution variables in the incompressible - restart. We always carry a space in nVar for the energy equation in the - mean flow solver, but we only write it to the restart if it is active. - Therefore, we must reduce skipVars here if energy is inactive so that - the turbulent variables are read correctly. ---*/ - - bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - bool energy = config->GetEnergy_Equation(); - bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); - - if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; - - /*--- Load data from the restart into correct containers. ---*/ - - unsigned long counter = 0, iPoint_Global = 0; - for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { - - - /*--- Retrieve local index. If this node from the restart file lives - on the current processor, we will load and instantiate the vars. ---*/ - - auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); - - if (iPoint_Local > -1) { - - /*--- We need to store this point's data, so jump to the correct - offset in the buffer of data from the restart file and load it. ---*/ - - index = counter*Restart_Vars[1] + skipVars; - for (iVar = 0; iVar < nVar; ++iVar) - nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]); - - /*--- Increment the overall counter for how many points have been loaded. ---*/ - counter++; - } - - } - - /*--- Detect a wrong solution file ---*/ - - if (counter != nPointDomain) { - SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + - string("It could be empty lines at the end of the file."), CURRENT_FUNCTION); - } - - } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. - END_SU2_OMP_MASTER - SU2_OMP_BARRIER - - /*--- MPI solution and compute the eddy viscosity ---*/ - - solver[MESH_0][TURB_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION); - solver[MESH_0][TURB_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION); - - solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, RUNTIME_FLOW_SYS, false); - solver[MESH_0][TURB_SOL]->Postprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0); - - /*--- Interpolate the solution down to the coarse multigrid levels ---*/ - - for (iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) { - SU2_OMP_FOR_STAT(omp_chunk_size) - for (iPoint = 0; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) { - Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint); - su2double Solution_Coarse[MAXNVAR] = {0.0}; - for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) { - Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren); - Area_Children = geometry[iMesh-1]->nodes->GetVolume(Point_Fine); - Solution_Fine = solver[iMesh-1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); - for (iVar = 0; iVar < nVar; iVar++) { - Solution_Coarse[iVar] += Solution_Fine[iVar]*Area_Children/Area_Parent; - } - } - solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint,Solution_Coarse); - } - END_SU2_OMP_FOR - - solver[iMesh][TURB_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION); - solver[iMesh][TURB_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION); - - solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, false); - solver[iMesh][TURB_SOL]->Postprocessing(geometry[iMesh], solver[iMesh], config, iMesh); - } - - /*--- Go back to single threaded execution. ---*/ - SU2_OMP_MASTER - { - /*--- Delete the class memory that is used to load the restart. ---*/ - - delete [] Restart_Vars; Restart_Vars = nullptr; - delete [] Restart_Data; Restart_Data = nullptr; - - } - END_SU2_OMP_MASTER - SU2_OMP_BARRIER - } diff --git a/SU2_CFD/src/variables/CScalarVariable.cpp b/SU2_CFD/src/variables/CScalarVariable.cpp new file mode 100644 index 000000000000..b4087252d24e --- /dev/null +++ b/SU2_CFD/src/variables/CScalarVariable.cpp @@ -0,0 +1,66 @@ +/*! + * \file CScalarVariable.cpp + * \brief Definition of the solution fields. + * \author F. Palacios, A. Bueno + * \version 7.1.1 "Blackbird" + * + * SU2 Project Website: https://su2code.github.io + * + * The SU2 Project is maintained by the SU2 Foundation + * (http://su2foundation.org) + * + * Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md) + * + * SU2 is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * SU2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SU2. If not, see . + */ + + +#include "../../include/variables/CScalarVariable.hpp" + + +CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) + : CVariable(npoint, ndim, nvar, config), Gradient_Reconstruction(config->GetReconstructionGradientRequired() ? Gradient_Aux : Gradient) { + + /*--- Allocate space for the harmonic balance source terms ---*/ + + if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { + HB_Source.resize(nPoint,nVar) = su2double(0.0); + } + + /*--- Gradient related fields ---*/ + + Gradient.resize(nPoint,nVar,nDim,0.0); + + if (config->GetReconstructionGradientRequired()) { + Gradient_Aux.resize(nPoint,nVar,nDim,0.0); + } + + if (config->GetLeastSquaresRequired()) { + Rmatrix.resize(nPoint,nDim,nDim,0.0); + } + + /*--- Always allocate the slope limiter, and the auxiliar + variables (check the logic - JST with 2nd order Turb model) ---*/ + + Limiter.resize(nPoint,nVar) = su2double(0.0); + Solution_Max.resize(nPoint,nVar) = su2double(0.0); + Solution_Min.resize(nPoint,nVar) = su2double(0.0); + + Delta_Time.resize(nPoint) = su2double(0.0); + + /* Under-relaxation parameter. */ + UnderRelaxation.resize(nPoint) = su2double(1.0); + LocalCFL.resize(nPoint) = su2double(0.0); + +} diff --git a/SU2_CFD/src/variables/CTurbVariable.cpp b/SU2_CFD/src/variables/CTurbVariable.cpp index f01c4f130115..1bccc612547e 100644 --- a/SU2_CFD/src/variables/CTurbVariable.cpp +++ b/SU2_CFD/src/variables/CTurbVariable.cpp @@ -30,37 +30,6 @@ CTurbVariable::CTurbVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) - : CVariable(npoint, ndim, nvar, config), Gradient_Reconstruction(config->GetReconstructionGradientRequired() ? Gradient_Aux : Gradient) { - - /*--- Allocate space for the harmonic balance source terms ---*/ - - if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { - HB_Source.resize(nPoint,nVar) = su2double(0.0); - } - - /*--- Gradient related fields ---*/ - - Gradient.resize(nPoint,nVar,nDim,0.0); - - if (config->GetReconstructionGradientRequired()) { - Gradient_Aux.resize(nPoint,nVar,nDim,0.0); - } - - if (config->GetLeastSquaresRequired()) { - Rmatrix.resize(nPoint,nDim,nDim,0.0); - } - - /*--- Always allocate the slope limiter, and the auxiliar - variables (check the logic - JST with 2nd order Turb model) ---*/ - - Limiter.resize(nPoint,nVar) = su2double(0.0); - Solution_Max.resize(nPoint,nVar) = su2double(0.0); - Solution_Min.resize(nPoint,nVar) = su2double(0.0); - - Delta_Time.resize(nPoint) = su2double(0.0); - - /* Under-relaxation parameter. */ - UnderRelaxation.resize(nPoint) = su2double(1.0); - LocalCFL.resize(nPoint) = su2double(0.0); + : CScalarVariable(npoint, ndim, nvar, config) { } From 7342a328779fc92e222a4e646fe3c4cbeb66ba12 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 21 Jul 2021 17:21:22 +0200 Subject: [PATCH 02/48] opy turb testcases to front for faster local testing. Will be reverted --- TestCases/parallel_regression.py | 182 ++++++++++++++++++++++++++++ TestCases/serial_regression.py | 196 +++++++++++++++++++++++++++++++ 2 files changed, 378 insertions(+) diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index db98e43c0d25..f469af5276ff 100644 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -38,6 +38,188 @@ def main(): test_list = [] + ############################ + ### Incompressible RANS ### + ############################ + + # NACA0012 + inc_turb_naca0012 = TestCase('inc_turb_naca0012') + inc_turb_naca0012.cfg_dir = "incomp_rans/naca0012" + inc_turb_naca0012.cfg_file = "naca0012.cfg" + inc_turb_naca0012.test_iter = 20 + inc_turb_naca0012.test_vals = [-4.788595, -11.040557, -0.000002, 0.309519] + inc_turb_naca0012.su2_exec = "parallel_computation.py -f" + inc_turb_naca0012.timeout = 1600 + inc_turb_naca0012.tol = 0.00001 + test_list.append(inc_turb_naca0012) + + # NACA0012, SST_SUST + inc_turb_naca0012_sst_sust = TestCase('inc_turb_naca0012_sst_sust') + inc_turb_naca0012_sst_sust.cfg_dir = "incomp_rans/naca0012" + inc_turb_naca0012_sst_sust.cfg_file = "naca0012_SST_SUST.cfg" + inc_turb_naca0012_sst_sust.test_iter = 20 + inc_turb_naca0012_sst_sust.test_vals = [-7.276430, 0.145859, -0.000001, 0.312020] + inc_turb_naca0012_sst_sust.su2_exec = "parallel_computation.py -f" + inc_turb_naca0012_sst_sust.timeout = 1600 + inc_turb_naca0012_sst_sust.tol = 0.00001 + test_list.append(inc_turb_naca0012_sst_sust) + + ########################## + ### Compressible RANS ### + ########################## + + # RAE2822 SA + rae2822_sa = TestCase('rae2822_sa') + rae2822_sa.cfg_dir = "rans/rae2822" + rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" + rae2822_sa.test_iter = 20 + rae2822_sa.test_vals = [-2.004689, -5.265793, 0.809463, 0.062016] + rae2822_sa.su2_exec = "parallel_computation.py -f" + rae2822_sa.timeout = 1600 + rae2822_sa.tol = 0.00001 + test_list.append(rae2822_sa) + + # RAE2822 SST + rae2822_sst = TestCase('rae2822_sst') + rae2822_sst.cfg_dir = "rans/rae2822" + rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" + rae2822_sst.test_iter = 20 + rae2822_sst.test_vals = [-0.510641, 4.870022, 0.813722, 0.062439] + rae2822_sst.su2_exec = "parallel_computation.py -f" + rae2822_sst.timeout = 1600 + rae2822_sst.tol = 0.00001 + test_list.append(rae2822_sst) + + # RAE2822 SST_SUST + rae2822_sst_sust = TestCase('rae2822_sst_sust') + rae2822_sst_sust.cfg_dir = "rans/rae2822" + rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" + rae2822_sst_sust.test_iter = 20 + rae2822_sst_sust.test_vals = [-2.435890, 4.870022, 0.813722, 0.062439] + rae2822_sst_sust.su2_exec = "parallel_computation.py -f" + rae2822_sst_sust.timeout = 1600 + rae2822_sst_sust.tol = 0.00001 + test_list.append(rae2822_sst_sust) + + # Flat plate + turb_flatplate = TestCase('turb_flatplate') + turb_flatplate.cfg_dir = "rans/flatplate" + turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" + turb_flatplate.test_iter = 20 + turb_flatplate.test_vals = [-4.147548, -6.729213, -0.176227, 0.057731] + turb_flatplate.su2_exec = "parallel_computation.py -f" + turb_flatplate.timeout = 1600 + turb_flatplate.tol = 0.00001 + test_list.append(turb_flatplate) + + # ONERA M6 Wing + turb_oneram6 = TestCase('turb_oneram6') + turb_oneram6.cfg_dir = "rans/oneram6" + turb_oneram6.cfg_file = "turb_ONERAM6.cfg" + turb_oneram6.test_iter = 10 + turb_oneram6.test_vals = [-2.388839, -6.689413, 0.230321, 0.157640] #last 4 columns + turb_oneram6.su2_exec = "parallel_computation.py -f" + turb_oneram6.timeout = 3200 + turb_oneram6.tol = 0.00001 + test_list.append(turb_oneram6) + + # ONERA M6 Wing - Newton-Krylov + turb_oneram6_nk = TestCase('turb_oneram6_nk') + turb_oneram6_nk.cfg_dir = "rans/oneram6" + turb_oneram6_nk.cfg_file = "turb_ONERAM6_nk.cfg" + turb_oneram6_nk.test_iter = 20 + turb_oneram6_nk.test_vals = [-4.892257, -4.514011, -11.432312, 0.221025, 0.045570, 2, -0.899459, 3.1384e+01] + turb_oneram6_nk.su2_exec = "mpirun -n 2 SU2_CFD" + turb_oneram6_nk.timeout = 600 + turb_oneram6_nk.tol = 0.0001 + test_list.append(turb_oneram6_nk) + + # NACA0012 (SA, FUN3D finest grid results: CL=1.0983, CD=0.01242) + turb_naca0012_sa = TestCase('turb_naca0012_sa') + turb_naca0012_sa.cfg_dir = "rans/naca0012" + turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" + turb_naca0012_sa.test_iter = 10 + turb_naca0012_sa.test_vals = [-11.147929, -14.466781, 1.064330, 0.019756] + turb_naca0012_sa.su2_exec = "parallel_computation.py -f" + turb_naca0012_sa.timeout = 3200 + turb_naca0012_sa.tol = 0.00001 + test_list.append(turb_naca0012_sa) + + # NACA0012 (SST, FUN3D finest grid results: CL=1.0840, CD=0.01253) + turb_naca0012_sst = TestCase('turb_naca0012_sst') + turb_naca0012_sst.cfg_dir = "rans/naca0012" + turb_naca0012_sst.cfg_file = "turb_NACA0012_sst.cfg" + turb_naca0012_sst.test_iter = 10 + turb_naca0012_sst.test_vals = [-11.456387, -12.800055, -5.865784, 1.049989, 0.019163, -1.838252] + turb_naca0012_sst.su2_exec = "parallel_computation.py -f" + turb_naca0012_sst.timeout = 3200 + turb_naca0012_sst.tol = 0.00001 + test_list.append(turb_naca0012_sst) + + # NACA0012 (SST_SUST, FUN3D finest grid results: CL=1.0840, CD=0.01253) + turb_naca0012_sst_sust = TestCase('turb_naca0012_sst_sust') + turb_naca0012_sst_sust.cfg_dir = "rans/naca0012" + turb_naca0012_sst_sust.cfg_file = "turb_NACA0012_sst_sust.cfg" + turb_naca0012_sst_sust.test_iter = 10 + turb_naca0012_sst_sust.test_vals = [-11.370785, -12.641676, -5.748419, 1.005233, 0.019017, -2.057144] + turb_naca0012_sst_sust.su2_exec = "parallel_computation.py -f" + turb_naca0012_sst_sust.timeout = 3200 + turb_naca0012_sst_sust.tol = 0.00001 + test_list.append(turb_naca0012_sst_sust) + + # NACA0012 (SST, fixed values for turbulence quantities) + turb_naca0012_sst_fixedvalues = TestCase('turb_naca0012_sst_fixedvalues') + turb_naca0012_sst_fixedvalues.cfg_dir = "rans/naca0012" + turb_naca0012_sst_fixedvalues.cfg_file = "turb_NACA0012_sst_fixedvalues.cfg" + turb_naca0012_sst_fixedvalues.test_iter = 10 + turb_naca0012_sst_fixedvalues.test_vals = [ -5.216685, -9.562448, -1.565778, 1.022393, 0.040542, -3.729648] + turb_naca0012_sst_fixedvalues.su2_exec = "parallel_computation.py -f" + turb_naca0012_sst_fixedvalues.timeout = 3200 + turb_naca0012_sst_fixedvalues.tol = 0.00001 + test_list.append(turb_naca0012_sst_fixedvalues) + + # PROPELLER + propeller = TestCase('propeller') + propeller.cfg_dir = "rans/propeller" + propeller.cfg_file = "propeller.cfg" + propeller.test_iter = 10 + propeller.test_vals = [-3.389575, -8.409529, 0.000048, 0.056329] #last 4 columns + propeller.su2_exec = "parallel_computation.py -f" + propeller.timeout = 3200 + propeller.tol = 0.00001 + test_list.append(propeller) + + ####################################### + ### Axisymmetric Compressible RANS ### + ####################################### + + # Axisymmetric air nozzle (transonic) + axi_rans_air_nozzle = TestCase('axi_rans_air_nozzle') + axi_rans_air_nozzle.cfg_dir = "axisymmetric_rans/air_nozzle" + axi_rans_air_nozzle.cfg_file = "air_nozzle.cfg" + axi_rans_air_nozzle.test_iter = 10 + axi_rans_air_nozzle.test_vals = [-6.278454, -0.744813, -2.243285, 2.312481] + axi_rans_air_nozzle.su2_exec = "mpirun -n 2 SU2_CFD" + axi_rans_air_nozzle.timeout = 1600 + axi_rans_air_nozzle.tol = 0.0001 + test_list.append(axi_rans_air_nozzle) + + ################################# + ## Compressible RANS Restart ### + ################################# + + # NACA0012 SST Multigrid restart + turb_naca0012_sst_restart_mg = TestCase('turb_naca0012_sst_restart_mg') + turb_naca0012_sst_restart_mg.cfg_dir = "rans/naca0012" + turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" + turb_naca0012_sst_restart_mg.test_iter = 20 + turb_naca0012_sst_restart_mg.ntest_vals = 5 + turb_naca0012_sst_restart_mg.test_vals = [-7.619889, -7.729499, -1.981039, -0.000016, 0.079062] + turb_naca0012_sst_restart_mg.su2_exec = "parallel_computation.py -f" + turb_naca0012_sst_restart_mg.timeout = 3200 + turb_naca0012_sst_restart_mg.tol = 0.000001 + test_list.append(turb_naca0012_sst_restart_mg) + ######################### ## NEMO solver ### ######################### diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index 807f81f9f793..32386f127707 100644 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -36,6 +36,202 @@ def main(): test_list = [] + ############################ + ### Incompressible RANS ### + ############################ + + # Dry run Inc. RANS + inc_turb_naca0012_d = TestCase('dry run Inc. RANS') + inc_turb_naca0012_d.cfg_dir = "incomp_rans/naca0012" + inc_turb_naca0012_d.cfg_file = "naca0012.cfg" + inc_turb_naca0012_d.su2_exec = "SU2_CFD -d" + inc_turb_naca0012_d.timeout = 1600 + test_list.append(inc_turb_naca0012_d) + + # NACA0012, SA + inc_turb_naca0012 = TestCase('inc_turb_naca0012') + inc_turb_naca0012.cfg_dir = "incomp_rans/naca0012" + inc_turb_naca0012.cfg_file = "naca0012.cfg" + inc_turb_naca0012.test_iter = 20 + inc_turb_naca0012.test_vals = [-4.788495, -11.040511, 0.000023, 0.309503] #last 4 columns + inc_turb_naca0012.new_output = True + inc_turb_naca0012.su2_exec = "SU2_CFD" + inc_turb_naca0012.timeout = 1600 + inc_turb_naca0012.tol = 0.00001 + test_list.append(inc_turb_naca0012) + + # NACA0012, SST_SUST + inc_turb_naca0012_sst_sust = TestCase('inc_turb_naca0012_sst_sust') + inc_turb_naca0012_sst_sust.cfg_dir = "incomp_rans/naca0012" + inc_turb_naca0012_sst_sust.cfg_file = "naca0012_SST_SUST.cfg" + inc_turb_naca0012_sst_sust.test_iter = 20 + inc_turb_naca0012_sst_sust.test_vals = [-7.276273, 0.145895, 0.000021, 0.312004] #last 4 columns + inc_turb_naca0012_sst_sust.su2_exec = "SU2_CFD" + inc_turb_naca0012_sst_sust.timeout = 1600 + inc_turb_naca0012_sst_sust.tol = 0.00001 + test_list.append(inc_turb_naca0012_sst_sust) + + ########################## + ### Compressible RANS ### + ########################## + + # Dry run RANS + rae2822_sa_d = TestCase('dry run RANS') + rae2822_sa_d .cfg_dir = "rans/rae2822" + rae2822_sa_d .cfg_file = "turb_SA_RAE2822.cfg" + rae2822_sa_d .su2_exec = "SU2_CFD -d" + rae2822_sa_d .timeout = 1600 + test_list.append(rae2822_sa_d) + + # RAE2822 SA + rae2822_sa = TestCase('rae2822_sa') + rae2822_sa.cfg_dir = "rans/rae2822" + rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" + rae2822_sa.test_iter = 20 + rae2822_sa.test_vals = [-2.020123, -5.269330, 0.807147, 0.060499] + rae2822_sa.su2_exec = "SU2_CFD" + rae2822_sa.timeout = 1600 + rae2822_sa.new_output = True + rae2822_sa.tol = 0.00001 + test_list.append(rae2822_sa) + + # RAE2822 SST + rae2822_sst = TestCase('rae2822_sst') + rae2822_sst.cfg_dir = "rans/rae2822" + rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" + rae2822_sst.test_iter = 20 + rae2822_sst.test_vals = [-0.510639, 4.872266, 0.812659, 0.061095] + rae2822_sst.su2_exec = "SU2_CFD" + rae2822_sst.new_output = True + rae2822_sst.timeout = 1600 + rae2822_sst.tol = 0.00001 + test_list.append(rae2822_sst) + + # RAE2822 SST_SUST + rae2822_sst_sust = TestCase('rae2822_sst_sust') + rae2822_sst_sust.cfg_dir = "rans/rae2822" + rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" + rae2822_sst_sust.test_iter = 20 + rae2822_sst_sust.test_vals = [-2.431741, 4.872266, 0.812658, 0.061095] + rae2822_sst_sust.su2_exec = "SU2_CFD" + rae2822_sst_sust.timeout = 1600 + rae2822_sst_sust.tol = 0.00001 + test_list.append(rae2822_sst_sust) + + # Flat plate + turb_flatplate = TestCase('turb_flatplate') + turb_flatplate.cfg_dir = "rans/flatplate" + turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" + turb_flatplate.test_iter = 20 + turb_flatplate.test_vals = [-4.157169, -6.737133, -0.176253, 0.057446] #last 4 columns + turb_flatplate.su2_exec = "SU2_CFD" + turb_flatplate.new_output = True + turb_flatplate.timeout = 1600 + turb_flatplate.tol = 0.00001 + test_list.append(turb_flatplate) + + # ONERA M6 Wing + turb_oneram6 = TestCase('turb_oneram6') + turb_oneram6.cfg_dir = "rans/oneram6" + turb_oneram6.cfg_file = "turb_ONERAM6.cfg" + turb_oneram6.test_iter = 10 + turb_oneram6.test_vals = [-2.388841, -6.689414, 0.230321, 0.157640]#last 4 columns + turb_oneram6.su2_exec = "SU2_CFD" + turb_oneram6.new_output = True + turb_oneram6.timeout = 3200 + turb_oneram6.tol = 0.00001 + test_list.append(turb_oneram6) + + # NACA0012 (SA, FUN3D results for finest grid: CL=1.0983, CD=0.01242) + turb_naca0012_sa = TestCase('turb_naca0012_sa') + turb_naca0012_sa.cfg_dir = "rans/naca0012" + turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" + turb_naca0012_sa.test_iter = 10 + turb_naca0012_sa.test_vals = [-11.133933, -14.498178, 1.064330, 0.019756] + turb_naca0012_sa.su2_exec = "SU2_CFD" + turb_naca0012_sa.new_output = True + turb_naca0012_sa.timeout = 3200 + turb_naca0012_sa.tol = 0.00001 + test_list.append(turb_naca0012_sa) + + # NACA0012 (SST, FUN3D results for finest grid: CL=1.0840, CD=0.01253) + turb_naca0012_sst = TestCase('turb_naca0012_sst') + turb_naca0012_sst.cfg_dir = "rans/naca0012" + turb_naca0012_sst.cfg_file = "turb_NACA0012_sst.cfg" + turb_naca0012_sst.test_iter = 10 + turb_naca0012_sst.test_vals = [-11.451010, -12.798258, -5.863895, 1.049989, 0.019163, -1.925018] + turb_naca0012_sst.su2_exec = "SU2_CFD" + turb_naca0012_sst.new_output = True + turb_naca0012_sst.timeout = 3200 + turb_naca0012_sst.tol = 0.00001 + test_list.append(turb_naca0012_sst) + + # NACA0012 (SST_SUST, FUN3D results for finest grid: CL=1.0840, CD=0.01253) + turb_naca0012_sst_sust = TestCase('turb_naca0012_sst_sust') + turb_naca0012_sst_sust.cfg_dir = "rans/naca0012" + turb_naca0012_sst_sust.cfg_file = "turb_NACA0012_sst_sust.cfg" + turb_naca0012_sst_sust.test_iter = 10 + turb_naca0012_sst_sust.test_vals = [-11.367386, -12.640857, -5.747260, 1.005233, 0.019017, -1.985871] + turb_naca0012_sst_sust.su2_exec = "SU2_CFD" + turb_naca0012_sst_sust.timeout = 3200 + turb_naca0012_sst_sust.tol = 0.00001 + test_list.append(turb_naca0012_sst_sust) + + # NACA0012 (SST, fixed values for turbulence quantities) + turb_naca0012_sst_fixedvalues = TestCase('turb_naca0012_sst_fixedvalues') + turb_naca0012_sst_fixedvalues.cfg_dir = "rans/naca0012" + turb_naca0012_sst_fixedvalues.cfg_file = "turb_NACA0012_sst_fixedvalues.cfg" + turb_naca0012_sst_fixedvalues.test_iter = 10 + turb_naca0012_sst_fixedvalues.test_vals = [-5.206744, -9.562435, -1.566603, 1.022029, 0.040549, -3.483576] + turb_naca0012_sst_fixedvalues.su2_exec = "SU2_CFD" + turb_naca0012_sst_fixedvalues.timeout = 3200 + turb_naca0012_sst_fixedvalues.tol = 0.00001 + test_list.append(turb_naca0012_sst_fixedvalues) + + # PROPELLER + propeller = TestCase('propeller') + propeller.cfg_dir = "rans/propeller" + propeller.cfg_file = "propeller.cfg" + propeller.test_iter = 10 + propeller.test_vals = [-3.389575, -8.409529, 0.000048, 0.056329] #last 4 columns + propeller.su2_exec = "SU2_CFD" + propeller.new_output = True + propeller.timeout = 3200 + propeller.tol = 0.00001 + test_list.append(propeller) + + ####################################### + ### Axisymmetric Compressible RANS ### + ####################################### + + # Axisymmetric air nozzle (transonic) + axi_rans_air_nozzle = TestCase('axi_rans_air_nozzle') + axi_rans_air_nozzle.cfg_dir = "axisymmetric_rans/air_nozzle" + axi_rans_air_nozzle.cfg_file = "air_nozzle.cfg" + axi_rans_air_nozzle.test_iter = 10 + axi_rans_air_nozzle.test_vals = [ -6.279299, -0.747627, -2.237638, 2.321596] + axi_rans_air_nozzle.su2_exec = "SU2_CFD" + axi_rans_air_nozzle.timeout = 1600 + axi_rans_air_nozzle.tol = 0.0001 + test_list.append(axi_rans_air_nozzle) + + ################################# + ## Compressible RANS Restart ### + ################################# + + # NACA0012 SST Multigrid restart + turb_naca0012_sst_restart_mg = TestCase('turb_naca0012_sst_restart_mg') + turb_naca0012_sst_restart_mg.cfg_dir = "rans/naca0012" + turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" + turb_naca0012_sst_restart_mg.test_iter = 50 + turb_naca0012_sst_restart_mg.ntest_vals = 5 + turb_naca0012_sst_restart_mg.test_vals = [-7.653235, -7.729550, -1.981855, -0.000015, 0.079061] + turb_naca0012_sst_restart_mg.su2_exec = "SU2_CFD" + turb_naca0012_sst_restart_mg.new_output = True + turb_naca0012_sst_restart_mg.timeout = 3200 + turb_naca0012_sst_restart_mg.tol = 0.000001 + test_list.append(turb_naca0012_sst_restart_mg) + ######################### ## NEMO solver ### ######################### From 519178fc584c7840b2bdf67889bbc0822de8adbd Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 16 Aug 2021 17:58:02 +0200 Subject: [PATCH 03/48] Move back turb-specific diffusion numerics. --- .../numerics/scalar/scalar_diffusion.hpp | 115 ----------------- .../numerics/turbulent/turb_diffusion.hpp | 117 +++++++++++++++++ SU2_CFD/src/drivers/CDriver.cpp | 1 + .../src/numerics/scalar/scalar_diffusion.cpp | 120 ----------------- .../src/numerics/turbulent/turb_diffusion.cpp | 121 ++++++++++++++++++ 5 files changed, 239 insertions(+), 235 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index fb07044dc044..a1a97f158eb3 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -92,118 +92,3 @@ class CAvgGrad_Scalar : public CNumerics { ResidualType<> ComputeResidual(const CConfig* config) override; }; - -/*! - * \class CAvgGrad_TurbSA - * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). - * \ingroup ViscDiscr - * \author A. Bueno. - */ -class CAvgGrad_TurbSA final : public CAvgGrad_Scalar { -private: - const su2double sigma = 2.0/3.0; - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config); -}; - -/*! - * \class CAvgGrad_TurbSA_Neg - * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). - * \ingroup ViscDiscr - * \author F. Palacios - */ -class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar { -private: - const su2double sigma = 2.0/3.0; - const su2double cn1 = 16.0; - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config); -}; - -/*! - * \class CAvgGrad_TurbSST - * \brief Class for computing viscous term using average of gradient with correction (Menter SST turbulence model). - * \ingroup ViscDiscr - * \author A. Bueno. - */ -class CAvgGrad_TurbSST final : public CAvgGrad_Scalar { -private: - const su2double - sigma_k1 = 0.0, /*!< \brief Constants for the viscous terms, k-w (1), k-eps (2)*/ - sigma_k2 = 0.0, - sigma_om1 = 0.0, - sigma_om2 = 0.0; - - su2double F1_i, F1_j; /*!< \brief Menter's first blending function */ - - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn(void) override; - - /*! - * \brief SST specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] constants - Constants of the model. - * \param[in] correct_grad - Whether to correct gradient for skewness. - * \param[in] config - Definition of the particular problem. - */ - CAvgGrad_TurbSST(unsigned short val_nDim, unsigned short val_nVar, - const su2double* constants, bool correct_grad, const CConfig* config); - - /*! - * \brief Sets value of first blending function. - */ - void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { - F1_i = val_F1_i; F1_j = val_F1_j; - } - -}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp index d0fbecdb8a06..e5c2f4020def 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp @@ -26,4 +26,121 @@ * License along with SU2. If not, see . */ +#include "../scalar/scalar_diffusion.hpp" + #pragma once + +/*! + * \class CAvgGrad_TurbSA + * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). + * \ingroup ViscDiscr + * \author A. Bueno. + */ +class CAvgGrad_TurbSA final : public CAvgGrad_Scalar { +private: + const su2double sigma = 2.0/3.0; + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config); +}; + +/*! + * \class CAvgGrad_TurbSA_Neg + * \brief Class for computing viscous term using average of gradients (Spalart-Allmaras Turbulence model). + * \ingroup ViscDiscr + * \author F. Palacios + */ +class CAvgGrad_TurbSA_Neg final : public CAvgGrad_Scalar { +private: + const su2double sigma = 2.0/3.0; + const su2double cn1 = 16.0; + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config); +}; + +/*! + * \class CAvgGrad_TurbSST + * \brief Class for computing viscous term using average of gradient with correction (Menter SST turbulence model). + * \ingroup ViscDiscr + * \author A. Bueno. + */ +class CAvgGrad_TurbSST final : public CAvgGrad_Scalar { +private: + const su2double + sigma_k1 = 0.0, /*!< \brief Constants for the viscous terms, k-w (1), k-eps (2)*/ + sigma_k2 = 0.0, + sigma_om1 = 0.0, + sigma_om2 = 0.0; + + su2double F1_i, F1_j; /*!< \brief Menter's first blending function */ + + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn(void) override; + + /*! + * \brief SST specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] constants - Constants of the model. + * \param[in] correct_grad - Whether to correct gradient for skewness. + * \param[in] config - Definition of the particular problem. + */ + CAvgGrad_TurbSST(unsigned short val_nDim, unsigned short val_nVar, + const su2double* constants, bool correct_grad, const CConfig* config); + + /*! + * \brief Sets value of first blending function. + */ + void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { + F1_i = val_F1_i; F1_j = val_F1_j; + } + +}; diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index ace00538fd20..b1d61aed2c07 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -77,6 +77,7 @@ #include "../../include/numerics/continuous_adjoint/adj_sources.hpp" #include "../../include/numerics/scalar/scalar_convection.hpp" #include "../../include/numerics/scalar/scalar_diffusion.hpp" +#include "../../include/numerics/turbulent/turb_diffusion.hpp" #include "../../include/numerics/scalar/scalar_sources.hpp" #include "../../include/numerics/elasticity/CFEAElasticity.hpp" #include "../../include/numerics/elasticity/CFEALinearElasticity.hpp" diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index a9ea198137b5..f0acac6dbfe9 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -103,123 +103,3 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config return ResidualType<>(Flux, Jacobian_i, Jacobian_j); } - -CAvgGrad_TurbSA::CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, - bool correct_grad, const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } - -void CAvgGrad_TurbSA::ExtraADPreaccIn() { } - -void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { - - /*--- Compute mean effective viscosity ---*/ - - su2double nu_i = Laminar_Viscosity_i/Density_i; - su2double nu_j = Laminar_Viscosity_j/Density_j; - su2double nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); - - Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - - if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; - } - -} - -CAvgGrad_TurbSA_Neg::CAvgGrad_TurbSA_Neg(unsigned short val_nDim, - unsigned short val_nVar, - bool correct_grad, - const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } - -void CAvgGrad_TurbSA_Neg::ExtraADPreaccIn() { } - -void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { - - /*--- Compute mean effective viscosity ---*/ - - su2double nu_i = Laminar_Viscosity_i/Density_i; - su2double nu_j = Laminar_Viscosity_j/Density_j; - - su2double nu_ij = 0.5*(nu_i+nu_j); - su2double nu_tilde_ij = 0.5*(TurbVar_i[0]+TurbVar_j[0]); - - su2double nu_e; - - if (nu_tilde_ij > 0.0) { - nu_e = nu_ij + nu_tilde_ij; - } - else { - su2double Xi = nu_tilde_ij/nu_ij; - su2double fn = (cn1 + Xi*Xi*Xi)/(cn1 - Xi*Xi*Xi); - nu_e = nu_ij + fn*nu_tilde_ij; - } - - Flux[0] = nu_e*Proj_Mean_GradTurbVar_Normal[0]/sigma; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - - if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; - } - -} - -CAvgGrad_TurbSST::CAvgGrad_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const su2double *constants, - bool correct_grad, - const CConfig* config) : - CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config), - sigma_k1(constants[0]), - sigma_k2(constants[1]), - sigma_om1(constants[2]), - sigma_om2(constants[3]) { - -} - -void CAvgGrad_TurbSST::ExtraADPreaccIn() { - AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F1_j); -} - -void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { - - su2double sigma_kine_i, sigma_kine_j, sigma_omega_i, sigma_omega_j; - su2double diff_i_kine, diff_i_omega, diff_j_kine, diff_j_omega; - - /*--- Compute the blended constant for the viscous terms ---*/ - sigma_kine_i = F1_i*sigma_k1 + (1.0 - F1_i)*sigma_k2; - sigma_kine_j = F1_j*sigma_k1 + (1.0 - F1_j)*sigma_k2; - sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2; - sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2; - - /*--- Compute mean effective viscosity ---*/ - diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i; - diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j; - diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i; - diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j; - - su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine); - su2double diff_omega = 0.5*(diff_i_omega + diff_j_omega); - - Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; - Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; - - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ - if (implicit) { - su2double proj_on_rho = proj_vector_ij/Density_i; - - Jacobian_i[0][0] = -diff_kine*proj_on_rho; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = -diff_omega*proj_on_rho; - - proj_on_rho = proj_vector_ij/Density_j; - - Jacobian_j[0][0] = diff_kine*proj_on_rho; Jacobian_j[0][1] = 0.0; - Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = diff_omega*proj_on_rho; - } - -} diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index 79792323f32e..18266b0658a0 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -27,3 +27,124 @@ */ #include "../../../include/numerics/turbulent/turb_diffusion.hpp" + + +CAvgGrad_TurbSA::CAvgGrad_TurbSA(unsigned short val_nDim, unsigned short val_nVar, + bool correct_grad, const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } + +void CAvgGrad_TurbSA::ExtraADPreaccIn() { } + +void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { + + /*--- Compute mean effective viscosity ---*/ + + su2double nu_i = Laminar_Viscosity_i/Density_i; + su2double nu_j = Laminar_Viscosity_j/Density_j; + su2double nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); + + Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + + if (implicit) { + Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + } + +} + +CAvgGrad_TurbSA_Neg::CAvgGrad_TurbSA_Neg(unsigned short val_nDim, + unsigned short val_nVar, + bool correct_grad, + const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config) { } + +void CAvgGrad_TurbSA_Neg::ExtraADPreaccIn() { } + +void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { + + /*--- Compute mean effective viscosity ---*/ + + su2double nu_i = Laminar_Viscosity_i/Density_i; + su2double nu_j = Laminar_Viscosity_j/Density_j; + + su2double nu_ij = 0.5*(nu_i+nu_j); + su2double nu_tilde_ij = 0.5*(TurbVar_i[0]+TurbVar_j[0]); + + su2double nu_e; + + if (nu_tilde_ij > 0.0) { + nu_e = nu_ij + nu_tilde_ij; + } + else { + su2double Xi = nu_tilde_ij/nu_ij; + su2double fn = (cn1 + Xi*Xi*Xi)/(cn1 - Xi*Xi*Xi); + nu_e = nu_ij + fn*nu_tilde_ij; + } + + Flux[0] = nu_e*Proj_Mean_GradTurbVar_Normal[0]/sigma; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + + if (implicit) { + Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + } + +} + +CAvgGrad_TurbSST::CAvgGrad_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const su2double *constants, + bool correct_grad, + const CConfig* config) : + CAvgGrad_Scalar(val_nDim, val_nVar, correct_grad, config), + sigma_k1(constants[0]), + sigma_k2(constants[1]), + sigma_om1(constants[2]), + sigma_om2(constants[3]) { + +} + +void CAvgGrad_TurbSST::ExtraADPreaccIn() { + AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F1_j); +} + +void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { + + su2double sigma_kine_i, sigma_kine_j, sigma_omega_i, sigma_omega_j; + su2double diff_i_kine, diff_i_omega, diff_j_kine, diff_j_omega; + + /*--- Compute the blended constant for the viscous terms ---*/ + sigma_kine_i = F1_i*sigma_k1 + (1.0 - F1_i)*sigma_k2; + sigma_kine_j = F1_j*sigma_k1 + (1.0 - F1_j)*sigma_k2; + sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2; + sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2; + + /*--- Compute mean effective viscosity ---*/ + diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i; + diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j; + diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i; + diff_j_omega = Laminar_Viscosity_j + sigma_omega_j*Eddy_Viscosity_j; + + su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine); + su2double diff_omega = 0.5*(diff_i_omega + diff_j_omega); + + Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; + Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; + + /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + if (implicit) { + su2double proj_on_rho = proj_vector_ij/Density_i; + + Jacobian_i[0][0] = -diff_kine*proj_on_rho; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = -diff_omega*proj_on_rho; + + proj_on_rho = proj_vector_ij/Density_j; + + Jacobian_j[0][0] = diff_kine*proj_on_rho; Jacobian_j[0][1] = 0.0; + Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = diff_omega*proj_on_rho; + } + +} From 3472dac4c2a5a6d9417c67204b38c404ed599280 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 16 Aug 2021 18:02:27 +0200 Subject: [PATCH 04/48] Move back turb-specific convection numerics. --- .../numerics/scalar/scalar_convection.hpp | 60 ------------------ .../numerics/turbulent/turb_convection.hpp | 62 +++++++++++++++++++ SU2_CFD/src/drivers/CDriver.cpp | 3 +- .../src/numerics/scalar/scalar_convection.cpp | 44 ------------- .../numerics/turbulent/turb_convection.cpp | 45 ++++++++++++++ 5 files changed, 109 insertions(+), 105 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp index 9e2cea2032aa..268619317068 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -89,63 +89,3 @@ class CUpwScalar : public CNumerics { ResidualType<> ComputeResidual(const CConfig* config) override; }; - -/*! - * \class CUpwSca_TurbSA - * \brief Class for doing a scalar upwind solver for the Spalar-Allmaras turbulence model equations. - * \ingroup ConvDiscr - * \author A. Bueno. - */ -class CUpwSca_TurbSA final : public CUpwScalar { -private: - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn() override; - - /*! - * \brief SA specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CUpwSca_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - -}; - -/*! - * \class CUpwSca_TurbSST - * \brief Class for doing a scalar upwind solver for the Menter SST turbulence model equations. - * \ingroup ConvDiscr - * \author A. Campos. - */ -class CUpwSca_TurbSST final : public CUpwScalar { -private: - /*! - * \brief Adds any extra variables to AD - */ - void ExtraADPreaccIn() override; - - /*! - * \brief SST specific steps in the ComputeResidual method - * \param[in] config - Definition of the particular problem. - */ - void FinishResidualCalc(const CConfig* config) override; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CUpwSca_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - -}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_convection.hpp b/SU2_CFD/include/numerics/turbulent/turb_convection.hpp index ccb69c2cf75a..c78c10887038 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_convection.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_convection.hpp @@ -27,3 +27,65 @@ */ #pragma once + +#include "../scalar/scalar_convection.hpp" + +/*! + * \class CUpwSca_TurbSA + * \brief Class for doing a scalar upwind solver for the Spalar-Allmaras turbulence model equations. + * \ingroup ConvDiscr + * \author A. Bueno. + */ +class CUpwSca_TurbSA final : public CUpwScalar { +private: + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn() override; + + /*! + * \brief SA specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CUpwSca_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + +}; + +/*! + * \class CUpwSca_TurbSST + * \brief Class for doing a scalar upwind solver for the Menter SST turbulence model equations. + * \ingroup ConvDiscr + * \author A. Campos. + */ +class CUpwSca_TurbSST final : public CUpwScalar { +private: + /*! + * \brief Adds any extra variables to AD + */ + void ExtraADPreaccIn() override; + + /*! + * \brief SST specific steps in the ComputeResidual method + * \param[in] config - Definition of the particular problem. + */ + void FinishResidualCalc(const CConfig* config) override; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CUpwSca_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + +}; diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index b1d61aed2c07..12df3421b844 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -77,8 +77,9 @@ #include "../../include/numerics/continuous_adjoint/adj_sources.hpp" #include "../../include/numerics/scalar/scalar_convection.hpp" #include "../../include/numerics/scalar/scalar_diffusion.hpp" -#include "../../include/numerics/turbulent/turb_diffusion.hpp" #include "../../include/numerics/scalar/scalar_sources.hpp" +#include "../../include/numerics/turbulent/turb_convection.hpp" +#include "../../include/numerics/turbulent/turb_diffusion.hpp" #include "../../include/numerics/elasticity/CFEAElasticity.hpp" #include "../../include/numerics/elasticity/CFEALinearElasticity.hpp" #include "../../include/numerics/elasticity/CFEANonlinearElasticity.hpp" diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp index 5c7bbb6820bb..206e94738ba7 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -99,47 +99,3 @@ CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { return ResidualType<>(Flux, Jacobian_i, Jacobian_j); } - -CUpwSca_TurbSA::CUpwSca_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CUpwScalar(val_nDim, val_nVar, config) { } - -void CUpwSca_TurbSA::ExtraADPreaccIn() { - AD::SetPreaccIn(V_i, nDim+1); - AD::SetPreaccIn(V_j, nDim+1); -} - -void CUpwSca_TurbSA::FinishResidualCalc(const CConfig* config) { - - Flux[0] = a0*TurbVar_i[0]+a1*TurbVar_j[0]; - - if (implicit) { - Jacobian_i[0][0] = a0; - Jacobian_j[0][0] = a1; - } -} - -CUpwSca_TurbSST::CUpwSca_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CUpwScalar(val_nDim, val_nVar, config) { } - -void CUpwSca_TurbSST::ExtraADPreaccIn() { - AD::SetPreaccIn(V_i, nDim+3); - AD::SetPreaccIn(V_j, nDim+3); -} - -void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { - - Flux[0] = a0*Density_i*TurbVar_i[0]+a1*Density_j*TurbVar_j[0]; - Flux[1] = a0*Density_i*TurbVar_i[1]+a1*Density_j*TurbVar_j[1]; - - if (implicit) { - Jacobian_i[0][0] = a0; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = a0; - - Jacobian_j[0][0] = a1; Jacobian_j[0][1] = 0.0; - Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = a1; - } -} diff --git a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp index 086eae2d6dee..13c1e81cb016 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp @@ -27,3 +27,48 @@ */ #include "../../../include/numerics/turbulent/turb_convection.hpp" + +CUpwSca_TurbSA::CUpwSca_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CUpwScalar(val_nDim, val_nVar, config) { } + +void CUpwSca_TurbSA::ExtraADPreaccIn() { + AD::SetPreaccIn(V_i, nDim+1); + AD::SetPreaccIn(V_j, nDim+1); +} + +void CUpwSca_TurbSA::FinishResidualCalc(const CConfig* config) { + + Flux[0] = a0*TurbVar_i[0]+a1*TurbVar_j[0]; + + if (implicit) { + Jacobian_i[0][0] = a0; + Jacobian_j[0][0] = a1; + } +} + +CUpwSca_TurbSST::CUpwSca_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CUpwScalar(val_nDim, val_nVar, config) { } + +void CUpwSca_TurbSST::ExtraADPreaccIn() { + AD::SetPreaccIn(V_i, nDim+3); + AD::SetPreaccIn(V_j, nDim+3); +} + +void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { + + Flux[0] = a0*Density_i*TurbVar_i[0]+a1*Density_j*TurbVar_j[0]; + Flux[1] = a0*Density_i*TurbVar_i[1]+a1*Density_j*TurbVar_j[1]; + + if (implicit) { + Jacobian_i[0][0] = a0; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = a0; + + Jacobian_j[0][0] = a1; Jacobian_j[0][1] = 0.0; + Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = a1; + } +} + From 6f684f98988e837c808b93444319abfa8103807c Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 16 Aug 2021 18:06:52 +0200 Subject: [PATCH 05/48] Move back turb-specific source numerics. --- .../numerics/scalar/scalar_sources.hpp | 386 -------- .../numerics/turbulent/turb_sources.hpp | 387 ++++++++ SU2_CFD/src/drivers/CDriver.cpp | 1 + .../src/numerics/scalar/scalar_sources.cpp | 901 ----------------- .../src/numerics/turbulent/turb_sources.cpp | 902 ++++++++++++++++++ 5 files changed, 1290 insertions(+), 1287 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp index 2e0e2b8cb62a..08941bf7343e 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp @@ -29,389 +29,3 @@ #pragma once #include "../CNumerics.hpp" - -/*! - * \class CSourcePieceWise_TurbSA - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author A. Bueno. - */ -class CSourceBase_TurbSA : public CNumerics { -protected: - su2double cv1_3; - su2double k2; - su2double cb1; - su2double cw2; - su2double ct3; - su2double ct4; - su2double cw3_6; - su2double cb2_sigma; - su2double sigma; - su2double cb2; - su2double cw1; - su2double cr1; - - su2double Gamma_BC = 0.0; - su2double intermittency; - su2double Production, Destruction, CrossProduction; - - su2double Residual, *Jacobian_i; -private: - su2double Jacobian_Buffer; /// Static storage for the Jacobian (which needs to be pointer for return type). - -protected: - const bool incompressible = false, rotating_frame = false; - bool roughwall = false; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourceBase_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] intermittency_in - Value of the intermittency. - */ - inline void SetIntermittency(su2double intermittency_in) final { intermittency = intermittency_in; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_production - Value of the Production. - */ - inline void SetProduction(su2double val_production) final { Production = val_production; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_destruction - Value of the Destruction. - */ - inline void SetDestruction(su2double val_destruction) final { Destruction = val_destruction; } - - /*! - * \brief Residual for source term integration. - * \param[in] val_crossproduction - Value of the CrossProduction. - */ - inline void SetCrossProduction(su2double val_crossproduction) final { CrossProduction = val_crossproduction; } - - /*! - * \brief ______________. - */ - inline su2double GetProduction(void) const final { return Production; } - - /*! - * \brief Get the intermittency for the BC trans. model. - * \return Value of the intermittency. - */ - inline su2double GetGammaBC(void) const final { return Gamma_BC; } - - /*! - * \brief ______________. - */ - inline su2double GetDestruction(void) const final { return Destruction; } - - /*! - * \brief ______________. - */ - inline su2double GetCrossProduction(void) const final { return CrossProduction; } -}; - - -/*! - * \class CSourcePieceWise_TurbSA - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author A. Bueno. - */ -class CSourcePieceWise_TurbSA final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - unsigned short iDim; - bool transition; - bool axisymmetric; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSA_COMP - * \brief Class for integrating the source terms of the Spalart-Allmaras CC modification turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_COMP final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double aux_cc, CompCorrection, c5; - unsigned short iDim, jDim; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSA_E - * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_E final : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double Sbar; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_E(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; -}; - -/*! - * \class CSourcePieceWise_TurbSA_E_COMP - * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification with CC turbulence model equation. - * \ingroup SourceDiscr - * \author E.Molina, A. Bueno. - * \version 7.1.1 "Blackbird" - */ -class CSourcePieceWise_TurbSA_E_COMP : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - su2double Sbar; - su2double aux_cc, CompCorrection, c5; - unsigned short jDim; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; -}; - -/*! - * \class CSourcePieceWise_TurbSA_Neg - * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. - * \ingroup SourceDiscr - * \author F. Palacios - */ -class CSourcePieceWise_TurbSA_Neg : public CSourceBase_TurbSA { -private: - su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; - su2double r, g, g_6, glim, fw; - su2double norm2_Grad; - su2double dfv1, dfv2, dShat; - su2double dr, dg, dfw; - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; - -/*! - * \class CSourcePieceWise_TurbSST - * \brief Class for integrating the source terms of the Menter SST turbulence model equations. - * \ingroup SourceDiscr - * \author A. Campos. - */ -class CSourcePieceWise_TurbSST final : public CNumerics { -private: - su2double F1_i, - F1_j, - F2_i, - F2_j; - - su2double alfa_1, - alfa_2, - beta_1, - beta_2, - sigma_k_1, - sigma_k_2, - sigma_w_1, - sigma_w_2, - beta_star, - a1; - - su2double CDkw_i, CDkw_j; - - su2double kAmb, omegaAmb; - - su2double Residual[2], - *Jacobian_i[2] = {nullptr}, - Jacobian_Buffer[4] = {0.0}; /// Static storage for the Jacobian (which needs to be pointer for return type). - - bool incompressible; - bool sustaining_terms; - bool axisymmetric; - - /*! - * \brief A virtual member. Get strain magnitude based on perturbed reynolds stress matrix - * \param[in] turb_ke: turbulent kinetic energy of the node - */ - void SetPerturbedStrainMag(su2double turb_ke); - - /*! - * \brief Add contribution due to axisymmetric formulation to 2D residual - */ - inline void ResidualAxisymmetric(su2double alfa_blended, su2double zeta){ - - if (Coord_i[1] < EPS) return; - - su2double yinv, rhov, k, w; - su2double sigma_k_i, sigma_w_i; - su2double pk_axi, pw_axi, cdk_axi, cdw_axi; - - AD::SetPreaccIn(Coord_i[1]); - - yinv = 1.0/Coord_i[1]; - rhov = Density_i*V_i[2]; - k = TurbVar_i[0]; - w = TurbVar_i[1]; - - /*--- Compute blended constants ---*/ - sigma_k_i = F1_i*sigma_k_1+(1.0-F1_i)*sigma_k_2; - sigma_w_i = F1_i*sigma_w_1+(1.0-F1_i)*sigma_w_2; - - /*--- Production ---*/ - pk_axi = max(0.0,2.0/3.0*rhov*k*(2.0/zeta*(yinv*V_i[2]-PrimVar_Grad_i[2][1]-PrimVar_Grad_i[1][0])-1.0)); - pw_axi = alfa_blended*zeta/k*pk_axi; - - /*--- Convection-Diffusion ---*/ - cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*TurbVar_Grad_i[0][1]; - cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*TurbVar_Grad_i[1][1]; - - /*--- Add terms to the residuals ---*/ - Residual[0] += yinv*Volume*(pk_axi-cdk_axi); - Residual[1] += yinv*Volume*(pw_axi-cdw_axi); - - } - -public: - /*! - * \brief Constructor of the class. - * \param[in] val_nDim - Number of dimensions of the problem. - * \param[in] val_nVar - Number of variables of the problem. - * \param[in] config - Definition of the particular problem. - */ - CSourcePieceWise_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const su2double* constants, - su2double val_kine_Inf, su2double val_omega_Inf, const CConfig* config); - - /*! - * \brief Set the value of the first blending function. - * \param[in] val_F1_i - Value of the first blending function at point i. - * \param[in] val_F1_j - Value of the first blending function at point j. - */ - inline void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { - F1_i = val_F1_i; - F1_j = val_F1_j; - } - - /*! - * \brief Set the value of the second blending function. - * \param[in] val_F2_i - Value of the second blending function at point i. - * \param[in] val_F2_j - Value of the second blending function at point j. - */ - inline void SetF2blending(su2double val_F2_i, su2double val_F2_j) override { - F2_i = val_F2_i; - F2_j = val_F2_j; - } - - /*! - * \brief Set the value of the cross diffusion for the SST model. - * \param[in] val_CDkw_i - Value of the cross diffusion at point i. - * \param[in] val_CDkw_j - Value of the cross diffusion at point j. - */ - inline void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) override { - CDkw_i = val_CDkw_i; - CDkw_j = val_CDkw_j; - } - - /*! - * \brief Residual for source term integration. - * \param[in] config - Definition of the particular problem. - * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. - */ - ResidualType<> ComputeResidual(const CConfig* config) override; - -}; diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp index 12a459436c89..c39916bf3adc 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp @@ -28,3 +28,390 @@ #pragma once +#include "../scalar/scalar_sources.hpp" + +/*! + * \class CSourcePieceWise_TurbSA + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author A. Bueno. + */ +class CSourceBase_TurbSA : public CNumerics { +protected: + su2double cv1_3; + su2double k2; + su2double cb1; + su2double cw2; + su2double ct3; + su2double ct4; + su2double cw3_6; + su2double cb2_sigma; + su2double sigma; + su2double cb2; + su2double cw1; + su2double cr1; + + su2double Gamma_BC = 0.0; + su2double intermittency; + su2double Production, Destruction, CrossProduction; + + su2double Residual, *Jacobian_i; +private: + su2double Jacobian_Buffer; /// Static storage for the Jacobian (which needs to be pointer for return type). + +protected: + const bool incompressible = false, rotating_frame = false; + bool roughwall = false; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourceBase_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] intermittency_in - Value of the intermittency. + */ + inline void SetIntermittency(su2double intermittency_in) final { intermittency = intermittency_in; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_production - Value of the Production. + */ + inline void SetProduction(su2double val_production) final { Production = val_production; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_destruction - Value of the Destruction. + */ + inline void SetDestruction(su2double val_destruction) final { Destruction = val_destruction; } + + /*! + * \brief Residual for source term integration. + * \param[in] val_crossproduction - Value of the CrossProduction. + */ + inline void SetCrossProduction(su2double val_crossproduction) final { CrossProduction = val_crossproduction; } + + /*! + * \brief ______________. + */ + inline su2double GetProduction(void) const final { return Production; } + + /*! + * \brief Get the intermittency for the BC trans. model. + * \return Value of the intermittency. + */ + inline su2double GetGammaBC(void) const final { return Gamma_BC; } + + /*! + * \brief ______________. + */ + inline su2double GetDestruction(void) const final { return Destruction; } + + /*! + * \brief ______________. + */ + inline su2double GetCrossProduction(void) const final { return CrossProduction; } +}; + + +/*! + * \class CSourcePieceWise_TurbSA + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author A. Bueno. + */ +class CSourcePieceWise_TurbSA final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + unsigned short iDim; + bool transition; + bool axisymmetric; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSA_COMP + * \brief Class for integrating the source terms of the Spalart-Allmaras CC modification turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_COMP final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double aux_cc, CompCorrection, c5; + unsigned short iDim, jDim; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSA_E + * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_E final : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double Sbar; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_E(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; +}; + +/*! + * \class CSourcePieceWise_TurbSA_E_COMP + * \brief Class for integrating the source terms of the Spalart-Allmaras Edwards modification with CC turbulence model equation. + * \ingroup SourceDiscr + * \author E.Molina, A. Bueno. + * \version 7.1.1 "Blackbird" + */ +class CSourcePieceWise_TurbSA_E_COMP : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + su2double Sbar; + su2double aux_cc, CompCorrection, c5; + unsigned short jDim; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; +}; + +/*! + * \class CSourcePieceWise_TurbSA_Neg + * \brief Class for integrating the source terms of the Spalart-Allmaras turbulence model equation. + * \ingroup SourceDiscr + * \author F. Palacios + */ +class CSourcePieceWise_TurbSA_Neg : public CSourceBase_TurbSA { +private: + su2double nu, Ji, fv1, fv2, ft2, Omega, S, Shat, inv_Shat, dist_i_2, Ji_2, Ji_3, inv_k2_d2; + su2double r, g, g_6, glim, fw; + su2double norm2_Grad; + su2double dfv1, dfv2, dShat; + su2double dr, dg, dfw; + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config); + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; + +/*! + * \class CSourcePieceWise_TurbSST + * \brief Class for integrating the source terms of the Menter SST turbulence model equations. + * \ingroup SourceDiscr + * \author A. Campos. + */ +class CSourcePieceWise_TurbSST final : public CNumerics { +private: + su2double F1_i, + F1_j, + F2_i, + F2_j; + + su2double alfa_1, + alfa_2, + beta_1, + beta_2, + sigma_k_1, + sigma_k_2, + sigma_w_1, + sigma_w_2, + beta_star, + a1; + + su2double CDkw_i, CDkw_j; + + su2double kAmb, omegaAmb; + + su2double Residual[2], + *Jacobian_i[2] = {nullptr}, + Jacobian_Buffer[4] = {0.0}; /// Static storage for the Jacobian (which needs to be pointer for return type). + + bool incompressible; + bool sustaining_terms; + bool axisymmetric; + + /*! + * \brief A virtual member. Get strain magnitude based on perturbed reynolds stress matrix + * \param[in] turb_ke: turbulent kinetic energy of the node + */ + void SetPerturbedStrainMag(su2double turb_ke); + + /*! + * \brief Add contribution due to axisymmetric formulation to 2D residual + */ + inline void ResidualAxisymmetric(su2double alfa_blended, su2double zeta){ + + if (Coord_i[1] < EPS) return; + + su2double yinv, rhov, k, w; + su2double sigma_k_i, sigma_w_i; + su2double pk_axi, pw_axi, cdk_axi, cdw_axi; + + AD::SetPreaccIn(Coord_i[1]); + + yinv = 1.0/Coord_i[1]; + rhov = Density_i*V_i[2]; + k = TurbVar_i[0]; + w = TurbVar_i[1]; + + /*--- Compute blended constants ---*/ + sigma_k_i = F1_i*sigma_k_1+(1.0-F1_i)*sigma_k_2; + sigma_w_i = F1_i*sigma_w_1+(1.0-F1_i)*sigma_w_2; + + /*--- Production ---*/ + pk_axi = max(0.0,2.0/3.0*rhov*k*(2.0/zeta*(yinv*V_i[2]-PrimVar_Grad_i[2][1]-PrimVar_Grad_i[1][0])-1.0)); + pw_axi = alfa_blended*zeta/k*pk_axi; + + /*--- Convection-Diffusion ---*/ + cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*TurbVar_Grad_i[0][1]; + cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*TurbVar_Grad_i[1][1]; + + /*--- Add terms to the residuals ---*/ + Residual[0] += yinv*Volume*(pk_axi-cdk_axi); + Residual[1] += yinv*Volume*(pw_axi-cdw_axi); + + } + +public: + /*! + * \brief Constructor of the class. + * \param[in] val_nDim - Number of dimensions of the problem. + * \param[in] val_nVar - Number of variables of the problem. + * \param[in] config - Definition of the particular problem. + */ + CSourcePieceWise_TurbSST(unsigned short val_nDim, unsigned short val_nVar, const su2double* constants, + su2double val_kine_Inf, su2double val_omega_Inf, const CConfig* config); + + /*! + * \brief Set the value of the first blending function. + * \param[in] val_F1_i - Value of the first blending function at point i. + * \param[in] val_F1_j - Value of the first blending function at point j. + */ + inline void SetF1blending(su2double val_F1_i, su2double val_F1_j) override { + F1_i = val_F1_i; + F1_j = val_F1_j; + } + + /*! + * \brief Set the value of the second blending function. + * \param[in] val_F2_i - Value of the second blending function at point i. + * \param[in] val_F2_j - Value of the second blending function at point j. + */ + inline void SetF2blending(su2double val_F2_i, su2double val_F2_j) override { + F2_i = val_F2_i; + F2_j = val_F2_j; + } + + /*! + * \brief Set the value of the cross diffusion for the SST model. + * \param[in] val_CDkw_i - Value of the cross diffusion at point i. + * \param[in] val_CDkw_j - Value of the cross diffusion at point j. + */ + inline void SetCrossDiff(su2double val_CDkw_i, su2double val_CDkw_j) override { + CDkw_i = val_CDkw_i; + CDkw_j = val_CDkw_j; + } + + /*! + * \brief Residual for source term integration. + * \param[in] config - Definition of the particular problem. + * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. + */ + ResidualType<> ComputeResidual(const CConfig* config) override; + +}; diff --git a/SU2_CFD/src/drivers/CDriver.cpp b/SU2_CFD/src/drivers/CDriver.cpp index 12df3421b844..4f9222f82a48 100644 --- a/SU2_CFD/src/drivers/CDriver.cpp +++ b/SU2_CFD/src/drivers/CDriver.cpp @@ -80,6 +80,7 @@ #include "../../include/numerics/scalar/scalar_sources.hpp" #include "../../include/numerics/turbulent/turb_convection.hpp" #include "../../include/numerics/turbulent/turb_diffusion.hpp" +#include "../../include/numerics/turbulent/turb_sources.hpp" #include "../../include/numerics/elasticity/CFEAElasticity.hpp" #include "../../include/numerics/elasticity/CFEALinearElasticity.hpp" #include "../../include/numerics/elasticity/CFEANonlinearElasticity.hpp" diff --git a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp index f12b76d3140d..58874b7313bc 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp @@ -27,904 +27,3 @@ */ #include "../../../include/numerics/scalar/scalar_sources.hpp" - -CSourceBase_TurbSA::CSourceBase_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), - rotating_frame(config->GetRotating_Frame()) -{ - /*--- Spalart-Allmaras closure constants ---*/ - - cv1_3 = pow(7.1, 3.0); - k2 = pow(0.41, 2.0); - cb1 = 0.1355; - cw2 = 0.3; - ct3 = 1.2; - ct4 = 0.5; - cw3_6 = pow(2.0, 6.0); - sigma = 2./3.; - cb2 = 0.622; - cb2_sigma = cb2/sigma; - cw1 = cb1/k2+(1.0+cb2)/sigma; - cr1 = 0.5; - - /*--- Setup the Jacobian pointer, we need to return su2double** but - * we know the Jacobian is 1x1 so we use this "trick" to avoid - * having to dynamically allocate. ---*/ - - Jacobian_i = &Jacobian_Buffer; - -} - -CSourcePieceWise_TurbSA::CSourcePieceWise_TurbSA(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { - - transition = (config->GetKind_Trans_Model() == BC); -} - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig* config) { - -// AD::StartPreacc(); -// AD::SetPreaccIn(V_i, nDim+6); -// AD::SetPreaccIn(Vorticity_i, nDim); -// AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); -// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - // Set the boolean here depending on whether the point is closest to a rough wall or not. - roughwall = (roughness_i > 0.0); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - - /*--- Modified values for roughness ---*/ - /*--- Ref: Aupoix, B. and Spalart, P. R., "Extensions of the Spalart-Allmaras Turbulence Model to Account for Wall Roughness," - * International Journal of Heat and Fluid Flow, Vol. 24, 2003, pp. 454-462. ---*/ - /* --- See https://turbmodels.larc.nasa.gov/spalart.html#sarough for detailed explanation. ---*/ - - Ji = TurbVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - - /*--- Using a modified relation so as to not change the Shat that depends on fv2. ---*/ - fv2 = 1.0 - TurbVar_i[0]/(nu+TurbVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper - - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - -// Original SA model -// Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; - - if (transition) { - - /*--- BC model constants (2020 revision). ---*/ - const su2double chi_1 = 0.002; - const su2double chi_2 = 50.0; - - /*--- turbulence intensity is u'/U so we multiply by 100 to get percentage ---*/ - su2double tu = 100.0 * config->GetTurbulenceIntensity_FreeStream(); - - su2double nu_t = (TurbVar_i[0]*fv1); //S-A variable - - su2double re_v = ((Density_i*pow(dist_i,2.))/(Laminar_Viscosity_i))*Omega; - su2double re_theta = re_v/2.193; - su2double re_theta_t = (803.73 * pow((tu + 0.6067),-1.027)); //MENTER correlation - //re_theta_t = 163.0 + exp(6.91-tu); //ABU-GHANNAM & SHAW correlation - - su2double term1 = sqrt(max(re_theta-re_theta_t,0.)/(chi_1*re_theta_t)); - su2double term2 = sqrt(max((nu_t*chi_2)/nu,0.)); - su2double term_exponential = (term1 + term2); - - Gamma_BC = 1.0 - exp(-term_exponential); - - Production = Gamma_BC*cb1*Shat*TurbVar_i[0]*Volume; - } - else { - Production = cb1*Shat*TurbVar_i[0]*Volume; - } - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - -// Original SA model -// Destruction = (cw1*fw-cb1*ft2/k2)*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - - if (transition) { - Jacobian_i[0] += Gamma_BC*cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - } - else { - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - } - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - if (r == 10.0) dr = 0.0; - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - -// AD::SetPreaccOut(Residual); -// AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_COMP::CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config), c5(3.5) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CConfig* config) { - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Compressibility Correction term ---*/ - Pressure_i = V_i[nDim+1]; - SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); - aux_cc=0; - for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_E::CSourcePieceWise_TurbSA_E(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConfig* config) { - - unsigned short iDim, jDim; - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /* - From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html - This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: - Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. - In this modificaton Omega is replaced by Strain Rate - */ - - /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ - - Sbar = 0.0; - for(iDim=0;iDim 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - //Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); - - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - r=tanh(r)/tanh(1.0); - - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - - // AD::SetPreaccOut(Residual); - // AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_E_COMP::CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const CConfig* config) { - - unsigned short iDim; - - // AD::StartPreacc(); - // AD::SetPreaccIn(V_i, nDim+6); - // AD::SetPreaccIn(Vorticity_i, nDim); - // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); - // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /* - From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html - This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: - Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. - In this modificaton Omega is replaced by Strain Rate - */ - - /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ - - Sbar = 0.0; - for(iDim=0;iDim 1e-10) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); - - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - r=tanh(r)/tanh(1.0); - - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Compressibility Correction term ---*/ - Pressure_i = V_i[nDim+1]; - SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); - aux_cc=0; - for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSA_Neg::CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CSourceBase_TurbSA(val_nDim, val_nVar, config) { } - -CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CConfig* config) { - - unsigned short iDim; - -// AD::StartPreacc(); -// AD::SetPreaccIn(V_i, nDim+6); -// AD::SetPreaccIn(Vorticity_i, nDim); -// AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); -// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - - if (incompressible) { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - } - else { - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - } - - Residual = 0.0; - Production = 0.0; - Destruction = 0.0; - CrossProduction = 0.0; - Jacobian_i[0] = 0.0; - - /*--- Evaluate Omega ---*/ - - Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); - - /*--- Rotational correction term ---*/ - - if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } - - if (dist_i > 1e-10) { - - if (TurbVar_i[0] > 0.0) { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; - Ji_2 = Ji*Ji; - Ji_3 = Ji_2*Ji; - fv1 = Ji_3/(Ji_3+cv1_3); - fv2 = 1.0 - Ji/(1.0+Ji*fv1); - ft2 = ct3*exp(-ct4*Ji_2); - S = Omega; - inv_k2_d2 = 1.0/(k2*dist_i_2); - - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; - Shat = max(Shat, 1.0e-10); - inv_Shat = 1.0/Shat; - - /*--- Production term ---*/; - - // Original SA model - // Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; - - Production = cb1*Shat*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); - g = r + cw2*(pow(r,6.0)-r); - g_6 = pow(g,6.0); - glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); - fw = g*glim; - - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production - Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); - dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); - if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; - - /*--- Implicit part, destruction term ---*/ - - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; - if (r == 10.0) dr = 0.0; - dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); - dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; - - } - - else { - - /*--- Production term ---*/ - - dist_i_2 = dist_i*dist_i; - - /*--- Production term ---*/; - - Production = cb1*(1.0-ct3)*Omega*TurbVar_i[0]*Volume; - - /*--- Destruction term ---*/ - - Destruction = cw1*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; - - /*--- Diffusion term ---*/ - - norm2_Grad = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; - - CrossProduction = cb2_sigma*norm2_Grad*Volume; - - Residual = Production + Destruction + CrossProduction; - - /*--- Implicit part, production term ---*/ - - Jacobian_i[0] += cb1*(1.0-ct3)*Omega*Volume; - - /*--- Implicit part, destruction term ---*/ - - Jacobian_i[0] += 2.0*cw1*TurbVar_i[0]/dist_i_2*Volume; - - } - - } - -// AD::SetPreaccOut(Residual); -// AD::EndPreacc(); - - return ResidualType<>(&Residual, &Jacobian_i, nullptr); - -} - -CSourcePieceWise_TurbSST::CSourcePieceWise_TurbSST(unsigned short val_nDim, - unsigned short val_nVar, - const su2double *constants, - su2double val_kine_Inf, - su2double val_omega_Inf, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config) { - - incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - sustaining_terms = (config->GetKind_Turb_Model() == SST_SUST); - axisymmetric = config->GetAxisymmetric(); - - /*--- Closure constants ---*/ - sigma_k_1 = constants[0]; - sigma_k_2 = constants[1]; - sigma_w_1 = constants[2]; - sigma_w_2 = constants[3]; - beta_1 = constants[4]; - beta_2 = constants[5]; - beta_star = constants[6]; - a1 = constants[7]; - alfa_1 = constants[8]; - alfa_2 = constants[9]; - - /*--- Set the ambient values of k and omega to the free stream values. ---*/ - kAmb = val_kine_Inf; - omegaAmb = val_omega_Inf; - - /*--- "Allocate" the Jacobian using the static buffer. ---*/ - Jacobian_i[0] = Jacobian_Buffer; - Jacobian_i[1] = Jacobian_Buffer+2; - -} - -CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfig* config) { - - AD::StartPreacc(); - AD::SetPreaccIn(StrainMag_i); - AD::SetPreaccIn(TurbVar_i, nVar); - AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); - AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); - AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); - AD::SetPreaccIn(PrimVar_Grad_i, nDim+1, nDim); - AD::SetPreaccIn(Vorticity_i, 3); - - unsigned short iDim; - su2double alfa_blended, beta_blended; - su2double diverg, pk, pw, zeta; - su2double VorticityMag = sqrt(Vorticity_i[0]*Vorticity_i[0] + - Vorticity_i[1]*Vorticity_i[1] + - Vorticity_i[2]*Vorticity_i[2]); - - if (incompressible) { - AD::SetPreaccIn(V_i, nDim+6); - - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; - Eddy_Viscosity_i = V_i[nDim+5]; - } - else { - AD::SetPreaccIn(V_i, nDim+7); - - Density_i = V_i[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; - Eddy_Viscosity_i = V_i[nDim+6]; - } - - Residual[0] = 0.0; Residual[1] = 0.0; - Jacobian_i[0][0] = 0.0; Jacobian_i[0][1] = 0.0; - Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = 0.0; - - /*--- Computation of blended constants for the source terms---*/ - - alfa_blended = F1_i*alfa_1 + (1.0 - F1_i)*alfa_2; - beta_blended = F1_i*beta_1 + (1.0 - F1_i)*beta_2; - - if (dist_i > 1e-10) { - - /*--- Production ---*/ - - diverg = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - diverg += PrimVar_Grad_i[iDim+1][iDim]; - - /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ - - if (using_uq){ - ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, - PrimVar_Grad_i+1, Density_i, Eddy_Viscosity_i, - TurbVar_i[0], MeanPerturbedRSM); - SetPerturbedStrainMag(TurbVar_i[0]); - pk = Eddy_Viscosity_i*PerturbedStrainMag*PerturbedStrainMag - - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; - } - else { - pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; - } - - pk = min(pk,20.0*beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]); - pk = max(pk,0.0); - - zeta = max(TurbVar_i[1], VorticityMag*F2_i/a1); - - /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ - - if (using_uq){ - pw = PerturbedStrainMag * PerturbedStrainMag - 2.0/3.0*zeta*diverg; - } - else { - pw = StrainMag_i*StrainMag_i - 2.0/3.0*zeta*diverg; - } - pw = alfa_blended*Density_i*max(pw,0.0); - - /*--- Sustaining terms, if desired. Note that if the production terms are - larger equal than the sustaining terms, the original formulation is - obtained again. This is in contrast to the version in literature - where the sustaining terms are simply added. This latter approach could - lead to problems for very big values of the free-stream turbulence - intensity. ---*/ - - if ( sustaining_terms ) { - const su2double sust_k = beta_star*Density_i*kAmb*omegaAmb; - const su2double sust_w = beta_blended*Density_i*omegaAmb*omegaAmb; - - pk = max(pk, sust_k); - pw = max(pw, sust_w); - } - - /*--- Add the production terms to the residuals. ---*/ - - Residual[0] += pk*Volume; - Residual[1] += pw*Volume; - - /*--- Dissipation ---*/ - - Residual[0] -= beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]*Volume; - Residual[1] -= beta_blended*Density_i*TurbVar_i[1]*TurbVar_i[1]*Volume; - - /*--- Cross diffusion ---*/ - - Residual[1] += (1.0 - F1_i)*CDkw_i*Volume; - - /*--- Contribution due to 2D axisymmetric formulation ---*/ - - if (axisymmetric) ResidualAxisymmetric(alfa_blended,zeta); - - /*--- Implicit part ---*/ - - Jacobian_i[0][0] = -beta_star*TurbVar_i[1]*Volume; - Jacobian_i[0][1] = -beta_star*TurbVar_i[0]*Volume; - Jacobian_i[1][0] = 0.0; - Jacobian_i[1][1] = -2.0*beta_blended*TurbVar_i[1]*Volume; - } - - AD::SetPreaccOut(Residual, nVar); - AD::EndPreacc(); - - return ResidualType<>(Residual, Jacobian_i, nullptr); - -} - -void CSourcePieceWise_TurbSST::SetPerturbedStrainMag(su2double turb_ke){ - - /*--- Compute norm of perturbed strain rate tensor. ---*/ - - PerturbedStrainMag = 0; - for (unsigned short iDim = 0; iDim < nDim; iDim++){ - for (unsigned short jDim = 0; jDim < nDim; jDim++){ - su2double StrainRate_ij = MeanPerturbedRSM[iDim][jDim] - TWO3 * turb_ke * delta[iDim][jDim]; - StrainRate_ij = - StrainRate_ij * Density_i / (2 * Eddy_Viscosity_i); - - PerturbedStrainMag += pow(StrainRate_ij, 2.0); - } - } - PerturbedStrainMag = sqrt(2.0*PerturbedStrainMag); - -} diff --git a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp index 39bb5e934cdd..8c041ae05463 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp @@ -27,3 +27,905 @@ */ #include "../../../include/numerics/turbulent/turb_sources.hpp" + + +CSourceBase_TurbSA::CSourceBase_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), + rotating_frame(config->GetRotating_Frame()) +{ + /*--- Spalart-Allmaras closure constants ---*/ + + cv1_3 = pow(7.1, 3.0); + k2 = pow(0.41, 2.0); + cb1 = 0.1355; + cw2 = 0.3; + ct3 = 1.2; + ct4 = 0.5; + cw3_6 = pow(2.0, 6.0); + sigma = 2./3.; + cb2 = 0.622; + cb2_sigma = cb2/sigma; + cw1 = cb1/k2+(1.0+cb2)/sigma; + cr1 = 0.5; + + /*--- Setup the Jacobian pointer, we need to return su2double** but + * we know the Jacobian is 1x1 so we use this "trick" to avoid + * having to dynamically allocate. ---*/ + + Jacobian_i = &Jacobian_Buffer; + +} + +CSourcePieceWise_TurbSA::CSourcePieceWise_TurbSA(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { + + transition = (config->GetKind_Trans_Model() == BC); +} + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig* config) { + +// AD::StartPreacc(); +// AD::SetPreaccIn(V_i, nDim+6); +// AD::SetPreaccIn(Vorticity_i, nDim); +// AD::SetPreaccIn(StrainMag_i); +// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + // Set the boolean here depending on whether the point is closest to a rough wall or not. + roughwall = (roughness_i > 0.0); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + + /*--- Modified values for roughness ---*/ + /*--- Ref: Aupoix, B. and Spalart, P. R., "Extensions of the Spalart-Allmaras Turbulence Model to Account for Wall Roughness," + * International Journal of Heat and Fluid Flow, Vol. 24, 2003, pp. 454-462. ---*/ + /* --- See https://turbmodels.larc.nasa.gov/spalart.html#sarough for detailed explanation. ---*/ + + Ji = TurbVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + + /*--- Using a modified relation so as to not change the Shat that depends on fv2. ---*/ + fv2 = 1.0 - TurbVar_i[0]/(nu+TurbVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper + + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + +// Original SA model +// Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; + + if (transition) { + + /*--- BC model constants (2020 revision). ---*/ + const su2double chi_1 = 0.002; + const su2double chi_2 = 50.0; + + /*--- turbulence intensity is u'/U so we multiply by 100 to get percentage ---*/ + su2double tu = 100.0 * config->GetTurbulenceIntensity_FreeStream(); + + su2double nu_t = (TurbVar_i[0]*fv1); //S-A variable + + su2double re_v = ((Density_i*pow(dist_i,2.))/(Laminar_Viscosity_i))*Omega; + su2double re_theta = re_v/2.193; + su2double re_theta_t = (803.73 * pow((tu + 0.6067),-1.027)); //MENTER correlation + //re_theta_t = 163.0 + exp(6.91-tu); //ABU-GHANNAM & SHAW correlation + + su2double term1 = sqrt(max(re_theta-re_theta_t,0.)/(chi_1*re_theta_t)); + su2double term2 = sqrt(max((nu_t*chi_2)/nu,0.)); + su2double term_exponential = (term1 + term2); + + Gamma_BC = 1.0 - exp(-term_exponential); + + Production = Gamma_BC*cb1*Shat*TurbVar_i[0]*Volume; + } + else { + Production = cb1*Shat*TurbVar_i[0]*Volume; + } + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + +// Original SA model +// Destruction = (cw1*fw-cb1*ft2/k2)*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; + + if (transition) { + Jacobian_i[0] += Gamma_BC*cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + } + else { + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + } + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + if (r == 10.0) dr = 0.0; + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + +// AD::SetPreaccOut(Residual); +// AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_COMP::CSourcePieceWise_TurbSA_COMP(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config), c5(3.5) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CConfig* config) { + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Compressibility Correction term ---*/ + Pressure_i = V_i[nDim+1]; + SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); + aux_cc=0; + for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_E::CSourcePieceWise_TurbSA_E(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConfig* config) { + + unsigned short iDim, jDim; + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /* + From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html + This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: + Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. + In this modificaton Omega is replaced by Strain Rate + */ + + /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ + + Sbar = 0.0; + for(iDim=0;iDim 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + //Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); + + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r=tanh(r)/tanh(1.0); + + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + + // AD::SetPreaccOut(Residual); + // AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_E_COMP::CSourcePieceWise_TurbSA_E_COMP(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const CConfig* config) { + + unsigned short iDim; + + // AD::StartPreacc(); + // AD::SetPreaccIn(V_i, nDim+6); + // AD::SetPreaccIn(Vorticity_i, nDim); + // AD::SetPreaccIn(StrainMag_i); + // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /* + From NASA Turbulence model site. http://turbmodels.larc.nasa.gov/spalart.html + This form was developed primarily to improve the near-wall numerical behavior of the model (i.e., the goal was to improve the convergence behavior). The reference is: + Edwards, J. R. and Chandra, S. "Comparison of Eddy Viscosity-Transport Turbulence Models for Three-Dimensional, Shock-Separated Flowfields," AIAA Journal, Vol. 34, No. 4, 1996, pp. 756-763. + In this modificaton Omega is replaced by Strain Rate + */ + + /*--- Evaluate Omega, here Omega is the Strain Rate ---*/ + + Sbar = 0.0; + for(iDim=0;iDim 1e-10) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); + + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r=tanh(r)/tanh(1.0); + + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Compressibility Correction term ---*/ + Pressure_i = V_i[nDim+1]; + SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); + aux_cc=0; + for(iDim=0;iDim(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSA_Neg::CSourcePieceWise_TurbSA_Neg(unsigned short val_nDim, + unsigned short val_nVar, + const CConfig* config) : + CSourceBase_TurbSA(val_nDim, val_nVar, config) { } + +CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CConfig* config) { + + unsigned short iDim; + +// AD::StartPreacc(); +// AD::SetPreaccIn(V_i, nDim+6); +// AD::SetPreaccIn(Vorticity_i, nDim); +// AD::SetPreaccIn(StrainMag_i); +// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + + if (incompressible) { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + } + else { + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + } + + Residual = 0.0; + Production = 0.0; + Destruction = 0.0; + CrossProduction = 0.0; + Jacobian_i[0] = 0.0; + + /*--- Evaluate Omega ---*/ + + Omega = sqrt(Vorticity_i[0]*Vorticity_i[0] + Vorticity_i[1]*Vorticity_i[1] + Vorticity_i[2]*Vorticity_i[2]); + + /*--- Rotational correction term ---*/ + + if (rotating_frame) { Omega += 2.0*min(0.0, StrainMag_i-Omega); } + + if (dist_i > 1e-10) { + + if (TurbVar_i[0] > 0.0) { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + nu = Laminar_Viscosity_i/Density_i; + Ji = TurbVar_i[0]/nu; + Ji_2 = Ji*Ji; + Ji_3 = Ji_2*Ji; + fv1 = Ji_3/(Ji_3+cv1_3); + fv2 = 1.0 - Ji/(1.0+Ji*fv1); + ft2 = ct3*exp(-ct4*Ji_2); + S = Omega; + inv_k2_d2 = 1.0/(k2*dist_i_2); + + Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = max(Shat, 1.0e-10); + inv_Shat = 1.0/Shat; + + /*--- Production term ---*/; + + // Original SA model + // Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; + + Production = cb1*Shat*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + g = r + cw2*(pow(r,6.0)-r); + g_6 = pow(g,6.0); + glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); + fw = g*glim; + + Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production - Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); + dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); + if ( Shat <= 1.0e-10 ) dShat = 0.0; + else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; + Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + + /*--- Implicit part, destruction term ---*/ + + dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + if (r == 10.0) dr = 0.0; + dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); + dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); + Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + + } + + else { + + /*--- Production term ---*/ + + dist_i_2 = dist_i*dist_i; + + /*--- Production term ---*/; + + Production = cb1*(1.0-ct3)*Omega*TurbVar_i[0]*Volume; + + /*--- Destruction term ---*/ + + Destruction = cw1*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + + /*--- Diffusion term ---*/ + + norm2_Grad = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + + CrossProduction = cb2_sigma*norm2_Grad*Volume; + + Residual = Production + Destruction + CrossProduction; + + /*--- Implicit part, production term ---*/ + + Jacobian_i[0] += cb1*(1.0-ct3)*Omega*Volume; + + /*--- Implicit part, destruction term ---*/ + + Jacobian_i[0] += 2.0*cw1*TurbVar_i[0]/dist_i_2*Volume; + + } + + } + +// AD::SetPreaccOut(Residual); +// AD::EndPreacc(); + + return ResidualType<>(&Residual, &Jacobian_i, nullptr); + +} + +CSourcePieceWise_TurbSST::CSourcePieceWise_TurbSST(unsigned short val_nDim, + unsigned short val_nVar, + const su2double *constants, + su2double val_kine_Inf, + su2double val_omega_Inf, + const CConfig* config) : + CNumerics(val_nDim, val_nVar, config) { + + incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + sustaining_terms = (config->GetKind_Turb_Model() == SST_SUST); + axisymmetric = config->GetAxisymmetric(); + + /*--- Closure constants ---*/ + sigma_k_1 = constants[0]; + sigma_k_2 = constants[1]; + sigma_w_1 = constants[2]; + sigma_w_2 = constants[3]; + beta_1 = constants[4]; + beta_2 = constants[5]; + beta_star = constants[6]; + a1 = constants[7]; + alfa_1 = constants[8]; + alfa_2 = constants[9]; + + /*--- Set the ambient values of k and omega to the free stream values. ---*/ + kAmb = val_kine_Inf; + omegaAmb = val_omega_Inf; + + /*--- "Allocate" the Jacobian using the static buffer. ---*/ + Jacobian_i[0] = Jacobian_Buffer; + Jacobian_i[1] = Jacobian_Buffer+2; + +} + +CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfig* config) { + + AD::StartPreacc(); + AD::SetPreaccIn(StrainMag_i); + AD::SetPreaccIn(TurbVar_i, nVar); + AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); + AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); + AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); + AD::SetPreaccIn(PrimVar_Grad_i, nDim+1, nDim); + AD::SetPreaccIn(Vorticity_i, 3); + + unsigned short iDim; + su2double alfa_blended, beta_blended; + su2double diverg, pk, pw, zeta; + su2double VorticityMag = sqrt(Vorticity_i[0]*Vorticity_i[0] + + Vorticity_i[1]*Vorticity_i[1] + + Vorticity_i[2]*Vorticity_i[2]); + + if (incompressible) { + AD::SetPreaccIn(V_i, nDim+6); + + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+4]; + Eddy_Viscosity_i = V_i[nDim+5]; + } + else { + AD::SetPreaccIn(V_i, nDim+7); + + Density_i = V_i[nDim+2]; + Laminar_Viscosity_i = V_i[nDim+5]; + Eddy_Viscosity_i = V_i[nDim+6]; + } + + Residual[0] = 0.0; Residual[1] = 0.0; + Jacobian_i[0][0] = 0.0; Jacobian_i[0][1] = 0.0; + Jacobian_i[1][0] = 0.0; Jacobian_i[1][1] = 0.0; + + /*--- Computation of blended constants for the source terms---*/ + + alfa_blended = F1_i*alfa_1 + (1.0 - F1_i)*alfa_2; + beta_blended = F1_i*beta_1 + (1.0 - F1_i)*beta_2; + + if (dist_i > 1e-10) { + + /*--- Production ---*/ + + diverg = 0.0; + for (iDim = 0; iDim < nDim; iDim++) + diverg += PrimVar_Grad_i[iDim+1][iDim]; + + /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ + + if (using_uq){ + ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, + PrimVar_Grad_i+1, Density_i, Eddy_Viscosity_i, + TurbVar_i[0], MeanPerturbedRSM); + SetPerturbedStrainMag(TurbVar_i[0]); + pk = Eddy_Viscosity_i*PerturbedStrainMag*PerturbedStrainMag + - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + } + else { + pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + } + + pk = min(pk,20.0*beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]); + pk = max(pk,0.0); + + zeta = max(TurbVar_i[1], VorticityMag*F2_i/a1); + + /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ + + if (using_uq){ + pw = PerturbedStrainMag * PerturbedStrainMag - 2.0/3.0*zeta*diverg; + } + else { + pw = StrainMag_i*StrainMag_i - 2.0/3.0*zeta*diverg; + } + pw = alfa_blended*Density_i*max(pw,0.0); + + /*--- Sustaining terms, if desired. Note that if the production terms are + larger equal than the sustaining terms, the original formulation is + obtained again. This is in contrast to the version in literature + where the sustaining terms are simply added. This latter approach could + lead to problems for very big values of the free-stream turbulence + intensity. ---*/ + + if ( sustaining_terms ) { + const su2double sust_k = beta_star*Density_i*kAmb*omegaAmb; + const su2double sust_w = beta_blended*Density_i*omegaAmb*omegaAmb; + + pk = max(pk, sust_k); + pw = max(pw, sust_w); + } + + /*--- Add the production terms to the residuals. ---*/ + + Residual[0] += pk*Volume; + Residual[1] += pw*Volume; + + /*--- Dissipation ---*/ + + Residual[0] -= beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]*Volume; + Residual[1] -= beta_blended*Density_i*TurbVar_i[1]*TurbVar_i[1]*Volume; + + /*--- Cross diffusion ---*/ + + Residual[1] += (1.0 - F1_i)*CDkw_i*Volume; + + /*--- Contribution due to 2D axisymmetric formulation ---*/ + + if (axisymmetric) ResidualAxisymmetric(alfa_blended,zeta); + + /*--- Implicit part ---*/ + + Jacobian_i[0][0] = -beta_star*TurbVar_i[1]*Volume; + Jacobian_i[0][1] = -beta_star*TurbVar_i[0]*Volume; + Jacobian_i[1][0] = 0.0; + Jacobian_i[1][1] = -2.0*beta_blended*TurbVar_i[1]*Volume; + } + + AD::SetPreaccOut(Residual, nVar); + AD::EndPreacc(); + + return ResidualType<>(Residual, Jacobian_i, nullptr); + +} + +void CSourcePieceWise_TurbSST::SetPerturbedStrainMag(su2double turb_ke){ + + /*--- Compute norm of perturbed strain rate tensor. ---*/ + + PerturbedStrainMag = 0; + for (unsigned short iDim = 0; iDim < nDim; iDim++){ + for (unsigned short jDim = 0; jDim < nDim; jDim++){ + su2double StrainRate_ij = MeanPerturbedRSM[iDim][jDim] - TWO3 * turb_ke * delta[iDim][jDim]; + StrainRate_ij = - StrainRate_ij * Density_i / (2 * Eddy_Viscosity_i); + + PerturbedStrainMag += pow(StrainRate_ij, 2.0); + } + } + PerturbedStrainMag = sqrt(2.0*PerturbedStrainMag); + +} From 51bbc8450e70fdfcf82eee273a536ddf530e74da Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 23 Aug 2021 18:19:33 +0200 Subject: [PATCH 06/48] Move muT and HBSources back to Turb Solver --- SU2_CFD/include/variables/CScalarVariable.hpp | 16 ---------------- SU2_CFD/include/variables/CTurbVariable.hpp | 19 +++++++++++++++++++ SU2_CFD/src/variables/CScalarVariable.cpp | 6 ------ SU2_CFD/src/variables/CTurbVariable.cpp | 5 +++++ 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 2542ab2733cd..7713e7ecf939 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -37,8 +37,6 @@ */ class CScalarVariable : public CVariable { protected: - VectorType muT; /*!< \brief Eddy viscosity. */ - MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */ CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ @@ -58,20 +56,6 @@ class CScalarVariable : public CVariable { */ ~CScalarVariable() override = default; - /*! - * \brief Get the value of the eddy viscosity. - * \param[in] iPoint - Point index. - * \return the value of the eddy viscosity. - */ - inline su2double GetmuT(unsigned long iPoint) const final { return muT(iPoint); } - - /*! - * \brief Set the value of the eddy viscosity. - * \param[in] iPoint - Point index. - * \param[in] val_muT - Value of the eddy viscosity. - */ - inline void SetmuT(unsigned long iPoint, su2double val_muT) final { muT(iPoint) = val_muT; } - /*! * \brief Get the array of the reconstruction variables gradient at a node. * \param[in] iPoint - Index of the current node. diff --git a/SU2_CFD/include/variables/CTurbVariable.hpp b/SU2_CFD/include/variables/CTurbVariable.hpp index 50b89dadb812..995f8a269cd1 100644 --- a/SU2_CFD/include/variables/CTurbVariable.hpp +++ b/SU2_CFD/include/variables/CTurbVariable.hpp @@ -36,6 +36,11 @@ * \author A. Bueno. */ class CTurbVariable : public CScalarVariable { +protected: + + VectorType muT; /*!< \brief Eddy viscosity. */ + MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ + public: /*! * \brief Constructor of the class. @@ -51,5 +56,19 @@ class CTurbVariable : public CScalarVariable { */ ~CTurbVariable() override = default; + /*! + * \brief Get the value of the eddy viscosity. + * \param[in] iPoint - Point index. + * \return the value of the eddy viscosity. + */ + inline su2double GetmuT(unsigned long iPoint) const final { return muT(iPoint); } + + /*! + * \brief Set the value of the eddy viscosity. + * \param[in] iPoint - Point index. + * \param[in] val_muT - Value of the eddy viscosity. + */ + inline void SetmuT(unsigned long iPoint, su2double val_muT) final { muT(iPoint) = val_muT; } + }; diff --git a/SU2_CFD/src/variables/CScalarVariable.cpp b/SU2_CFD/src/variables/CScalarVariable.cpp index b4087252d24e..2a2bde7d6782 100644 --- a/SU2_CFD/src/variables/CScalarVariable.cpp +++ b/SU2_CFD/src/variables/CScalarVariable.cpp @@ -32,12 +32,6 @@ CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) : CVariable(npoint, ndim, nvar, config), Gradient_Reconstruction(config->GetReconstructionGradientRequired() ? Gradient_Aux : Gradient) { - /*--- Allocate space for the harmonic balance source terms ---*/ - - if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { - HB_Source.resize(nPoint,nVar) = su2double(0.0); - } - /*--- Gradient related fields ---*/ Gradient.resize(nPoint,nVar,nDim,0.0); diff --git a/SU2_CFD/src/variables/CTurbVariable.cpp b/SU2_CFD/src/variables/CTurbVariable.cpp index d1ea6fa7cdad..4fc27d2f09f3 100644 --- a/SU2_CFD/src/variables/CTurbVariable.cpp +++ b/SU2_CFD/src/variables/CTurbVariable.cpp @@ -32,4 +32,9 @@ CTurbVariable::CTurbVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) : CScalarVariable(npoint, ndim, nvar, config) { + /*--- Allocate space for the harmonic balance source terms ---*/ + if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { + HB_Source.resize(nPoint,nVar) = su2double(0.0); + } + } From bf1201775f090f7449a448b445c3d1b322bc7326 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 23 Aug 2021 19:14:06 +0200 Subject: [PATCH 07/48] Push some Functions back from CScalarSolver to CTurbSolver. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 70 ++++---- SU2_CFD/include/solvers/CTurbSolver.hpp | 166 +++++++++++++++++ SU2_CFD/src/solvers/CScalarSolver.cpp | 206 +--------------------- SU2_CFD/src/solvers/CTurbSolver.cpp | 205 ++++++++++++++++++++- 4 files changed, 400 insertions(+), 247 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index d60bdbac89d5..2ba417255b5f 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -53,15 +53,9 @@ class CScalarSolver : public CSolver { upperlimit[MAXNVAR] = {0.0}, /*!< \brief contains upper limits for turbulence variables. */ Gamma, /*!< \brief Fluid's Gamma constant (ratio of specific heats). */ Gamma_Minus_One; /*!< \brief Fluids's Gamma - 1.0 . */ - vector Inlet_TurbVars; /*!< \brief Turbulence variables at inlet profiles */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ - /*--- Sliding meshes variables. ---*/ - - vector > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone) - vector > SlidingStateNodes; - /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ #ifdef HAVE_OMP @@ -193,7 +187,9 @@ class CScalarSolver : public CSolver { CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, - unsigned short val_marker) final; + unsigned short val_marker) override{ + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Impose via the residual the Euler wall boundary condition. @@ -208,7 +204,9 @@ class CScalarSolver : public CSolver { CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, - unsigned short val_marker) final; + unsigned short val_marker) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Impose via the residual the Euler wall boundary condition. @@ -223,7 +221,9 @@ class CScalarSolver : public CSolver { CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, - unsigned short val_marker) final; + unsigned short val_marker) override{ + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Impose a periodic boundary condition by summing contributions from the complete control volume. @@ -249,8 +249,9 @@ class CScalarSolver : public CSolver { CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, - CConfig *config) final; - + CConfig *config) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Set the solution using the Freestream values. * \param[in] config - Definition of the particular problem. @@ -268,7 +269,9 @@ class CScalarSolver : public CSolver { * \details Turbulence quantities are set to far-field values in an upstream half-plane * in order to keep them from decaying. */ - void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) final; + void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Prepare an implicit iteration. @@ -336,8 +339,9 @@ class CScalarSolver : public CSolver { inline su2double GetSlidingState(unsigned short val_marker, unsigned long val_vertex, unsigned short val_state, - unsigned long donor_index) const final { - return SlidingState[val_marker][val_vertex][val_state][donor_index]; + unsigned long donor_index) const override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + return 0.0; } /*! @@ -345,16 +349,8 @@ class CScalarSolver : public CSolver { * \param[in] val_marker - marker index * \param[in] val_vertex - vertex index */ - inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) final { - int iVar; - - for( iVar = 0; iVar < nVar+1; iVar++){ - if( SlidingState[val_marker][val_vertex][iVar] != nullptr ) - delete [] SlidingState[val_marker][val_vertex][iVar]; - } - - for( iVar = 0; iVar < nVar+1; iVar++) - SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ]; + inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); } @@ -370,8 +366,8 @@ class CScalarSolver : public CSolver { unsigned long val_vertex, unsigned short val_state, unsigned long donor_index, - su2double component) final { - SlidingState[val_marker][val_vertex][val_state][donor_index] = component; + su2double component) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); } @@ -383,15 +379,18 @@ class CScalarSolver : public CSolver { */ inline void SetnSlidingStates(unsigned short val_marker, unsigned long val_vertex, - int value) final { SlidingStateNodes[val_marker][val_vertex] = value; } + int value) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + } /*! * \brief Get the number of outer state for fluid interface nodes. * \param[in] val_marker - marker index * \param[in] val_vertex - vertex index */ - inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const final { - return SlidingStateNodes[val_marker][val_vertex]; + inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); + return 0; } /*! @@ -404,17 +403,8 @@ class CScalarSolver : public CSolver { inline void SetInlet_TurbVar(unsigned short val_marker, unsigned long val_vertex, unsigned short val_dim, - su2double val_turb_var) final { - /*--- Since this call can be accessed indirectly using python, do some error - * checking to prevent segmentation faults ---*/ - if (val_marker >= nMarker) - SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION); - else if (val_vertex >= nVertex[val_marker]) - SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION); - else if (val_dim >= nVar) - SU2_MPI::Error("Out-of-bounds index used for inlet turbulence variable.", CURRENT_FUNCTION); - else - Inlet_TurbVars[val_marker][val_vertex][val_dim] = val_turb_var; + su2double val_turb_var) override { + SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); } /*! diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index 4c5180007755..895767bc70aa 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -38,6 +38,16 @@ * \author A. Bueno. */ class CTurbSolver : public CScalarSolver { +protected: + + vector Inlet_TurbVars; /*!< \brief Turbulence variables at inlet profiles */ + + /*--- Sliding meshes variables. ---*/ + + vector > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone) + vector > SlidingStateNodes; + + public: /*! @@ -57,4 +67,160 @@ class CTurbSolver : public CScalarSolver { */ CTurbSolver(CGeometry* geometry, CConfig *config); + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Riemann(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_TurboRiemann(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose via the residual the Euler wall boundary condition. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \param[in] val_marker - Surface marker where the boundary condition is applied. + */ + void BC_Giles(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) final; + + /*! + * \brief Impose the fluid interface boundary condition using tranfer data. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] conv_numerics - Description of the numerical method. + * \param[in] visc_numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + */ + void BC_Fluid_Interface(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config) final; + + /*! + * \brief Impose fixed values to turbulence quantities. + * \details Turbulence quantities are set to far-field values in an upstream half-plane + * in order to keep them from decaying. + */ + void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) final; + + /*! + * \brief Get the outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] val_state - requested state component + * \param[in] donor_index- index of the donor node to get + */ + inline su2double GetSlidingState(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_state, + unsigned long donor_index) const final { + return SlidingState[val_marker][val_vertex][val_state][donor_index]; + } + + /*! + * \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it. That number is stored in SlidingStateNodes[val_marker][val_vertex]. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + */ + inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) final { + int iVar; + + for( iVar = 0; iVar < nVar+1; iVar++){ + if( SlidingState[val_marker][val_vertex][iVar] != nullptr ) + delete [] SlidingState[val_marker][val_vertex][iVar]; + } + + for( iVar = 0; iVar < nVar+1; iVar++) + SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ]; + } + + /*! + * \brief Set the outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] val_state - requested state component + * \param[in] donor_index - index of the donor node to set + * \param[in] component - set value + */ + inline void SetSlidingState(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_state, + unsigned long donor_index, + su2double component) final { + SlidingState[val_marker][val_vertex][val_state][donor_index] = component; + } + + + /*! + * \brief Set the number of outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + * \param[in] value - number of outer states + */ + inline void SetnSlidingStates(unsigned short val_marker, + unsigned long val_vertex, + int value) final { SlidingStateNodes[val_marker][val_vertex] = value; } + + /*! + * \brief Get the number of outer state for fluid interface nodes. + * \param[in] val_marker - marker index + * \param[in] val_vertex - vertex index + */ + inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const final { + return SlidingStateNodes[val_marker][val_vertex]; + } + + /*! + * \brief Set custom turbulence variables at the vertex of an inlet. + * \param[in] iMarker - Marker identifier. + * \param[in] iVertex - Vertex identifier. + * \param[in] iDim - Index of the turbulence variable (i.e. k is 0 in SST) + * \param[in] val_turb_var - Value of the turbulence variable to be used. + */ + inline void SetInlet_TurbVar(unsigned short val_marker, + unsigned long val_vertex, + unsigned short val_dim, + su2double val_turb_var) final { + /*--- Since this call can be accessed indirectly using python, do some error + * checking to prevent segmentation faults ---*/ + if (val_marker >= nMarker) + SU2_MPI::Error("Out-of-bounds marker index used on inlet.", CURRENT_FUNCTION); + else if (val_vertex >= nVertex[val_marker]) + SU2_MPI::Error("Out-of-bounds vertex index used on inlet.", CURRENT_FUNCTION); + else if (val_dim >= nVar) + SU2_MPI::Error("Out-of-bounds index used for inlet turbulence variable.", CURRENT_FUNCTION); + else + Inlet_TurbVars[val_marker][val_vertex][val_dim] = val_turb_var; + } + }; diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 7454b16f0b53..9e76eb7c6362 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -73,11 +73,7 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { #endif } -CScalarSolver::~CScalarSolver(void) { - - for (auto& mat : SlidingState) { - for (auto ptr : mat) delete [] ptr; - } +CScalarSolver::~CScalarSolver() { delete nodes; @@ -342,61 +338,6 @@ void CScalarSolver::BC_Euler_Wall(CGeometry *geometry, } -void CScalarSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Riemann(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: - BC_Inlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case STATIC_PRESSURE: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - -void CScalarSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Riemann(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case STATIC_PRESSURE: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - - -void CScalarSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { - - string Marker_Tag = config->GetMarker_All_TagBound(val_marker); - - switch(config->GetKind_Data_Giles(Marker_Tag)) - { - case TOTAL_CONDITIONS_PT:case TOTAL_CONDITIONS_PT_1D: case DENSITY_VELOCITY: - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - case MIXING_IN: - if (config->GetBoolTurbMixingPlane()){ - BC_Inlet_MixingPlane(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - } - else{ - BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - } - break; - - case STATIC_PRESSURE: case MIXING_OUT: case STATIC_PRESSURE_1D: case RADIAL_EQUILIBRIUM: - BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); - break; - } -} - void CScalarSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, CNumerics *numerics, CConfig *config) { @@ -413,151 +354,6 @@ void CScalarSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, } -void CScalarSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, - CNumerics *visc_numerics, CConfig *config) { - - const bool sst = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); - const auto nPrimVar = solver_container[FLOW_SOL]->GetnPrimVar(); - su2double *PrimVar_j = new su2double[nPrimVar]; - su2double solution_j[MAXNVAR] = {0.0}; - - for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { - - if (config->GetMarker_All_KindBC(iMarker) != FLUID_INTERFACE) continue; - - SU2_OMP_FOR_STAT(OMP_MIN_SIZE) - for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) { - - const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); - - if (!geometry->nodes->GetDomain(iPoint)) continue; - - const auto Point_Normal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor(); - const auto nDonorVertex = GetnSlidingStates(iMarker,iVertex); - - su2double Normal[MAXNDIM] = {0.0}; - for (auto iDim = 0u; iDim < nDim; iDim++) - Normal[iDim] = -geometry->vertex[iMarker][iVertex]->GetNormal()[iDim]; - - su2double* PrimVar_i = solver_container[FLOW_SOL]->GetNodes()->GetPrimitive(iPoint); - - auto Jacobian_i = Jacobian.GetBlock(iPoint,iPoint); - - /*--- Loop over the nDonorVertexes and compute the averaged flux ---*/ - - for (auto jVertex = 0; jVertex < nDonorVertex; jVertex++) { - - for (auto iVar = 0u; iVar < nPrimVar; iVar++) - PrimVar_j[iVar] = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, iVar, jVertex); - - /*--- Get the weight computed in the interpolator class for the j-th donor vertex ---*/ - - const su2double weight = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, nPrimVar, jVertex); - - /*--- Set primitive variables ---*/ - - conv_numerics->SetPrimitive( PrimVar_i, PrimVar_j ); - - /*--- Set the turbulent variable states ---*/ - - for (auto iVar = 0u; iVar < nVar; ++iVar) - solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex); - - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - - /*--- Set the normal vector ---*/ - - conv_numerics->SetNormal(Normal); - - if (dynamic_grid) - conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(iPoint)); - - auto residual = conv_numerics->ComputeResidual(config); - - /*--- Accumulate the residuals to compute the average ---*/ - - for (auto iVar = 0u; iVar < nVar; iVar++) { - LinSysRes(iPoint,iVar) += weight*residual[iVar]; - for (auto jVar = 0u; jVar < nVar; jVar++) - Jacobian_i[iVar*nVar+jVar] += SU2_TYPE::GetValue(weight*residual.jacobian_i[iVar][jVar]); - } - } - - /*--- Set the normal vector and the coordinates ---*/ - - visc_numerics->SetNormal(Normal); - su2double Coord_Reflected[MAXNDIM]; - GeometryToolbox::PointPointReflect(nDim, geometry->nodes->GetCoord(Point_Normal), - geometry->nodes->GetCoord(iPoint), Coord_Reflected); - visc_numerics->SetCoord(geometry->nodes->GetCoord(iPoint), Coord_Reflected); - - /*--- Primitive variables ---*/ - - visc_numerics->SetPrimitive(PrimVar_i, PrimVar_j); - - /*--- Turbulent variables and their gradients ---*/ - - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); - - /*--- Menter's first blending function ---*/ - - if(sst) visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); - - /*--- Compute and update residual ---*/ - - auto residual = visc_numerics->ComputeResidual(config); - - LinSysRes.SubtractBlock(iPoint, residual); - - /*--- Jacobian contribution for implicit integration ---*/ - - Jacobian.SubtractBlock2Diag(iPoint, residual.jacobian_i); - - } - END_SU2_OMP_FOR - } - - delete [] PrimVar_j; - -} - -void CScalarSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config){ - - /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ - if(config->GetTurb_Fixed_Values()){ - - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - - /*--- Form normalized far-field velocity ---*/ - const su2double* velocity_inf = config->GetVelocity_FreeStreamND(); - su2double velmag_inf = GeometryToolbox::Norm(nDim, velocity_inf); - if(velmag_inf==0) - SU2_MPI::Error("Far-field velocity is zero, cannot fix turbulence quantities to inflow values.", CURRENT_FUNCTION); - su2double unit_velocity_inf[MAXNDIM]; - for(unsigned short iDim=0; iDimnodes->GetCoord(iPoint), unit_velocity_inf) - < config->GetTurb_Fixed_Values_MaxScalarProd() ) { - /*--- Set the solution values and zero the residual ---*/ - nodes->SetSolution_Old(iPoint, Solution_Inf); - nodes->SetSolution(iPoint, Solution_Inf); - LinSysRes.SetBlock_Zero(iPoint); - if (implicit) { - /*--- Change rows of the Jacobian (includes 1 in the diagonal) ---*/ - for(unsigned long iVar=0; iVarGetNodes(); diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index ad9a8d534b18..07dcf54b58d9 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -32,10 +32,211 @@ CTurbSolver::CTurbSolver(void) : CScalarSolver() { } -CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config) : CScalarSolver(geometry, config) { +CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config) : CScalarSolver(geometry, config) { } +CTurbSolver::~CTurbSolver() { + + for (auto& mat : SlidingState) { + for (auto ptr : mat) delete [] ptr; + } + +} + +void CTurbSolver::BC_Riemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Riemann(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: + BC_Inlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case STATIC_PRESSURE: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } +} + +void CTurbSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Riemann(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT: case STATIC_SUPERSONIC_INFLOW_PT: case STATIC_SUPERSONIC_INFLOW_PD: case DENSITY_VELOCITY: + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case STATIC_PRESSURE: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } +} + +void CTurbSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { + + string Marker_Tag = config->GetMarker_All_TagBound(val_marker); + + switch(config->GetKind_Data_Giles(Marker_Tag)) + { + case TOTAL_CONDITIONS_PT:case TOTAL_CONDITIONS_PT_1D: case DENSITY_VELOCITY: + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + case MIXING_IN: + if (config->GetBoolTurbMixingPlane()){ + BC_Inlet_MixingPlane(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + } + else{ + BC_Inlet_Turbo(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + } + break; + + case STATIC_PRESSURE: case MIXING_OUT: case STATIC_PRESSURE_1D: case RADIAL_EQUILIBRIUM: + BC_Outlet(geometry, solver_container, conv_numerics, visc_numerics, config, val_marker); + break; + } } -CTurbSolver::~CTurbSolver(void) { +void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, + CNumerics *visc_numerics, CConfig *config) { + + const bool sst = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); + const auto nPrimVar = solver_container[FLOW_SOL]->GetnPrimVar(); + su2double *PrimVar_j = new su2double[nPrimVar]; + su2double solution_j[MAXNVAR] = {0.0}; + + for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) { + + if (config->GetMarker_All_KindBC(iMarker) != FLUID_INTERFACE) continue; + + SU2_OMP_FOR_STAT(OMP_MIN_SIZE) + for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) { + + const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); + + if (!geometry->nodes->GetDomain(iPoint)) continue; + + const auto Point_Normal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor(); + const auto nDonorVertex = GetnSlidingStates(iMarker,iVertex); + + su2double Normal[MAXNDIM] = {0.0}; + for (auto iDim = 0u; iDim < nDim; iDim++) + Normal[iDim] = -geometry->vertex[iMarker][iVertex]->GetNormal()[iDim]; + + su2double* PrimVar_i = solver_container[FLOW_SOL]->GetNodes()->GetPrimitive(iPoint); + + auto Jacobian_i = Jacobian.GetBlock(iPoint,iPoint); + + /*--- Loop over the nDonorVertexes and compute the averaged flux ---*/ + + for (auto jVertex = 0; jVertex < nDonorVertex; jVertex++) { + + for (auto iVar = 0u; iVar < nPrimVar; iVar++) + PrimVar_j[iVar] = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, iVar, jVertex); + + /*--- Get the weight computed in the interpolator class for the j-th donor vertex ---*/ + + const su2double weight = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, nPrimVar, jVertex); + + /*--- Set primitive variables ---*/ + + conv_numerics->SetPrimitive( PrimVar_i, PrimVar_j ); + + /*--- Set the turbulent variable states ---*/ + + for (auto iVar = 0u; iVar < nVar; ++iVar) + solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex); + + conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + + /*--- Set the normal vector ---*/ + + conv_numerics->SetNormal(Normal); + + if (dynamic_grid) + conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(iPoint)); + + auto residual = conv_numerics->ComputeResidual(config); + + /*--- Accumulate the residuals to compute the average ---*/ + + for (auto iVar = 0u; iVar < nVar; iVar++) { + LinSysRes(iPoint,iVar) += weight*residual[iVar]; + for (auto jVar = 0u; jVar < nVar; jVar++) + Jacobian_i[iVar*nVar+jVar] += SU2_TYPE::GetValue(weight*residual.jacobian_i[iVar][jVar]); + } + } + + /*--- Set the normal vector and the coordinates ---*/ + + visc_numerics->SetNormal(Normal); + su2double Coord_Reflected[MAXNDIM]; + GeometryToolbox::PointPointReflect(nDim, geometry->nodes->GetCoord(Point_Normal), + geometry->nodes->GetCoord(iPoint), Coord_Reflected); + visc_numerics->SetCoord(geometry->nodes->GetCoord(iPoint), Coord_Reflected); + + /*--- Primitive variables ---*/ + + visc_numerics->SetPrimitive(PrimVar_i, PrimVar_j); + + /*--- Turbulent variables and their gradients ---*/ + + visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); + + /*--- Menter's first blending function ---*/ + + if(sst) visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); + + /*--- Compute and update residual ---*/ + + auto residual = visc_numerics->ComputeResidual(config); + + LinSysRes.SubtractBlock(iPoint, residual); + + /*--- Jacobian contribution for implicit integration ---*/ + + Jacobian.SubtractBlock2Diag(iPoint, residual.jacobian_i); + + } + END_SU2_OMP_FOR + } + + delete [] PrimVar_j; } + +void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) { + + /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ + if(config->GetTurb_Fixed_Values()){ + + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + + /*--- Form normalized far-field velocity ---*/ + const su2double* velocity_inf = config->GetVelocity_FreeStreamND(); + su2double velmag_inf = GeometryToolbox::Norm(nDim, velocity_inf); + if(velmag_inf==0) + SU2_MPI::Error("Far-field velocity is zero, cannot fix turbulence quantities to inflow values.", CURRENT_FUNCTION); + su2double unit_velocity_inf[MAXNDIM]; + for(unsigned short iDim=0; iDimnodes->GetCoord(iPoint), unit_velocity_inf) + < config->GetTurb_Fixed_Values_MaxScalarProd() ) { + /*--- Set the solution values and zero the residual ---*/ + nodes->SetSolution_Old(iPoint, Solution_Inf); + nodes->SetSolution(iPoint, Solution_Inf); + LinSysRes.SetBlock_Zero(iPoint); + if (implicit) { + /*--- Change rows of the Jacobian (includes 1 in the diagonal) ---*/ + for(unsigned long iVar=0; iVar Date: Mon, 23 Aug 2021 19:14:38 +0200 Subject: [PATCH 08/48] I am just asking some questions :) --- SU2_CFD/src/solvers/CScalarSolver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 9e76eb7c6362..c5f493b2c27d 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -788,7 +788,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c /*--- This is temporary and only valid for constant-density problems: density could also be temperature dependent, but as it is not a part of the solution vector it's neither stored for previous time steps - nor updated with the solution at the end of each iteration. */ + nor updated with the solution at the end of each iteration. */ //TK:: Then we should prohibit that use? Density_nM1 = flowNodes->GetDensity(iPoint); Density_n = flowNodes->GetDensity(iPoint); Density_nP1 = flowNodes->GetDensity(iPoint); @@ -860,7 +860,7 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig unsigned short skipVars = 0; - if (nDim == 2) skipVars += 6; + if (nDim == 2) skipVars += 6; //TK:: Which order to load write, i.e. mean_flow, turb, scalar1, scalar2, ... if (nDim == 3) skipVars += 8; /*--- Adjust the number of solution variables in the incompressible @@ -877,7 +877,7 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig /*--- Load data from the restart into correct containers. ---*/ - unsigned long counter = 0, iPoint_Global = 0; + unsigned long counter = 0, iPoint_Global = 0;//TK::why ouside, not used outside loop... for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { From 411f80742e657eea3d1162508ac5e3ff38b9ceb2 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 23 Aug 2021 19:43:02 +0200 Subject: [PATCH 09/48] A few chores to make the diff smaller. --- .../numerics/turbulent/turb_diffusion.hpp | 3 +- SU2_CFD/include/solvers/CTurbSolver.hpp | 3 +- SU2_CFD/include/variables/CTurbVariable.hpp | 3 +- SU2_CFD/obj/Makefile.am | 1 + .../numerics/turbulent/turb_convection.cpp | 1 - .../src/numerics/turbulent/turb_sources.cpp | 1 - SU2_CFD/src/solvers/CTurbSolver.cpp | 5 +- TestCases/parallel_regression.py | 182 ---------------- TestCases/serial_regression.py | 196 ------------------ 9 files changed, 8 insertions(+), 387 deletions(-) diff --git a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp index cf5723d55586..a3a536f50b91 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_diffusion.hpp @@ -26,9 +26,10 @@ * License along with SU2. If not, see . */ +#pragma once + #include "../scalar/scalar_diffusion.hpp" -#pragma once /*! * \class CAvgGrad_TurbSA diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index 895767bc70aa..f3b9f811dd9f 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -180,7 +180,6 @@ class CTurbSolver : public CScalarSolver { SlidingState[val_marker][val_vertex][val_state][donor_index] = component; } - /*! * \brief Set the number of outer state for fluid interface nodes. * \param[in] val_marker - marker index @@ -200,7 +199,7 @@ class CTurbSolver : public CScalarSolver { return SlidingStateNodes[val_marker][val_vertex]; } - /*! + /*! * \brief Set custom turbulence variables at the vertex of an inlet. * \param[in] iMarker - Marker identifier. * \param[in] iVertex - Vertex identifier. diff --git a/SU2_CFD/include/variables/CTurbVariable.hpp b/SU2_CFD/include/variables/CTurbVariable.hpp index 995f8a269cd1..c5b901f09bd8 100644 --- a/SU2_CFD/include/variables/CTurbVariable.hpp +++ b/SU2_CFD/include/variables/CTurbVariable.hpp @@ -37,7 +37,6 @@ */ class CTurbVariable : public CScalarVariable { protected: - VectorType muT; /*!< \brief Eddy viscosity. */ MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ @@ -56,7 +55,7 @@ class CTurbVariable : public CScalarVariable { */ ~CTurbVariable() override = default; - /*! + /*! * \brief Get the value of the eddy viscosity. * \param[in] iPoint - Point index. * \return the value of the eddy viscosity. diff --git a/SU2_CFD/obj/Makefile.am b/SU2_CFD/obj/Makefile.am index a56369d17092..6d357c966caf 100644 --- a/SU2_CFD/obj/Makefile.am +++ b/SU2_CFD/obj/Makefile.am @@ -106,6 +106,7 @@ libSU2Core_sources = ../src/definition_structure.cpp \ ../src/numerics/continuous_adjoint/adj_convection.cpp \ ../src/numerics/continuous_adjoint/adj_diffusion.cpp \ ../src/numerics/continuous_adjoint/adj_sources.cpp \ + //TK:: add necessary files here in the end when it is clear what will all be added ../src/numerics/turbulent/turb_convection.cpp \ ../src/numerics/turbulent/turb_diffusion.cpp \ ../src/numerics/turbulent/turb_sources.cpp \ diff --git a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp index c7e5fa57e6a7..0755719596ba 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp @@ -71,4 +71,3 @@ void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { Jacobian_j[1][0] = 0.0; Jacobian_j[1][1] = a1; } } - diff --git a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp index 0fd1a6c50868..7b33636c7216 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp @@ -28,7 +28,6 @@ #include "../../../include/numerics/turbulent/turb_sources.hpp" - CSourceBase_TurbSA::CSourceBase_TurbSA(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config) : diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index 07dcf54b58d9..0a42d2ab3116 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -72,6 +72,7 @@ void CTurbSolver::BC_TurboRiemann(CGeometry *geometry, CSolver **solver_containe } } + void CTurbSolver::BC_Giles(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) { string Marker_Tag = config->GetMarker_All_TagBound(val_marker); @@ -205,7 +206,7 @@ void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_conta } -void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) { +void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config){ /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ if(config->GetTurb_Fixed_Values()){ @@ -239,4 +240,4 @@ void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig * END_SU2_OMP_FOR } -} \ No newline at end of file +} diff --git a/TestCases/parallel_regression.py b/TestCases/parallel_regression.py index 500c30f184ef..2d6eb9772609 100644 --- a/TestCases/parallel_regression.py +++ b/TestCases/parallel_regression.py @@ -38,188 +38,6 @@ def main(): test_list = [] - ############################ - ### Incompressible RANS ### - ############################ - - # NACA0012 - inc_turb_naca0012 = TestCase('inc_turb_naca0012') - inc_turb_naca0012.cfg_dir = "incomp_rans/naca0012" - inc_turb_naca0012.cfg_file = "naca0012.cfg" - inc_turb_naca0012.test_iter = 20 - inc_turb_naca0012.test_vals = [-4.788595, -11.040557, -0.000002, 0.309519] - inc_turb_naca0012.su2_exec = "parallel_computation.py -f" - inc_turb_naca0012.timeout = 1600 - inc_turb_naca0012.tol = 0.00001 - test_list.append(inc_turb_naca0012) - - # NACA0012, SST_SUST - inc_turb_naca0012_sst_sust = TestCase('inc_turb_naca0012_sst_sust') - inc_turb_naca0012_sst_sust.cfg_dir = "incomp_rans/naca0012" - inc_turb_naca0012_sst_sust.cfg_file = "naca0012_SST_SUST.cfg" - inc_turb_naca0012_sst_sust.test_iter = 20 - inc_turb_naca0012_sst_sust.test_vals = [-7.276430, 0.145859, -0.000001, 0.312020] - inc_turb_naca0012_sst_sust.su2_exec = "parallel_computation.py -f" - inc_turb_naca0012_sst_sust.timeout = 1600 - inc_turb_naca0012_sst_sust.tol = 0.00001 - test_list.append(inc_turb_naca0012_sst_sust) - - ########################## - ### Compressible RANS ### - ########################## - - # RAE2822 SA - rae2822_sa = TestCase('rae2822_sa') - rae2822_sa.cfg_dir = "rans/rae2822" - rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" - rae2822_sa.test_iter = 20 - rae2822_sa.test_vals = [-2.004689, -5.265793, 0.809463, 0.062016] - rae2822_sa.su2_exec = "parallel_computation.py -f" - rae2822_sa.timeout = 1600 - rae2822_sa.tol = 0.00001 - test_list.append(rae2822_sa) - - # RAE2822 SST - rae2822_sst = TestCase('rae2822_sst') - rae2822_sst.cfg_dir = "rans/rae2822" - rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" - rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-0.510641, 4.870022, 0.813722, 0.062439] - rae2822_sst.su2_exec = "parallel_computation.py -f" - rae2822_sst.timeout = 1600 - rae2822_sst.tol = 0.00001 - test_list.append(rae2822_sst) - - # RAE2822 SST_SUST - rae2822_sst_sust = TestCase('rae2822_sst_sust') - rae2822_sst_sust.cfg_dir = "rans/rae2822" - rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" - rae2822_sst_sust.test_iter = 20 - rae2822_sst_sust.test_vals = [-2.435890, 4.870022, 0.813722, 0.062439] - rae2822_sst_sust.su2_exec = "parallel_computation.py -f" - rae2822_sst_sust.timeout = 1600 - rae2822_sst_sust.tol = 0.00001 - test_list.append(rae2822_sst_sust) - - # Flat plate - turb_flatplate = TestCase('turb_flatplate') - turb_flatplate.cfg_dir = "rans/flatplate" - turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" - turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-4.147548, -6.729213, -0.176227, 0.057731] - turb_flatplate.su2_exec = "parallel_computation.py -f" - turb_flatplate.timeout = 1600 - turb_flatplate.tol = 0.00001 - test_list.append(turb_flatplate) - - # ONERA M6 Wing - turb_oneram6 = TestCase('turb_oneram6') - turb_oneram6.cfg_dir = "rans/oneram6" - turb_oneram6.cfg_file = "turb_ONERAM6.cfg" - turb_oneram6.test_iter = 10 - turb_oneram6.test_vals = [-2.388839, -6.689413, 0.230321, 0.157640] #last 4 columns - turb_oneram6.su2_exec = "parallel_computation.py -f" - turb_oneram6.timeout = 3200 - turb_oneram6.tol = 0.00001 - test_list.append(turb_oneram6) - - # ONERA M6 Wing - Newton-Krylov - turb_oneram6_nk = TestCase('turb_oneram6_nk') - turb_oneram6_nk.cfg_dir = "rans/oneram6" - turb_oneram6_nk.cfg_file = "turb_ONERAM6_nk.cfg" - turb_oneram6_nk.test_iter = 20 - turb_oneram6_nk.test_vals = [-4.892257, -4.514011, -11.432312, 0.221025, 0.045570, 2, -0.899459, 3.1384e+01] - turb_oneram6_nk.su2_exec = "mpirun -n 2 SU2_CFD" - turb_oneram6_nk.timeout = 600 - turb_oneram6_nk.tol = 0.0001 - test_list.append(turb_oneram6_nk) - - # NACA0012 (SA, FUN3D finest grid results: CL=1.0983, CD=0.01242) - turb_naca0012_sa = TestCase('turb_naca0012_sa') - turb_naca0012_sa.cfg_dir = "rans/naca0012" - turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" - turb_naca0012_sa.test_iter = 10 - turb_naca0012_sa.test_vals = [-11.147929, -14.466781, 1.064330, 0.019756] - turb_naca0012_sa.su2_exec = "parallel_computation.py -f" - turb_naca0012_sa.timeout = 3200 - turb_naca0012_sa.tol = 0.00001 - test_list.append(turb_naca0012_sa) - - # NACA0012 (SST, FUN3D finest grid results: CL=1.0840, CD=0.01253) - turb_naca0012_sst = TestCase('turb_naca0012_sst') - turb_naca0012_sst.cfg_dir = "rans/naca0012" - turb_naca0012_sst.cfg_file = "turb_NACA0012_sst.cfg" - turb_naca0012_sst.test_iter = 10 - turb_naca0012_sst.test_vals = [-11.456387, -12.800055, -5.865784, 1.049989, 0.019163, -1.838252] - turb_naca0012_sst.su2_exec = "parallel_computation.py -f" - turb_naca0012_sst.timeout = 3200 - turb_naca0012_sst.tol = 0.00001 - test_list.append(turb_naca0012_sst) - - # NACA0012 (SST_SUST, FUN3D finest grid results: CL=1.0840, CD=0.01253) - turb_naca0012_sst_sust = TestCase('turb_naca0012_sst_sust') - turb_naca0012_sst_sust.cfg_dir = "rans/naca0012" - turb_naca0012_sst_sust.cfg_file = "turb_NACA0012_sst_sust.cfg" - turb_naca0012_sst_sust.test_iter = 10 - turb_naca0012_sst_sust.test_vals = [-11.370785, -12.641676, -5.748419, 1.005233, 0.019017, -2.057144] - turb_naca0012_sst_sust.su2_exec = "parallel_computation.py -f" - turb_naca0012_sst_sust.timeout = 3200 - turb_naca0012_sst_sust.tol = 0.00001 - test_list.append(turb_naca0012_sst_sust) - - # NACA0012 (SST, fixed values for turbulence quantities) - turb_naca0012_sst_fixedvalues = TestCase('turb_naca0012_sst_fixedvalues') - turb_naca0012_sst_fixedvalues.cfg_dir = "rans/naca0012" - turb_naca0012_sst_fixedvalues.cfg_file = "turb_NACA0012_sst_fixedvalues.cfg" - turb_naca0012_sst_fixedvalues.test_iter = 10 - turb_naca0012_sst_fixedvalues.test_vals = [ -5.216685, -9.562448, -1.565778, 1.022393, 0.040542, -3.729648] - turb_naca0012_sst_fixedvalues.su2_exec = "parallel_computation.py -f" - turb_naca0012_sst_fixedvalues.timeout = 3200 - turb_naca0012_sst_fixedvalues.tol = 0.00001 - test_list.append(turb_naca0012_sst_fixedvalues) - - # PROPELLER - propeller = TestCase('propeller') - propeller.cfg_dir = "rans/propeller" - propeller.cfg_file = "propeller.cfg" - propeller.test_iter = 10 - propeller.test_vals = [-3.389575, -8.409529, 0.000048, 0.056329] #last 4 columns - propeller.su2_exec = "parallel_computation.py -f" - propeller.timeout = 3200 - propeller.tol = 0.00001 - test_list.append(propeller) - - ####################################### - ### Axisymmetric Compressible RANS ### - ####################################### - - # Axisymmetric air nozzle (transonic) - axi_rans_air_nozzle = TestCase('axi_rans_air_nozzle') - axi_rans_air_nozzle.cfg_dir = "axisymmetric_rans/air_nozzle" - axi_rans_air_nozzle.cfg_file = "air_nozzle.cfg" - axi_rans_air_nozzle.test_iter = 10 - axi_rans_air_nozzle.test_vals = [-6.278454, -0.744813, -2.243285, 2.312481] - axi_rans_air_nozzle.su2_exec = "mpirun -n 2 SU2_CFD" - axi_rans_air_nozzle.timeout = 1600 - axi_rans_air_nozzle.tol = 0.0001 - test_list.append(axi_rans_air_nozzle) - - ################################# - ## Compressible RANS Restart ### - ################################# - - # NACA0012 SST Multigrid restart - turb_naca0012_sst_restart_mg = TestCase('turb_naca0012_sst_restart_mg') - turb_naca0012_sst_restart_mg.cfg_dir = "rans/naca0012" - turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" - turb_naca0012_sst_restart_mg.test_iter = 20 - turb_naca0012_sst_restart_mg.ntest_vals = 5 - turb_naca0012_sst_restart_mg.test_vals = [-7.619889, -7.729499, -1.981039, -0.000016, 0.079062] - turb_naca0012_sst_restart_mg.su2_exec = "parallel_computation.py -f" - turb_naca0012_sst_restart_mg.timeout = 3200 - turb_naca0012_sst_restart_mg.tol = 0.000001 - test_list.append(turb_naca0012_sst_restart_mg) - ######################### ## NEMO solver ### ######################### diff --git a/TestCases/serial_regression.py b/TestCases/serial_regression.py index 248d0f7bc47f..c7576f3999e9 100644 --- a/TestCases/serial_regression.py +++ b/TestCases/serial_regression.py @@ -36,202 +36,6 @@ def main(): test_list = [] - ############################ - ### Incompressible RANS ### - ############################ - - # Dry run Inc. RANS - inc_turb_naca0012_d = TestCase('dry run Inc. RANS') - inc_turb_naca0012_d.cfg_dir = "incomp_rans/naca0012" - inc_turb_naca0012_d.cfg_file = "naca0012.cfg" - inc_turb_naca0012_d.su2_exec = "SU2_CFD -d" - inc_turb_naca0012_d.timeout = 1600 - test_list.append(inc_turb_naca0012_d) - - # NACA0012, SA - inc_turb_naca0012 = TestCase('inc_turb_naca0012') - inc_turb_naca0012.cfg_dir = "incomp_rans/naca0012" - inc_turb_naca0012.cfg_file = "naca0012.cfg" - inc_turb_naca0012.test_iter = 20 - inc_turb_naca0012.test_vals = [-4.788495, -11.040511, 0.000023, 0.309503] #last 4 columns - inc_turb_naca0012.new_output = True - inc_turb_naca0012.su2_exec = "SU2_CFD" - inc_turb_naca0012.timeout = 1600 - inc_turb_naca0012.tol = 0.00001 - test_list.append(inc_turb_naca0012) - - # NACA0012, SST_SUST - inc_turb_naca0012_sst_sust = TestCase('inc_turb_naca0012_sst_sust') - inc_turb_naca0012_sst_sust.cfg_dir = "incomp_rans/naca0012" - inc_turb_naca0012_sst_sust.cfg_file = "naca0012_SST_SUST.cfg" - inc_turb_naca0012_sst_sust.test_iter = 20 - inc_turb_naca0012_sst_sust.test_vals = [-7.276273, 0.145895, 0.000021, 0.312004] #last 4 columns - inc_turb_naca0012_sst_sust.su2_exec = "SU2_CFD" - inc_turb_naca0012_sst_sust.timeout = 1600 - inc_turb_naca0012_sst_sust.tol = 0.00001 - test_list.append(inc_turb_naca0012_sst_sust) - - ########################## - ### Compressible RANS ### - ########################## - - # Dry run RANS - rae2822_sa_d = TestCase('dry run RANS') - rae2822_sa_d .cfg_dir = "rans/rae2822" - rae2822_sa_d .cfg_file = "turb_SA_RAE2822.cfg" - rae2822_sa_d .su2_exec = "SU2_CFD -d" - rae2822_sa_d .timeout = 1600 - test_list.append(rae2822_sa_d) - - # RAE2822 SA - rae2822_sa = TestCase('rae2822_sa') - rae2822_sa.cfg_dir = "rans/rae2822" - rae2822_sa.cfg_file = "turb_SA_RAE2822.cfg" - rae2822_sa.test_iter = 20 - rae2822_sa.test_vals = [-2.020123, -5.269330, 0.807147, 0.060499] - rae2822_sa.su2_exec = "SU2_CFD" - rae2822_sa.timeout = 1600 - rae2822_sa.new_output = True - rae2822_sa.tol = 0.00001 - test_list.append(rae2822_sa) - - # RAE2822 SST - rae2822_sst = TestCase('rae2822_sst') - rae2822_sst.cfg_dir = "rans/rae2822" - rae2822_sst.cfg_file = "turb_SST_RAE2822.cfg" - rae2822_sst.test_iter = 20 - rae2822_sst.test_vals = [-0.510639, 4.872266, 0.812659, 0.061095] - rae2822_sst.su2_exec = "SU2_CFD" - rae2822_sst.new_output = True - rae2822_sst.timeout = 1600 - rae2822_sst.tol = 0.00001 - test_list.append(rae2822_sst) - - # RAE2822 SST_SUST - rae2822_sst_sust = TestCase('rae2822_sst_sust') - rae2822_sst_sust.cfg_dir = "rans/rae2822" - rae2822_sst_sust.cfg_file = "turb_SST_SUST_RAE2822.cfg" - rae2822_sst_sust.test_iter = 20 - rae2822_sst_sust.test_vals = [-2.431741, 4.872266, 0.812658, 0.061095] - rae2822_sst_sust.su2_exec = "SU2_CFD" - rae2822_sst_sust.timeout = 1600 - rae2822_sst_sust.tol = 0.00001 - test_list.append(rae2822_sst_sust) - - # Flat plate - turb_flatplate = TestCase('turb_flatplate') - turb_flatplate.cfg_dir = "rans/flatplate" - turb_flatplate.cfg_file = "turb_SA_flatplate.cfg" - turb_flatplate.test_iter = 20 - turb_flatplate.test_vals = [-4.157169, -6.737133, -0.176253, 0.057446] #last 4 columns - turb_flatplate.su2_exec = "SU2_CFD" - turb_flatplate.new_output = True - turb_flatplate.timeout = 1600 - turb_flatplate.tol = 0.00001 - test_list.append(turb_flatplate) - - # ONERA M6 Wing - turb_oneram6 = TestCase('turb_oneram6') - turb_oneram6.cfg_dir = "rans/oneram6" - turb_oneram6.cfg_file = "turb_ONERAM6.cfg" - turb_oneram6.test_iter = 10 - turb_oneram6.test_vals = [-2.388841, -6.689414, 0.230321, 0.157640]#last 4 columns - turb_oneram6.su2_exec = "SU2_CFD" - turb_oneram6.new_output = True - turb_oneram6.timeout = 3200 - turb_oneram6.tol = 0.00001 - test_list.append(turb_oneram6) - - # NACA0012 (SA, FUN3D results for finest grid: CL=1.0983, CD=0.01242) - turb_naca0012_sa = TestCase('turb_naca0012_sa') - turb_naca0012_sa.cfg_dir = "rans/naca0012" - turb_naca0012_sa.cfg_file = "turb_NACA0012_sa.cfg" - turb_naca0012_sa.test_iter = 10 - turb_naca0012_sa.test_vals = [-11.133933, -14.498178, 1.064330, 0.019756] - turb_naca0012_sa.su2_exec = "SU2_CFD" - turb_naca0012_sa.new_output = True - turb_naca0012_sa.timeout = 3200 - turb_naca0012_sa.tol = 0.00001 - test_list.append(turb_naca0012_sa) - - # NACA0012 (SST, FUN3D results for finest grid: CL=1.0840, CD=0.01253) - turb_naca0012_sst = TestCase('turb_naca0012_sst') - turb_naca0012_sst.cfg_dir = "rans/naca0012" - turb_naca0012_sst.cfg_file = "turb_NACA0012_sst.cfg" - turb_naca0012_sst.test_iter = 10 - turb_naca0012_sst.test_vals = [-11.451010, -12.798258, -5.863895, 1.049989, 0.019163, -1.925018] - turb_naca0012_sst.su2_exec = "SU2_CFD" - turb_naca0012_sst.new_output = True - turb_naca0012_sst.timeout = 3200 - turb_naca0012_sst.tol = 0.00001 - test_list.append(turb_naca0012_sst) - - # NACA0012 (SST_SUST, FUN3D results for finest grid: CL=1.0840, CD=0.01253) - turb_naca0012_sst_sust = TestCase('turb_naca0012_sst_sust') - turb_naca0012_sst_sust.cfg_dir = "rans/naca0012" - turb_naca0012_sst_sust.cfg_file = "turb_NACA0012_sst_sust.cfg" - turb_naca0012_sst_sust.test_iter = 10 - turb_naca0012_sst_sust.test_vals = [-11.367386, -12.640857, -5.747260, 1.005233, 0.019017, -1.985871] - turb_naca0012_sst_sust.su2_exec = "SU2_CFD" - turb_naca0012_sst_sust.timeout = 3200 - turb_naca0012_sst_sust.tol = 0.00001 - test_list.append(turb_naca0012_sst_sust) - - # NACA0012 (SST, fixed values for turbulence quantities) - turb_naca0012_sst_fixedvalues = TestCase('turb_naca0012_sst_fixedvalues') - turb_naca0012_sst_fixedvalues.cfg_dir = "rans/naca0012" - turb_naca0012_sst_fixedvalues.cfg_file = "turb_NACA0012_sst_fixedvalues.cfg" - turb_naca0012_sst_fixedvalues.test_iter = 10 - turb_naca0012_sst_fixedvalues.test_vals = [-5.206744, -9.562435, -1.566603, 1.022029, 0.040549, -3.483576] - turb_naca0012_sst_fixedvalues.su2_exec = "SU2_CFD" - turb_naca0012_sst_fixedvalues.timeout = 3200 - turb_naca0012_sst_fixedvalues.tol = 0.00001 - test_list.append(turb_naca0012_sst_fixedvalues) - - # PROPELLER - propeller = TestCase('propeller') - propeller.cfg_dir = "rans/propeller" - propeller.cfg_file = "propeller.cfg" - propeller.test_iter = 10 - propeller.test_vals = [-3.389575, -8.409529, 0.000048, 0.056329] #last 4 columns - propeller.su2_exec = "SU2_CFD" - propeller.new_output = True - propeller.timeout = 3200 - propeller.tol = 0.00001 - test_list.append(propeller) - - ####################################### - ### Axisymmetric Compressible RANS ### - ####################################### - - # Axisymmetric air nozzle (transonic) - axi_rans_air_nozzle = TestCase('axi_rans_air_nozzle') - axi_rans_air_nozzle.cfg_dir = "axisymmetric_rans/air_nozzle" - axi_rans_air_nozzle.cfg_file = "air_nozzle.cfg" - axi_rans_air_nozzle.test_iter = 10 - axi_rans_air_nozzle.test_vals = [ -6.279299, -0.747627, -2.237638, 2.321596] - axi_rans_air_nozzle.su2_exec = "SU2_CFD" - axi_rans_air_nozzle.timeout = 1600 - axi_rans_air_nozzle.tol = 0.0001 - test_list.append(axi_rans_air_nozzle) - - ################################# - ## Compressible RANS Restart ### - ################################# - - # NACA0012 SST Multigrid restart - turb_naca0012_sst_restart_mg = TestCase('turb_naca0012_sst_restart_mg') - turb_naca0012_sst_restart_mg.cfg_dir = "rans/naca0012" - turb_naca0012_sst_restart_mg.cfg_file = "turb_NACA0012_sst_multigrid_restart.cfg" - turb_naca0012_sst_restart_mg.test_iter = 50 - turb_naca0012_sst_restart_mg.ntest_vals = 5 - turb_naca0012_sst_restart_mg.test_vals = [-7.653235, -7.729550, -1.981855, -0.000015, 0.079061] - turb_naca0012_sst_restart_mg.su2_exec = "SU2_CFD" - turb_naca0012_sst_restart_mg.new_output = True - turb_naca0012_sst_restart_mg.timeout = 3200 - turb_naca0012_sst_restart_mg.tol = 0.000001 - test_list.append(turb_naca0012_sst_restart_mg) - ######################### ## NEMO solver ### ######################### From 8d16256f3a933d78f6ccb98e7d3302bb7ca8f708 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 23 Aug 2021 19:47:12 +0200 Subject: [PATCH 10/48] Delete some uncessary functions. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 152 ---------------------- 1 file changed, 152 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 2ba417255b5f..74130a8ff91a 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -174,56 +174,6 @@ class CScalarSolver : public CSolver { CNumerics *visc_numerics, CConfig *config, unsigned short val_marker) override; - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Riemann(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override{ - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_TurboRiemann(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - - /*! - * \brief Impose via the residual the Euler wall boundary condition. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - * \param[in] val_marker - Surface marker where the boundary condition is applied. - */ - void BC_Giles(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override{ - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } /*! * \brief Impose a periodic boundary condition by summing contributions from the complete control volume. @@ -237,21 +187,6 @@ class CScalarSolver : public CSolver { CNumerics *numerics, CConfig *config) final; - /*! - * \brief Impose the fluid interface boundary condition using tranfer data. - * \param[in] geometry - Geometrical definition of the problem. - * \param[in] solver_container - Container vector with all the solutions. - * \param[in] conv_numerics - Description of the numerical method. - * \param[in] visc_numerics - Description of the numerical method. - * \param[in] config - Definition of the particular problem. - */ - void BC_Fluid_Interface(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } /*! * \brief Set the solution using the Freestream values. * \param[in] config - Definition of the particular problem. @@ -264,15 +199,6 @@ class CScalarSolver : public CSolver { END_SU2_OMP_FOR } - /*! - * \brief Impose fixed values to turbulence quantities. - * \details Turbulence quantities are set to far-field values in an upstream half-plane - * in order to keep them from decaying. - */ - void Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - /*! * \brief Prepare an implicit iteration. * \param[in] geometry - Geometrical definition of the problem. @@ -329,84 +255,6 @@ class CScalarSolver : public CSolver { int val_iter, bool val_update_geo) final; - /*! - * \brief Get the outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] val_state - requested state component - * \param[in] donor_index- index of the donor node to get - */ - inline su2double GetSlidingState(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_state, - unsigned long donor_index) const override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - return 0.0; - } - - /*! - * \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it. That number is stored in SlidingStateNodes[val_marker][val_vertex]. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - */ - inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - - - /*! - * \brief Set the outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] val_state - requested state component - * \param[in] donor_index - index of the donor node to set - * \param[in] component - set value - */ - inline void SetSlidingState(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_state, - unsigned long donor_index, - su2double component) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - - - /*! - * \brief Set the number of outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - * \param[in] value - number of outer states - */ - inline void SetnSlidingStates(unsigned short val_marker, - unsigned long val_vertex, - int value) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - - /*! - * \brief Get the number of outer state for fluid interface nodes. - * \param[in] val_marker - marker index - * \param[in] val_vertex - vertex index - */ - inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - return 0; - } - - /*! - * \brief Set custom turbulence variables at the vertex of an inlet. - * \param[in] iMarker - Marker identifier. - * \param[in] iVertex - Vertex identifier. - * \param[in] iDim - Index of the turbulence variable (i.e. k is 0 in SST) - * \param[in] val_turb_var - Value of the turbulence variable to be used. - */ - inline void SetInlet_TurbVar(unsigned short val_marker, - unsigned long val_vertex, - unsigned short val_dim, - su2double val_turb_var) override { - SU2_MPI::Error("Function not implemented.", CURRENT_FUNCTION); - } - /*! * \brief SA and SST support OpenMP+MPI. */ From 336852f1341d6487096f5a1d9d022c2af9488e5b Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Mon, 23 Aug 2021 19:53:25 +0200 Subject: [PATCH 11/48] Some very minor changes to make the diff smaller --- SU2_CFD/include/solvers/CTurbSolver.hpp | 2 ++ SU2_CFD/include/variables/CScalarVariable.hpp | 1 - SU2_CFD/include/variables/CTurbVariable.hpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index f3b9f811dd9f..7174eae12f26 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -164,6 +164,7 @@ class CTurbSolver : public CScalarSolver { SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ]; } + /*! * \brief Set the outer state for fluid interface nodes. * \param[in] val_marker - marker index @@ -180,6 +181,7 @@ class CTurbSolver : public CScalarSolver { SlidingState[val_marker][val_vertex][val_state][donor_index] = component; } + /*! * \brief Set the number of outer state for fluid interface nodes. * \param[in] val_marker - marker index diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 7713e7ecf939..0052aa23c239 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -71,4 +71,3 @@ class CScalarVariable : public CVariable { inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; } }; - diff --git a/SU2_CFD/include/variables/CTurbVariable.hpp b/SU2_CFD/include/variables/CTurbVariable.hpp index c5b901f09bd8..7c2838fe7c6e 100644 --- a/SU2_CFD/include/variables/CTurbVariable.hpp +++ b/SU2_CFD/include/variables/CTurbVariable.hpp @@ -37,8 +37,8 @@ */ class CTurbVariable : public CScalarVariable { protected: - VectorType muT; /*!< \brief Eddy viscosity. */ - MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ + VectorType muT; /*!< \brief Eddy viscosity. */ + MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ public: /*! From 98a302e5131eeef47e34cd99eff23db72dd0144b Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 25 Aug 2021 14:16:37 +0200 Subject: [PATCH 12/48] Change SetTurbVar* to SetScalarVar*. --- SU2_CFD/include/numerics/CNumerics.hpp | 26 +++++----- .../src/numerics/turbulent/turb_diffusion.cpp | 4 +- SU2_CFD/src/solvers/CAdjNSSolver.cpp | 6 +-- SU2_CFD/src/solvers/CAdjTurbSolver.cpp | 10 ++-- SU2_CFD/src/solvers/CScalarSolver.cpp | 18 +++---- SU2_CFD/src/solvers/CTurbSASolver.cpp | 50 +++++++++---------- SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 30 +++++------ SU2_CFD/src/solvers/CTurbSolver.cpp | 6 +-- 8 files changed, 75 insertions(+), 75 deletions(-) diff --git a/SU2_CFD/include/numerics/CNumerics.hpp b/SU2_CFD/include/numerics/CNumerics.hpp index 1487f77a14af..d7b69d421319 100644 --- a/SU2_CFD/include/numerics/CNumerics.hpp +++ b/SU2_CFD/include/numerics/CNumerics.hpp @@ -347,13 +347,13 @@ class CNumerics { } /*! - * \brief Set the value of the turbulent variable. - * \param[in] val_turbvar_i - Value of the turbulent variable at point i. - * \param[in] val_turbvar_j - Value of the turbulent variable at point j. + * \brief Set the value of the scalar variable. + * \param[in] val_scalarvar_i - Value of the scalar variable at point i. + * \param[in] val_scalarvar_j - Value of the scalar variable at point j. */ - inline void SetTurbVar(const su2double *val_turbvar_i, const su2double *val_turbvar_j) { - TurbVar_i = val_turbvar_i; - TurbVar_j = val_turbvar_j; + inline void SetScalarVar(const su2double *val_scalarvar_i, const su2double *val_scalarvar_j) { + TurbVar_i = val_scalarvar_i; + TurbVar_j = val_scalarvar_j; } /*! @@ -367,14 +367,14 @@ class CNumerics { } /*! - * \brief Set the gradient of the turbulent variables. - * \param[in] val_turbvar_grad_i - Gradient of the turbulent variable at point i. - * \param[in] val_turbvar_grad_j - Gradient of the turbulent variable at point j. + * \brief Set the gradient of the scalar variables. + * \param[in] val_scalarvar_grad_i - Gradient of the scalar variable at point i. + * \param[in] val_scalarvar_grad_j - Gradient of the scalar variable at point j. */ - inline void SetTurbVarGradient(CMatrixView val_turbvar_grad_i, - CMatrixView val_turbvar_grad_j) { - TurbVar_Grad_i = val_turbvar_grad_i; - TurbVar_Grad_j = val_turbvar_grad_j; + inline void SetScalarVarGradient(CMatrixView val_scalarvar_grad_i, + CMatrixView val_scalarvar_grad_j) { + TurbVar_Grad_i = val_scalarvar_grad_i; + TurbVar_Grad_j = val_scalarvar_grad_j; } /*! diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index 72331c096ccb..07bcecf07384 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -122,7 +122,7 @@ void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { sigma_omega_i = F1_i*sigma_om1 + (1.0 - F1_i)*sigma_om2; sigma_omega_j = F1_j*sigma_om1 + (1.0 - F1_j)*sigma_om2; - /*--- Compute mean effective viscosity ---*/ + /*--- Compute mean effective dynamic viscosity ---*/ diff_i_kine = Laminar_Viscosity_i + sigma_kine_i*Eddy_Viscosity_i; diff_j_kine = Laminar_Viscosity_j + sigma_kine_j*Eddy_Viscosity_j; diff_i_omega = Laminar_Viscosity_i + sigma_omega_i*Eddy_Viscosity_i; @@ -134,7 +134,7 @@ void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; - /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ + /*--- For Jacobians -> Use of TSL (Thin Shear Layer?) approx. to compute derivatives of the gradients ---*/ if (implicit) { su2double proj_on_rho = proj_vector_ij/Density_i; diff --git a/SU2_CFD/src/solvers/CAdjNSSolver.cpp b/SU2_CFD/src/solvers/CAdjNSSolver.cpp index b15490a9c389..611cb9f4b7dc 100644 --- a/SU2_CFD/src/solvers/CAdjNSSolver.cpp +++ b/SU2_CFD/src/solvers/CAdjNSSolver.cpp @@ -485,9 +485,9 @@ void CAdjNSSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain /*--- Turbulent variables w/o reconstruction and its gradient ---*/ - numerics->SetTurbVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), nullptr); + numerics->SetScalarVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), nullptr); - numerics->SetTurbVarGradient(solver_container[TURB_SOL]->GetNodes()->GetGradient(iPoint), nullptr); + numerics->SetScalarVarGradient(solver_container[TURB_SOL]->GetNodes()->GetGradient(iPoint), nullptr); /*--- Turbulent adjoint variables w/o reconstruction and its gradient ---*/ @@ -540,7 +540,7 @@ void CAdjNSSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain /*--- Turbulent variables w/o reconstruction ---*/ - second_numerics->SetTurbVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), + second_numerics->SetScalarVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), solver_container[TURB_SOL]->GetNodes()->GetSolution(jPoint)); /*--- Turbulent adjoint variables w/o reconstruction ---*/ diff --git a/SU2_CFD/src/solvers/CAdjTurbSolver.cpp b/SU2_CFD/src/solvers/CAdjTurbSolver.cpp index b8bf79da0187..d0078319c678 100644 --- a/SU2_CFD/src/solvers/CAdjTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CAdjTurbSolver.cpp @@ -312,7 +312,7 @@ void CAdjTurbSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_conta /*--- Gradient of turbulent variables w/o reconstruction ---*/ const auto TurbVar_Grad_i = solver_container[TURB_SOL]->GetNodes()->GetGradient(iPoint); const auto TurbVar_Grad_j = solver_container[TURB_SOL]->GetNodes()->GetGradient(jPoint); - numerics->SetTurbVarGradient(TurbVar_Grad_i, TurbVar_Grad_j); + numerics->SetScalarVarGradient(TurbVar_Grad_i, TurbVar_Grad_j); /*--- Set normal vectors and length ---*/ numerics->SetNormal(geometry->edges->GetNormal(iEdge)); @@ -354,7 +354,7 @@ void CAdjTurbSolver::Viscous_Residual(CGeometry *geometry, CSolver **solver_cont /*--- Conservative variables w/o reconstruction, turbulent variables w/o reconstruction, and turbulent adjoint variables w/o reconstruction ---*/ numerics->SetConservative(solver_container[FLOW_SOL]->GetNodes()->GetSolution(iPoint), solver_container[FLOW_SOL]->GetNodes()->GetSolution(jPoint)); - numerics->SetTurbVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), solver_container[TURB_SOL]->GetNodes()->GetSolution(jPoint)); + numerics->SetScalarVar(solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint), solver_container[TURB_SOL]->GetNodes()->GetSolution(jPoint)); numerics->SetTurbAdjointVar(nodes->GetSolution(iPoint), nodes->GetSolution(jPoint)); /*--- Viscosity ---*/ @@ -406,11 +406,11 @@ void CAdjTurbSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta /*--- Turbulent variables w/o reconstruction ---*/ TurbVar_i = solver_container[TURB_SOL]->GetNodes()->GetSolution(iPoint); - numerics->SetTurbVar(TurbVar_i, nullptr); + numerics->SetScalarVar(TurbVar_i, nullptr); /*--- Gradient of Turbulent Variables w/o reconstruction ---*/ auto TurbVar_Grad_i = solver_container[TURB_SOL]->GetNodes()->GetGradient(iPoint); - numerics->SetTurbVarGradient(TurbVar_Grad_i, nullptr); + numerics->SetScalarVarGradient(TurbVar_Grad_i, nullptr); /*--- Turbulent adjoint variables w/o reconstruction ---*/ TurbPsi_i = nodes->GetSolution(iPoint); @@ -445,7 +445,7 @@ void CAdjTurbSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta // /*--- Gradient of turbulent variables w/o reconstruction ---*/ // TurbVar_Grad_i = solver_container[TURB_SOL]->GetNodes()->GetGradient(iPoint); // TurbVar_Grad_j = solver_container[TURB_SOL]->GetNodes()->GetGradient(jPoint); -// second_numerics->SetTurbVarGradient(TurbVar_Grad_i, TurbVar_Grad_j); +// second_numerics->SetScalarVarGradient(TurbVar_Grad_i, TurbVar_Grad_j); // // /*--- Turbulent adjoint variables w/o reconstruction ---*/ // TurbPsi_i = nodes->GetSolution(iPoint); diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index c5f493b2c27d..f981ee6a0c2f 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -132,11 +132,11 @@ void CScalarSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contai const auto V_j = flowNodes->GetPrimitive(jPoint); numerics->SetPrimitive(V_i, V_j); - /*--- Turbulent variables w/o reconstruction ---*/ + /*--- Scalar variables w/o reconstruction ---*/ - const auto Turb_i = nodes->GetSolution(iPoint); - const auto Turb_j = nodes->GetSolution(jPoint); - numerics->SetTurbVar(Turb_i, Turb_j); + const auto Scalar_i = nodes->GetSolution(iPoint); + const auto Scalar_j = nodes->GetSolution(jPoint); + numerics->SetScalarVar(Scalar_i, Scalar_j); /*--- Grid Movement ---*/ @@ -204,11 +204,11 @@ void CScalarSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contai Project_Grad_i *= Limiter_i[iVar]; Project_Grad_j *= Limiter_j[iVar]; } - solution_i[iVar] = Turb_i[iVar] + Project_Grad_i; - solution_j[iVar] = Turb_j[iVar] + Project_Grad_j; + solution_i[iVar] = Scalar_i[iVar] + Project_Grad_i; + solution_j[iVar] = Scalar_j[iVar] + Project_Grad_j; } - numerics->SetTurbVar(solution_i, solution_j); + numerics->SetScalarVar(solution_i, solution_j); } } @@ -268,9 +268,9 @@ void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, C /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - numerics->SetTurbVar(nodes->GetSolution(iPoint), + numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(jPoint)); - numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), + numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(jPoint)); /*--- Menter's first blending function (only SST)---*/ diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index b196a0ee8c0d..ce4284696569 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -332,8 +332,8 @@ void CTurbSASolver::Source_Residual(CGeometry *geometry, CSolver **solver_contai /*--- Turbulent variables w/o reconstruction, and its gradient ---*/ - numerics->SetTurbVar(nodes->GetSolution(iPoint), nullptr); - numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nullptr); + numerics->SetScalarVar(nodes->GetSolution(iPoint), nullptr); + numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nullptr); /*--- Set volume ---*/ @@ -528,7 +528,7 @@ void CTurbSASolver::BC_Far_Field(CGeometry *geometry, CSolver **solver_container /*--- Set turbulent variable at the wall, and at infinity ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), Solution_Inf); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), Solution_Inf); /*--- Set Normal (it is necessary to change the sign) ---*/ @@ -588,7 +588,7 @@ void CTurbSASolver::BC_Inlet(CGeometry *geometry, CSolver **solver_container, CN /*--- Load the inlet turbulence variable (uniform by default). ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), Inlet_TurbVars[val_marker][iVertex]); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), Inlet_TurbVars[val_marker][iVertex]); /*--- Set various other quantities in the conv_numerics class ---*/ @@ -621,8 +621,8 @@ void CTurbSASolver::BC_Inlet(CGeometry *geometry, CSolver **solver_container, CN // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(Solution_i, Solution_j); -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVar(Solution_i, Solution_j); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Compute residual, and Jacobians ---*/ // @@ -671,7 +671,7 @@ void CTurbSASolver::BC_Outlet(CGeometry *geometry, CSolver **solver_container, C that the turbulent variable is copied from the interior of the domain to the outlet before computing the residual. ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); /*--- Set Normal (negate for outward convention) ---*/ @@ -707,8 +707,8 @@ void CTurbSASolver::BC_Outlet(CGeometry *geometry, CSolver **solver_container, C // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(Solution_i, Solution_j); -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVar(Solution_i, Solution_j); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Compute residual, and Jacobians ---*/ // @@ -757,7 +757,7 @@ void CTurbSASolver::BC_Engine_Inflow(CGeometry *geometry, CSolver **solver_conta that the turbulent variable is copied from the interior of the domain to the outlet before computing the residual. ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); /*--- Set Normal (negate for outward convention) ---*/ @@ -795,8 +795,8 @@ void CTurbSASolver::BC_Engine_Inflow(CGeometry *geometry, CSolver **solver_conta // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(node[iPoint]->GetSolution(), node[iPoint]->GetSolution()); -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVar(node[iPoint]->GetSolution(), node[iPoint]->GetSolution()); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Compute residual, and Jacobians ---*/ // @@ -850,7 +850,7 @@ void CTurbSASolver::BC_Engine_Exhaust(CGeometry *geometry, CSolver **solver_cont /*--- Set the turbulent variable states (prescribed for an inflow) ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), &nu_tilde_Engine); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), &nu_tilde_Engine); /*--- Set various other quantities in the conv_numerics class ---*/ @@ -885,8 +885,8 @@ void CTurbSASolver::BC_Engine_Exhaust(CGeometry *geometry, CSolver **solver_cont // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(Solution_i, Solution_j); -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVar(Solution_i, Solution_j); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Compute residual, and Jacobians ---*/ // @@ -999,11 +999,11 @@ void CTurbSASolver::BC_ActDisk(CGeometry *geometry, CSolver **solver_container, if (((val_inlet_surface) && (!ReverseFlow)) || ((!val_inlet_surface) && (ReverseFlow))) { /*--- Inflow analysis (interior extrapolation) ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); } else { /*--- Outflow analysis ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), &nu_tilde_ActDisk); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), &nu_tilde_ActDisk); } /*--- Grid Movement ---*/ @@ -1035,9 +1035,9 @@ void CTurbSASolver::BC_ActDisk(CGeometry *geometry, CSolver **solver_container, // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(Solution_i, Solution_j); +// visc_numerics->SetScalarVar(Solution_i, Solution_j); // -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Compute residual, and Jacobians ---*/ // @@ -1098,7 +1098,7 @@ void CTurbSASolver::BC_Inlet_MixingPlane(CGeometry *geometry, CSolver **solver_c /*--- Set the turbulent variable states (prescribed for an inflow) ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), &extAverageNu); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), &extAverageNu); /*--- Set various other quantities in the conv_numerics class ---*/ @@ -1128,9 +1128,9 @@ void CTurbSASolver::BC_Inlet_MixingPlane(CGeometry *geometry, CSolver **solver_c /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), &extAverageNu); + visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), &extAverageNu); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), + visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); /*--- Compute residual, and Jacobians ---*/ @@ -1203,7 +1203,7 @@ void CTurbSASolver::BC_Inlet_Turbo(CGeometry *geometry, CSolver **solver_contain /*--- Set the turbulent variable states (prescribed for an inflow) ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), &nu_tilde); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), &nu_tilde); if (dynamic_grid) conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), @@ -1233,9 +1233,9 @@ void CTurbSASolver::BC_Inlet_Turbo(CGeometry *geometry, CSolver **solver_contain /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), &nu_tilde); + visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), &nu_tilde); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), + visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); /*--- Compute residual, and Jacobians ---*/ diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 5714acf219c9..59443a13e758 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -309,8 +309,8 @@ void CTurbSSTSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta /*--- Turbulent variables w/o reconstruction, and its gradient ---*/ - numerics->SetTurbVar(nodes->GetSolution(iPoint), nullptr); - numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nullptr); + numerics->SetScalarVar(nodes->GetSolution(iPoint), nullptr); + numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nullptr); /*--- Set volume ---*/ @@ -554,7 +554,7 @@ void CTurbSSTSolver::BC_Far_Field(CGeometry *geometry, CSolver **solver_containe /*--- Set turbulent variable at the wall, and at infinity ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), Solution_Inf); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), Solution_Inf); /*--- Set Normal (it is necessary to change the sign) ---*/ @@ -622,7 +622,7 @@ void CTurbSSTSolver::BC_Inlet(CGeometry *geometry, CSolver **solver_container, C values for the turbulent state at the inflow. ---*/ /*--- Load the inlet turbulence variables (uniform by default). ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), Inlet_TurbVars[val_marker][iVertex]); /*--- Set various other quantities in the solver class ---*/ @@ -654,8 +654,8 @@ void CTurbSSTSolver::BC_Inlet(CGeometry *geometry, CSolver **solver_container, C // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // - // visc_numerics->SetTurbVar(Solution_i, Solution_j); - // visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); + // visc_numerics->SetScalarVar(Solution_i, Solution_j); + // visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Menter's first blending function ---*/ // @@ -709,7 +709,7 @@ void CTurbSSTSolver::BC_Outlet(CGeometry *geometry, CSolver **solver_container, that the turbulent variable is copied from the interior of the domain to the outlet before computing the residual. ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint)); /*--- Set Normal (negate for outward convention) ---*/ @@ -746,8 +746,8 @@ void CTurbSSTSolver::BC_Outlet(CGeometry *geometry, CSolver **solver_container, // // /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ // -// visc_numerics->SetTurbVar(Solution_i, Solution_j); -// visc_numerics->SetTurbVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); +// visc_numerics->SetScalarVar(Solution_i, Solution_j); +// visc_numerics->SetScalarVarGradient(node[iPoint]->GetGradient(), node[iPoint]->GetGradient()); // // /*--- Menter's first blending function ---*/ // @@ -818,7 +818,7 @@ void CTurbSSTSolver::BC_Inlet_MixingPlane(CGeometry *geometry, CSolver **solver_ /*--- Set the turbulent variable states (prescribed for an inflow) ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); if (dynamic_grid) conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), @@ -842,8 +842,8 @@ void CTurbSSTSolver::BC_Inlet_MixingPlane(CGeometry *geometry, CSolver **solver_ visc_numerics->SetPrimitive(V_domain, V_inlet); /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); + visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); + visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); /*--- Menter's first blending function ---*/ visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); @@ -928,7 +928,7 @@ void CTurbSSTSolver::BC_Inlet_Turbo(CGeometry *geometry, CSolver **solver_contai /*--- Set the turbulent variable states. Use average span-wise values values for the turbulent state at the inflow. ---*/ - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); if (dynamic_grid) conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), @@ -952,9 +952,9 @@ void CTurbSSTSolver::BC_Inlet_Turbo(CGeometry *geometry, CSolver **solver_contai visc_numerics->SetPrimitive(V_domain, V_inlet); /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); + visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); /*--- Menter's first blending function ---*/ visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint)); diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index 0a42d2ab3116..09633baa551b 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -147,7 +147,7 @@ void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_conta for (auto iVar = 0u; iVar < nVar; ++iVar) solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex); - conv_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); + conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); /*--- Set the normal vector ---*/ @@ -181,8 +181,8 @@ void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_conta /*--- Turbulent variables and their gradients ---*/ - visc_numerics->SetTurbVar(nodes->GetSolution(iPoint), solution_j); - visc_numerics->SetTurbVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); + visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j); + visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint)); /*--- Menter's first blending function ---*/ From 9ba916747d2e18c8a1702b3adf097b7786699e90 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 25 Aug 2021 14:29:31 +0200 Subject: [PATCH 13/48] Changing CNumerics class var TurbVar* to ScalarVar*. --- SU2_CFD/include/numerics/CNumerics.hpp | 8 +- .../numerics/turbulent/turb_sources.hpp | 4 +- .../continuous_adjoint/adj_diffusion.cpp | 12 +- .../continuous_adjoint/adj_sources.cpp | 56 +++---- .../src/numerics/scalar/scalar_convection.cpp | 2 +- .../src/numerics/scalar/scalar_diffusion.cpp | 4 +- SU2_CFD/src/numerics/transition.cpp | 4 +- .../numerics/turbulent/turb_convection.cpp | 6 +- .../src/numerics/turbulent/turb_diffusion.cpp | 4 +- .../src/numerics/turbulent/turb_sources.cpp | 148 +++++++++--------- 10 files changed, 124 insertions(+), 124 deletions(-) diff --git a/SU2_CFD/include/numerics/CNumerics.hpp b/SU2_CFD/include/numerics/CNumerics.hpp index d7b69d421319..68d333c71ed8 100644 --- a/SU2_CFD/include/numerics/CNumerics.hpp +++ b/SU2_CFD/include/numerics/CNumerics.hpp @@ -130,8 +130,8 @@ class CNumerics { *Psi_i, /*!< \brief Vector of adjoint variables at point i. */ *Psi_j; /*!< \brief Vector of adjoint variables at point j. */ const su2double - *TurbVar_i, /*!< \brief Vector of turbulent variables at point i. */ - *TurbVar_j; /*!< \brief Vector of turbulent variables at point j. */ + *ScalarVar_i, /*!< \brief Vector of turbulent variables at point i. */ + *ScalarVar_j; /*!< \brief Vector of turbulent variables at point j. */ const su2double *TransVar_i, /*!< \brief Vector of turbulent variables at point i. */ *TransVar_j; /*!< \brief Vector of turbulent variables at point j. */ @@ -352,8 +352,8 @@ class CNumerics { * \param[in] val_scalarvar_j - Value of the scalar variable at point j. */ inline void SetScalarVar(const su2double *val_scalarvar_i, const su2double *val_scalarvar_j) { - TurbVar_i = val_scalarvar_i; - TurbVar_j = val_scalarvar_j; + ScalarVar_i = val_scalarvar_i; + ScalarVar_j = val_scalarvar_j; } /*! diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp index 0c048bf31cd6..d733eb75f239 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp @@ -346,8 +346,8 @@ class CSourcePieceWise_TurbSST final : public CNumerics { yinv = 1.0/Coord_i[1]; rhov = Density_i*V_i[2]; - k = TurbVar_i[0]; - w = TurbVar_i[1]; + k = ScalarVar_i[0]; + w = ScalarVar_i[1]; /*--- Compute blended constants ---*/ sigma_k_i = F1_i*sigma_k_1+(1.0-F1_i)*sigma_k_2; diff --git a/SU2_CFD/src/numerics/continuous_adjoint/adj_diffusion.cpp b/SU2_CFD/src/numerics/continuous_adjoint/adj_diffusion.cpp index e1d742a679d8..e2772f968698 100644 --- a/SU2_CFD/src/numerics/continuous_adjoint/adj_diffusion.cpp +++ b/SU2_CFD/src/numerics/continuous_adjoint/adj_diffusion.cpp @@ -323,7 +323,7 @@ void CAvgGrad_AdjTurb::ComputeResidual(su2double *val_residual, su2double **val_ /*--- Compute mean effective viscosity ---*/ nu_i = Laminar_Viscosity_i/U_i[0]; nu_j = Laminar_Viscosity_j/U_j[0]; - nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0])/sigma; + nu_e = 0.5*(nu_i+nu_j+ScalarVar_i[0]+ScalarVar_j[0])/sigma; /*--- Compute vector going from iPoint to jPoint ---*/ for (iDim = 0; iDim < nDim; iDim++) { @@ -370,8 +370,8 @@ void CAvgGrad_AdjTurb::ComputeResidual(su2double *val_residual_i, su2double *val /*--- Compute mean effective viscosity ---*/ nu_i = Laminar_Viscosity_i/U_i[0]; nu_j = Laminar_Viscosity_j/U_j[0]; - nu_e_i = (nu_i+TurbVar_i[0])/sigma; - nu_e_j = (nu_j+TurbVar_j[0])/sigma; + nu_e_i = (nu_i+ScalarVar_i[0])/sigma; + nu_e_j = (nu_j+ScalarVar_j[0])/sigma; /*--- Compute vector going from iPoint to jPoint ---*/ for (iDim = 0; iDim < nDim; iDim++) { @@ -444,7 +444,7 @@ void CAvgGradCorrected_AdjTurb::ComputeResidual(su2double *val_residual, su2doub /*--- Compute mean effective viscosity ---*/ nu_i = Laminar_Viscosity_i/U_i[0]; nu_j = Laminar_Viscosity_j/U_j[0]; - nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0])/sigma; + nu_e = 0.5*(nu_i+nu_j+ScalarVar_i[0]+ScalarVar_j[0])/sigma; /*--- Compute vector going from iPoint to jPoint ---*/ for (iDim = 0; iDim < nDim; iDim++) { @@ -495,8 +495,8 @@ void CAvgGradCorrected_AdjTurb::ComputeResidual(su2double *val_residual_i, su2do /*--- Compute mean effective viscosity ---*/ nu_i = Laminar_Viscosity_i/U_i[0]; nu_j = Laminar_Viscosity_j/U_j[0]; - nu_e_i = (nu_i+TurbVar_i[0])/sigma; - nu_e_j = (nu_j+TurbVar_j[0])/sigma; + nu_e_i = (nu_i+ScalarVar_i[0])/sigma; + nu_e_j = (nu_j+ScalarVar_j[0])/sigma; /*--- Compute vector going from iPoint to jPoint ---*/ for (iDim = 0; iDim < nDim; iDim++) { diff --git a/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp b/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp index 10a44e596dce..d5cb0f9c8f73 100644 --- a/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp +++ b/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp @@ -140,15 +140,15 @@ void CSourceConservative_AdjFlow::ComputeResidual (su2double *val_residual, CCon if (dist_i > 0) { dist_sq = dist_i*dist_i; nu = Laminar_Viscosity_i/rho; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); one_o_oneplusJifv1 = 1.0/(1.0+Ji*fv1); fv2 = 1.0 - Ji*one_o_oneplusJifv1; - Shat = max(Omega + TurbVar_i[0]*fv2/(k2*dist_sq), TURB_EPS); + Shat = max(Omega + ScalarVar_i[0]*fv2/(k2*dist_sq), TURB_EPS); - r = min(TurbVar_i[0]/(Shat*k2*dist_sq),10.); + r = min(ScalarVar_i[0]/(Shat*k2*dist_sq),10.); g = r + cw2*(pow(r,6.)-r); g_6 = pow(g,6.); glim = pow((1+cw3_6)/(g_6+cw3_6),1./6.); @@ -156,9 +156,9 @@ void CSourceConservative_AdjFlow::ComputeResidual (su2double *val_residual, CCon dfw_g = glim*cw3_6/(g_6+cw3_6); dg_r = 1.0 + cw2*(6.0*pow(r,5.0)-1.0); dr_nuhat = 1.0/(Shat*k2*dist_sq); - dr_Shat = -dr_nuhat*TurbVar_i[0]/Shat; + dr_Shat = -dr_nuhat*ScalarVar_i[0]/Shat; - Ms_coeff = (cb1*TurbVar_i[0]-cw1*TurbVar_i[0]*TurbVar_i[0]/dist_sq*dfw_g*dg_r*dr_Shat); + Ms_coeff = (cb1*ScalarVar_i[0]-cw1*ScalarVar_i[0]*ScalarVar_i[0]/dist_sq*dfw_g*dg_r*dr_Shat); } Ms_coeff *= TurbPsi_i[0]*invOmega/rho; @@ -195,15 +195,15 @@ void CSourceConservative_AdjFlow::ComputeResidual (su2double *val_residual, CCon if (dist_j > 0) { dist_sq = dist_j*dist_j; nu = Laminar_Viscosity_j/rho; - Ji = TurbVar_j[0]/nu; + Ji = ScalarVar_j[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); one_o_oneplusJifv1 = 1.0/(1.0+Ji*fv1); fv2 = 1.0 - Ji*one_o_oneplusJifv1; - Shat = max(Omega + TurbVar_j[0]*fv2/(k2*dist_sq), TURB_EPS); + Shat = max(Omega + ScalarVar_j[0]*fv2/(k2*dist_sq), TURB_EPS); - r = min(TurbVar_j[0]/(Shat*k2*dist_sq),10.); + r = min(ScalarVar_j[0]/(Shat*k2*dist_sq),10.); g = r + cw2*(pow(r,6.)-r); g_6 = pow(g,6.); glim = pow((1+cw3_6)/(g_6+cw3_6),1./6.); @@ -211,9 +211,9 @@ void CSourceConservative_AdjFlow::ComputeResidual (su2double *val_residual, CCon dfw_g = glim*cw3_6/(g_6+cw3_6); dg_r = 1.0 + cw2*(6.0*pow(r,5.0)-1.0); dr_nuhat = 1.0/(Shat*k2*dist_sq); - dr_Shat = -dr_nuhat*TurbVar_j[0]/Shat; + dr_Shat = -dr_nuhat*ScalarVar_j[0]/Shat; - Ms_coeff = (cb1*TurbVar_j[0]-cw1*TurbVar_j[0]*TurbVar_j[0]/dist_sq*dfw_g*dg_r*dr_Shat); + Ms_coeff = (cb1*ScalarVar_j[0]-cw1*ScalarVar_j[0]*ScalarVar_j[0]/dist_sq*dfw_g*dg_r*dr_Shat); } Ms_coeff *= TurbPsi_j[0]*invOmega/rho; @@ -506,7 +506,7 @@ void CSourceViscous_AdjFlow::ComputeResidual (su2double *val_residual, CConfig * // // su2double nu, Ji, Ji_2, Ji_3, fv1; // nu = Laminar_Viscosity/Density; -// Ji = TurbVar_i[0]/nu; +// Ji = ScalarVar_i[0]/nu; // Ji_2 = Ji*Ji; // Ji_3 = Ji_2*Ji; // fv1 = Ji_3/(Ji_3+cv1_3); @@ -550,9 +550,9 @@ void CSourceViscous_AdjFlow::ComputeResidual (su2double *val_residual, CConfig * // dist_0_2 = dist_i*dist_i; // one_o_oneplusJifv1 = 1.0/(1.0+Ji*fv1); // fv2 = 1.0 - Ji*one_o_oneplusJifv1; -// Shat = max(Omega + TurbVar_i[0]*fv2/(k2*dist_0_2), TURB_EPS); +// Shat = max(Omega + ScalarVar_i[0]*fv2/(k2*dist_0_2), TURB_EPS); // -// r = min(TurbVar_i[0]/(Shat*k2*dist_0_2), 10.); +// r = min(ScalarVar_i[0]/(Shat*k2*dist_0_2), 10.); // g = r + cw2*(pow(r,6.)-r); // g_6 = pow(g,6.); // glim = pow((1+cw3_6)/(g_6+cw3_6),1./6.); @@ -561,9 +561,9 @@ void CSourceViscous_AdjFlow::ComputeResidual (su2double *val_residual, CConfig * // dfw_g = glim*cw3_6/(g_6+cw3_6); // dg_r = 1.0 + cw2*(6.0*pow(r,5.0)-1.0); // dr_nuhat = 1.0/(Shat*k2*dist_0_2); -// dr_Shat = -dr_nuhat*TurbVar_i[0]/Shat; +// dr_Shat = -dr_nuhat*ScalarVar_i[0]/Shat; // -// dShat_fv2 = TurbVar_i[0]/(k2*dist_0_2); +// dShat_fv2 = ScalarVar_i[0]/(k2*dist_0_2); // dfv2_fv1 = Ji_2*one_o_oneplusJifv1*one_o_oneplusJifv1; // dfv1_Ji = 3.0*cv1_3*Ji_2/((Ji_3+cv1_3)*(Ji_3+cv1_3)); // dJi_nuhat = 1.0/nu; @@ -580,18 +580,18 @@ void CSourceViscous_AdjFlow::ComputeResidual (su2double *val_residual, CConfig * // // su2double alpha_coeff = Gamma_Minus_One/(Gas_Constant*Density)*dVisc_T; // su2double beta_coeff = alpha_coeff*(sq_vel-Energy)-Laminar_Viscosity_i/Density; -// su2double Fs_coeff = TurbPsi_i[0]*(cb1*TurbVar_i[0]-cw1*TurbVar_i[0]*TurbVar_i[0]/dist_0_2*dfw_g*dg_r*dr_Shat)* +// su2double Fs_coeff = TurbPsi_i[0]*(cb1*ScalarVar_i[0]-cw1*ScalarVar_i[0]*ScalarVar_i[0]/dist_0_2*dfw_g*dg_r*dr_Shat)* // dShat_fv2*(dfv2_Ji+dfv2_fv1*dfv1_Ji)*dJi_nu; // su2double Gamma = Fs_coeff - gradTurbVar_gradTurbPsi/sigma; // -// val_residual[0] -= (Gamma*beta_coeff - TurbVar_i[0]*vel_gradTurbPsi)/Density*Volume; +// val_residual[0] -= (Gamma*beta_coeff - ScalarVar_i[0]*vel_gradTurbPsi)/Density*Volume; // for (iDim = 0; iDim < nDim; iDim++) -// val_residual[iDim+1] += (Gamma*alpha_coeff*V_i[iDim+1] - TurbVar_i[0]*TurbPsi_Grad_i[0][iDim])/Density*Volume; +// val_residual[iDim+1] += (Gamma*alpha_coeff*V_i[iDim+1] - ScalarVar_i[0]*TurbPsi_Grad_i[0][iDim])/Density*Volume; // val_residual[nVar-1] -= (Gamma*alpha_coeff)/Density*Volume; // // // this should improve stability (when commented): // /*--- Terms 3: -partial{T^s}_GradVel x GradN ---*/ -// // su2double Ms_coeff = (cb1*TurbVar_i[0]-cw1*TurbVar_i[0]*TurbVar_i[0]/dist_0_2*dfw_g*dg_r*dr_Shat); +// // su2double Ms_coeff = (cb1*ScalarVar_i[0]-cw1*ScalarVar_i[0]*ScalarVar_i[0]/dist_0_2*dfw_g*dg_r*dr_Shat); // // Ms_coeff *= TurbPsi_i[0]/(Omega + TURB_EPS); // // // // for (iDim = 0; iDim < nDim; iDim++) { @@ -712,31 +712,31 @@ void CSourcePieceWise_AdjTurb::ComputeResidual(su2double *val_residual, su2doubl dist_0_2 = dist_i*dist_i; nu = Laminar_Viscosity_i/U_i[0]; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); one_o_oneplusJifv1 = 1.0/(1.0+Ji*fv1); fv2 = 1.0 - Ji*one_o_oneplusJifv1; - Shat = max(Vorticity + TurbVar_i[0]*fv2/(k2*dist_0_2), TURB_EPS); + Shat = max(Vorticity + ScalarVar_i[0]*fv2/(k2*dist_0_2), TURB_EPS); - // r = TurbVar_i[0]/(Shat*k2*dist_0_2); - r = min(TurbVar_i[0]/(Shat*k2*dist_0_2),10.); + // r = ScalarVar_i[0]/(Shat*k2*dist_0_2); + r = min(ScalarVar_i[0]/(Shat*k2*dist_0_2),10.); g = r + cw2*(pow(r,6.)-r); g_6 = pow(g,6.); glim = pow((1+cw3_6)/(g_6+cw3_6),1./6.); fw = g*glim; - dTs_nuhat = cb1*Shat-2.0*cw1*fw*TurbVar_i[0]/dist_0_2; - dTs_Shat = cb1*TurbVar_i[0]; - dTs_fw = -cw1*TurbVar_i[0]*TurbVar_i[0]/dist_0_2; + dTs_nuhat = cb1*Shat-2.0*cw1*fw*ScalarVar_i[0]/dist_0_2; + dTs_Shat = cb1*ScalarVar_i[0]; + dTs_fw = -cw1*ScalarVar_i[0]*ScalarVar_i[0]/dist_0_2; dfw_g = glim*cw3_6/(g_6+cw3_6); dg_r = 1.0 + cw2*(6.0*pow(r,5.0)-1.0); dr_nuhat = 1.0/(Shat*k2*dist_0_2); - dr_Shat = -dr_nuhat*TurbVar_i[0]/Shat; + dr_Shat = -dr_nuhat*ScalarVar_i[0]/Shat; dShat_nuhat = fv2/(k2*dist_0_2); - dShat_fv2 = TurbVar_i[0]/(k2*dist_0_2); + dShat_fv2 = ScalarVar_i[0]/(k2*dist_0_2); dfv2_fv1 = Ji_2*one_o_oneplusJifv1*one_o_oneplusJifv1; dfv1_Ji = 3.0*cv1_3*Ji_2/((Ji_3+cv1_3)*(Ji_3+cv1_3)); dJi_nuhat = 1.0/nu; diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp index 206e94738ba7..f4f341746466 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -64,7 +64,7 @@ CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { AD::StartPreacc(); AD::SetPreaccIn(Normal, nDim); - AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j, nVar); + AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j, nVar); if (dynamic_grid) { AD::SetPreaccIn(GridVel_i, nDim); AD::SetPreaccIn(GridVel_j, nDim); } diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index f0acac6dbfe9..ac96c6ded8ad 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -73,7 +73,7 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); AD::SetPreaccIn(TurbVar_Grad_j, nVar, nDim); if (correct_gradient) { - AD::SetPreaccIn(TurbVar_i, nVar); AD::SetPreaccIn(TurbVar_j ,nVar); + AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j ,nVar); } ExtraADPreaccIn(); @@ -93,7 +93,7 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config } proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, TurbVar_Grad_i, - TurbVar_Grad_j, correct_gradient, TurbVar_i, TurbVar_j, + TurbVar_Grad_j, correct_gradient, ScalarVar_i, ScalarVar_j, Proj_Mean_GradTurbVar_Normal, Proj_Mean_GradTurbVar); FinishResidualCalc(config); diff --git a/SU2_CFD/src/numerics/transition.cpp b/SU2_CFD/src/numerics/transition.cpp index 1bd8e112c238..324fe7bf22da 100644 --- a/SU2_CFD/src/numerics/transition.cpp +++ b/SU2_CFD/src/numerics/transition.cpp @@ -270,7 +270,7 @@ void CAvgGradCorrected_TransLM::ComputeResidual(su2double *val_residual, su2doub // /*--- Compute mean effective viscosity ---*/ // nu_i = Laminar_Viscosity_i/U_i[0]; // nu_j = Laminar_Viscosity_j/U_j[0]; - // nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); + // nu_e = 0.5*(nu_i+nu_j+ScalarVar_i[0]+ScalarVar_j[0]); // // /*--- Compute vector going from iPoint to jPoint ---*/ // dist_ij_2 = 0; proj_vector_ij = 0; @@ -293,7 +293,7 @@ void CAvgGradCorrected_TransLM::ComputeResidual(su2double *val_residual, su2doub // } // Proj_Mean_GradTurbVar_Corrected[iVar] = Proj_Mean_GradTurbVar_Kappa[iVar]; // Proj_Mean_GradTurbVar_Corrected[iVar] -= Proj_Mean_GradTurbVar_Edge[iVar]*proj_vector_ij - - // (TurbVar_j[iVar]-TurbVar_i[iVar])*proj_vector_ij; + // (ScalarVar_j[iVar]-ScalarVar_i[iVar])*proj_vector_ij; // } // // val_residual[0] = nu_e*Proj_Mean_GradTurbVar_Corrected[0]/sigma; diff --git a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp index 0755719596ba..1741d37de2c9 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_convection.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_convection.cpp @@ -40,7 +40,7 @@ void CUpwSca_TurbSA::ExtraADPreaccIn() { void CUpwSca_TurbSA::FinishResidualCalc(const CConfig* config) { - Flux[0] = a0*TurbVar_i[0]+a1*TurbVar_j[0]; + Flux[0] = a0*ScalarVar_i[0]+a1*ScalarVar_j[0]; if (implicit) { Jacobian_i[0][0] = a0; @@ -60,8 +60,8 @@ void CUpwSca_TurbSST::ExtraADPreaccIn() { void CUpwSca_TurbSST::FinishResidualCalc(const CConfig* config) { - Flux[0] = a0*Density_i*TurbVar_i[0]+a1*Density_j*TurbVar_j[0]; - Flux[1] = a0*Density_i*TurbVar_i[1]+a1*Density_j*TurbVar_j[1]; + Flux[0] = a0*Density_i*ScalarVar_i[0]+a1*Density_j*ScalarVar_j[0]; + Flux[1] = a0*Density_i*ScalarVar_i[1]+a1*Density_j*ScalarVar_j[1]; if (implicit) { Jacobian_i[0][0] = a0; Jacobian_i[0][1] = 0.0; diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index 07bcecf07384..53bd328e3faf 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -41,7 +41,7 @@ void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { su2double nu_i = Laminar_Viscosity_i/Density_i; su2double nu_j = Laminar_Viscosity_j/Density_j; - su2double nu_e = 0.5*(nu_i+nu_j+TurbVar_i[0]+TurbVar_j[0]); + su2double nu_e = 0.5*(nu_i+nu_j+ScalarVar_i[0]+ScalarVar_j[0]); Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; @@ -70,7 +70,7 @@ void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { su2double nu_j = Laminar_Viscosity_j/Density_j; su2double nu_ij = 0.5*(nu_i+nu_j); - su2double nu_tilde_ij = 0.5*(TurbVar_i[0]+TurbVar_j[0]); + su2double nu_tilde_ij = 0.5*(ScalarVar_i[0]+ScalarVar_j[0]); su2double nu_e; diff --git a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp index 7b33636c7216..d393600f8759 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp @@ -72,7 +72,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig // AD::SetPreaccIn(V_i, nDim+6); // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(ScalarVar_i[0]); // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); @@ -114,24 +114,24 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig * International Journal of Heat and Fluid Flow, Vol. 24, 2003, pp. 454-462. ---*/ /* --- See https://turbmodels.larc.nasa.gov/spalart.html#sarough for detailed explanation. ---*/ - Ji = TurbVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. + Ji = ScalarVar_i[0]/nu + cr1*(roughness_i/(dist_i+EPS)); //roughness_i = 0 for smooth walls and Ji remains the same, changes only if roughness is specified. Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); /*--- Using a modified relation so as to not change the Shat that depends on fv2. ---*/ - fv2 = 1.0 - TurbVar_i[0]/(nu+TurbVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper + fv2 = 1.0 - ScalarVar_i[0]/(nu+ScalarVar_i[0]*fv1); // From NASA turb modeling resource and 2003 paper ft2 = ct3*exp(-ct4*Ji_2); S = Omega; inv_k2_d2 = 1.0/(k2*dist_i_2); - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = S + ScalarVar_i[0]*fv2*inv_k2_d2; Shat = max(Shat, 1.0e-10); inv_Shat = 1.0/Shat; // Original SA model -// Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; +// Production = cb1*(1.0-ft2)*Shat*ScalarVar_i[0]*Volume; if (transition) { @@ -142,7 +142,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig /*--- turbulence intensity is u'/U so we multiply by 100 to get percentage ---*/ su2double tu = 100.0 * config->GetTurbulenceIntensity_FreeStream(); - su2double nu_t = (TurbVar_i[0]*fv1); //S-A variable + su2double nu_t = (ScalarVar_i[0]*fv1); //S-A variable su2double re_v = ((Density_i*pow(dist_i,2.))/(Laminar_Viscosity_i))*Omega; su2double re_theta = re_v/2.193; @@ -155,24 +155,24 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig Gamma_BC = 1.0 - exp(-term_exponential); - Production = Gamma_BC*cb1*Shat*TurbVar_i[0]*Volume; + Production = Gamma_BC*cb1*Shat*ScalarVar_i[0]*Volume; } else { - Production = cb1*Shat*TurbVar_i[0]*Volume; + Production = cb1*Shat*ScalarVar_i[0]*Volume; } /*--- Destruction term ---*/ - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r = min(ScalarVar_i[0]*inv_Shat*inv_k2_d2,10.0); g = r + cw2*(pow(r,6.0)-r); g_6 = pow(g,6.0); glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); fw = g*glim; // Original SA model -// Destruction = (cw1*fw-cb1*ft2/k2)*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; +// Destruction = (cw1*fw-cb1*ft2/k2)*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*fw*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -189,22 +189,22 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; + else dShat = (fv2+ScalarVar_i[0]*dfv2)*inv_k2_d2; if (transition) { - Jacobian_i[0] += Gamma_BC*cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + Jacobian_i[0] += Gamma_BC*cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; } else { - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + Jacobian_i[0] += cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; } /*--- Implicit part, destruction term ---*/ - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr = (Shat-ScalarVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; if (r == 10.0) dr = 0.0; dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] -= cw1*(dfw*ScalarVar_i[0] + 2.0*fw)*ScalarVar_i[0]/dist_i_2*Volume; } @@ -226,7 +226,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC // AD::SetPreaccIn(V_i, nDim+6); // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(ScalarVar_i[0]); // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); @@ -259,7 +259,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC dist_i_2 = dist_i*dist_i; nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); @@ -268,23 +268,23 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC S = Omega; inv_k2_d2 = 1.0/(k2*dist_i_2); - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = S + ScalarVar_i[0]*fv2*inv_k2_d2; Shat = max(Shat, 1.0e-10); inv_Shat = 1.0/Shat; /*--- Production term ---*/; - Production = cb1*Shat*TurbVar_i[0]*Volume; + Production = cb1*Shat*ScalarVar_i[0]*Volume; /*--- Destruction term ---*/ - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r = min(ScalarVar_i[0]*inv_Shat*inv_k2_d2,10.0); g = r + cw2*(pow(r,6.0)-r); g_6 = pow(g,6.0); glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); fw = g*glim; - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*fw*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -303,7 +303,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC for(iDim=0;iDim CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + else dShat = (fv2+ScalarVar_i[0]*dfv2)*inv_k2_d2; + Jacobian_i[0] += cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; /*--- Implicit part, destruction term ---*/ - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr = (Shat-ScalarVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; if (r == 10.0) dr = 0.0; dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] -= cw1*(dfw*ScalarVar_i[0] + 2.0*fw)*ScalarVar_i[0]/dist_i_2*Volume; /* Compressibility Correction */ - Jacobian_i[0] -= 2.0*c5*(TurbVar_i[0]/(SoundSpeed_i*SoundSpeed_i))*aux_cc*Volume; + Jacobian_i[0] -= 2.0*c5*(ScalarVar_i[0]/(SoundSpeed_i*SoundSpeed_i))*aux_cc*Volume; } @@ -348,7 +348,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf // AD::SetPreaccIn(V_i, nDim+6); // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(ScalarVar_i[0]); // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); @@ -395,7 +395,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf dist_i_2 = dist_i*dist_i; nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); @@ -404,7 +404,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf S = Omega; inv_k2_d2 = 1.0/(k2*dist_i_2); - //Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + //Shat = S + ScalarVar_i[0]*fv2*inv_k2_d2; Shat = max(S*((1.0/max(Ji,1.0e-16))+fv1),1.0e-16); Shat = max(Shat, 1.0e-10); @@ -412,11 +412,11 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf /*--- Production term ---*/; - Production = cb1*Shat*TurbVar_i[0]*Volume; + Production = cb1*Shat*ScalarVar_i[0]*Volume; /*--- Destruction term ---*/ - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r = min(ScalarVar_i[0]*inv_Shat*inv_k2_d2,10.0); r=tanh(r)/tanh(1.0); g = r + cw2*(pow(r,6.0)-r); @@ -424,7 +424,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); fw = g*glim; - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*fw*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -443,15 +443,15 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf if ( Shat <= 1.0e-10 ) dShat = 0.0; else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + Jacobian_i[0] += cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; /*--- Implicit part, destruction term ---*/ - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr = (Shat-ScalarVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] -= cw1*(dfw*ScalarVar_i[0] + 2.0*fw)*ScalarVar_i[0]/dist_i_2*Volume; } @@ -475,7 +475,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const // AD::SetPreaccIn(V_i, nDim+6); // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); - // AD::SetPreaccIn(TurbVar_i[0]); + // AD::SetPreaccIn(ScalarVar_i[0]); // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); @@ -522,7 +522,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const dist_i_2 = dist_i*dist_i; nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); @@ -538,11 +538,11 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const /*--- Production term ---*/; - Production = cb1*Shat*TurbVar_i[0]*Volume; + Production = cb1*Shat*ScalarVar_i[0]*Volume; /*--- Destruction term ---*/ - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r = min(ScalarVar_i[0]*inv_Shat*inv_k2_d2,10.0); r=tanh(r)/tanh(1.0); g = r + cw2*(pow(r,6.0)-r); @@ -550,7 +550,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); fw = g*glim; - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*fw*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -569,7 +569,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const for(iDim=0;iDim CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const if ( Shat <= 1.0e-10 ) dShat = 0.0; else dShat = -S*pow(Ji,-2.0)/nu + S*dfv1; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + Jacobian_i[0] += cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; /*--- Implicit part, destruction term ---*/ - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr = (Shat-ScalarVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; dr=(1-pow(tanh(r),2.0))*(dr)/tanh(1.0); dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] -= cw1*(dfw*ScalarVar_i[0] + 2.0*fw)*ScalarVar_i[0]/dist_i_2*Volume; /* Compressibility Correction */ - Jacobian_i[0] -= 2.0*c5*(TurbVar_i[0]/(SoundSpeed_i*SoundSpeed_i))*aux_cc*Volume; + Jacobian_i[0] -= 2.0*c5*(ScalarVar_i[0]/(SoundSpeed_i*SoundSpeed_i))*aux_cc*Volume; } @@ -615,7 +615,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo // AD::SetPreaccIn(V_i, nDim+6); // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); -// AD::SetPreaccIn(TurbVar_i[0]); +// AD::SetPreaccIn(ScalarVar_i[0]); // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); @@ -644,13 +644,13 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo if (dist_i > 1e-10) { - if (TurbVar_i[0] > 0.0) { + if (ScalarVar_i[0] > 0.0) { /*--- Production term ---*/ dist_i_2 = dist_i*dist_i; nu = Laminar_Viscosity_i/Density_i; - Ji = TurbVar_i[0]/nu; + Ji = ScalarVar_i[0]/nu; Ji_2 = Ji*Ji; Ji_3 = Ji_2*Ji; fv1 = Ji_3/(Ji_3+cv1_3); @@ -659,26 +659,26 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo S = Omega; inv_k2_d2 = 1.0/(k2*dist_i_2); - Shat = S + TurbVar_i[0]*fv2*inv_k2_d2; + Shat = S + ScalarVar_i[0]*fv2*inv_k2_d2; Shat = max(Shat, 1.0e-10); inv_Shat = 1.0/Shat; /*--- Production term ---*/; // Original SA model - // Production = cb1*(1.0-ft2)*Shat*TurbVar_i[0]*Volume; + // Production = cb1*(1.0-ft2)*Shat*ScalarVar_i[0]*Volume; - Production = cb1*Shat*TurbVar_i[0]*Volume; + Production = cb1*Shat*ScalarVar_i[0]*Volume; /*--- Destruction term ---*/ - r = min(TurbVar_i[0]*inv_Shat*inv_k2_d2,10.0); + r = min(ScalarVar_i[0]*inv_Shat*inv_k2_d2,10.0); g = r + cw2*(pow(r,6.0)-r); g_6 = pow(g,6.0); glim = pow((1.0+cw3_6)/(g_6+cw3_6),1.0/6.0); fw = g*glim; - Destruction = cw1*fw*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*fw*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -695,16 +695,16 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo dfv1 = 3.0*Ji_2*cv1_3/(nu*pow(Ji_3+cv1_3,2.)); dfv2 = -(1/nu-Ji_2*dfv1)/pow(1.+Ji*fv1,2.); if ( Shat <= 1.0e-10 ) dShat = 0.0; - else dShat = (fv2+TurbVar_i[0]*dfv2)*inv_k2_d2; - Jacobian_i[0] += cb1*(TurbVar_i[0]*dShat+Shat)*Volume; + else dShat = (fv2+ScalarVar_i[0]*dfv2)*inv_k2_d2; + Jacobian_i[0] += cb1*(ScalarVar_i[0]*dShat+Shat)*Volume; /*--- Implicit part, destruction term ---*/ - dr = (Shat-TurbVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; + dr = (Shat-ScalarVar_i[0]*dShat)*inv_Shat*inv_Shat*inv_k2_d2; if (r == 10.0) dr = 0.0; dg = dr*(1.+cw2*(6.0*pow(r,5.0)-1.0)); dfw = dg*glim*(1.-g_6/(g_6+cw3_6)); - Jacobian_i[0] -= cw1*(dfw*TurbVar_i[0] + 2.0*fw)*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] -= cw1*(dfw*ScalarVar_i[0] + 2.0*fw)*ScalarVar_i[0]/dist_i_2*Volume; } @@ -716,11 +716,11 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo /*--- Production term ---*/; - Production = cb1*(1.0-ct3)*Omega*TurbVar_i[0]*Volume; + Production = cb1*(1.0-ct3)*Omega*ScalarVar_i[0]*Volume; /*--- Destruction term ---*/ - Destruction = cw1*TurbVar_i[0]*TurbVar_i[0]/dist_i_2*Volume; + Destruction = cw1*ScalarVar_i[0]*ScalarVar_i[0]/dist_i_2*Volume; /*--- Diffusion term ---*/ @@ -738,7 +738,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo /*--- Implicit part, destruction term ---*/ - Jacobian_i[0] += 2.0*cw1*TurbVar_i[0]/dist_i_2*Volume; + Jacobian_i[0] += 2.0*cw1*ScalarVar_i[0]/dist_i_2*Volume; } @@ -789,7 +789,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfi AD::StartPreacc(); AD::SetPreaccIn(StrainMag_i); - AD::SetPreaccIn(TurbVar_i, nVar); + AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); @@ -840,19 +840,19 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfi if (using_uq){ ComputePerturbedRSM(nDim, Eig_Val_Comp, uq_permute, uq_delta_b, uq_urlx, PrimVar_Grad_i+1, Density_i, Eddy_Viscosity_i, - TurbVar_i[0], MeanPerturbedRSM); - SetPerturbedStrainMag(TurbVar_i[0]); + ScalarVar_i[0], MeanPerturbedRSM); + SetPerturbedStrainMag(ScalarVar_i[0]); pk = Eddy_Viscosity_i*PerturbedStrainMag*PerturbedStrainMag - - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + - 2.0/3.0*Density_i*ScalarVar_i[0]*diverg; } else { - pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*TurbVar_i[0]*diverg; + pk = Eddy_Viscosity_i*StrainMag_i*StrainMag_i - 2.0/3.0*Density_i*ScalarVar_i[0]*diverg; } - pk = min(pk,20.0*beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]); + pk = min(pk,20.0*beta_star*Density_i*ScalarVar_i[1]*ScalarVar_i[0]); pk = max(pk,0.0); - zeta = max(TurbVar_i[1], VorticityMag*F2_i/a1); + zeta = max(ScalarVar_i[1], VorticityMag*F2_i/a1); /* if using UQ methodolgy, calculate production using perturbed Reynolds stress matrix */ @@ -886,8 +886,8 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfi /*--- Dissipation ---*/ - Residual[0] -= beta_star*Density_i*TurbVar_i[1]*TurbVar_i[0]*Volume; - Residual[1] -= beta_blended*Density_i*TurbVar_i[1]*TurbVar_i[1]*Volume; + Residual[0] -= beta_star*Density_i*ScalarVar_i[1]*ScalarVar_i[0]*Volume; + Residual[1] -= beta_blended*Density_i*ScalarVar_i[1]*ScalarVar_i[1]*Volume; /*--- Cross diffusion ---*/ @@ -899,10 +899,10 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfi /*--- Implicit part ---*/ - Jacobian_i[0][0] = -beta_star*TurbVar_i[1]*Volume; - Jacobian_i[0][1] = -beta_star*TurbVar_i[0]*Volume; + Jacobian_i[0][0] = -beta_star*ScalarVar_i[1]*Volume; + Jacobian_i[0][1] = -beta_star*ScalarVar_i[0]*Volume; Jacobian_i[1][0] = 0.0; - Jacobian_i[1][1] = -2.0*beta_blended*TurbVar_i[1]*Volume; + Jacobian_i[1][1] = -2.0*beta_blended*ScalarVar_i[1]*Volume; } AD::SetPreaccOut(Residual, nVar); From 81d4b42452e95e9a48d2c99f437dced81eca7bc0 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 25 Aug 2021 14:44:20 +0200 Subject: [PATCH 14/48] Changing CNumerics class var TurbVar_Grad* to ScalarVar_Grad*. --- SU2_CFD/include/numerics/CNumerics.hpp | 12 +++++----- .../numerics/turbulent/turb_sources.hpp | 4 ++-- .../continuous_adjoint/adj_convection.cpp | 4 ++-- .../continuous_adjoint/adj_sources.cpp | 6 ++--- .../src/numerics/scalar/scalar_diffusion.cpp | 8 +++---- SU2_CFD/src/numerics/transition.cpp | 2 +- .../src/numerics/turbulent/turb_sources.cpp | 24 +++++++++---------- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/SU2_CFD/include/numerics/CNumerics.hpp b/SU2_CFD/include/numerics/CNumerics.hpp index 68d333c71ed8..111defe50f3e 100644 --- a/SU2_CFD/include/numerics/CNumerics.hpp +++ b/SU2_CFD/include/numerics/CNumerics.hpp @@ -130,8 +130,8 @@ class CNumerics { *Psi_i, /*!< \brief Vector of adjoint variables at point i. */ *Psi_j; /*!< \brief Vector of adjoint variables at point j. */ const su2double - *ScalarVar_i, /*!< \brief Vector of turbulent variables at point i. */ - *ScalarVar_j; /*!< \brief Vector of turbulent variables at point j. */ + *ScalarVar_i, /*!< \brief Vector of scalar variables at point i. */ + *ScalarVar_j; /*!< \brief Vector of scalar variables at point j. */ const su2double *TransVar_i, /*!< \brief Vector of turbulent variables at point i. */ *TransVar_j; /*!< \brief Vector of turbulent variables at point j. */ @@ -146,8 +146,8 @@ class CNumerics { PrimVar_Grad_j, /*!< \brief Gradient of primitive variables at point j. */ PsiVar_Grad_i, /*!< \brief Gradient of adjoint variables at point i. */ PsiVar_Grad_j, /*!< \brief Gradient of adjoint variables at point j. */ - TurbVar_Grad_i, /*!< \brief Gradient of turbulent variables at point i. */ - TurbVar_Grad_j, /*!< \brief Gradient of turbulent variables at point j. */ + ScalarVar_Grad_i, /*!< \brief Gradient of scalar variables at point i. */ + ScalarVar_Grad_j, /*!< \brief Gradient of scalar variables at point j. */ TransVar_Grad_i, /*!< \brief Gradient of turbulent variables at point i. */ TransVar_Grad_j, /*!< \brief Gradient of turbulent variables at point j. */ TurbPsi_Grad_i, /*!< \brief Gradient of adjoint turbulent variables at point i. */ @@ -373,8 +373,8 @@ class CNumerics { */ inline void SetScalarVarGradient(CMatrixView val_scalarvar_grad_i, CMatrixView val_scalarvar_grad_j) { - TurbVar_Grad_i = val_scalarvar_grad_i; - TurbVar_Grad_j = val_scalarvar_grad_j; + ScalarVar_Grad_i = val_scalarvar_grad_i; + ScalarVar_Grad_j = val_scalarvar_grad_j; } /*! diff --git a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp index d733eb75f239..f7777d0e6df0 100644 --- a/SU2_CFD/include/numerics/turbulent/turb_sources.hpp +++ b/SU2_CFD/include/numerics/turbulent/turb_sources.hpp @@ -358,8 +358,8 @@ class CSourcePieceWise_TurbSST final : public CNumerics { pw_axi = alfa_blended*zeta/k*pk_axi; /*--- Convection-Diffusion ---*/ - cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*TurbVar_Grad_i[0][1]; - cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*TurbVar_Grad_i[1][1]; + cdk_axi = rhov*k-(Laminar_Viscosity_i+sigma_k_i*Eddy_Viscosity_i)*ScalarVar_Grad_i[0][1]; + cdw_axi = rhov*w-(Laminar_Viscosity_i+sigma_w_i*Eddy_Viscosity_i)*ScalarVar_Grad_i[1][1]; /*--- Add terms to the residuals ---*/ Residual[0] += yinv*Volume*(pk_axi-cdk_axi); diff --git a/SU2_CFD/src/numerics/continuous_adjoint/adj_convection.cpp b/SU2_CFD/src/numerics/continuous_adjoint/adj_convection.cpp index 355a4a617060..d439d9f40a21 100644 --- a/SU2_CFD/src/numerics/continuous_adjoint/adj_convection.cpp +++ b/SU2_CFD/src/numerics/continuous_adjoint/adj_convection.cpp @@ -829,8 +829,8 @@ void CUpwSca_AdjTurb::ComputeResidual (su2double *val_residual_i, su2double *val for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = U_i[iDim+1]/U_i[0]; Velocity_j[iDim] = U_j[iDim+1]/U_j[0]; - proj_conv_flux_i += (TurbVar_Grad_i[0][iDim]/sigma - Velocity_i[iDim])*Normal[iDim]; // projection of convective flux at iPoint - proj_conv_flux_j += (TurbVar_Grad_j[0][iDim]/sigma - Velocity_j[iDim])*Normal[iDim]; // projection of convective flux at jPoint + proj_conv_flux_i += (ScalarVar_Grad_i[0][iDim]/sigma - Velocity_i[iDim])*Normal[iDim]; // projection of convective flux at iPoint + proj_conv_flux_j += (ScalarVar_Grad_j[0][iDim]/sigma - Velocity_j[iDim])*Normal[iDim]; // projection of convective flux at jPoint } proj_conv_flux_ij = 0.5*fabs(proj_conv_flux_i+proj_conv_flux_j); // projection of average convective flux diff --git a/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp b/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp index d5cb0f9c8f73..f86d2445f7ea 100644 --- a/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp +++ b/SU2_CFD/src/numerics/continuous_adjoint/adj_sources.cpp @@ -574,7 +574,7 @@ void CSourceViscous_AdjFlow::ComputeResidual (su2double *val_residual, CConfig * // // su2double gradTurbVar_gradTurbPsi = 0, vel_gradTurbPsi = 0; // for (iDim = 0; iDim < nDim; iDim++) { -// gradTurbVar_gradTurbPsi += TurbVar_Grad_i[0][iDim]*TurbPsi_Grad_i[0][iDim]; +// gradTurbVar_gradTurbPsi += ScalarVar_Grad_i[0][iDim]*TurbPsi_Grad_i[0][iDim]; // vel_gradTurbPsi += V_i[iDim+1]*TurbPsi_Grad_i[0][iDim]; // } // @@ -633,8 +633,8 @@ void CSourceConservative_AdjTurb::ComputeResidual(su2double *val_residual, su2do E_ij = 0.0; proj_TurbVar_Grad_i = 0.0; proj_TurbVar_Grad_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { - proj_TurbVar_Grad_i += coeff*TurbVar_Grad_i[0][iDim]*Normal[iDim]; - proj_TurbVar_Grad_j += coeff*TurbVar_Grad_j[0][iDim]*Normal[iDim]; + proj_TurbVar_Grad_i += coeff*ScalarVar_Grad_i[0][iDim]*Normal[iDim]; + proj_TurbVar_Grad_j += coeff*ScalarVar_Grad_j[0][iDim]*Normal[iDim]; E_ij += 0.5*(TurbPsi_i[0]*proj_TurbVar_Grad_i + TurbPsi_j[0]*proj_TurbVar_Grad_j); } diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index ac96c6ded8ad..3d127d76f2e1 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -70,8 +70,8 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config AD::StartPreacc(); AD::SetPreaccIn(Coord_i, nDim); AD::SetPreaccIn(Coord_j, nDim); AD::SetPreaccIn(Normal, nDim); - AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); - AD::SetPreaccIn(TurbVar_Grad_j, nVar, nDim); + AD::SetPreaccIn(ScalarVar_Grad_i, nVar, nDim); + AD::SetPreaccIn(ScalarVar_Grad_j, nVar, nDim); if (correct_gradient) { AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j ,nVar); } @@ -92,8 +92,8 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config Eddy_Viscosity_i = V_i[nDim+6]; Eddy_Viscosity_j = V_j[nDim+6]; } - proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, TurbVar_Grad_i, - TurbVar_Grad_j, correct_gradient, ScalarVar_i, ScalarVar_j, + proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, ScalarVar_Grad_i, + ScalarVar_Grad_j, correct_gradient, ScalarVar_i, ScalarVar_j, Proj_Mean_GradTurbVar_Normal, Proj_Mean_GradTurbVar); FinishResidualCalc(config); diff --git a/SU2_CFD/src/numerics/transition.cpp b/SU2_CFD/src/numerics/transition.cpp index 324fe7bf22da..1eaa90b4850e 100644 --- a/SU2_CFD/src/numerics/transition.cpp +++ b/SU2_CFD/src/numerics/transition.cpp @@ -287,7 +287,7 @@ void CAvgGradCorrected_TransLM::ComputeResidual(su2double *val_residual, su2doub // Proj_Mean_GradTurbVar_Kappa[iVar] = 0.0; // Proj_Mean_GradTurbVar_Edge[iVar] = 0.0; // for (iDim = 0; iDim < nDim; iDim++) { - // Mean_GradTurbVar[iVar][iDim] = 0.5*(TurbVar_Grad_i[iVar][iDim] + TurbVar_Grad_j[iVar][iDim]); + // Mean_GradTurbVar[iVar][iDim] = 0.5*(ScalarVar_Grad_i[iVar][iDim] + ScalarVar_Grad_j[iVar][iDim]); // Proj_Mean_GradTurbVar_Kappa[iVar] += Mean_GradTurbVar[iVar][iDim]*Normal[iDim]; // Proj_Mean_GradTurbVar_Edge[iVar] += Mean_GradTurbVar[iVar][iDim]*Edge_Vector[iDim]; // } diff --git a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp index d393600f8759..368e40367ec0 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_sources.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_sources.cpp @@ -73,7 +73,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); // AD::SetPreaccIn(ScalarVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(ScalarVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); // Set the boolean here depending on whether the point is closest to a rough wall or not. @@ -178,7 +178,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA::ComputeResidual(const CConfig norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -227,7 +227,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); // AD::SetPreaccIn(ScalarVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(ScalarVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); if (incompressible) { @@ -290,7 +290,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_COMP::ComputeResidual(const CC norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -349,7 +349,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); // AD::SetPreaccIn(ScalarVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(ScalarVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); if (incompressible) { @@ -430,7 +430,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E::ComputeResidual(const CConf norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -476,7 +476,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); // AD::SetPreaccIn(ScalarVar_i[0]); - // AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); + // AD::SetPreaccIn(ScalarVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); if (incompressible) { @@ -556,7 +556,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_E_COMP::ComputeResidual(const norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -616,7 +616,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo // AD::SetPreaccIn(Vorticity_i, nDim); // AD::SetPreaccIn(StrainMag_i); // AD::SetPreaccIn(ScalarVar_i[0]); -// AD::SetPreaccIn(TurbVar_Grad_i[0], nDim); +// AD::SetPreaccIn(ScalarVar_Grad_i[0], nDim); // AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); if (incompressible) { @@ -684,7 +684,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -726,7 +726,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSA_Neg::ComputeResidual(const CCo norm2_Grad = 0.0; for (iDim = 0; iDim < nDim; iDim++) - norm2_Grad += TurbVar_Grad_i[0][iDim]*TurbVar_Grad_i[0][iDim]; + norm2_Grad += ScalarVar_Grad_i[0][iDim]*ScalarVar_Grad_i[0][iDim]; CrossProduction = cb2_sigma*norm2_Grad*Volume; @@ -790,7 +790,7 @@ CNumerics::ResidualType<> CSourcePieceWise_TurbSST::ComputeResidual(const CConfi AD::StartPreacc(); AD::SetPreaccIn(StrainMag_i); AD::SetPreaccIn(ScalarVar_i, nVar); - AD::SetPreaccIn(TurbVar_Grad_i, nVar, nDim); + AD::SetPreaccIn(ScalarVar_Grad_i, nVar, nDim); AD::SetPreaccIn(Volume); AD::SetPreaccIn(dist_i); AD::SetPreaccIn(F1_i); AD::SetPreaccIn(F2_i); AD::SetPreaccIn(CDkw_i); AD::SetPreaccIn(PrimVar_Grad_i, nDim+1, nDim); From 86e608daf784a1909d56edb058796e55856fbe8f Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 25 Aug 2021 15:44:11 +0200 Subject: [PATCH 15/48] Rename Turb->Scalar var in scalar_diffusion. --- .../include/numerics/scalar/scalar_diffusion.hpp | 4 ++-- SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp | 10 +++++----- .../src/numerics/turbulent/turb_diffusion.cpp | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index a1a97f158eb3..f2e396855d04 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -47,8 +47,8 @@ class CAvgGrad_Scalar : public CNumerics { protected: su2double - *Proj_Mean_GradTurbVar_Normal = nullptr, /*!< \brief Mean_gradTurbVar DOT normal. */ - *Proj_Mean_GradTurbVar = nullptr, /*!< \brief Mean_gradTurbVar DOT normal, corrected if required. */ + *Proj_Mean_GradScalarVar_Normal = nullptr, /*!< \brief Mean_gradScalarVar DOT normal. */ + *Proj_Mean_GradScalarVar = nullptr, /*!< \brief Mean_gradScalarVar DOT normal, corrected if required. */ proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index 3d127d76f2e1..ec6bb0ea13ac 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -37,8 +37,8 @@ CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) { - Proj_Mean_GradTurbVar_Normal = new su2double [nVar] (); - Proj_Mean_GradTurbVar = new su2double [nVar] (); + Proj_Mean_GradScalarVar_Normal = new su2double [nVar] (); + Proj_Mean_GradScalarVar = new su2double [nVar] (); Flux = new su2double [nVar] (); Jacobian_i = new su2double* [nVar]; @@ -51,8 +51,8 @@ CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, CAvgGrad_Scalar::~CAvgGrad_Scalar(void) { - delete [] Proj_Mean_GradTurbVar_Normal; - delete [] Proj_Mean_GradTurbVar; + delete [] Proj_Mean_GradScalarVar_Normal; + delete [] Proj_Mean_GradScalarVar; delete [] Flux; if (Jacobian_i != nullptr) { @@ -94,7 +94,7 @@ CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, ScalarVar_Grad_i, ScalarVar_Grad_j, correct_gradient, ScalarVar_i, ScalarVar_j, - Proj_Mean_GradTurbVar_Normal, Proj_Mean_GradTurbVar); + Proj_Mean_GradScalarVar_Normal, Proj_Mean_GradScalarVar); FinishResidualCalc(config); AD::SetPreaccOut(Flux, nVar); diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index 53bd328e3faf..8bdbf22636e4 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -43,13 +43,13 @@ void CAvgGrad_TurbSA::FinishResidualCalc(const CConfig* config) { su2double nu_j = Laminar_Viscosity_j/Density_j; su2double nu_e = 0.5*(nu_i+nu_j+ScalarVar_i[0]+ScalarVar_j[0]); - Flux[0] = nu_e*Proj_Mean_GradTurbVar[0]/sigma; + Flux[0] = nu_e*Proj_Mean_GradScalarVar[0]/sigma; /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + Jacobian_i[0][0] = (0.5*Proj_Mean_GradScalarVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradScalarVar[0]+nu_e*proj_vector_ij)/sigma; } } @@ -83,13 +83,13 @@ void CAvgGrad_TurbSA_Neg::FinishResidualCalc(const CConfig* config) { nu_e = nu_ij + fn*nu_tilde_ij; } - Flux[0] = nu_e*Proj_Mean_GradTurbVar_Normal[0]/sigma; + Flux[0] = nu_e*Proj_Mean_GradScalarVar_Normal[0]/sigma; /*--- For Jacobians -> Use of TSL approx. to compute derivatives of the gradients ---*/ if (implicit) { - Jacobian_i[0][0] = (0.5*Proj_Mean_GradTurbVar[0]-nu_e*proj_vector_ij)/sigma; - Jacobian_j[0][0] = (0.5*Proj_Mean_GradTurbVar[0]+nu_e*proj_vector_ij)/sigma; + Jacobian_i[0][0] = (0.5*Proj_Mean_GradScalarVar[0]-nu_e*proj_vector_ij)/sigma; + Jacobian_j[0][0] = (0.5*Proj_Mean_GradScalarVar[0]+nu_e*proj_vector_ij)/sigma; } } @@ -131,8 +131,8 @@ void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { su2double diff_kine = 0.5*(diff_i_kine + diff_j_kine); su2double diff_omega = 0.5*(diff_i_omega + diff_j_omega); - Flux[0] = diff_kine*Proj_Mean_GradTurbVar[0]; - Flux[1] = diff_omega*Proj_Mean_GradTurbVar[1]; + Flux[0] = diff_kine*Proj_Mean_GradScalarVar[0]; + Flux[1] = diff_omega*Proj_Mean_GradScalarVar[1]; /*--- For Jacobians -> Use of TSL (Thin Shear Layer?) approx. to compute derivatives of the gradients ---*/ if (implicit) { From 273fc390b68dcf17e3689bd5b51694b50a65da38 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 25 Aug 2021 15:54:01 +0200 Subject: [PATCH 16/48] Remove seemingly unused var in CTurbsolver.hpp/cpp. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 4 +--- SU2_CFD/src/solvers/CScalarSolver.cpp | 3 --- SU2_CFD/src/solvers/CTransLMSolver.cpp | 2 -- SU2_CFD/src/solvers/CTurbSASolver.cpp | 3 --- SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 5 ----- 5 files changed, 1 insertion(+), 16 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 74130a8ff91a..053e8538b4da 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -50,9 +50,7 @@ class CScalarSolver : public CSolver { su2double lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ - upperlimit[MAXNVAR] = {0.0}, /*!< \brief contains upper limits for turbulence variables. */ - Gamma, /*!< \brief Fluid's Gamma constant (ratio of specific heats). */ - Gamma_Minus_One; /*!< \brief Fluids's Gamma - 1.0 . */ + upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index f981ee6a0c2f..3d672d12b31d 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -34,9 +34,6 @@ CScalarSolver::CScalarSolver(void) : CSolver() { } CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { - Gamma = config->GetGamma(); - Gamma_Minus_One = Gamma - 1.0; - nMarker = config->GetnMarker_All(); /*--- Store the number of vertices on each marker for deallocation later ---*/ diff --git a/SU2_CFD/src/solvers/CTransLMSolver.cpp b/SU2_CFD/src/solvers/CTransLMSolver.cpp index 12e10e595a98..b96401b70480 100644 --- a/SU2_CFD/src/solvers/CTransLMSolver.cpp +++ b/SU2_CFD/src/solvers/CTransLMSolver.cpp @@ -47,8 +47,6 @@ CTransLMSolver::CTransLMSolver(CGeometry *geometry, CConfig *config, unsigned sh bool restart = (config->GetRestart() || config->GetRestart_Flow()); cout << "Entered constructor for CTransLMSolver -AA\n"; - Gamma = config->GetGamma(); - Gamma_Minus_One = Gamma - 1.0; /*--- Define geometry constans in the solver structure ---*/ nDim = geometry->GetnDim(); diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index ce4284696569..6877cb92b9ad 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -42,9 +42,6 @@ CTurbSASolver::CTurbSASolver(CGeometry *geometry, CConfig *config, unsigned shor bool multizone = config->GetMultizone_Problem(); - Gamma = config->GetGamma(); - Gamma_Minus_One = Gamma - 1.0; - /*--- Dimension of the problem --> dependent of the turbulent model ---*/ nVar = 1; diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 59443a13e758..67e20ccb97db 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -42,11 +42,6 @@ CTurbSSTSolver::CTurbSSTSolver(CGeometry *geometry, CConfig *config, unsigned sh bool multizone = config->GetMultizone_Problem(); - /*--- Array initialization ---*/ - - Gamma = config->GetGamma(); - Gamma_Minus_One = Gamma - 1.0; - /*--- Dimension of the problem --> dependent on the turbulence model. ---*/ nVar = 2; From 7c06119c997338da1da4e6db9743da5b6104da41 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 09:43:47 +0200 Subject: [PATCH 17/48] Add new files to old build system. --- SU2_CFD/obj/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SU2_CFD/obj/Makefile.am b/SU2_CFD/obj/Makefile.am index 6d357c966caf..e6929159e966 100644 --- a/SU2_CFD/obj/Makefile.am +++ b/SU2_CFD/obj/Makefile.am @@ -106,7 +106,9 @@ libSU2Core_sources = ../src/definition_structure.cpp \ ../src/numerics/continuous_adjoint/adj_convection.cpp \ ../src/numerics/continuous_adjoint/adj_diffusion.cpp \ ../src/numerics/continuous_adjoint/adj_sources.cpp \ - //TK:: add necessary files here in the end when it is clear what will all be added + ../src/numerics/scalar/scalar_convection.cpp \ + ../src/numerics/scalar/scalar_diffusion.cpp \ + ../src/numerics/scalar/scalar_sources.cpp \ ../src/numerics/turbulent/turb_convection.cpp \ ../src/numerics/turbulent/turb_diffusion.cpp \ ../src/numerics/turbulent/turb_sources.cpp \ @@ -177,6 +179,7 @@ libSU2Core_sources = ../src/definition_structure.cpp \ ../src/solvers/CSolver.cpp \ ../src/solvers/CTemplateSolver.cpp \ ../src/solvers/CTransLMSolver.cpp \ + ../src/solvers/CScalarSolver.cpp \ ../src/solvers/CTurbSolver.cpp \ ../src/solvers/CTurbSASolver.cpp \ ../src/solvers/CTurbSSTSolver.cpp \ @@ -206,6 +209,7 @@ libSU2Core_sources = ../src/definition_structure.cpp \ ../src/variables/CTransLMVariable.cpp \ ../src/variables/CDiscAdjFEABoundVariable.cpp \ ../src/variables/CIncEulerVariable.cpp \ + ../src/variables/CScalarVariable.cpp \ ../src/variables/CTurbVariable.cpp \ ../src/variables/CNSVariable.cpp \ ../src/variables/CNEMOEulerVariable.cpp \ From 63dcf11e57a24a61760017c8f3a1cd8b125c496c Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 09:46:20 +0200 Subject: [PATCH 18/48] Revert "I am just asking some questions :)" This reverts commit c922bc6381be2a69b97b7e8845d08295366916eb. --- SU2_CFD/src/solvers/CScalarSolver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 3d672d12b31d..757f29eaafc4 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -785,7 +785,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c /*--- This is temporary and only valid for constant-density problems: density could also be temperature dependent, but as it is not a part of the solution vector it's neither stored for previous time steps - nor updated with the solution at the end of each iteration. */ //TK:: Then we should prohibit that use? + nor updated with the solution at the end of each iteration. */ Density_nM1 = flowNodes->GetDensity(iPoint); Density_n = flowNodes->GetDensity(iPoint); Density_nP1 = flowNodes->GetDensity(iPoint); @@ -857,7 +857,7 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig unsigned short skipVars = 0; - if (nDim == 2) skipVars += 6; //TK:: Which order to load write, i.e. mean_flow, turb, scalar1, scalar2, ... + if (nDim == 2) skipVars += 6; if (nDim == 3) skipVars += 8; /*--- Adjust the number of solution variables in the incompressible @@ -874,7 +874,7 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig /*--- Load data from the restart into correct containers. ---*/ - unsigned long counter = 0, iPoint_Global = 0;//TK::why ouside, not used outside loop... + unsigned long counter = 0, iPoint_Global = 0; for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { From 076bfcd9a78569f7eb6b82ea4b3dde9c42050ec4 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 15:03:51 +0200 Subject: [PATCH 19/48] Move ComputeUnderRelaxation to CTurbSASolver. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 4 +- SU2_CFD/include/solvers/CTurbSASolver.hpp | 7 ++++ SU2_CFD/src/solvers/CScalarSolver.cpp | 51 ----------------------- SU2_CFD/src/solvers/CTurbSASolver.cpp | 44 +++++++++++++++++++ 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 053e8538b4da..ec860ae8d26b 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -103,10 +103,10 @@ class CScalarSolver : public CSolver { /*! * \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over - * a nonlinear iteration for stability. + * a nonlinear iteration for stability. Default value 1.0 set in ctor of CScalarVariable. * \param[in] config - Definition of the particular problem. */ - void ComputeUnderRelaxationFactor(const CConfig *config); + virtual void ComputeUnderRelaxationFactor(const CConfig *config) { } public: diff --git a/SU2_CFD/include/solvers/CTurbSASolver.hpp b/SU2_CFD/include/solvers/CTurbSASolver.hpp index 4ffd06f3e1cc..3ca3b84e1f3f 100644 --- a/SU2_CFD/include/solvers/CTurbSASolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSASolver.hpp @@ -65,6 +65,13 @@ class CTurbSASolver final : public CTurbSolver { const CConfig *config, unsigned short val_marker); + /*! + * \brief Compute a suitable under-relaxation parameter to limit the change in the solution variables over + * a nonlinear iteration for stability. + * \param[in] config - Definition of the particular problem. + */ + void ComputeUnderRelaxationFactor(const CConfig *config) final; + public: /*! * \brief Constructor of the class. diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 757f29eaafc4..6e45e99f91fc 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -497,57 +497,6 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry *geometry, CSolver **solve } -void CScalarSolver::ComputeUnderRelaxationFactor(const CConfig *config) { - - /* Only apply the turbulent under-relaxation to the SA variants. The - SA_NEG model is more robust due to allowing for negative nu_tilde, - so the under-relaxation is not applied to that variant. */ - - bool sa_model = ((config->GetKind_Turb_Model() == SA) || - (config->GetKind_Turb_Model() == SA_E) || - (config->GetKind_Turb_Model() == SA_COMP) || - (config->GetKind_Turb_Model() == SA_E_COMP)); - - /* Loop over the solution update given by relaxing the linear - system for this nonlinear iteration. */ - - su2double localUnderRelaxation = 1.00; - const su2double allowableRatio = 0.99; - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - - localUnderRelaxation = 1.0; - if (sa_model) { - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - - /* We impose a limit on the maximum percentage that the - turbulence variables can change over a nonlinear iteration. */ - - const unsigned long index = iPoint * nVar + iVar; - su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); - if (ratio > allowableRatio) { - localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); - } - - } - } - - /* Threshold the relaxation factor in the event that there is - a very small value. This helps avoid catastrophic crashes due - to non-realizable states by canceling the update. */ - - if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0; - - /* Store the under-relaxation factor for this point. */ - - nodes->SetUnderRelaxation(iPoint, localUnderRelaxation); - - } - END_SU2_OMP_FOR - -} - void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_container, CConfig *config, unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 6877cb92b9ad..bb16b5f6e2cf 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -1588,3 +1588,47 @@ void CTurbSASolver::SetUniformInlet(const CConfig* config, unsigned short iMarke } } + +void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { + + /* Apply the turbulent under-relaxation to the SA variants. The + SA_NEG model is more robust due to allowing for negative nu_tilde, + so the under-relaxation is not applied to that variant. */ + + /* Loop over the solution update given by relaxing the linear + system for this nonlinear iteration. */ + + su2double localUnderRelaxation = 1.00; + const su2double allowableRatio = 0.99; + + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + + localUnderRelaxation = 1.0; + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + + /* We impose a limit on the maximum percentage that the + turbulence variables can change over a nonlinear iteration. */ + + const unsigned long index = iPoint * nVar + iVar; + su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); + if (ratio > allowableRatio) { + localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); + } + + } + + /* Threshold the relaxation factor in the event that there is + a very small value. This helps avoid catastrophic crashes due + to non-realizable states by canceling the update. */ + + if (localUnderRelaxation < 1e-10) localUnderRelaxation = 0.0; + + /* Store the under-relaxation factor for this point. */ + + nodes->SetUnderRelaxation(iPoint, localUnderRelaxation); + + } + END_SU2_OMP_FOR + +} \ No newline at end of file From eb360d9da8b5fd57d32d721768d9aded7cb87af8 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 15:10:28 +0200 Subject: [PATCH 20/48] Update SU2 version on added scalar files. --- SU2_CFD/include/numerics/scalar/scalar_convection.hpp | 4 ++-- SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp | 4 ++-- SU2_CFD/include/numerics/scalar/scalar_sources.hpp | 4 ++-- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- SU2_CFD/include/variables/CScalarVariable.hpp | 2 +- SU2_CFD/src/numerics/scalar/scalar_convection.cpp | 4 ++-- SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp | 4 ++-- SU2_CFD/src/numerics/scalar/scalar_sources.cpp | 4 ++-- SU2_CFD/src/solvers/CScalarSolver.cpp | 2 +- SU2_CFD/src/variables/CScalarVariable.cpp | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp index 268619317068..6bd5c4fdddcb 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -1,9 +1,9 @@ /*! * \file turb_convection.hpp * \brief Delarations of numerics classes for discretization of - * convective fluxes in turbulence problems. + * convective fluxes in scalar problems. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index f2e396855d04..64b5336b14b5 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -1,9 +1,9 @@ /*! * \file turb_diffusion.hpp * \brief Declarations of numerics classes for discretization of - * viscous fluxes in turbulence problems. + * viscous fluxes in scalar problems. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp index 08941bf7343e..9871905c3fa4 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp @@ -1,9 +1,9 @@ /*! * \file turb_sources.hpp * \brief Delarations of numerics classes for integration of source - * terms in turbulence problems. + * terms in scalar problems. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index ec860ae8d26b..6d610ff80ae6 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -2,7 +2,7 @@ * \file CScalarSolver.hpp * \brief Headers of the CScalarSolver class * \author A. Bueno. - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 0052aa23c239..948b9735056f 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -2,7 +2,7 @@ * \file CScalarVariable.hpp * \brief Base class for defining the variables of the turbulence model. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp index f4f341746466..a6ef5f7cd40a 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -1,9 +1,9 @@ /*! * \file turb_convection.cpp * \brief Implementation of numerics classes to compute convective - * fluxes in turbulence problems. + * fluxes in scalar problems. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index ec6bb0ea13ac..b6ea2cfe0cb2 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -1,9 +1,9 @@ /*! * \file turb_diffusion.cpp * \brief Implementation of numerics classes to compute viscous - * fluxes in turbulence problems. + * fluxes in scalar problems. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp index 58874b7313bc..9e4b637429ab 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp @@ -1,9 +1,9 @@ /*! * \file turb_sources.cpp * \brief Implementation of numerics classes for integration of - * turbulence source-terms. + * scalar source-terms. * \author F. Palacios, T. Economon - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 6e45e99f91fc..b90b1569ed64 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -2,7 +2,7 @@ * \file CScalarSolver.cpp * \brief Main subrotuines of CScalarSolver class * \author F. Palacios, A. Bueno - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * diff --git a/SU2_CFD/src/variables/CScalarVariable.cpp b/SU2_CFD/src/variables/CScalarVariable.cpp index 2a2bde7d6782..0bbf4460db85 100644 --- a/SU2_CFD/src/variables/CScalarVariable.cpp +++ b/SU2_CFD/src/variables/CScalarVariable.cpp @@ -2,7 +2,7 @@ * \file CScalarVariable.cpp * \brief Definition of the solution fields. * \author F. Palacios, A. Bueno - * \version 7.1.1 "Blackbird" + * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io * From d9a5e4df3bd01b83797ec60b3f0ca83d958e7395 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 15:22:21 +0200 Subject: [PATCH 21/48] Move HB_Source back from CTurbVariable to CScalarVariable. --- SU2_CFD/include/variables/CScalarVariable.hpp | 1 + SU2_CFD/include/variables/CTurbVariable.hpp | 3 +-- SU2_CFD/src/variables/CScalarVariable.cpp | 7 ++++++- SU2_CFD/src/variables/CTurbVariable.cpp | 9 +-------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 948b9735056f..19ed687b024e 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -37,6 +37,7 @@ */ class CScalarVariable : public CVariable { protected: + MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */ CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ diff --git a/SU2_CFD/include/variables/CTurbVariable.hpp b/SU2_CFD/include/variables/CTurbVariable.hpp index 7c2838fe7c6e..533cfa2ffbf7 100644 --- a/SU2_CFD/include/variables/CTurbVariable.hpp +++ b/SU2_CFD/include/variables/CTurbVariable.hpp @@ -37,8 +37,7 @@ */ class CTurbVariable : public CScalarVariable { protected: - VectorType muT; /*!< \brief Eddy viscosity. */ - MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ + VectorType muT; /*!< \brief Eddy viscosity. */ public: /*! diff --git a/SU2_CFD/src/variables/CScalarVariable.cpp b/SU2_CFD/src/variables/CScalarVariable.cpp index 0bbf4460db85..7fc67bb17256 100644 --- a/SU2_CFD/src/variables/CScalarVariable.cpp +++ b/SU2_CFD/src/variables/CScalarVariable.cpp @@ -44,7 +44,7 @@ CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsig Rmatrix.resize(nPoint,nDim,nDim,0.0); } - /*--- Always allocate the slope limiter, and the auxiliar + /*--- Always allocate the slope limiter, and the auxiliary variables (check the logic - JST with 2nd order Turb model) ---*/ Limiter.resize(nPoint,nVar) = su2double(0.0); @@ -57,4 +57,9 @@ CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsig UnderRelaxation.resize(nPoint) = su2double(1.0); LocalCFL.resize(nPoint) = su2double(0.0); + /*--- Allocate space for the harmonic balance source terms ---*/ + if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { + HB_Source.resize(nPoint,nVar) = su2double(0.0); + } + } diff --git a/SU2_CFD/src/variables/CTurbVariable.cpp b/SU2_CFD/src/variables/CTurbVariable.cpp index 4fc27d2f09f3..2df5c1ae5717 100644 --- a/SU2_CFD/src/variables/CTurbVariable.cpp +++ b/SU2_CFD/src/variables/CTurbVariable.cpp @@ -30,11 +30,4 @@ CTurbVariable::CTurbVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) - : CScalarVariable(npoint, ndim, nvar, config) { - - /*--- Allocate space for the harmonic balance source terms ---*/ - if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { - HB_Source.resize(nPoint,nVar) = su2double(0.0); - } - -} + : CScalarVariable(npoint, ndim, nvar, config) { } From 987d60e5ca76337e3c92c47b09706e9ab6041c36 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 15:31:44 +0200 Subject: [PATCH 22/48] Make empty BC_Sym/BC_EulerWall of CScalar inline and remove cpp impl. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 28 +++++++++++++---------- SU2_CFD/src/solvers/CScalarSolver.cpp | 22 ------------------ 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 6d610ff80ae6..1a6f60e59268 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -150,12 +150,14 @@ class CScalarSolver : public CSolver { * \param[in] config - Definition of the particular problem. * \param[in] val_marker - Surface marker where the boundary condition is applied. */ - void BC_Sym_Plane(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override; + inline void BC_Sym_Plane(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) override { + /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ + }; /*! * \brief Impose via the residual the Euler wall boundary condition. @@ -166,12 +168,14 @@ class CScalarSolver : public CSolver { * \param[in] config - Definition of the particular problem. * \param[in] val_marker - Surface marker where the boundary condition is applied. */ - void BC_Euler_Wall(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override; + inline void BC_Euler_Wall(CGeometry *geometry, + CSolver **solver_container, + CNumerics *conv_numerics, + CNumerics *visc_numerics, + CConfig *config, + unsigned short val_marker) override { + /*--- Convective fluxes across euler wall are equal to zero. ---*/ + }; /*! * \brief Impose a periodic boundary condition by summing contributions from the complete control volume. diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index b90b1569ed64..f13d8d43db16 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -313,28 +313,6 @@ void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { } -void CScalarSolver::BC_Sym_Plane(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) { - - /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ - -} - -void CScalarSolver::BC_Euler_Wall(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) { - - /*--- Convective fluxes across euler wall are equal to zero. ---*/ - -} - void CScalarSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, CNumerics *numerics, CConfig *config) { From 0b60a280323a5fa757e8d1636a0a2ee486d3ab18 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 17:34:43 +0200 Subject: [PATCH 23/48] SA UnderRelax error fixed. --- SU2_CFD/src/solvers/CTurbSASolver.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index bb16b5f6e2cf..91fdea667f6d 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -1595,6 +1595,11 @@ void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { SA_NEG model is more robust due to allowing for negative nu_tilde, so the under-relaxation is not applied to that variant. */ + bool sa_model = ((config->GetKind_Turb_Model() == SA) || + (config->GetKind_Turb_Model() == SA_E) || + (config->GetKind_Turb_Model() == SA_COMP) || + (config->GetKind_Turb_Model() == SA_E_COMP)); + /* Loop over the solution update given by relaxing the linear system for this nonlinear iteration. */ @@ -1605,17 +1610,19 @@ void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { localUnderRelaxation = 1.0; - for (unsigned short iVar = 0; iVar < nVar; iVar++) { + if (sa_model) { + for (unsigned short iVar = 0; iVar < nVar; iVar++) { - /* We impose a limit on the maximum percentage that the - turbulence variables can change over a nonlinear iteration. */ + /* We impose a limit on the maximum percentage that the + turbulence variables can change over a nonlinear iteration. */ - const unsigned long index = iPoint * nVar + iVar; - su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); - if (ratio > allowableRatio) { - localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); - } + const unsigned long index = iPoint * nVar + iVar; + su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); + if (ratio > allowableRatio) { + localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); + } + } } /* Threshold the relaxation factor in the event that there is From ab6d8e6cb7fbc53e4a607efb3c458d4b76044c43 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Fri, 27 Aug 2021 23:54:46 +0200 Subject: [PATCH 24/48] Apply clang-format to (C)scalar* files. Changes necessary. Applied via clang-format -i -style=file filename. Wrong indentations for vars sharing the same type. One space indentations of protected, public keywords. --- .../numerics/scalar/scalar_convection.hpp | 16 +- .../numerics/scalar/scalar_diffusion.hpp | 21 +- SU2_CFD/include/solvers/CScalarSolver.hpp | 101 ++-- SU2_CFD/include/variables/CScalarVariable.hpp | 17 +- .../src/numerics/scalar/scalar_convection.cpp | 61 +- .../src/numerics/scalar/scalar_diffusion.cpp | 85 +-- SU2_CFD/src/solvers/CScalarSolver.cpp | 551 ++++++++---------- SU2_CFD/src/variables/CScalarVariable.cpp | 23 +- 8 files changed, 388 insertions(+), 487 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp index 6bd5c4fdddcb..a12cd966dcd5 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -45,13 +45,12 @@ * \author C. Pederson, A. Bueno., and A. Campos. */ class CUpwScalar : public CNumerics { -protected: - su2double - a0 = 0.0, /*!< \brief The maximum of the face-normal velocity and 0 */ - a1 = 0.0, /*!< \brief The minimum of the face-normal velocity and 0 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + protected: + su2double a0 = 0.0, /*!< \brief The maximum of the face-normal velocity and 0 */ + a1 = 0.0, /*!< \brief The minimum of the face-normal velocity and 0 */ + *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ + **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ + **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ const bool implicit = false, incompressible = false, dynamic_grid = false; @@ -67,7 +66,7 @@ class CUpwScalar : public CNumerics { */ virtual void FinishResidualCalc(const CConfig* config) = 0; -public: + public: /*! * \brief Constructor of the class. * \param[in] val_nDim - Number of dimensions of the problem. @@ -87,5 +86,4 @@ class CUpwScalar : public CNumerics { * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. */ ResidualType<> ComputeResidual(const CConfig* config) override; - }; diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index 64b5336b14b5..f1fe3f1985c3 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -45,14 +45,13 @@ * \author C. Pederson, A. Bueno, and F. Palacios */ class CAvgGrad_Scalar : public CNumerics { -protected: - su2double - *Proj_Mean_GradScalarVar_Normal = nullptr, /*!< \brief Mean_gradScalarVar DOT normal. */ - *Proj_Mean_GradScalarVar = nullptr, /*!< \brief Mean_gradScalarVar DOT normal, corrected if required. */ - proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + protected: + su2double *Proj_Mean_GradScalarVar_Normal = nullptr, /*!< \brief Mean_gradScalarVar DOT normal. */ + *Proj_Mean_GradScalarVar = nullptr, /*!< \brief Mean_gradScalarVar DOT normal, corrected if required. */ + proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ + *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ + **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ + **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ const bool correct_gradient = false, implicit = false, incompressible = false; @@ -68,7 +67,7 @@ class CAvgGrad_Scalar : public CNumerics { */ virtual void FinishResidualCalc(const CConfig* config) = 0; -public: + public: /*! * \brief Constructor of the class. * \param[in] val_nDim - Number of dimensions of the problem. @@ -76,8 +75,7 @@ class CAvgGrad_Scalar : public CNumerics { * \param[in] correct_gradient - Whether to correct gradient for skewness. * \param[in] config - Definition of the particular problem. */ - CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, - bool correct_gradient, const CConfig* config); + CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, bool correct_gradient, const CConfig* config); /*! * \brief Destructor of the class. @@ -90,5 +88,4 @@ class CAvgGrad_Scalar : public CNumerics { * \return A lightweight const-view (read-only) of the residual/flux and Jacobians. */ ResidualType<> ComputeResidual(const CConfig* config) override; - }; diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 1a6f60e59268..a0cfd668176b 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -27,9 +27,9 @@ #pragma once -#include "CSolver.hpp" -#include "../variables/CScalarVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" +#include "../variables/CScalarVariable.hpp" +#include "CSolver.hpp" /*! * \class CScalarSolver @@ -38,29 +38,28 @@ * \author A. Bueno. */ class CScalarSolver : public CSolver { -protected: - enum : size_t {MAXNDIM = 3}; /*!< \brief Max number of space dimensions, used in some static arrays. */ - enum : size_t {MAXNVAR = 2}; /*!< \brief Max number of variables, used in some static arrays. */ - enum : size_t {MAXNVARFLOW = 12}; /*!< \brief Max number of flow variables, used in some static arrays. */ + protected: + enum : size_t { MAXNDIM = 3 }; /*!< \brief Max number of space dimensions, used in some static arrays. */ + enum : size_t { MAXNVAR = 2 }; /*!< \brief Max number of variables, used in some static arrays. */ + enum : size_t { MAXNVARFLOW = 12 }; /*!< \brief Max number of flow variables, used in some static arrays. */ - enum : size_t {OMP_MAX_SIZE = 512}; /*!< \brief Max chunk size for light point loops. */ - enum : size_t {OMP_MIN_SIZE = 32}; /*!< \brief Min chunk size for edge loops (max is color group size). */ + enum : size_t { OMP_MAX_SIZE = 512 }; /*!< \brief Max chunk size for light point loops. */ + enum : size_t { OMP_MIN_SIZE = 32 }; /*!< \brief Min chunk size for edge loops (max is color group size). */ unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double - lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ - upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ + su2double lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ + upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ #ifdef HAVE_OMP - vector > EdgeColoring; /*!< \brief Edge colors. */ - bool ReducerStrategy = false; /*!< \brief If the reducer strategy is in use. */ + vector > EdgeColoring; /*!< \brief Edge colors. */ + bool ReducerStrategy = false; /*!< \brief If the reducer strategy is in use. */ #else - array,1> EdgeColoring; + array, 1> EdgeColoring; /*--- Never use the reducer strategy if compiling for MPI-only. ---*/ static constexpr bool ReducerStrategy = false; #endif @@ -78,8 +77,7 @@ class CScalarSolver : public CSolver { */ inline CVariable* GetBaseClassPointerToNodes() final { return nodes; } -private: //changed from private in CTurbSolver.hpp - + private: // changed from private in CTurbSolver.hpp /*! * \brief Compute the viscous flux for the turbulent equation at a particular edge. * \param[in] iEdge - Edge for which we want to compute the flux @@ -88,11 +86,8 @@ class CScalarSolver : public CSolver { * \param[in] numerics - Description of the numerical method. * \param[in] config - Definition of the particular problem. */ - void Viscous_Residual(unsigned long iEdge, - CGeometry *geometry, - CSolver **solver_container, - CNumerics *numerics, - CConfig *config); + void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, + CConfig* config); using CSolver::Viscous_Residual; /*--- Silence warning ---*/ /*! @@ -106,10 +101,9 @@ class CScalarSolver : public CSolver { * a nonlinear iteration for stability. Default value 1.0 set in ctor of CScalarVariable. * \param[in] config - Definition of the particular problem. */ - virtual void ComputeUnderRelaxationFactor(const CConfig *config) { } - -public: + virtual void ComputeUnderRelaxationFactor(const CConfig* config) {} + public: /*! * \brief Constructor of the class. */ @@ -125,7 +119,7 @@ class CScalarSolver : public CSolver { * \param[in] geometry - Geometrical definition of the problem. * \param[in] config - Definition of the particular problem. */ - CScalarSolver(CGeometry* geometry, CConfig *config); + CScalarSolver(CGeometry* geometry, CConfig* config); /*! * \brief Compute the spatial integration using a upwind scheme. @@ -135,10 +129,7 @@ class CScalarSolver : public CSolver { * \param[in] config - Definition of the particular problem. * \param[in] iMesh - Index of the mesh in multigrid computations. */ - void Upwind_Residual(CGeometry *geometry, - CSolver **solver_container, - CNumerics **numerics_container, - CConfig *config, + void Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config, unsigned short iMesh) override; /*! @@ -150,13 +141,9 @@ class CScalarSolver : public CSolver { * \param[in] config - Definition of the particular problem. * \param[in] val_marker - Surface marker where the boundary condition is applied. */ - inline void BC_Sym_Plane(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override { - /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ + inline void BC_Sym_Plane(CGeometry* geometry, CSolver** solver_container, CNumerics* conv_numerics, + CNumerics* visc_numerics, CConfig* config, unsigned short val_marker) override{ + /*--- Convective and viscous fluxes across symmetry plane are equal to zero. ---*/ }; /*! @@ -168,13 +155,9 @@ class CScalarSolver : public CSolver { * \param[in] config - Definition of the particular problem. * \param[in] val_marker - Surface marker where the boundary condition is applied. */ - inline void BC_Euler_Wall(CGeometry *geometry, - CSolver **solver_container, - CNumerics *conv_numerics, - CNumerics *visc_numerics, - CConfig *config, - unsigned short val_marker) override { - /*--- Convective fluxes across euler wall are equal to zero. ---*/ + inline void BC_Euler_Wall(CGeometry* geometry, CSolver** solver_container, CNumerics* conv_numerics, + CNumerics* visc_numerics, CConfig* config, unsigned short val_marker) override{ + /*--- Convective fluxes across euler wall are equal to zero. ---*/ }; /*! @@ -184,18 +167,15 @@ class CScalarSolver : public CSolver { * \param[in] numerics - Description of the numerical method. * \param[in] config - Definition of the particular problem. */ - void BC_Periodic(CGeometry *geometry, - CSolver **solver_container, - CNumerics *numerics, - CConfig *config) final; + void BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) final; /*! * \brief Set the solution using the Freestream values. * \param[in] config - Definition of the particular problem. */ - inline void SetFreeStream_Solution(const CConfig *config) final { + inline void SetFreeStream_Solution(const CConfig* config) final { SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++){ + for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { nodes->SetSolution(iPoint, Solution_Inf); } END_SU2_OMP_FOR @@ -207,7 +187,7 @@ class CScalarSolver : public CSolver { * \param[in] solver_container - Container vector with all the solutions. * \param[in] config - Definition of the particular problem. */ - void PrepareImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; + void PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) final; /*! * \brief Complete an implicit iteration. @@ -215,7 +195,7 @@ class CScalarSolver : public CSolver { * \param[in] solver_container - Container vector with all the solutions. * \param[in] config - Definition of the particular problem. */ - void CompleteImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) final; + void CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) final; /*! * \brief Update the solution using an implicit solver. @@ -223,9 +203,7 @@ class CScalarSolver : public CSolver { * \param[in] solver_container - Container vector with all the solutions. * \param[in] config - Definition of the particular problem. */ - void ImplicitEuler_Iteration(CGeometry *geometry, - CSolver **solver_container, - CConfig *config) override; + void ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) override; /*! * \brief Set the total residual adding the term that comes from the Dual Time-Stepping Strategy. @@ -236,12 +214,8 @@ class CScalarSolver : public CSolver { * \param[in] iMesh - Index of the mesh in multigrid computations. * \param[in] RunTime_EqSystem - System of equations which is going to be solved. */ - void SetResidual_DualTime(CGeometry *geometry, - CSolver **solver_container, - CConfig *config, - unsigned short iRKStep, - unsigned short iMesh, - unsigned short RunTime_EqSystem) final; + void SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, unsigned short iRKStep, + unsigned short iMesh, unsigned short RunTime_EqSystem) final; /*! * \brief Load a solution from a restart file. @@ -251,15 +225,10 @@ class CScalarSolver : public CSolver { * \param[in] val_iter - Current external iteration number. * \param[in] val_update_geo - Flag for updating coords and grid velocity. */ - void LoadRestart(CGeometry **geometry, - CSolver ***solver, - CConfig *config, - int val_iter, - bool val_update_geo) final; + void LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) final; /*! * \brief SA and SST support OpenMP+MPI. */ inline bool GetHasHybridParallel() const override { return true; } - }; diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 19ed687b024e..02fc5d5d9960 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -36,13 +36,15 @@ * \author A. Bueno. */ class CScalarVariable : public CVariable { -protected: + protected: MatrixType HB_Source; /*!< \brief Harmonic Balance source term. */ - CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */ - CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ + CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL + reconstruction for the convective term */ + CVectorOfMatrix + Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */ -public: + public: /*! * \brief Constructor of the class. * \param[in] npoint - Number of points/nodes/vertices in the domain. @@ -50,7 +52,7 @@ class CScalarVariable : public CVariable { * \param[in] nvar - Number of variables of the problem. * \param[in] config - Definition of the particular problem. */ - CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config); + CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig* config); /*! * \brief Destructor of the class. @@ -62,7 +64,9 @@ class CScalarVariable : public CVariable { * \param[in] iPoint - Index of the current node. * \return Array of the reconstruction variables gradient at a node. */ - inline CMatrixView GetGradient_Reconstruction(unsigned long iPoint) final { return Gradient_Reconstruction[iPoint]; } + inline CMatrixView GetGradient_Reconstruction(unsigned long iPoint) final { + return Gradient_Reconstruction[iPoint]; + } /*! * \brief Get the reconstruction gradient for primitive variable at all points. @@ -70,5 +74,4 @@ class CScalarVariable : public CVariable { */ inline CVectorOfMatrix& GetGradient_Reconstruction() final { return Gradient_Reconstruction; } inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; } - }; diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp index a6ef5f7cd40a..f07e8123917d 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -28,68 +28,64 @@ #include "../../../include/numerics/scalar/scalar_convection.hpp" -CUpwScalar::CUpwScalar(unsigned short val_nDim, - unsigned short val_nVar, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), - dynamic_grid(config->GetDynamic_Grid()) -{ - Flux = new su2double [nVar]; - Jacobian_i = new su2double* [nVar]; - Jacobian_j = new su2double* [nVar]; +CUpwScalar::CUpwScalar(unsigned short val_nDim, unsigned short val_nVar, const CConfig* config) + : CNumerics(val_nDim, val_nVar, config), + implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE), + dynamic_grid(config->GetDynamic_Grid()) { + Flux = new su2double[nVar]; + Jacobian_i = new su2double*[nVar]; + Jacobian_j = new su2double*[nVar]; for (unsigned short iVar = 0; iVar < nVar; iVar++) { - Jacobian_i[iVar] = new su2double [nVar]; - Jacobian_j[iVar] = new su2double [nVar]; + Jacobian_i[iVar] = new su2double[nVar]; + Jacobian_j[iVar] = new su2double[nVar]; } } CUpwScalar::~CUpwScalar(void) { - - delete [] Flux; + delete[] Flux; if (Jacobian_i != nullptr) { for (unsigned short iVar = 0; iVar < nVar; iVar++) { - delete [] Jacobian_i[iVar]; - delete [] Jacobian_j[iVar]; + delete[] Jacobian_i[iVar]; + delete[] Jacobian_j[iVar]; } - delete [] Jacobian_i; - delete [] Jacobian_j; + delete[] Jacobian_i; + delete[] Jacobian_j; } } CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { - unsigned short iDim; AD::StartPreacc(); AD::SetPreaccIn(Normal, nDim); - AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j, nVar); + AD::SetPreaccIn(ScalarVar_i, nVar); + AD::SetPreaccIn(ScalarVar_j, nVar); if (dynamic_grid) { - AD::SetPreaccIn(GridVel_i, nDim); AD::SetPreaccIn(GridVel_j, nDim); + AD::SetPreaccIn(GridVel_i, nDim); + AD::SetPreaccIn(GridVel_j, nDim); } ExtraADPreaccIn(); - Density_i = V_i[nDim+2]; - Density_j = V_j[nDim+2]; + Density_i = V_i[nDim + 2]; + Density_j = V_j[nDim + 2]; su2double q_ij = 0.0; if (dynamic_grid) { for (iDim = 0; iDim < nDim; iDim++) { - su2double Velocity_i = V_i[iDim+1] - GridVel_i[iDim]; - su2double Velocity_j = V_j[iDim+1] - GridVel_j[iDim]; - q_ij += 0.5*(Velocity_i+Velocity_j)*Normal[iDim]; + su2double Velocity_i = V_i[iDim + 1] - GridVel_i[iDim]; + su2double Velocity_j = V_j[iDim + 1] - GridVel_j[iDim]; + q_ij += 0.5 * (Velocity_i + Velocity_j) * Normal[iDim]; } - } - else { + } else { for (iDim = 0; iDim < nDim; iDim++) { - q_ij += 0.5*(V_i[iDim+1]+V_j[iDim+1])*Normal[iDim]; + q_ij += 0.5 * (V_i[iDim + 1] + V_j[iDim + 1]) * Normal[iDim]; } } - a0 = 0.5*(q_ij+fabs(q_ij)); - a1 = 0.5*(q_ij-fabs(q_ij)); + a0 = 0.5 * (q_ij + fabs(q_ij)); + a1 = 0.5 * (q_ij - fabs(q_ij)); FinishResidualCalc(config); @@ -97,5 +93,4 @@ CNumerics::ResidualType<> CUpwScalar::ComputeResidual(const CConfig* config) { AD::EndPreacc(); return ResidualType<>(Flux, Jacobian_i, Jacobian_j); - } diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index b6ea2cfe0cb2..b3fc5d873a35 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -28,78 +28,81 @@ #include "../../../include/numerics/scalar/scalar_diffusion.hpp" -CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, - unsigned short val_nVar, - bool correct_grad, - const CConfig* config) : - CNumerics(val_nDim, val_nVar, config), - correct_gradient(correct_grad), - implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), - incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) -{ - Proj_Mean_GradScalarVar_Normal = new su2double [nVar] (); - Proj_Mean_GradScalarVar = new su2double [nVar] (); +CAvgGrad_Scalar::CAvgGrad_Scalar(unsigned short val_nDim, unsigned short val_nVar, bool correct_grad, + const CConfig* config) + : CNumerics(val_nDim, val_nVar, config), + correct_gradient(correct_grad), + implicit(config->GetKind_TimeIntScheme_Turb() == EULER_IMPLICIT), + incompressible(config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) { + Proj_Mean_GradScalarVar_Normal = new su2double[nVar](); + Proj_Mean_GradScalarVar = new su2double[nVar](); - Flux = new su2double [nVar] (); - Jacobian_i = new su2double* [nVar]; - Jacobian_j = new su2double* [nVar]; + Flux = new su2double[nVar](); + Jacobian_i = new su2double*[nVar]; + Jacobian_j = new su2double*[nVar]; for (unsigned short iVar = 0; iVar < nVar; iVar++) { - Jacobian_i[iVar] = new su2double [nVar] (); - Jacobian_j[iVar] = new su2double [nVar] (); + Jacobian_i[iVar] = new su2double[nVar](); + Jacobian_j[iVar] = new su2double[nVar](); } } CAvgGrad_Scalar::~CAvgGrad_Scalar(void) { + delete[] Proj_Mean_GradScalarVar_Normal; + delete[] Proj_Mean_GradScalarVar; - delete [] Proj_Mean_GradScalarVar_Normal; - delete [] Proj_Mean_GradScalarVar; - - delete [] Flux; + delete[] Flux; if (Jacobian_i != nullptr) { for (unsigned short iVar = 0; iVar < nVar; iVar++) { - delete [] Jacobian_i[iVar]; - delete [] Jacobian_j[iVar]; + delete[] Jacobian_i[iVar]; + delete[] Jacobian_j[iVar]; } - delete [] Jacobian_i; - delete [] Jacobian_j; + delete[] Jacobian_i; + delete[] Jacobian_j; } } CNumerics::ResidualType<> CAvgGrad_Scalar::ComputeResidual(const CConfig* config) { - AD::StartPreacc(); - AD::SetPreaccIn(Coord_i, nDim); AD::SetPreaccIn(Coord_j, nDim); + AD::SetPreaccIn(Coord_i, nDim); + AD::SetPreaccIn(Coord_j, nDim); AD::SetPreaccIn(Normal, nDim); AD::SetPreaccIn(ScalarVar_Grad_i, nVar, nDim); AD::SetPreaccIn(ScalarVar_Grad_j, nVar, nDim); if (correct_gradient) { - AD::SetPreaccIn(ScalarVar_i, nVar); AD::SetPreaccIn(ScalarVar_j ,nVar); + AD::SetPreaccIn(ScalarVar_i, nVar); + AD::SetPreaccIn(ScalarVar_j, nVar); } ExtraADPreaccIn(); if (incompressible) { - AD::SetPreaccIn(V_i, nDim+6); AD::SetPreaccIn(V_j, nDim+6); + AD::SetPreaccIn(V_i, nDim + 6); + AD::SetPreaccIn(V_j, nDim + 6); - Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+4]; Laminar_Viscosity_j = V_j[nDim+4]; - Eddy_Viscosity_i = V_i[nDim+5]; Eddy_Viscosity_j = V_j[nDim+5]; - } - else { - AD::SetPreaccIn(V_i, nDim+7); AD::SetPreaccIn(V_j, nDim+7); + Density_i = V_i[nDim + 2]; + Density_j = V_j[nDim + 2]; + Laminar_Viscosity_i = V_i[nDim + 4]; + Laminar_Viscosity_j = V_j[nDim + 4]; + Eddy_Viscosity_i = V_i[nDim + 5]; + Eddy_Viscosity_j = V_j[nDim + 5]; + } else { + AD::SetPreaccIn(V_i, nDim + 7); + AD::SetPreaccIn(V_j, nDim + 7); - Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; - Laminar_Viscosity_i = V_i[nDim+5]; Laminar_Viscosity_j = V_j[nDim+5]; - Eddy_Viscosity_i = V_i[nDim+6]; Eddy_Viscosity_j = V_j[nDim+6]; + Density_i = V_i[nDim + 2]; + Density_j = V_j[nDim + 2]; + Laminar_Viscosity_i = V_i[nDim + 5]; + Laminar_Viscosity_j = V_j[nDim + 5]; + Eddy_Viscosity_i = V_i[nDim + 6]; + Eddy_Viscosity_j = V_j[nDim + 6]; } - proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, ScalarVar_Grad_i, - ScalarVar_Grad_j, correct_gradient, ScalarVar_i, ScalarVar_j, - Proj_Mean_GradScalarVar_Normal, Proj_Mean_GradScalarVar); + proj_vector_ij = ComputeProjectedGradient(nDim, nVar, Normal, Coord_i, Coord_j, ScalarVar_Grad_i, ScalarVar_Grad_j, + correct_gradient, ScalarVar_i, ScalarVar_j, Proj_Mean_GradScalarVar_Normal, + Proj_Mean_GradScalarVar); FinishResidualCalc(config); AD::SetPreaccOut(Flux, nVar); AD::EndPreacc(); return ResidualType<>(Flux, Jacobian_i, Jacobian_j); - } diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index f13d8d43db16..466fd5356f2b 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -26,20 +26,18 @@ */ #include "../../include/solvers/CScalarSolver.hpp" + #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" +CScalarSolver::CScalarSolver(void) : CSolver() {} -CScalarSolver::CScalarSolver(void) : CSolver() { } - -CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { - +CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config) : CSolver() { nMarker = config->GetnMarker_All(); /*--- Store the number of vertices on each marker for deallocation later ---*/ nVertex.resize(nMarker); - for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) - nVertex[iMarker] = geometry->nVertex[iMarker]; + for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) nVertex[iMarker] = geometry->nVertex[iMarker]; /* A grid is defined as dynamic if there's rigid grid movement or grid deformation AND the problem is time domain */ dynamic_grid = config->GetDynamic_Grid(); @@ -51,15 +49,14 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { ReducerStrategy = parallelEff < COLORING_EFF_THRESH; - if (ReducerStrategy && (coloring.getOuterSize()>1)) - geometry->SetNaturalEdgeColoring(); + if (ReducerStrategy && (coloring.getOuterSize() > 1)) geometry->SetNaturalEdgeColoring(); if (!coloring.empty()) { - auto groupSize = ReducerStrategy? 1ul : geometry->GetEdgeColorGroupSize(); + auto groupSize = ReducerStrategy ? 1ul : geometry->GetEdgeColorGroupSize(); auto nColor = coloring.getOuterSize(); EdgeColoring.reserve(nColor); - for(auto iColor = 0ul; iColor < nColor; ++iColor) + for (auto iColor = 0ul; iColor < nColor; ++iColor) EdgeColoring.emplace_back(coloring.innerIdx(iColor), coloring.getNumNonZeros(iColor), groupSize); } @@ -70,166 +67,157 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig *config) : CSolver() { #endif } -CScalarSolver::~CScalarSolver() { - - delete nodes; - -} - -void CScalarSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_container, - CNumerics **numerics_container, CConfig *config, unsigned short iMesh) { +CScalarSolver::~CScalarSolver() { delete nodes; } +void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, + CConfig* config, unsigned short iMesh) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool muscl = config->GetMUSCL_Turb(); const bool limiter = (config->GetKind_SlopeLimit_Turb() != NO_LIMITER); /*--- Only reconstruct flow variables if MUSCL is on for flow (requires upwind) and turbulence. ---*/ - const bool musclFlow = config->GetMUSCL_Flow() && muscl && - (config->GetKind_ConvNumScheme_Flow() == SPACE_UPWIND); + const bool musclFlow = config->GetMUSCL_Flow() && muscl && (config->GetKind_ConvNumScheme_Flow() == SPACE_UPWIND); /*--- Only consider flow limiters for cell-based limiters, edge-based would need to be recomputed. ---*/ - const bool limiterFlow = (config->GetKind_SlopeLimit_Flow() != NO_LIMITER) && - (config->GetKind_SlopeLimit_Flow() != VAN_ALBADA_EDGE); + const bool limiterFlow = + (config->GetKind_SlopeLimit_Flow() != NO_LIMITER) && (config->GetKind_SlopeLimit_Flow() != VAN_ALBADA_EDGE); CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); /*--- Pick one numerics object per thread. ---*/ - CNumerics* numerics = numerics_container[CONV_TERM + omp_get_thread_num()*MAX_TERMS]; + CNumerics* numerics = numerics_container[CONV_TERM + omp_get_thread_num() * MAX_TERMS]; /*--- Static arrays of MUSCL-reconstructed flow primitives and turbulence variables (thread safety). ---*/ su2double solution_i[MAXNVAR] = {0.0}, flowPrimVar_i[MAXNVARFLOW] = {0.0}; su2double solution_j[MAXNVAR] = {0.0}, flowPrimVar_j[MAXNVARFLOW] = {0.0}; /*--- For hybrid parallel AD, pause preaccumulation if there is shared reading of - * variables, otherwise switch to the faster adjoint evaluation mode. ---*/ + * variables, otherwise switch to the faster adjoint evaluation mode. ---*/ bool pausePreacc = false; - if (ReducerStrategy) pausePreacc = AD::PausePreaccumulation(); - else AD::StartNoSharedReading(); + if (ReducerStrategy) + pausePreacc = AD::PausePreaccumulation(); + else + AD::StartNoSharedReading(); /*--- Loop over edge colors. ---*/ - for (auto color : EdgeColoring) - { - /*--- Chunk size is at least OMP_MIN_SIZE and a multiple of the color group size. ---*/ - SU2_OMP_FOR_DYN(nextMultiple(OMP_MIN_SIZE, color.groupSize)) - for(auto k = 0ul; k < color.size; ++k) { - - auto iEdge = color.indices[k]; + for (auto color : EdgeColoring) { + /*--- Chunk size is at least OMP_MIN_SIZE and a multiple of the color group size. ---*/ + SU2_OMP_FOR_DYN(nextMultiple(OMP_MIN_SIZE, color.groupSize)) + for (auto k = 0ul; k < color.size; ++k) { + auto iEdge = color.indices[k]; - unsigned short iDim, iVar; + unsigned short iDim, iVar; - /*--- Points in edge and normal vectors ---*/ + /*--- Points in edge and normal vectors ---*/ - auto iPoint = geometry->edges->GetNode(iEdge,0); - auto jPoint = geometry->edges->GetNode(iEdge,1); + auto iPoint = geometry->edges->GetNode(iEdge, 0); + auto jPoint = geometry->edges->GetNode(iEdge, 1); - numerics->SetNormal(geometry->edges->GetNormal(iEdge)); + numerics->SetNormal(geometry->edges->GetNormal(iEdge)); - /*--- Primitive variables w/o reconstruction ---*/ + /*--- Primitive variables w/o reconstruction ---*/ - const auto V_i = flowNodes->GetPrimitive(iPoint); - const auto V_j = flowNodes->GetPrimitive(jPoint); - numerics->SetPrimitive(V_i, V_j); + const auto V_i = flowNodes->GetPrimitive(iPoint); + const auto V_j = flowNodes->GetPrimitive(jPoint); + numerics->SetPrimitive(V_i, V_j); - /*--- Scalar variables w/o reconstruction ---*/ + /*--- Scalar variables w/o reconstruction ---*/ - const auto Scalar_i = nodes->GetSolution(iPoint); - const auto Scalar_j = nodes->GetSolution(jPoint); - numerics->SetScalarVar(Scalar_i, Scalar_j); + const auto Scalar_i = nodes->GetSolution(iPoint); + const auto Scalar_j = nodes->GetSolution(jPoint); + numerics->SetScalarVar(Scalar_i, Scalar_j); - /*--- Grid Movement ---*/ + /*--- Grid Movement ---*/ - if (dynamic_grid) - numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), - geometry->nodes->GetGridVel(jPoint)); + if (dynamic_grid) numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(jPoint)); - if (muscl || musclFlow) { - const su2double *Limiter_i = nullptr, *Limiter_j = nullptr; + if (muscl || musclFlow) { + const su2double *Limiter_i = nullptr, *Limiter_j = nullptr; - const auto Coord_i = geometry->nodes->GetCoord(iPoint); - const auto Coord_j = geometry->nodes->GetCoord(jPoint); + const auto Coord_i = geometry->nodes->GetCoord(iPoint); + const auto Coord_j = geometry->nodes->GetCoord(jPoint); - su2double Vector_ij[MAXNDIM] = {0.0}; - for (iDim = 0; iDim < nDim; iDim++) { - Vector_ij[iDim] = 0.5*(Coord_j[iDim] - Coord_i[iDim]); - } - - if (musclFlow) { - /*--- Reconstruct mean flow primitive variables. ---*/ + su2double Vector_ij[MAXNDIM] = {0.0}; + for (iDim = 0; iDim < nDim; iDim++) { + Vector_ij[iDim] = 0.5 * (Coord_j[iDim] - Coord_i[iDim]); + } - auto Gradient_i = flowNodes->GetGradient_Reconstruction(iPoint); - auto Gradient_j = flowNodes->GetGradient_Reconstruction(jPoint); + if (musclFlow) { + /*--- Reconstruct mean flow primitive variables. ---*/ - if (limiterFlow) { - Limiter_i = flowNodes->GetLimiter_Primitive(iPoint); - Limiter_j = flowNodes->GetLimiter_Primitive(jPoint); - } + auto Gradient_i = flowNodes->GetGradient_Reconstruction(iPoint); + auto Gradient_j = flowNodes->GetGradient_Reconstruction(jPoint); - for (iVar = 0; iVar < solver_container[FLOW_SOL]->GetnPrimVarGrad(); iVar++) { - su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; - for (iDim = 0; iDim < nDim; iDim++) { - Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; - Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; - } if (limiterFlow) { - Project_Grad_i *= Limiter_i[iVar]; - Project_Grad_j *= Limiter_j[iVar]; + Limiter_i = flowNodes->GetLimiter_Primitive(iPoint); + Limiter_j = flowNodes->GetLimiter_Primitive(jPoint); } - flowPrimVar_i[iVar] = V_i[iVar] + Project_Grad_i; - flowPrimVar_j[iVar] = V_j[iVar] + Project_Grad_j; - } - numerics->SetPrimitive(flowPrimVar_i, flowPrimVar_j); - } + for (iVar = 0; iVar < solver_container[FLOW_SOL]->GetnPrimVarGrad(); iVar++) { + su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; + for (iDim = 0; iDim < nDim; iDim++) { + Project_Grad_i += Vector_ij[iDim] * Gradient_i[iVar][iDim]; + Project_Grad_j -= Vector_ij[iDim] * Gradient_j[iVar][iDim]; + } + if (limiterFlow) { + Project_Grad_i *= Limiter_i[iVar]; + Project_Grad_j *= Limiter_j[iVar]; + } + flowPrimVar_i[iVar] = V_i[iVar] + Project_Grad_i; + flowPrimVar_j[iVar] = V_j[iVar] + Project_Grad_j; + } - if (muscl) { - /*--- Reconstruct turbulence variables. ---*/ + numerics->SetPrimitive(flowPrimVar_i, flowPrimVar_j); + } - auto Gradient_i = nodes->GetGradient_Reconstruction(iPoint); - auto Gradient_j = nodes->GetGradient_Reconstruction(jPoint); + if (muscl) { + /*--- Reconstruct turbulence variables. ---*/ - if (limiter) { - Limiter_i = nodes->GetLimiter(iPoint); - Limiter_j = nodes->GetLimiter(jPoint); - } + auto Gradient_i = nodes->GetGradient_Reconstruction(iPoint); + auto Gradient_j = nodes->GetGradient_Reconstruction(jPoint); - for (iVar = 0; iVar < nVar; iVar++) { - su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; - for (iDim = 0; iDim < nDim; iDim++) { - Project_Grad_i += Vector_ij[iDim]*Gradient_i[iVar][iDim]; - Project_Grad_j -= Vector_ij[iDim]*Gradient_j[iVar][iDim]; - } if (limiter) { - Project_Grad_i *= Limiter_i[iVar]; - Project_Grad_j *= Limiter_j[iVar]; + Limiter_i = nodes->GetLimiter(iPoint); + Limiter_j = nodes->GetLimiter(jPoint); + } + + for (iVar = 0; iVar < nVar; iVar++) { + su2double Project_Grad_i = 0.0, Project_Grad_j = 0.0; + for (iDim = 0; iDim < nDim; iDim++) { + Project_Grad_i += Vector_ij[iDim] * Gradient_i[iVar][iDim]; + Project_Grad_j -= Vector_ij[iDim] * Gradient_j[iVar][iDim]; + } + if (limiter) { + Project_Grad_i *= Limiter_i[iVar]; + Project_Grad_j *= Limiter_j[iVar]; + } + solution_i[iVar] = Scalar_i[iVar] + Project_Grad_i; + solution_j[iVar] = Scalar_j[iVar] + Project_Grad_j; } - solution_i[iVar] = Scalar_i[iVar] + Project_Grad_i; - solution_j[iVar] = Scalar_j[iVar] + Project_Grad_j; - } - numerics->SetScalarVar(solution_i, solution_j); + numerics->SetScalarVar(solution_i, solution_j); + } } - } - /*--- Update convective residual value ---*/ + /*--- Update convective residual value ---*/ - auto residual = numerics->ComputeResidual(config); + auto residual = numerics->ComputeResidual(config); - if (ReducerStrategy) { - EdgeFluxes.SetBlock(iEdge, residual); - if (implicit) Jacobian.SetBlocks(iEdge, residual.jacobian_i, residual.jacobian_j); - } - else { - LinSysRes.AddBlock(iPoint, residual); - LinSysRes.SubtractBlock(jPoint, residual); - if (implicit) Jacobian.UpdateBlocks(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); - } + if (ReducerStrategy) { + EdgeFluxes.SetBlock(iEdge, residual); + if (implicit) Jacobian.SetBlocks(iEdge, residual.jacobian_i, residual.jacobian_j); + } else { + LinSysRes.AddBlock(iPoint, residual); + LinSysRes.SubtractBlock(jPoint, residual); + if (implicit) Jacobian.UpdateBlocks(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); + } - /*--- Viscous contribution. ---*/ + /*--- Viscous contribution. ---*/ - Viscous_Residual(iEdge, geometry, solver_container, - numerics_container[VISC_TERM + omp_get_thread_num()*MAX_TERMS], config); - } - END_SU2_OMP_FOR - } // end color loop + Viscous_Residual(iEdge, geometry, solver_container, + numerics_container[VISC_TERM + omp_get_thread_num() * MAX_TERMS], config); + } + END_SU2_OMP_FOR + } // end color loop /*--- Restore preaccumulation and adjoint evaluation state. ---*/ AD::ResumePreaccumulation(pausePreacc); @@ -241,44 +229,37 @@ void CScalarSolver::Upwind_Residual(CGeometry *geometry, CSolver **solver_contai } } -void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, CSolver **solver_container, - CNumerics *numerics, CConfig *config) { - +void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); /*--- Points in edge ---*/ - auto iPoint = geometry->edges->GetNode(iEdge,0); - auto jPoint = geometry->edges->GetNode(iEdge,1); + auto iPoint = geometry->edges->GetNode(iEdge, 0); + auto jPoint = geometry->edges->GetNode(iEdge, 1); /*--- Points coordinates, and normal vector ---*/ - numerics->SetCoord(geometry->nodes->GetCoord(iPoint), - geometry->nodes->GetCoord(jPoint)); + numerics->SetCoord(geometry->nodes->GetCoord(iPoint), geometry->nodes->GetCoord(jPoint)); numerics->SetNormal(geometry->edges->GetNormal(iEdge)); /*--- Conservative variables w/o reconstruction ---*/ - numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), - flowNodes->GetPrimitive(jPoint)); + numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), flowNodes->GetPrimitive(jPoint)); /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - numerics->SetScalarVar(nodes->GetSolution(iPoint), - nodes->GetSolution(jPoint)); - numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), - nodes->GetGradient(jPoint)); + numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(jPoint)); + numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(jPoint)); /*--- Menter's first blending function (only SST)---*/ if ((config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST)) - numerics->SetF1blending(nodes->GetF1blending(iPoint), - nodes->GetF1blending(jPoint)); + numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(jPoint)); /*--- Roughness heights. ---*/ if (config->GetKind_Turb_Model() == SA) - numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), - geometry->nodes->GetRoughnessHeight(jPoint)); + numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), geometry->nodes->GetRoughnessHeight(jPoint)); /*--- Compute residual, and Jacobians ---*/ @@ -287,8 +268,7 @@ void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, C if (ReducerStrategy) { EdgeFluxes.SubtractBlock(iEdge, residual); if (implicit) Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j); - } - else { + } else { LinSysRes.SubtractBlock(iPoint, residual); LinSysRes.AddBlock(jPoint, residual); if (implicit) Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); @@ -296,41 +276,34 @@ void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry *geometry, C } void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { - SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { - LinSysRes.SetBlock_Zero(iPoint); for (auto iEdge : geometry->nodes->GetEdges(iPoint)) { - if (iPoint == geometry->edges->GetNode(iEdge,0)) + if (iPoint == geometry->edges->GetNode(iEdge, 0)) LinSysRes.AddBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); else LinSysRes.SubtractBlock(iPoint, EdgeFluxes.GetBlock(iEdge)); } } END_SU2_OMP_FOR - } -void CScalarSolver::BC_Periodic(CGeometry *geometry, CSolver **solver_container, - CNumerics *numerics, CConfig *config) { - +void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { /*--- Complete residuals for periodic boundary conditions. We loop over the periodic BCs in matching pairs so that, in the event that there are adjacent periodic markers, the repeated points will have their residuals accumulated corectly during the communications. For implicit calculations the Jacobians and linear system are also correctly adjusted here. ---*/ - for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { + for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic() / 2; iPeriodic++) { InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_RESIDUAL); } - } -void CScalarSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver** solver_container, CConfig *config) { - +void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); /*--- Set shared residual variables to 0 and declare @@ -344,9 +317,8 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver** solv /*--- Build implicit system ---*/ - SU2_OMP_FOR_(schedule(static,omp_chunk_size) SU2_NOWAIT) + SU2_OMP_FOR_(schedule(static, omp_chunk_size) SU2_NOWAIT) for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - /// TODO: This could be the SetTime_Step of this solver. su2double dt = nodes->GetLocalCFL(iPoint) / flowNodes->GetLocalCFL(iPoint) * flowNodes->GetDelta_Time(iPoint); nodes->SetDelta_Time(iPoint, dt); @@ -356,8 +328,7 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver** solv if (dt != 0.0) { su2double Vol = geometry->nodes->GetVolume(iPoint) + geometry->nodes->GetPeriodicVolume(iPoint); Jacobian.AddVal2Diag(iPoint, Vol / dt); - } - else { + } else { Jacobian.SetVal2Diag(iPoint, 1.0); LinSysRes.SetBlock_Zero(iPoint); } @@ -365,12 +336,12 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver** solv /*--- Right hand side of the system (-Residual) and initial guess (x = 0) ---*/ for (unsigned short iVar = 0; iVar < nVar; iVar++) { - unsigned long total_index = iPoint*nVar + iVar; + unsigned long total_index = iPoint * nVar + iVar; LinSysRes[total_index] = -LinSysRes[total_index]; LinSysSol[total_index] = 0.0; su2double Res = fabs(LinSysRes[total_index]); - resRMS[iVar] += Res*Res; + resRMS[iVar] += Res * Res; if (Res > resMax[iVar]) { resMax[iVar] = Res; idxMax[iVar] = iPoint; @@ -391,8 +362,7 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry *geometry, CSolver** solv SetResidual_RMS(geometry, config); } -void CScalarSolver::CompleteImplicitIteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { - +void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); @@ -402,60 +372,57 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry *geometry, CSolver **sol /*--- Update solution (system written in terms of increments) ---*/ if (!adjoint) { - /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ switch (config->GetKind_Turb_Model()) { - - case SA: case SA_E: case SA_COMP: case SA_E_COMP: case SA_NEG: + case SA: + case SA_E: + case SA_COMP: + case SA_E_COMP: + case SA_NEG: SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - nodes->AddSolution(iPoint, 0, nodes->GetUnderRelaxation(iPoint)*LinSysSol[iPoint]); + nodes->AddSolution(iPoint, 0, nodes->GetUnderRelaxation(iPoint) * LinSysSol[iPoint]); } END_SU2_OMP_FOR break; - case SST: case SST_SUST: + case SST: + case SST_SUST: SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - su2double density = flowNodes->GetDensity(iPoint); su2double density_old = density; - if (compressible) - density_old = flowNodes->GetSolution_Old(iPoint,0); + if (compressible) density_old = flowNodes->GetSolution_Old(iPoint, 0); for (unsigned short iVar = 0; iVar < nVar; iVar++) { - nodes->AddConservativeSolution(iPoint, iVar, - nodes->GetUnderRelaxation(iPoint)*LinSysSol(iPoint,iVar), - density, density_old, lowerlimit[iVar], upperlimit[iVar]); + nodes->AddConservativeSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), + density, density_old, lowerlimit[iVar], upperlimit[iVar]); } } END_SU2_OMP_FOR break; - } } - for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic()/2; iPeriodic++) { + for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic() / 2; iPeriodic++) { InitiatePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT); } InitiateComms(geometry, config, SOLUTION_EDDY); CompleteComms(geometry, config, SOLUTION_EDDY); - } -void CScalarSolver::ImplicitEuler_Iteration(CGeometry *geometry, CSolver **solver_container, CConfig *config) { - +void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { PrepareImplicitIteration(geometry, solver_container, config); /*--- Solve or smooth the linear system. ---*/ - SU2_OMP_FOR_(schedule(static,OMP_MIN_SIZE) SU2_NOWAIT) + SU2_OMP_FOR_(schedule(static, OMP_MIN_SIZE) SU2_NOWAIT) for (unsigned long iPoint = nPointDomain; iPoint < nPoint; iPoint++) { LinSysRes.SetBlock_Zero(iPoint); LinSysSol.SetBlock_Zero(iPoint); @@ -472,12 +439,11 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry *geometry, CSolver **solve SU2_OMP_BARRIER CompleteImplicitIteration(geometry, solver_container, config); - } -void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_container, CConfig *config, - unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { - +void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, + unsigned short iRKStep, unsigned short iMesh, + unsigned short RunTime_EqSystem) { const bool sst_model = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST); @@ -506,20 +472,18 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c /*--- Compute the dual time-stepping source term for static meshes ---*/ if (!dynamic_grid) { - /*--- Loop over all nodes (excluding halos) ---*/ AD::StartNoSharedReading(); SU2_OMP_FOR_STAT(omp_chunk_size) for (iPoint = 0; iPoint < nPointDomain; iPoint++) { - /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, previous solutions that are stored in memory. ---*/ U_time_nM1 = nodes->GetSolution_time_n1(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); U_time_nP1 = nodes->GetSolution(iPoint); /*--- CV volume at time n+1. As we are on a static mesh, the volume @@ -531,56 +495,52 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c time discretization scheme (1st- or 2nd-order).---*/ if (sst_model) { - /*--- If this is the SST model, we need to multiply by the density in order to get the conservative variables ---*/ - if (incompressible){ + if (incompressible) { /*--- This is temporary and only valid for constant-density problems: density could also be temperature dependent, but as it is not a part of the solution vector it's neither stored for previous time steps nor updated with the solution at the end of each iteration. */ Density_nM1 = flowNodes->GetDensity(iPoint); - Density_n = flowNodes->GetDensity(iPoint); + Density_n = flowNodes->GetDensity(iPoint); Density_nP1 = flowNodes->GetDensity(iPoint); - } - else{ + } else { Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - Density_nP1 = flowNodes->GetSolution(iPoint,0); + Density_n = flowNodes->GetSolution_time_n(iPoint, 0); + Density_nP1 = flowNodes->GetSolution(iPoint, 0); } for (iVar = 0; iVar < nVar; iVar++) { if (first_order) - LinSysRes(iPoint,iVar) += ( Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*Volume_nP1 / TimeStep; + LinSysRes(iPoint, iVar) += + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * Volume_nP1 / TimeStep; if (second_order) - LinSysRes(iPoint,iVar) += ( 3.0*Density_nP1*U_time_nP1[iVar] - 4.0*Density_n*U_time_n[iVar] - +1.0*Density_nM1*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); + LinSysRes(iPoint, iVar) += (3.0 * Density_nP1 * U_time_nP1[iVar] - 4.0 * Density_n * U_time_n[iVar] + + 1.0 * Density_nM1 * U_time_nM1[iVar]) * + Volume_nP1 / (2.0 * TimeStep); } } else { - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*Volume_nP1 / TimeStep; + if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * Volume_nP1 / TimeStep; if (second_order) - LinSysRes(iPoint,iVar) += ( 3.0*U_time_nP1[iVar] - 4.0*U_time_n[iVar] - +1.0*U_time_nM1[iVar] ) * Volume_nP1/(2.0*TimeStep); + LinSysRes(iPoint, iVar) += (3.0 * U_time_nP1[iVar] - 4.0 * U_time_n[iVar] + 1.0 * U_time_nM1[iVar]) * + Volume_nP1 / (2.0 * TimeStep); } } /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ if (implicit) { - if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); - if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); + if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1 / TimeStep); + if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1 * 3.0) / (2.0 * TimeStep)); } - } END_SU2_OMP_FOR AD::EndNoSharedReading(); } else { - /*--- For unsteady flows on dynamic meshes (rigidly transforming or dynamically deforming), the Geometric Conservation Law (GCL) should be satisfied in conjunction with the ALE formulation of the governing @@ -591,20 +551,18 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c SU2_OMP_FOR_STAT(omp_chunk_size) for (iPoint = 0; iPoint < nPointDomain; ++iPoint) { - GridVel_i = geometry->nodes->GetGridVel(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); Density_n = 1.0; if (sst_model) { if (incompressible) - Density_n = flowNodes->GetDensity(iPoint); // Temporary fix + Density_n = flowNodes->GetDensity(iPoint); // Temporary fix else - Density_n = flowNodes->GetSolution_time_n(iPoint,0); + Density_n = flowNodes->GetSolution_time_n(iPoint, 0); } for (iNeigh = 0; iNeigh < geometry->nodes->GetnPoint(iPoint); iNeigh++) { - iEdge = geometry->nodes->GetEdge(iPoint, iNeigh); Normal = geometry->edges->GetNormal(iEdge); @@ -612,16 +570,14 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c GridVel_j = geometry->nodes->GetGridVel(jPoint); /*--- Determine whether to consider the normal outward or inward. ---*/ - su2double dir = (iPoint < jPoint)? 0.5 : -0.5; + su2double dir = (iPoint < jPoint) ? 0.5 : -0.5; Residual_GCL = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - Residual_GCL += dir*(GridVel_i[iDim]+GridVel_j[iDim])*Normal[iDim]; + for (iDim = 0; iDim < nDim; iDim++) Residual_GCL += dir * (GridVel_i[iDim] + GridVel_j[iDim]) * Normal[iDim]; Residual_GCL *= Density_n; - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; + for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += U_time_n[iVar] * Residual_GCL; } } END_SU2_OMP_FOR @@ -632,10 +588,8 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c if ((config->GetMarker_All_KindBC(iMarker) != INTERNAL_BOUNDARY) && (config->GetMarker_All_KindBC(iMarker) != NEARFIELD_BOUNDARY) && (config->GetMarker_All_KindBC(iMarker) != PERIODIC_BOUNDARY)) { - SU2_OMP_FOR_STAT(OMP_MIN_SIZE) for (iVertex = 0; iVertex < geometry->GetnVertex(iMarker); iVertex++) { - /*--- Get the index for node i plus the boundary face normal ---*/ iPoint = geometry->vertex[iMarker][iVertex]->GetNode(); @@ -649,8 +603,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c normal. The normal is negated to match the boundary convention. ---*/ Residual_GCL = 0.0; - for (iDim = 0; iDim < nDim; iDim++) - Residual_GCL -= 0.5*(GridVel_i[iDim]+GridVel_i[iDim])*Normal[iDim]; + for (iDim = 0; iDim < nDim; iDim++) Residual_GCL -= 0.5 * (GridVel_i[iDim] + GridVel_i[iDim]) * Normal[iDim]; /*--- Compute the GCL component of the source term for node i ---*/ @@ -660,18 +613,14 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c if (sst_model) { if (incompressible) - Density_n = flowNodes->GetDensity(iPoint); // Temporary fix + Density_n = flowNodes->GetDensity(iPoint); // Temporary fix else - Density_n = flowNodes->GetSolution_time_n(iPoint,0); + Density_n = flowNodes->GetSolution_time_n(iPoint, 0); - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += Density_n*U_time_n[iVar]*Residual_GCL; - } - else { - for (iVar = 0; iVar < nVar; iVar++) - LinSysRes(iPoint,iVar) += U_time_n[iVar]*Residual_GCL; + for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += Density_n * U_time_n[iVar] * Residual_GCL; + } else { + for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += U_time_n[iVar] * Residual_GCL; } - } END_SU2_OMP_FOR } @@ -684,13 +633,12 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c SU2_OMP_FOR_STAT(omp_chunk_size) for (iPoint = 0; iPoint < nPointDomain; iPoint++) { - /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, previous solutions that are stored in memory. ---*/ U_time_nM1 = nodes->GetSolution_time_n1(iPoint); - U_time_n = nodes->GetSolution_time_n(iPoint); + U_time_n = nodes->GetSolution_time_n(iPoint); U_time_nP1 = nodes->GetSolution(iPoint); /*--- CV volume at time n-1 and n+1. In the case of dynamically deforming @@ -705,7 +653,6 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c due to the time discretization has a new form.---*/ if (sst_model) { - /*--- If this is the SST model, we need to multiply by the density in order to get the conservative variables ---*/ if (incompressible) { @@ -714,125 +661,116 @@ void CScalarSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver_c of the solution vector it's neither stored for previous time steps nor updated with the solution at the end of each iteration. */ Density_nM1 = flowNodes->GetDensity(iPoint); - Density_n = flowNodes->GetDensity(iPoint); + Density_n = flowNodes->GetDensity(iPoint); Density_nP1 = flowNodes->GetDensity(iPoint); - } - else { + } else { Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; - Density_n = flowNodes->GetSolution_time_n(iPoint,0); - Density_nP1 = flowNodes->GetSolution(iPoint,0); + Density_n = flowNodes->GetSolution_time_n(iPoint, 0); + Density_nP1 = flowNodes->GetSolution(iPoint, 0); } for (iVar = 0; iVar < nVar; iVar++) { if (first_order) - LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(Volume_nP1/TimeStep); + LinSysRes(iPoint, iVar) += + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nP1 / TimeStep); if (second_order) - LinSysRes(iPoint,iVar) += (Density_nP1*U_time_nP1[iVar] - Density_n*U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) - + (Density_nM1*U_time_nM1[iVar] - Density_n*U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); + LinSysRes(iPoint, iVar) += + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) + + (Density_nM1 * U_time_nM1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep)); } } else { - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(Volume_nP1/TimeStep); + if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * (Volume_nP1 / TimeStep); if (second_order) - LinSysRes(iPoint,iVar) += (U_time_nP1[iVar] - U_time_n[iVar])*(3.0*Volume_nP1/(2.0*TimeStep)) - + (U_time_nM1[iVar] - U_time_n[iVar])*(Volume_nM1/(2.0*TimeStep)); + LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) + + (U_time_nM1[iVar] - U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep)); } } /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ if (implicit) { - if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1/TimeStep); - if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1*3.0)/(2.0*TimeStep)); + if (first_order) Jacobian.AddVal2Diag(iPoint, Volume_nP1 / TimeStep); + if (second_order) Jacobian.AddVal2Diag(iPoint, (Volume_nP1 * 3.0) / (2.0 * TimeStep)); } } END_SU2_OMP_FOR AD::EndNoSharedReading(); - } // end dynamic grid - + } // end dynamic grid } - -void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) { - +void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, + bool val_update_geo) { /*--- Restart the solution from file information ---*/ unsigned short iVar, iMesh; unsigned long iPoint, index, iChildren, Point_Fine; su2double Area_Children, Area_Parent; - const su2double *Solution_Fine = nullptr; + const su2double* Solution_Fine = nullptr; string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter); /*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/ - SU2_OMP_MASTER - { - - /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ - - if (config->GetRead_Binary_Restart()) { - Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); - } else { - Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); - } - - /*--- Skip flow variables ---*/ - - unsigned short skipVars = 0; + SU2_OMP_MASTER { + /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ - if (nDim == 2) skipVars += 6; - if (nDim == 3) skipVars += 8; + if (config->GetRead_Binary_Restart()) { + Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); + } else { + Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); + } - /*--- Adjust the number of solution variables in the incompressible - restart. We always carry a space in nVar for the energy equation in the - mean flow solver, but we only write it to the restart if it is active. - Therefore, we must reduce skipVars here if energy is inactive so that - the turbulent variables are read correctly. ---*/ + /*--- Skip flow variables ---*/ - bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - bool energy = config->GetEnergy_Equation(); - bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); + unsigned short skipVars = 0; - if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; + if (nDim == 2) skipVars += 6; + if (nDim == 3) skipVars += 8; - /*--- Load data from the restart into correct containers. ---*/ + /*--- Adjust the number of solution variables in the incompressible + restart. We always carry a space in nVar for the energy equation in the + mean flow solver, but we only write it to the restart if it is active. + Therefore, we must reduce skipVars here if energy is inactive so that + the turbulent variables are read correctly. ---*/ - unsigned long counter = 0, iPoint_Global = 0; - for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { + bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + bool energy = config->GetEnergy_Equation(); + bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); + if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; - /*--- Retrieve local index. If this node from the restart file lives - on the current processor, we will load and instantiate the vars. ---*/ + /*--- Load data from the restart into correct containers. ---*/ - auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); + unsigned long counter = 0, iPoint_Global = 0; + for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { + /*--- Retrieve local index. If this node from the restart file lives + on the current processor, we will load and instantiate the vars. ---*/ - if (iPoint_Local > -1) { + auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); - /*--- We need to store this point's data, so jump to the correct - offset in the buffer of data from the restart file and load it. ---*/ + if (iPoint_Local > -1) { + /*--- We need to store this point's data, so jump to the correct + offset in the buffer of data from the restart file and load it. ---*/ - index = counter*Restart_Vars[1] + skipVars; - for (iVar = 0; iVar < nVar; ++iVar) - nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]); + index = counter * Restart_Vars[1] + skipVars; + for (iVar = 0; iVar < nVar; ++iVar) nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index + iVar]); - /*--- Increment the overall counter for how many points have been loaded. ---*/ - counter++; + /*--- Increment the overall counter for how many points have been loaded. ---*/ + counter++; + } } - } - - /*--- Detect a wrong solution file ---*/ + /*--- Detect a wrong solution file ---*/ - if (counter != nPointDomain) { - SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + - string("It could be empty lines at the end of the file."), CURRENT_FUNCTION); - } + if (counter != nPointDomain) { + SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + + string("It could be empty lines at the end of the file."), + CURRENT_FUNCTION); + } - } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. + } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. END_SU2_OMP_MASTER SU2_OMP_BARRIER @@ -841,7 +779,8 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig solver[MESH_0][TURB_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION); solver[MESH_0][TURB_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION); - solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, RUNTIME_FLOW_SYS, false); + solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, + RUNTIME_FLOW_SYS, false); solver[MESH_0][TURB_SOL]->Postprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0); /*--- Interpolate the solution down to the coarse multigrid levels ---*/ @@ -853,33 +792,33 @@ void CScalarSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig su2double Solution_Coarse[MAXNVAR] = {0.0}; for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) { Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren); - Area_Children = geometry[iMesh-1]->nodes->GetVolume(Point_Fine); - Solution_Fine = solver[iMesh-1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); + Area_Children = geometry[iMesh - 1]->nodes->GetVolume(Point_Fine); + Solution_Fine = solver[iMesh - 1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); for (iVar = 0; iVar < nVar; iVar++) { - Solution_Coarse[iVar] += Solution_Fine[iVar]*Area_Children/Area_Parent; + Solution_Coarse[iVar] += Solution_Fine[iVar] * Area_Children / Area_Parent; } } - solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint,Solution_Coarse); + solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint, Solution_Coarse); } END_SU2_OMP_FOR solver[iMesh][TURB_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION); solver[iMesh][TURB_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION); - solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, false); + solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, + false); solver[iMesh][TURB_SOL]->Postprocessing(geometry[iMesh], solver[iMesh], config, iMesh); } /*--- Go back to single threaded execution. ---*/ - SU2_OMP_MASTER - { - /*--- Delete the class memory that is used to load the restart. ---*/ - - delete [] Restart_Vars; Restart_Vars = nullptr; - delete [] Restart_Data; Restart_Data = nullptr; + SU2_OMP_MASTER { + /*--- Delete the class memory that is used to load the restart. ---*/ + delete[] Restart_Vars; + Restart_Vars = nullptr; + delete[] Restart_Data; + Restart_Data = nullptr; } END_SU2_OMP_MASTER SU2_OMP_BARRIER - } diff --git a/SU2_CFD/src/variables/CScalarVariable.cpp b/SU2_CFD/src/variables/CScalarVariable.cpp index 7fc67bb17256..42f275ee325e 100644 --- a/SU2_CFD/src/variables/CScalarVariable.cpp +++ b/SU2_CFD/src/variables/CScalarVariable.cpp @@ -25,31 +25,29 @@ * License along with SU2. If not, see . */ - #include "../../include/variables/CScalarVariable.hpp" - -CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config) - : CVariable(npoint, ndim, nvar, config), Gradient_Reconstruction(config->GetReconstructionGradientRequired() ? Gradient_Aux : Gradient) { - +CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig* config) + : CVariable(npoint, ndim, nvar, config), + Gradient_Reconstruction(config->GetReconstructionGradientRequired() ? Gradient_Aux : Gradient) { /*--- Gradient related fields ---*/ - Gradient.resize(nPoint,nVar,nDim,0.0); + Gradient.resize(nPoint, nVar, nDim, 0.0); if (config->GetReconstructionGradientRequired()) { - Gradient_Aux.resize(nPoint,nVar,nDim,0.0); + Gradient_Aux.resize(nPoint, nVar, nDim, 0.0); } if (config->GetLeastSquaresRequired()) { - Rmatrix.resize(nPoint,nDim,nDim,0.0); + Rmatrix.resize(nPoint, nDim, nDim, 0.0); } /*--- Always allocate the slope limiter, and the auxiliary variables (check the logic - JST with 2nd order Turb model) ---*/ - Limiter.resize(nPoint,nVar) = su2double(0.0); - Solution_Max.resize(nPoint,nVar) = su2double(0.0); - Solution_Min.resize(nPoint,nVar) = su2double(0.0); + Limiter.resize(nPoint, nVar) = su2double(0.0); + Solution_Max.resize(nPoint, nVar) = su2double(0.0); + Solution_Min.resize(nPoint, nVar) = su2double(0.0); Delta_Time.resize(nPoint) = su2double(0.0); @@ -59,7 +57,6 @@ CScalarVariable::CScalarVariable(unsigned long npoint, unsigned long ndim, unsig /*--- Allocate space for the harmonic balance source terms ---*/ if (config->GetTime_Marching() == TIME_MARCHING::HARMONIC_BALANCE) { - HB_Source.resize(nPoint,nVar) = su2double(0.0); + HB_Source.resize(nPoint, nVar) = su2double(0.0); } - } From a3a5ccb5d8732c1a064bf619dac0f2baf13a9bd3 Mon Sep 17 00:00:00 2001 From: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com> Date: Sat, 28 Aug 2021 00:12:47 +0200 Subject: [PATCH 25/48] Apply suggestions from code review. Comment changes. Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com> --- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index a0cfd668176b..345d98ff65c4 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -228,7 +228,7 @@ class CScalarSolver : public CSolver { void LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) final; /*! - * \brief SA and SST support OpenMP+MPI. + * \brief Scalar solvers support OpenMP+MPI. */ inline bool GetHasHybridParallel() const override { return true; } }; diff --git a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp index 8bdbf22636e4..e2614f828537 100644 --- a/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp +++ b/SU2_CFD/src/numerics/turbulent/turb_diffusion.cpp @@ -134,7 +134,7 @@ void CAvgGrad_TurbSST::FinishResidualCalc(const CConfig* config) { Flux[0] = diff_kine*Proj_Mean_GradScalarVar[0]; Flux[1] = diff_omega*Proj_Mean_GradScalarVar[1]; - /*--- For Jacobians -> Use of TSL (Thin Shear Layer?) approx. to compute derivatives of the gradients ---*/ + /*--- For Jacobians -> Use of TSL (Thin Shear Layer) approx. to compute derivatives of the gradients ---*/ if (implicit) { su2double proj_on_rho = proj_vector_ij/Density_i; From 13007f9545300f8d2acdee43e91ee7fb65d0045d Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Tue, 31 Aug 2021 13:58:04 +0200 Subject: [PATCH 26/48] Manually resolve some clang-format issues. --- .../include/numerics/scalar/scalar_convection.hpp | 10 +++++----- SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp | 12 ++++++------ SU2_CFD/include/solvers/CScalarSolver.hpp | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp index a12cd966dcd5..552861e57680 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -46,11 +46,11 @@ */ class CUpwScalar : public CNumerics { protected: - su2double a0 = 0.0, /*!< \brief The maximum of the face-normal velocity and 0 */ - a1 = 0.0, /*!< \brief The minimum of the face-normal velocity and 0 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + su2double a0 = 0.0; /*!< \brief The maximum of the face-normal velocity and 0 */ + su2double a1 = 0.0; /*!< \brief The minimum of the face-normal velocity and 0 */ + su2double* Flux = nullptr; /*!< \brief Final result, diffusive flux/residual. */ + su2double** Jacobian_i = nullptr; /*!< \brief Flux Jacobian w.r.t. node i. */ + su2double** Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ const bool implicit = false, incompressible = false, dynamic_grid = false; diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index f1fe3f1985c3..df99a4e9d0af 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -46,12 +46,12 @@ */ class CAvgGrad_Scalar : public CNumerics { protected: - su2double *Proj_Mean_GradScalarVar_Normal = nullptr, /*!< \brief Mean_gradScalarVar DOT normal. */ - *Proj_Mean_GradScalarVar = nullptr, /*!< \brief Mean_gradScalarVar DOT normal, corrected if required. */ - proj_vector_ij = 0.0, /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ - *Flux = nullptr, /*!< \brief Final result, diffusive flux/residual. */ - **Jacobian_i = nullptr, /*!< \brief Flux Jacobian w.r.t. node i. */ - **Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ + su2double* Proj_Mean_GradScalarVar_Normal = nullptr; /*!< \brief Mean_gradScalarVar DOT normal. */ + su2double* Proj_Mean_GradScalarVar = nullptr; /*!< \brief Mean_gradScalarVar DOT normal, corrected if required. */ + su2double proj_vector_ij = 0.0; /*!< \brief (Edge_Vector DOT normal)/|Edge_Vector|^2 */ + su2double* Flux = nullptr; /*!< \brief Final result, diffusive flux/residual. */ + su2double** Jacobian_i = nullptr; /*!< \brief Flux Jacobian w.r.t. node i. */ + su2double** Jacobian_j = nullptr; /*!< \brief Flux Jacobian w.r.t. node j. */ const bool correct_gradient = false, implicit = false, incompressible = false; diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 345d98ff65c4..37bbb51156cb 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -48,8 +48,8 @@ class CScalarSolver : public CSolver { unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double lowerlimit[MAXNVAR] = {0.0}, /*!< \brief contains lower limits for turbulence variables. */ - upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ + su2double lowerlimit[MAXNVAR] = {0.0}; /*!< \brief contains lower limits for turbulence variables. */ + su2double upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ From b465ef4287b8d9f1244dc7dc345a5cfa22f79769 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Tue, 31 Aug 2021 15:25:56 +0200 Subject: [PATCH 27/48] Introduce Conservative Var. Make CompleteImplicitIteration general. For SST the stored solution is just k,w. The transported var rho*k or rho*w, respectively, is conservative . So the solution to the linear system in implicit time-stepping is an update to the conservative vars so that needs to be taken into account. The class bool Conservative triggers this multiplication/division by rho. For e.g. SA this bool is false. The TansLM solver uses its own Implicit update function, therefore this does not apply. Note though that it seems that the transported and Solution var are conservative, which is yet another case. fml --- SU2_CFD/include/solvers/CScalarSolver.hpp | 12 +++--- SU2_CFD/include/solvers/CTurbSolver.hpp | 6 +-- SU2_CFD/src/solvers/CScalarSolver.cpp | 45 +++++++---------------- SU2_CFD/src/solvers/CTransLMSolver.cpp | 4 +- SU2_CFD/src/solvers/CTurbSASolver.cpp | 4 +- SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 4 +- SU2_CFD/src/solvers/CTurbSolver.cpp | 4 +- 7 files changed, 32 insertions(+), 47 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 37bbb51156cb..4f581166904c 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -48,11 +48,13 @@ class CScalarSolver : public CSolver { unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double lowerlimit[MAXNVAR] = {0.0}; /*!< \brief contains lower limits for turbulence variables. */ - su2double upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ + su2double lowerlimit[MAXNVAR] = {std::numeric_limits::min()}; /*!< \brief contains lower limits for turbulence variables. */ + su2double upperlimit[MAXNVAR] = {std::numeric_limits::max()}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ + const bool Conservative; /*!< \brief Transported Variable is conservative. Solution has to be multiplied with rho. */ + /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ #ifdef HAVE_OMP @@ -107,19 +109,19 @@ class CScalarSolver : public CSolver { /*! * \brief Constructor of the class. */ - CScalarSolver(void); + CScalarSolver(bool conservative); /*! * \brief Destructor of the class. */ - ~CScalarSolver(void) override; + ~CScalarSolver() override; /*! * \brief Constructor of the class. * \param[in] geometry - Geometrical definition of the problem. * \param[in] config - Definition of the particular problem. */ - CScalarSolver(CGeometry* geometry, CConfig* config); + CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative); /*! * \brief Compute the spatial integration using a upwind scheme. diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index 7174eae12f26..cb7768ef64ec 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -53,19 +53,19 @@ class CTurbSolver : public CScalarSolver { /*! * \brief Constructor of the class. */ - CTurbSolver(void); + CTurbSolver(bool conservative); /*! * \brief Destructor of the class. */ - ~CTurbSolver(void) override; + ~CTurbSolver() override; /*! * \brief Constructor of the class. * \param[in] geometry - Geometrical definition of the problem. * \param[in] config - Definition of the particular problem. */ - CTurbSolver(CGeometry* geometry, CConfig *config); + CTurbSolver(CGeometry* geometry, CConfig *config, bool conservative); /*! * \brief Impose via the residual the Euler wall boundary condition. diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 466fd5356f2b..a3cb03dea4a7 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -30,9 +30,10 @@ #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CScalarSolver::CScalarSolver(void) : CSolver() {} +CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} -CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config) : CSolver() { +CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) + : CSolver(), Conservative(conservative) { nMarker = config->GetnMarker_All(); /*--- Store the number of vertices on each marker for deallocation later ---*/ @@ -374,38 +375,20 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** sol if (!adjoint) { /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ - switch (config->GetKind_Turb_Model()) { - case SA: - case SA_E: - case SA_COMP: - case SA_E_COMP: - case SA_NEG: - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - nodes->AddSolution(iPoint, 0, nodes->GetUnderRelaxation(iPoint) * LinSysSol[iPoint]); - } - END_SU2_OMP_FOR - break; - - case SST: - case SST_SUST: - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - su2double density = flowNodes->GetDensity(iPoint); - su2double density_old = density; + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + /*--- Multiply the Solution var with density to get the conservative transported quantity, if necessary. ---*/ + su2double density = Conservative ? flowNodes->GetDensity(iPoint) : 1; + su2double density_old = Conservative ? density : 1; - if (compressible) density_old = flowNodes->GetSolution_Old(iPoint, 0); + if (compressible) density_old = Conservative ? flowNodes->GetSolution_Old(iPoint, 0) : 1; - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - nodes->AddConservativeSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), - density, density_old, lowerlimit[iVar], upperlimit[iVar]); - } - } - END_SU2_OMP_FOR - break; + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + nodes->AddConservativeSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), + density, density_old, lowerlimit[iVar], upperlimit[iVar]); + } } + END_SU2_OMP_FOR } for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic() / 2; iPeriodic++) { diff --git a/SU2_CFD/src/solvers/CTransLMSolver.cpp b/SU2_CFD/src/solvers/CTransLMSolver.cpp index b96401b70480..bba0515ce799 100644 --- a/SU2_CFD/src/solvers/CTransLMSolver.cpp +++ b/SU2_CFD/src/solvers/CTransLMSolver.cpp @@ -34,9 +34,9 @@ The main reference for this model is:Langtry, Menter, AIAA J. 47(12) 2009 DOI: https://doi.org/10.2514/1.42362 ---*/ -CTransLMSolver::CTransLMSolver(void) : CTurbSolver() {} +CTransLMSolver::CTransLMSolver(void) : CTurbSolver(true) {} ///Note: TransLM seems to rho*gamma, rho*Re_sigma as Solution variables -CTransLMSolver::CTransLMSolver(CGeometry *geometry, CConfig *config, unsigned short iMesh) : CTurbSolver() { +CTransLMSolver::CTransLMSolver(CGeometry *geometry, CConfig *config, unsigned short iMesh) : CTurbSolver(true) { unsigned short iVar, nLineLets; unsigned long iPoint, index; su2double tu_Inf, dull_val, rey; diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 91fdea667f6d..2fa4c81b25f4 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -31,10 +31,10 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CTurbSASolver::CTurbSASolver(void) : CTurbSolver() { } +CTurbSASolver::CTurbSASolver(void) : CTurbSolver(false) { } CTurbSASolver::CTurbSASolver(CGeometry *geometry, CConfig *config, unsigned short iMesh, CFluidModel* FluidModel) - : CTurbSolver(geometry, config) { + : CTurbSolver(geometry, config, false) { unsigned short nLineLets; unsigned long iPoint; diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 67e20ccb97db..b0de4843287a 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -31,10 +31,10 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CTurbSSTSolver::CTurbSSTSolver(void) : CTurbSolver() { } +CTurbSSTSolver::CTurbSSTSolver(void) : CTurbSolver(true) { } CTurbSSTSolver::CTurbSSTSolver(CGeometry *geometry, CConfig *config, unsigned short iMesh) - : CTurbSolver(geometry, config) { + : CTurbSolver(geometry, config, true) { unsigned short nLineLets; unsigned long iPoint; ifstream restart_file; diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index 09633baa551b..d77a958c689b 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -30,9 +30,9 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CTurbSolver::CTurbSolver(void) : CScalarSolver() { } +CTurbSolver::CTurbSolver(bool conservative) : CScalarSolver(conservative) { } -CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config) : CScalarSolver(geometry, config) { } +CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config, bool conservative) : CScalarSolver(geometry, config, conservative) { } CTurbSolver::~CTurbSolver() { From 74cc116068f66e5fd47f9d8ae3b52e8abafad513 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Tue, 31 Aug 2021 16:12:20 +0200 Subject: [PATCH 28/48] Equivalent Change to Scalar CompleteImplicitIteration --- SU2_CFD/src/solvers/CScalarSolver.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index a3cb03dea4a7..fa03e945d1ea 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -373,15 +373,19 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** sol /*--- Update solution (system written in terms of increments) ---*/ if (!adjoint) { + + su2double density = 1.0; + su2double density_old = 1.0; + /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { /*--- Multiply the Solution var with density to get the conservative transported quantity, if necessary. ---*/ - su2double density = Conservative ? flowNodes->GetDensity(iPoint) : 1; - su2double density_old = Conservative ? density : 1; - - if (compressible) density_old = Conservative ? flowNodes->GetSolution_Old(iPoint, 0) : 1; + if (Conservative) { + density = flowNodes->GetDensity(iPoint); + density_old = compressible ? flowNodes->GetSolution_Old(iPoint, 0) : density; + } for (unsigned short iVar = 0; iVar < nVar; iVar++) { nodes->AddConservativeSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), From 6b9f276748a10fa428a5ab160f8a8579c2340da6 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 14:11:41 +0200 Subject: [PATCH 29/48] Fix reg tests. numeric_limits<>::min returns lowest positive value. Use ::lowest instead. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- TestCases/rans/naca0012/turb_NACA0012_sa.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 4f581166904c..f40a2824acc1 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -48,7 +48,7 @@ class CScalarSolver : public CSolver { unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double lowerlimit[MAXNVAR] = {std::numeric_limits::min()}; /*!< \brief contains lower limits for turbulence variables. */ + su2double lowerlimit[MAXNVAR] = {std::numeric_limits::lowest()}; /*!< \brief contains lower limits for turbulence variables. Note that ::min() returns the smallest positive value for floats. */ su2double upperlimit[MAXNVAR] = {std::numeric_limits::max()}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ diff --git a/TestCases/rans/naca0012/turb_NACA0012_sa.cfg b/TestCases/rans/naca0012/turb_NACA0012_sa.cfg index e7d981efd457..71c3023c7f97 100644 --- a/TestCases/rans/naca0012/turb_NACA0012_sa.cfg +++ b/TestCases/rans/naca0012/turb_NACA0012_sa.cfg @@ -6,7 +6,7 @@ % Author: Francisco Palacios % % Institution: Stanford University % % Date: Feb 18th, 2013 % -% File Version 7.1.1 "Blackbird % +% File Version 7.1.1 "Blackbird" % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% From 2ba9a72061bc5989d9ed92ca3d82d8f4d6611dfe Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 14:44:02 +0200 Subject: [PATCH 30/48] Make Scalar DualTimeRes independet of Turb specifics. Added lambda that adds density to vector of Solution. If Conservative=true. Dynamic grid part should work but not looked at further. --- SU2_CFD/src/solvers/CScalarSolver.cpp | 78 +++++++++++++-------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index fa03e945d1ea..9e7aeb1a220b 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -373,7 +373,6 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** sol /*--- Update solution (system written in terms of increments) ---*/ if (!adjoint) { - su2double density = 1.0; su2double density_old = 1.0; @@ -431,7 +430,6 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solve void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { - const bool sst_model = (config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST); const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST); const bool second_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND); @@ -450,12 +448,17 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c unsigned short iVar, iMarker, iDim, iNeigh; unsigned long iPoint, jPoint, iVertex, iEdge; - const su2double *U_time_nM1 = nullptr, *U_time_n = nullptr, *U_time_nP1 = nullptr; + su2double *U_time_nM1 = nullptr, *U_time_n = nullptr, *U_time_nP1 = nullptr; + su2double Density_nM1 = 1.0, Density_n = 1.0, Density_nP1 = 1.0; su2double Volume_nM1, Volume_nP1; - su2double Density_nM1, Density_n, Density_nP1; const su2double *Normal = nullptr, *GridVel_i = nullptr, *GridVel_j = nullptr; su2double Residual_GCL; + const int nvar = nVar; + auto FactorTimesVector = [nvar](su2double factor, su2double* vec) { + for (int iVar = 0; iVar < nvar; iVar++) vec[iVar] = factor * vec[iVar]; + }; + /*--- Compute the dual time-stepping source term for static meshes ---*/ if (!dynamic_grid) { @@ -465,6 +468,22 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c SU2_OMP_FOR_STAT(omp_chunk_size) for (iPoint = 0; iPoint < nPointDomain; iPoint++) { + if (Conservative) { + if (incompressible) { + /*--- This is temporary and only valid for constant-density problems: + density could also be temperature dependent, but as it is not a part + of the solution vector it's neither stored for previous time steps + nor updated with the solution at the end of each iteration. */ + Density_nM1 = flowNodes->GetDensity(iPoint); + Density_n = flowNodes->GetDensity(iPoint); + Density_nP1 = flowNodes->GetDensity(iPoint); + } else { + Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; + Density_n = flowNodes->GetSolution_time_n(iPoint, 0); + Density_nP1 = flowNodes->GetSolution(iPoint, 0); + } + } + /*--- Retrieve the solution at time levels n-1, n, and n+1. Note that we are currently iterating on U^n+1 and that U^n & U^n-1 are fixed, previous solutions that are stored in memory. ---*/ @@ -473,6 +492,12 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c U_time_n = nodes->GetSolution_time_n(iPoint); U_time_nP1 = nodes->GetSolution(iPoint); + /*--- Multiply with Density, if necessary. ---*/ + + FactorTimesVector(Density_nM1, U_time_nM1); + FactorTimesVector(Density_n, U_time_n); + FactorTimesVector(Density_nP1, U_time_nP1); + /*--- CV volume at time n+1. As we are on a static mesh, the volume of the CV will remained fixed for all time steps. ---*/ @@ -481,40 +506,11 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c /*--- Compute the dual time-stepping source term based on the chosen time discretization scheme (1st- or 2nd-order).---*/ - if (sst_model) { - /*--- If this is the SST model, we need to multiply by the density - in order to get the conservative variables ---*/ - if (incompressible) { - /*--- This is temporary and only valid for constant-density problems: - density could also be temperature dependent, but as it is not a part - of the solution vector it's neither stored for previous time steps - nor updated with the solution at the end of each iteration. */ - Density_nM1 = flowNodes->GetDensity(iPoint); - Density_n = flowNodes->GetDensity(iPoint); - Density_nP1 = flowNodes->GetDensity(iPoint); - } else { - Density_nM1 = flowNodes->GetSolution_time_n1(iPoint)[0]; - Density_n = flowNodes->GetSolution_time_n(iPoint, 0); - Density_nP1 = flowNodes->GetSolution(iPoint, 0); - } - - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint, iVar) += - (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * Volume_nP1 / TimeStep; - if (second_order) - LinSysRes(iPoint, iVar) += (3.0 * Density_nP1 * U_time_nP1[iVar] - 4.0 * Density_n * U_time_n[iVar] + - 1.0 * Density_nM1 * U_time_nM1[iVar]) * - Volume_nP1 / (2.0 * TimeStep); - } - - } else { - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * Volume_nP1 / TimeStep; - if (second_order) - LinSysRes(iPoint, iVar) += (3.0 * U_time_nP1[iVar] - 4.0 * U_time_n[iVar] + 1.0 * U_time_nM1[iVar]) * - Volume_nP1 / (2.0 * TimeStep); - } + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * Volume_nP1 / TimeStep; + if (second_order) + LinSysRes(iPoint, iVar) += + (3.0 * U_time_nP1[iVar] - 4.0 * U_time_n[iVar] + 1.0 * U_time_nM1[iVar]) * Volume_nP1 / (2.0 * TimeStep); } /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ @@ -542,7 +538,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c U_time_n = nodes->GetSolution_time_n(iPoint); Density_n = 1.0; - if (sst_model) { + if (Conservative) { if (incompressible) Density_n = flowNodes->GetDensity(iPoint); // Temporary fix else @@ -598,7 +594,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c /*--- Multiply by density at node i for the SST model ---*/ - if (sst_model) { + if (Conservative) { if (incompressible) Density_n = flowNodes->GetDensity(iPoint); // Temporary fix else @@ -639,7 +635,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c introduction of the GCL term above, the remainder of the source residual due to the time discretization has a new form.---*/ - if (sst_model) { + if (Conservative) { /*--- If this is the SST model, we need to multiply by the density in order to get the conservative variables ---*/ if (incompressible) { From 2d2be7d901c4f5026ad45c02fc975290d50a8247 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 15:37:11 +0200 Subject: [PATCH 31/48] Init lower/upperlimit for sol.clipping in ctor of CScalarSolver. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 5 +++-- SU2_CFD/src/solvers/CScalarSolver.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index f40a2824acc1..fcfe1ca24ec3 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -27,6 +27,7 @@ #pragma once +#include #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../variables/CScalarVariable.hpp" #include "CSolver.hpp" @@ -48,8 +49,8 @@ class CScalarSolver : public CSolver { unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double lowerlimit[MAXNVAR] = {std::numeric_limits::lowest()}; /*!< \brief contains lower limits for turbulence variables. Note that ::min() returns the smallest positive value for floats. */ - su2double upperlimit[MAXNVAR] = {std::numeric_limits::max()}; /*!< \brief contains upper limits for turbulence variables. */ + su2double lowerlimit[MAXNVAR] = {0.0}; /*!< \brief contains lower limits for turbulence variables. Note that ::min() returns the smallest positive value for floats. */ + su2double upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 9e7aeb1a220b..cec6143d2b4c 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -66,6 +66,12 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conserva #else EdgeColoring[0] = DummyGridColor<>(geometry->GetnEdge()); #endif + + /*--- Initialize lower and upper limits for solution clipping. Solvers might overwrite these values. ---*/ + for (int iVar = 0; iVar < nVar; iVar++) { + lowerlimit[iVar] = std::numeric_limits::lowest(); + upperlimit[iVar] = std::numeric_limits::max(); + } } CScalarSolver::~CScalarSolver() { delete nodes; } From 817186f826785e43d5aa8ae397846b39698dabbd Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 15:58:05 +0200 Subject: [PATCH 32/48] Make distinction for (non)Conservative solution updates for the scalar Solver. Unified AddClipped/ConservativeSolution to incoporate both cases with default values. --- SU2_CFD/include/variables/CVariable.hpp | 31 ++++++-------------- SU2_CFD/src/solvers/CScalarSolver.cpp | 38 ++++++++++++++----------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/SU2_CFD/include/variables/CVariable.hpp b/SU2_CFD/include/variables/CVariable.hpp index 2abc770cb7bb..df3bba2712d1 100644 --- a/SU2_CFD/include/variables/CVariable.hpp +++ b/SU2_CFD/include/variables/CVariable.hpp @@ -406,36 +406,21 @@ class CVariable { for(unsigned long iVar = 0; iVar < nVar; iVar++) External(iPoint,iVar) += val_sol[iVar]; } - /*! - * \brief Add a value to the solution, clipping the values. - * \param[in] iPoint - Point index. - * \param[in] iVar - Index of the variable. - * \param[in] solution - Value of the solution change. - * \param[in] lowerlimit - Lower value. - * \param[in] upperlimit - Upper value. - */ - inline void AddClippedSolution(unsigned long iPoint, unsigned long iVar, su2double solution, - su2double lowerlimit, su2double upperlimit) { - - su2double val_new = Solution_Old(iPoint, iVar) + solution; - Solution(iPoint,iVar) = min(max(val_new, lowerlimit), upperlimit); - } - /*! * \brief Update the variables using a conservative format. * \param[in] iPoint - Point index. * \param[in] iVar - Index of the variable. * \param[in] solution - Value of the solution change. - * \param[in] val_density - Value of the density. - * \param[in] val_density_old - Value of the old density. - * \param[in] lowerlimit - Lower value. - * \param[in] upperlimit - Upper value. + * \param[in] lowerlimit - Lower value for Solution clipping. + * \param[in] upperlimit - Upper value for Solution clipping. + * \param[in] Sol2Conservative - Factor multiplied to Solution to get transported variable. + * \param[in] Sol2Conservative_old - Factor multiplied to Solution to get transported variable, of the previous Iteration. */ - inline void AddConservativeSolution(unsigned long iPoint, unsigned long iVar, su2double solution, - su2double val_density, su2double val_density_old, - su2double lowerlimit, su2double upperlimit) { + inline void AddClippedSolution(unsigned long iPoint, unsigned long iVar, su2double solution, + su2double lowerlimit, su2double upperlimit, + su2double Sol2Conservative = 1.0, su2double Sol2Conservative_old = 1.0) { - su2double val_new = (Solution_Old(iPoint,iVar)*val_density_old + solution)/val_density; + su2double val_new = (Solution_Old(iPoint,iVar)*Sol2Conservative_old + solution)/Sol2Conservative; Solution(iPoint,iVar) = min(max(val_new, lowerlimit), upperlimit); } diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index cec6143d2b4c..260265c4f2e4 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -379,25 +379,31 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** sol /*--- Update solution (system written in terms of increments) ---*/ if (!adjoint) { - su2double density = 1.0; - su2double density_old = 1.0; - - /*--- Update the turbulent solution. Only SST variants are clipped. ---*/ - - SU2_OMP_FOR_STAT(omp_chunk_size) - for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { - /*--- Multiply the Solution var with density to get the conservative transported quantity, if necessary. ---*/ - if (Conservative) { - density = flowNodes->GetDensity(iPoint); - density_old = compressible ? flowNodes->GetSolution_Old(iPoint, 0) : density; + /*--- Update the scalar solution. For transport equations, where Solution is not equivalent with the transported + * quantity, multiply the respective factor. ---*/ + if (Conservative) { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + /*--- Multiply the Solution var with density to get the conservative transported quantity, if necessary. ---*/ + const su2double density = flowNodes->GetDensity(iPoint); + const su2double density_old = compressible ? flowNodes->GetSolution_Old(iPoint, 0) : density; + + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + nodes->AddClippedSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), + lowerlimit[iVar], upperlimit[iVar], density, density_old); + } } - - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - nodes->AddConservativeSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), - density, density_old, lowerlimit[iVar], upperlimit[iVar]); + END_SU2_OMP_FOR + } else { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { + for (unsigned short iVar = 0; iVar < nVar; iVar++) { + nodes->AddClippedSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint) * LinSysSol(iPoint, iVar), + lowerlimit[iVar], upperlimit[iVar]); + } } + END_SU2_OMP_FOR } - END_SU2_OMP_FOR } for (unsigned short iPeriodic = 1; iPeriodic <= config->GetnMarker_Periodic() / 2; iPeriodic++) { From 044f53f630cc9801fb2a7a4802774d21d7af5137 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 17:57:44 +0200 Subject: [PATCH 33/48] Fix nVar bug in CScalarolver. --- SU2_CFD/src/solvers/CScalarSolver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 260265c4f2e4..aea0a5870824 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -68,7 +68,7 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conserva #endif /*--- Initialize lower and upper limits for solution clipping. Solvers might overwrite these values. ---*/ - for (int iVar = 0; iVar < nVar; iVar++) { + for (unsigned int iVar = 0; iVar < MAXNVAR; iVar++) { lowerlimit[iVar] = std::numeric_limits::lowest(); upperlimit[iVar] = std::numeric_limits::max(); } From cb99a168e9c658a48650c6dec815dfb076e88874 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 1 Sep 2021 18:11:17 +0200 Subject: [PATCH 34/48] Fix Dual Time Derivative for CScalarSolver. --- SU2_CFD/src/solvers/CScalarSolver.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index aea0a5870824..8cc5d830e728 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -466,11 +466,6 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c const su2double *Normal = nullptr, *GridVel_i = nullptr, *GridVel_j = nullptr; su2double Residual_GCL; - const int nvar = nVar; - auto FactorTimesVector = [nvar](su2double factor, su2double* vec) { - for (int iVar = 0; iVar < nvar; iVar++) vec[iVar] = factor * vec[iVar]; - }; - /*--- Compute the dual time-stepping source term for static meshes ---*/ if (!dynamic_grid) { @@ -504,12 +499,6 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c U_time_n = nodes->GetSolution_time_n(iPoint); U_time_nP1 = nodes->GetSolution(iPoint); - /*--- Multiply with Density, if necessary. ---*/ - - FactorTimesVector(Density_nM1, U_time_nM1); - FactorTimesVector(Density_n, U_time_n); - FactorTimesVector(Density_nP1, U_time_nP1); - /*--- CV volume at time n+1. As we are on a static mesh, the volume of the CV will remained fixed for all time steps. ---*/ @@ -519,10 +508,13 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c time discretization scheme (1st- or 2nd-order).---*/ for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * Volume_nP1 / TimeStep; - if (second_order) + if (first_order) LinSysRes(iPoint, iVar) += - (3.0 * U_time_nP1[iVar] - 4.0 * U_time_n[iVar] + 1.0 * U_time_nM1[iVar]) * Volume_nP1 / (2.0 * TimeStep); + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * Volume_nP1 / TimeStep; + if (second_order) + LinSysRes(iPoint, iVar) += (3.0 * Density_nP1 * U_time_nP1[iVar] - 4.0 * Density_n * U_time_n[iVar] + + 1.0 * Density_nM1 * U_time_nM1[iVar]) * + Volume_nP1 / (2.0 * TimeStep); } /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ From 462e95cc4618c6fae3b99730cc6a42e7ae1f99ef Mon Sep 17 00:00:00 2001 From: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com> Date: Thu, 9 Sep 2021 09:56:17 +0200 Subject: [PATCH 35/48] Apply suggestions from code review Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com> --- SU2_CFD/src/solvers/CScalarSolver.cpp | 5 +---- SU2_CFD/src/solvers/CTurbSASolver.cpp | 23 ++++++----------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 8cc5d830e728..7a328ab1cc91 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -711,10 +711,7 @@ void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig /*--- Skip flow variables ---*/ - unsigned short skipVars = 0; - - if (nDim == 2) skipVars += 6; - if (nDim == 3) skipVars += 8; + unsigned short skipVars = nDim + solver[MESH_0][FLOW_SOL]->GetnVar(); /*--- Adjust the number of solution variables in the incompressible restart. We always carry a space in nVar for the energy equation in the diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 2fa4c81b25f4..d2cc6055e552 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -1595,10 +1595,7 @@ void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { SA_NEG model is more robust due to allowing for negative nu_tilde, so the under-relaxation is not applied to that variant. */ - bool sa_model = ((config->GetKind_Turb_Model() == SA) || - (config->GetKind_Turb_Model() == SA_E) || - (config->GetKind_Turb_Model() == SA_COMP) || - (config->GetKind_Turb_Model() == SA_E_COMP)); + if (config->GetKind_Turb_Model() == SA_NEG) return; /* Loop over the solution update given by relaxing the linear system for this nonlinear iteration. */ @@ -1610,19 +1607,11 @@ void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) { localUnderRelaxation = 1.0; - if (sa_model) { - for (unsigned short iVar = 0; iVar < nVar; iVar++) { - - /* We impose a limit on the maximum percentage that the - turbulence variables can change over a nonlinear iteration. */ - - const unsigned long index = iPoint * nVar + iVar; - su2double ratio = fabs(LinSysSol[index]) / (fabs(nodes->GetSolution(iPoint, iVar)) + EPS); - if (ratio > allowableRatio) { - localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); - } - - } + su2double ratio = fabs(LinSysSol[iPoint]) / (fabs(nodes->GetSolution(iPoint, 0)) + EPS); + /* We impose a limit on the maximum percentage that the + turbulence variables can change over a nonlinear iteration. */ + if (ratio > allowableRatio) { + localUnderRelaxation = min(allowableRatio / ratio, localUnderRelaxation); } /* Threshold the relaxation factor in the event that there is From ed80960b83b58240eb3aa1b58a36f4be18da5195 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Thu, 9 Sep 2021 10:08:59 +0200 Subject: [PATCH 36/48] Use rho=1 trick for non-Conservative scalars for dynamic grids. This avoid some code duplication. --- SU2_CFD/src/solvers/CScalarSolver.cpp | 35 ++++++++++----------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 7a328ab1cc91..599586b8bf29 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -461,6 +461,7 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c unsigned long iPoint, jPoint, iVertex, iEdge; su2double *U_time_nM1 = nullptr, *U_time_n = nullptr, *U_time_nP1 = nullptr; + /*--- For non-Conservative scalars (e.g. SA), multiply the Primitives with 1.0 instead of Density. ---*/ su2double Density_nM1 = 1.0, Density_n = 1.0, Density_nP1 = 1.0; su2double Volume_nM1, Volume_nP1; const su2double *Normal = nullptr, *GridVel_i = nullptr, *GridVel_j = nullptr; @@ -540,7 +541,6 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c for (iPoint = 0; iPoint < nPointDomain; ++iPoint) { GridVel_i = geometry->nodes->GetGridVel(iPoint); U_time_n = nodes->GetSolution_time_n(iPoint); - Density_n = 1.0; if (Conservative) { if (incompressible) @@ -603,11 +603,10 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c Density_n = flowNodes->GetDensity(iPoint); // Temporary fix else Density_n = flowNodes->GetSolution_time_n(iPoint, 0); - - for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += Density_n * U_time_n[iVar] * Residual_GCL; - } else { - for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += U_time_n[iVar] * Residual_GCL; } + + for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += Density_n * U_time_n[iVar] * Residual_GCL; + } END_SU2_OMP_FOR } @@ -655,24 +654,16 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c Density_n = flowNodes->GetSolution_time_n(iPoint, 0); Density_nP1 = flowNodes->GetSolution(iPoint, 0); } + } - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) - LinSysRes(iPoint, iVar) += - (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nP1 / TimeStep); - if (second_order) - LinSysRes(iPoint, iVar) += - (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) + - (Density_nM1 * U_time_nM1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep)); - } - - } else { - for (iVar = 0; iVar < nVar; iVar++) { - if (first_order) LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * (Volume_nP1 / TimeStep); - if (second_order) - LinSysRes(iPoint, iVar) += (U_time_nP1[iVar] - U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) + - (U_time_nM1[iVar] - U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep)); - } + for (iVar = 0; iVar < nVar; iVar++) { + if (first_order) + LinSysRes(iPoint, iVar) += + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nP1 / TimeStep); + if (second_order) + LinSysRes(iPoint, iVar) += + (Density_nP1 * U_time_nP1[iVar] - Density_n * U_time_n[iVar]) * (3.0 * Volume_nP1 / (2.0 * TimeStep)) + + (Density_nM1 * U_time_nM1[iVar] - Density_n * U_time_n[iVar]) * (Volume_nM1 / (2.0 * TimeStep)); } /*--- Compute the Jacobian contribution due to the dual time source term. ---*/ From 4ea95294a3724c4f7a7eabfa165ea67f8f7d581a Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Thu, 9 Sep 2021 10:27:21 +0200 Subject: [PATCH 37/48] Move Get/SetHB_source from TurbSA to ScalarVariable. --- SU2_CFD/include/variables/CScalarVariable.hpp | 16 ++++++++++++++++ SU2_CFD/include/variables/CTurbSAVariable.hpp | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 02fc5d5d9960..0cebb3bb0e4a 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -74,4 +74,20 @@ class CScalarVariable : public CVariable { */ inline CVectorOfMatrix& GetGradient_Reconstruction() final { return Gradient_Reconstruction; } inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; } + + /*! + * \brief Set the harmonic balance source term. + * \param[in] iPoint - Point index. + * \param[in] iVar - Index of the variable. + * \param[in] source - Value of the harmonic balance source term. for the index iVar. + */ + inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) override { HB_Source(iPoint,iVar) = source; } + + /*! + * \brief Get the harmonic balance source term. + * \param[in] iPoint - Point index. + * \param[in] iVar - Index of the variable. + * \return Value of the harmonic balance source term for the index val_var. + */ + inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const override { return HB_Source(iPoint,iVar); } }; diff --git a/SU2_CFD/include/variables/CTurbSAVariable.hpp b/SU2_CFD/include/variables/CTurbSAVariable.hpp index c08969ebdded..0ac1dcd716c1 100644 --- a/SU2_CFD/include/variables/CTurbSAVariable.hpp +++ b/SU2_CFD/include/variables/CTurbSAVariable.hpp @@ -61,22 +61,6 @@ class CTurbSAVariable final : public CTurbVariable { */ ~CTurbSAVariable() override = default; - /*! - * \brief Set the harmonic balance source term. - * \param[in] iPoint - Point index. - * \param[in] iVar - Index of the variable. - * \param[in] source - Value of the harmonic balance source term. for the index iVar. - */ - inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) override { HB_Source(iPoint,iVar) = source; } - - /*! - * \brief Get the harmonic balance source term. - * \param[in] iPoint - Point index. - * \param[in] iVar - Index of the variable. - * \return Value of the harmonic balance source term for the index val_var. - */ - inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const override { return HB_Source(iPoint,iVar); } - /*! * \brief Get the intermittency of the BC transition model. * \param[in] iPoint - Point index. From 3e975d3a69f495dfc7507246c816012b1b520fde Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Thu, 16 Sep 2021 15:36:50 +0200 Subject: [PATCH 38/48] Add a generic Visc_res_impl in ScalarSolver. Template the specific contribution. Following the idea from SetTime_Step and SetTime_Step_impl from CFVMFlowSolver. The Base class has a Visc_Res_impl function that implements the majority. Each child has a Visc_Res routine that defines a struct with the Solvers-specifc-numerics and then calls the *_impl with this very struct. Like so one can has one base implemenation and each solver only adds its very specific change. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 65 ++++++++++++++++++++-- SU2_CFD/include/solvers/CTurbSASolver.hpp | 13 +++++ SU2_CFD/include/solvers/CTurbSSTSolver.hpp | 12 ++++ SU2_CFD/src/solvers/CScalarSolver.cpp | 47 ---------------- SU2_CFD/src/solvers/CTurbSASolver.cpp | 18 ++++++ SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 19 +++++++ 6 files changed, 123 insertions(+), 51 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index fcfe1ca24ec3..a2aedf0c0db1 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -28,6 +28,7 @@ #pragma once #include + #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../variables/CScalarVariable.hpp" #include "CSolver.hpp" @@ -49,7 +50,8 @@ class CScalarSolver : public CSolver { unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */ - su2double lowerlimit[MAXNVAR] = {0.0}; /*!< \brief contains lower limits for turbulence variables. Note that ::min() returns the smallest positive value for floats. */ + su2double lowerlimit[MAXNVAR] = {0.0}; /*!< \brief contains lower limits for turbulence variables. Note that ::min() + returns the smallest positive value for floats. */ su2double upperlimit[MAXNVAR] = {0.0}; /*!< \brief contains upper limits for turbulence variables. */ su2double Solution_Inf[MAXNVAR] = {0.0}; /*!< \brief Far-field solution. */ @@ -80,7 +82,61 @@ class CScalarSolver : public CSolver { */ inline CVariable* GetBaseClassPointerToNodes() final { return nodes; } - private: // changed from private in CTurbSolver.hpp + /*! + * \brief Compute the viscous flux for the turbulent equation at a particular edge. + * \tparam SolverSpecificNumericsFunc - Struct, that implements solver specific contributions to numerics. + * \note The functor has to implement (*geometry, *numerics, *config, *nodes, iPoint, jPoint) + * \param[in] iEdge - Edge for which we want to compute the flux + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + */ + template + FORCEINLINE void Viscous_Residual_impl(const SolverSpecificNumericsFunc& SolverSpecificNumerics, unsigned long iEdge, + CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, + CConfig* config) { + const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); + CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); + + /*--- Points in edge ---*/ + + auto iPoint = geometry->edges->GetNode(iEdge, 0); + auto jPoint = geometry->edges->GetNode(iEdge, 1); + + /*--- Points coordinates, and normal vector ---*/ + + numerics->SetCoord(geometry->nodes->GetCoord(iPoint), geometry->nodes->GetCoord(jPoint)); + numerics->SetNormal(geometry->edges->GetNormal(iEdge)); + + /*--- Conservative variables w/o reconstruction ---*/ + + numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), flowNodes->GetPrimitive(jPoint)); + + /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ + + numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(jPoint)); + numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(jPoint)); + + /*--- Call Numerics contribution which are Solver-Specifc. Implemented in the caller: Viscous_Residual. ---*/ + + SolverSpecificNumerics(*geometry, *numerics, *config, *nodes, iPoint, jPoint); + + /*--- Compute residual, and Jacobians ---*/ + + auto residual = numerics->ComputeResidual(config); + + if (ReducerStrategy) { + EdgeFluxes.SubtractBlock(iEdge, residual); + if (implicit) Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j); + } else { + LinSysRes.SubtractBlock(iPoint, residual); + LinSysRes.AddBlock(jPoint, residual); + if (implicit) Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); + } + } + + private: /*! * \brief Compute the viscous flux for the turbulent equation at a particular edge. * \param[in] iEdge - Edge for which we want to compute the flux @@ -88,9 +144,10 @@ class CScalarSolver : public CSolver { * \param[in] solver_container - Container vector with all the solutions. * \param[in] numerics - Description of the numerical method. * \param[in] config - Definition of the particular problem. + * \note Calls a generic implementation after defining a SolverSpecificNumerics object. */ - void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, - CConfig* config); + inline virtual void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) {} using CSolver::Viscous_Residual; /*--- Silence warning ---*/ /*! diff --git a/SU2_CFD/include/solvers/CTurbSASolver.hpp b/SU2_CFD/include/solvers/CTurbSASolver.hpp index 3ca3b84e1f3f..5b05ad95b958 100644 --- a/SU2_CFD/include/solvers/CTurbSASolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSASolver.hpp @@ -120,6 +120,19 @@ class CTurbSASolver final : public CTurbSolver { CSolver **solver_container, CConfig *config, unsigned short iMesh) override; + + /*! + * \brief Compute the viscous flux for the turbulent equation at a particular edge. + * \param[in] iEdge - Edge for which we want to compute the flux + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \note Calls a generic implementation after defining a SolverSpecificNumerics object. + */ + void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) override; + /*! * \brief Source term computation. * \param[in] geometry - Geometrical definition of the problem. diff --git a/SU2_CFD/include/solvers/CTurbSSTSolver.hpp b/SU2_CFD/include/solvers/CTurbSSTSolver.hpp index fbcc50204b87..25b05c2f5cd3 100644 --- a/SU2_CFD/include/solvers/CTurbSSTSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSSTSolver.hpp @@ -106,6 +106,18 @@ class CTurbSSTSolver final : public CTurbSolver { CConfig *config, unsigned short iMesh) override; + /*! + * \brief Compute the viscous flux for the turbulent equation at a particular edge. + * \param[in] iEdge - Edge for which we want to compute the flux + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver_container - Container vector with all the solutions. + * \param[in] numerics - Description of the numerical method. + * \param[in] config - Definition of the particular problem. + * \note Calls a generic implementation after defining a SolverSpecificNumerics object. + */ + void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) override; + /*! * \brief Source term computation. * \param[in] geometry - Geometrical definition of the problem. diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/src/solvers/CScalarSolver.cpp index 599586b8bf29..b55570c30671 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/src/solvers/CScalarSolver.cpp @@ -236,52 +236,6 @@ void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_contai } } -void CScalarSolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, - CNumerics* numerics, CConfig* config) { - const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); - CVariable* flowNodes = solver_container[FLOW_SOL]->GetNodes(); - - /*--- Points in edge ---*/ - - auto iPoint = geometry->edges->GetNode(iEdge, 0); - auto jPoint = geometry->edges->GetNode(iEdge, 1); - - /*--- Points coordinates, and normal vector ---*/ - - numerics->SetCoord(geometry->nodes->GetCoord(iPoint), geometry->nodes->GetCoord(jPoint)); - numerics->SetNormal(geometry->edges->GetNormal(iEdge)); - - /*--- Conservative variables w/o reconstruction ---*/ - - numerics->SetPrimitive(flowNodes->GetPrimitive(iPoint), flowNodes->GetPrimitive(jPoint)); - - /*--- Turbulent variables w/o reconstruction, and its gradients ---*/ - - numerics->SetScalarVar(nodes->GetSolution(iPoint), nodes->GetSolution(jPoint)); - numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(jPoint)); - - /*--- Menter's first blending function (only SST)---*/ - if ((config->GetKind_Turb_Model() == SST) || (config->GetKind_Turb_Model() == SST_SUST)) - numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(jPoint)); - - /*--- Roughness heights. ---*/ - if (config->GetKind_Turb_Model() == SA) - numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), geometry->nodes->GetRoughnessHeight(jPoint)); - - /*--- Compute residual, and Jacobians ---*/ - - auto residual = numerics->ComputeResidual(config); - - if (ReducerStrategy) { - EdgeFluxes.SubtractBlock(iEdge, residual); - if (implicit) Jacobian.UpdateBlocksSub(iEdge, residual.jacobian_i, residual.jacobian_j); - } else { - LinSysRes.SubtractBlock(iPoint, residual); - LinSysRes.AddBlock(jPoint, residual); - if (implicit) Jacobian.UpdateBlocksSub(iEdge, iPoint, jPoint, residual.jacobian_i, residual.jacobian_j); - } -} - void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { @@ -606,7 +560,6 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c } for (iVar = 0; iVar < nVar; iVar++) LinSysRes(iPoint, iVar) += Density_n * U_time_n[iVar] * Residual_GCL; - } END_SU2_OMP_FOR } diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index d2cc6055e552..34e2e19741b9 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -286,6 +286,24 @@ void CTurbSASolver::Postprocessing(CGeometry *geometry, CSolver **solver_contain AD::EndNoSharedReading(); } +void CTurbSASolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) { + + /*--- Define an object to set solver specific numerics contribution. ---*/ + struct SolverSpecificNumerics { + + FORCEINLINE void operator() (const CGeometry& geometry, CNumerics& numerics, CConfig& config, const CScalarVariable& nodes, unsigned long iPoint, unsigned long jPoint) const { + /*--- Roughness heights. ---*/ + if (config.GetKind_Turb_Model() == SA) + numerics.SetRoughness(geometry.nodes->GetRoughnessHeight(iPoint), geometry.nodes->GetRoughnessHeight(jPoint)); + } + + } SolverSpecificNumerics; + + /*--- Now instantiate the generic implementation with the functor above. ---*/ + + Viscous_Residual_impl(SolverSpecificNumerics, iEdge, geometry, solver_container, numerics, config); +} void CTurbSASolver::Source_Residual(CGeometry *geometry, CSolver **solver_container, CNumerics **numerics_container, CConfig *config, unsigned short iMesh) { diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index b0de4843287a..91d108d031ce 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -275,6 +275,25 @@ void CTurbSSTSolver::Postprocessing(CGeometry *geometry, CSolver **solver_contai AD::EndNoSharedReading(); } +void CTurbSSTSolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, + CNumerics* numerics, CConfig* config) { + + /*--- Define an object to set solver specific numerics contribution. ---*/ + struct SolverSpecificNumerics { + + FORCEINLINE void operator() (const CGeometry& geometry, CNumerics& numerics, CConfig& config, const CScalarVariable& nodes, unsigned long iPoint, unsigned long jPoint) const { + /*--- Menter's first blending function (only SST)---*/ + if ((config.GetKind_Turb_Model() == SST) || (config.GetKind_Turb_Model() == SST_SUST)) + numerics.SetF1blending(nodes.GetF1blending(iPoint), nodes.GetF1blending(jPoint)); + } + + } SolverSpecificNumerics; + + /*--- Now instantiate the generic implementation with the functor above. ---*/ + + Viscous_Residual_impl(SolverSpecificNumerics, iEdge, geometry, solver_container, numerics, config); +} + void CTurbSSTSolver::Source_Residual(CGeometry *geometry, CSolver **solver_container, CNumerics **numerics_container, CConfig *config, unsigned short iMesh) { From 3e86076ad4641710db97f5aa38cd23af11b419ae Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Thu, 16 Sep 2021 17:35:00 +0200 Subject: [PATCH 39/48] Change struct to a lambda function. That has the benefit of capturing the outside variables/objects by reference using [&] which makes the input list much smaller. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 4 ++-- SU2_CFD/src/solvers/CTurbSASolver.cpp | 14 +++++--------- SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 13 ++++--------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index a2aedf0c0db1..74e2faf8af36 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -84,7 +84,7 @@ class CScalarSolver : public CSolver { /*! * \brief Compute the viscous flux for the turbulent equation at a particular edge. - * \tparam SolverSpecificNumericsFunc - Struct, that implements solver specific contributions to numerics. + * \tparam SolverSpecificNumericsFunc - lambda-function, that implements solver specific contributions to numerics. * \note The functor has to implement (*geometry, *numerics, *config, *nodes, iPoint, jPoint) * \param[in] iEdge - Edge for which we want to compute the flux * \param[in] geometry - Geometrical definition of the problem. @@ -120,7 +120,7 @@ class CScalarSolver : public CSolver { /*--- Call Numerics contribution which are Solver-Specifc. Implemented in the caller: Viscous_Residual. ---*/ - SolverSpecificNumerics(*geometry, *numerics, *config, *nodes, iPoint, jPoint); + SolverSpecificNumerics(iPoint, jPoint); /*--- Compute residual, and Jacobians ---*/ diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 34e2e19741b9..396d0412661b 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -290,15 +290,11 @@ void CTurbSASolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, C CNumerics* numerics, CConfig* config) { /*--- Define an object to set solver specific numerics contribution. ---*/ - struct SolverSpecificNumerics { - - FORCEINLINE void operator() (const CGeometry& geometry, CNumerics& numerics, CConfig& config, const CScalarVariable& nodes, unsigned long iPoint, unsigned long jPoint) const { - /*--- Roughness heights. ---*/ - if (config.GetKind_Turb_Model() == SA) - numerics.SetRoughness(geometry.nodes->GetRoughnessHeight(iPoint), geometry.nodes->GetRoughnessHeight(jPoint)); - } - - } SolverSpecificNumerics; + auto SolverSpecificNumerics = [&](unsigned long iPoint, unsigned long jPoint) { + /*--- Roughness heights. ---*/ + if (config->GetKind_Turb_Model() == SA) + numerics->SetRoughness(geometry->nodes->GetRoughnessHeight(iPoint), geometry->nodes->GetRoughnessHeight(jPoint)); + }; /*--- Now instantiate the generic implementation with the functor above. ---*/ diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 91d108d031ce..3245a65e24ce 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -279,15 +279,10 @@ void CTurbSSTSolver::Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CNumerics* numerics, CConfig* config) { /*--- Define an object to set solver specific numerics contribution. ---*/ - struct SolverSpecificNumerics { - - FORCEINLINE void operator() (const CGeometry& geometry, CNumerics& numerics, CConfig& config, const CScalarVariable& nodes, unsigned long iPoint, unsigned long jPoint) const { - /*--- Menter's first blending function (only SST)---*/ - if ((config.GetKind_Turb_Model() == SST) || (config.GetKind_Turb_Model() == SST_SUST)) - numerics.SetF1blending(nodes.GetF1blending(iPoint), nodes.GetF1blending(jPoint)); - } - - } SolverSpecificNumerics; + auto SolverSpecificNumerics = [&](unsigned long iPoint, unsigned long jPoint) { + /*--- Menter's first blending function (only SST)---*/ + numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(jPoint)); + }; /*--- Now instantiate the generic implementation with the functor above. ---*/ From 1d8f520a9da2907b105b3f47f2fcd05e75d424c9 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Thu, 16 Sep 2021 17:44:29 +0200 Subject: [PATCH 40/48] Add empty SolverSpecificNumerics to generic ViscRes_impl. Alternatively one could go pure virtual as Pedro mentions, but I guess this is fine for now. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 74e2faf8af36..71b93c00ffcc 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -147,7 +147,16 @@ class CScalarSolver : public CSolver { * \note Calls a generic implementation after defining a SolverSpecificNumerics object. */ inline virtual void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, - CNumerics* numerics, CConfig* config) {} + CNumerics* numerics, CConfig* config) { + + /*--- Define an empty object for solver specific numerics contribution. In case there are none, this default + *--- implementation will be called ---*/ + auto SolverSpecificNumerics = [&](unsigned long iPoint, unsigned long jPoint) { }; + + /*--- Now instantiate the generic implementation with the functor above. ---*/ + + Viscous_Residual_impl(SolverSpecificNumerics, iEdge, geometry, solver_container, numerics, config); + } using CSolver::Viscous_Residual; /*--- Silence warning ---*/ /*! From 7cc2e8d4bd377850326067d6ddd224a631ce64a0 Mon Sep 17 00:00:00 2001 From: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com> Date: Fri, 17 Sep 2021 23:30:34 +0100 Subject: [PATCH 41/48] updating some comments, and override -> final where possible --- SU2_CFD/include/variables/CScalarVariable.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index 0cebb3bb0e4a..b459f233883c 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -1,6 +1,6 @@ /*! * \file CScalarVariable.hpp - * \brief Base class for defining the variables of the turbulence model. + * \brief Base class for defining the shared variables of scalar solvers. * \author F. Palacios, T. Economon * \version 7.2.0 "Blackbird" * @@ -31,9 +31,7 @@ /*! * \class CScalarVariable - * \brief Base class for defining the variables of the turbulence model. - * \ingroup Turbulence_Model - * \author A. Bueno. + * \brief Base class for defining the shared variables of scalar solvers. */ class CScalarVariable : public CVariable { protected: @@ -81,7 +79,7 @@ class CScalarVariable : public CVariable { * \param[in] iVar - Index of the variable. * \param[in] source - Value of the harmonic balance source term. for the index iVar. */ - inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) override { HB_Source(iPoint,iVar) = source; } + inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) final { HB_Source(iPoint,iVar) = source; } /*! * \brief Get the harmonic balance source term. @@ -89,5 +87,5 @@ class CScalarVariable : public CVariable { * \param[in] iVar - Index of the variable. * \return Value of the harmonic balance source term for the index val_var. */ - inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const override { return HB_Source(iPoint,iVar); } + inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const final { return HB_Source(iPoint,iVar); } }; From ca16276d50b2dc99ea40c511aa6df70b141b986c Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 22 Sep 2021 14:16:17 +0200 Subject: [PATCH 42/48] Template CScalarSolver on type of CVariable. Allowing optimized acces to muT of TurbSolvers. Implementation follows what is done for CFVMFlowSolverBase. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 11 +++--- .../solvers/CScalarSolver.inl} | 36 ++++++++++++------- SU2_CFD/include/solvers/CTurbSolver.hpp | 2 +- SU2_CFD/obj/Makefile.am | 1 - SU2_CFD/src/meson.build | 1 - SU2_CFD/src/solvers/CTransLMSolver.cpp | 6 +++- SU2_CFD/src/solvers/CTurbSASolver.cpp | 4 +++ SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 4 +++ SU2_CFD/src/solvers/CTurbSolver.cpp | 4 +-- 9 files changed, 44 insertions(+), 25 deletions(-) rename SU2_CFD/{src/solvers/CScalarSolver.cpp => include/solvers/CScalarSolver.inl} (95%) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 71b93c00ffcc..224cc118a8c0 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -1,7 +1,6 @@ /*! * \file CScalarSolver.hpp * \brief Headers of the CScalarSolver class - * \author A. Bueno. * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io @@ -35,10 +34,10 @@ /*! * \class CScalarSolver - * \brief Main class for defining the turbulence model solver. - * \ingroup Turbulence_Model - * \author A. Bueno. + * \brief Main class for defining a scalar solver. + * \tparam TVariable - Class of C*Variable of the specific solver */ +template class CScalarSolver : public CSolver { protected: enum : size_t { MAXNDIM = 3 }; /*!< \brief Max number of space dimensions, used in some static arrays. */ @@ -75,7 +74,7 @@ class CScalarSolver : public CSolver { /*! * \brief The highest level in the variable hierarchy this solver can safely use. */ - CScalarVariable* nodes = nullptr; + TVariable* nodes = nullptr; /*! * \brief Return nodes to allow CSolver::base_nodes to be set. @@ -85,7 +84,7 @@ class CScalarSolver : public CSolver { /*! * \brief Compute the viscous flux for the turbulent equation at a particular edge. * \tparam SolverSpecificNumericsFunc - lambda-function, that implements solver specific contributions to numerics. - * \note The functor has to implement (*geometry, *numerics, *config, *nodes, iPoint, jPoint) + * \note The functor has to implement (iPoint, jPoint) * \param[in] iEdge - Edge for which we want to compute the flux * \param[in] geometry - Geometrical definition of the problem. * \param[in] solver_container - Container vector with all the solutions. diff --git a/SU2_CFD/src/solvers/CScalarSolver.cpp b/SU2_CFD/include/solvers/CScalarSolver.inl similarity index 95% rename from SU2_CFD/src/solvers/CScalarSolver.cpp rename to SU2_CFD/include/solvers/CScalarSolver.inl index b55570c30671..d5e9d677bada 100644 --- a/SU2_CFD/src/solvers/CScalarSolver.cpp +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -1,7 +1,6 @@ /*! - * \file CScalarSolver.cpp + * \file CScalarSolver.inl * \brief Main subrotuines of CScalarSolver class - * \author F. Palacios, A. Bueno * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io @@ -30,9 +29,11 @@ #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} +template +CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} -CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) +template +CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) : CSolver(), Conservative(conservative) { nMarker = config->GetnMarker_All(); @@ -74,9 +75,11 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conserva } } -CScalarSolver::~CScalarSolver() { delete nodes; } +template +CScalarSolver::~CScalarSolver() { delete nodes; } -void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, +template +void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config, unsigned short iMesh) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool muscl = config->GetMUSCL_Turb(); @@ -236,7 +239,8 @@ void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_contai } } -void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { +template +void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { LinSysRes.SetBlock_Zero(iPoint); @@ -251,7 +255,8 @@ void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { END_SU2_OMP_FOR } -void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { +template +void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { /*--- Complete residuals for periodic boundary conditions. We loop over the periodic BCs in matching pairs so that, in the event that there are adjacent periodic markers, the repeated points will have their residuals @@ -264,7 +269,8 @@ void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, } } -void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); /*--- Set shared residual variables to 0 and declare @@ -323,7 +329,8 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solv SetResidual_RMS(geometry, config); } -void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); @@ -369,7 +376,8 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** sol CompleteComms(geometry, config, SOLUTION_EDDY); } -void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { PrepareImplicitIteration(geometry, solver_container, config); /*--- Solve or smooth the linear system. ---*/ @@ -393,7 +401,8 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solve CompleteImplicitIteration(geometry, solver_container, config); } -void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, +template +void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); @@ -632,7 +641,8 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_c } // end dynamic grid } -void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, +template +void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) { /*--- Restart the solution from file information ---*/ diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index cb7768ef64ec..1fcfbd07eab8 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -37,7 +37,7 @@ * \ingroup Turbulence_Model * \author A. Bueno. */ -class CTurbSolver : public CScalarSolver { +class CTurbSolver : public CScalarSolver { protected: vector Inlet_TurbVars; /*!< \brief Turbulence variables at inlet profiles */ diff --git a/SU2_CFD/obj/Makefile.am b/SU2_CFD/obj/Makefile.am index e6929159e966..50950b471ad0 100644 --- a/SU2_CFD/obj/Makefile.am +++ b/SU2_CFD/obj/Makefile.am @@ -179,7 +179,6 @@ libSU2Core_sources = ../src/definition_structure.cpp \ ../src/solvers/CSolver.cpp \ ../src/solvers/CTemplateSolver.cpp \ ../src/solvers/CTransLMSolver.cpp \ - ../src/solvers/CScalarSolver.cpp \ ../src/solvers/CTurbSolver.cpp \ ../src/solvers/CTurbSASolver.cpp \ ../src/solvers/CTurbSSTSolver.cpp \ diff --git a/SU2_CFD/src/meson.build b/SU2_CFD/src/meson.build index 5327a5b831a7..66f4ecbfde76 100644 --- a/SU2_CFD/src/meson.build +++ b/SU2_CFD/src/meson.build @@ -102,7 +102,6 @@ su2_cfd_src += files(['solvers/CSolverFactory.cpp', 'solvers/CSolver.cpp', 'solvers/CTemplateSolver.cpp', 'solvers/CTransLMSolver.cpp', - 'solvers/CScalarSolver.cpp', 'solvers/CTurbSolver.cpp', 'solvers/CTurbSASolver.cpp', 'solvers/CTurbSSTSolver.cpp']) diff --git a/SU2_CFD/src/solvers/CTransLMSolver.cpp b/SU2_CFD/src/solvers/CTransLMSolver.cpp index bba0515ce799..9071e0e7a0bd 100644 --- a/SU2_CFD/src/solvers/CTransLMSolver.cpp +++ b/SU2_CFD/src/solvers/CTransLMSolver.cpp @@ -25,11 +25,15 @@ * License along with SU2. If not, see . */ - +#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTransLMSolver.hpp" #include "../../include/variables/CTransLMVariable.hpp" #include "../../include/variables/CTurbSAVariable.hpp" +/*--- Explicit instantiation of the parent class of CTurbSolver, + * to spread the compilation over multiple cpp files. ---*/ +template class CScalarSolver; + /*--- This is the implementation of the Langtry-Menter transition model. The main reference for this model is:Langtry, Menter, AIAA J. 47(12) 2009 DOI: https://doi.org/10.2514/1.42362 ---*/ diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 396d0412661b..3ebed3710e1e 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -25,11 +25,15 @@ * License along with SU2. If not, see . */ +#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTurbSASolver.hpp" #include "../../include/variables/CTurbSAVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" +/*--- Explicit instantiation of the parent class of CTurbSolver, + * to spread the compilation over multiple cpp files. ---*/ +template class CScalarSolver; CTurbSASolver::CTurbSASolver(void) : CTurbSolver(false) { } diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 3245a65e24ce..776b47fc94dd 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -25,11 +25,15 @@ * License along with SU2. If not, see . */ +#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTurbSSTSolver.hpp" #include "../../include/variables/CTurbSSTVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" +/*--- Explicit instantiation of the parent class of CTurbSolver, + * to spread the compilation over multiple cpp files. ---*/ +template class CScalarSolver; CTurbSSTSolver::CTurbSSTSolver(void) : CTurbSolver(true) { } diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index d77a958c689b..55d472b78d5e 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -30,9 +30,9 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -CTurbSolver::CTurbSolver(bool conservative) : CScalarSolver(conservative) { } +CTurbSolver::CTurbSolver(bool conservative) : CScalarSolver(conservative) { } -CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config, bool conservative) : CScalarSolver(geometry, config, conservative) { } +CTurbSolver::CTurbSolver(CGeometry* geometry, CConfig *config, bool conservative) : CScalarSolver(geometry, config, conservative) { } CTurbSolver::~CTurbSolver() { From 811d58193d48c12599d0cf4eada0f0f27275a7c3 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 22 Sep 2021 14:35:56 +0200 Subject: [PATCH 43/48] Apply clang-format and some other cleanups. --- .../numerics/scalar/scalar_convection.hpp | 2 +- .../numerics/scalar/scalar_diffusion.hpp | 2 +- .../numerics/scalar/scalar_sources.hpp | 6 +-- SU2_CFD/include/solvers/CScalarSolver.hpp | 5 +- SU2_CFD/include/solvers/CScalarSolver.inl | 51 ++++++++++--------- SU2_CFD/include/variables/CScalarVariable.hpp | 8 ++- .../src/numerics/scalar/scalar_convection.cpp | 2 +- .../src/numerics/scalar/scalar_diffusion.cpp | 2 +- .../src/numerics/scalar/scalar_sources.cpp | 6 +-- 9 files changed, 44 insertions(+), 40 deletions(-) diff --git a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp index 552861e57680..bcedd49acf7c 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_convection.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_convection.hpp @@ -1,5 +1,5 @@ /*! - * \file turb_convection.hpp + * \file scalar_convection.hpp * \brief Delarations of numerics classes for discretization of * convective fluxes in scalar problems. * \author F. Palacios, T. Economon diff --git a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp index df99a4e9d0af..64b9aa20e413 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp @@ -1,5 +1,5 @@ /*! - * \file turb_diffusion.hpp + * \file scalar_diffusion.hpp * \brief Declarations of numerics classes for discretization of * viscous fluxes in scalar problems. * \author F. Palacios, T. Economon diff --git a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp index 9871905c3fa4..d70175ee02d3 100644 --- a/SU2_CFD/include/numerics/scalar/scalar_sources.hpp +++ b/SU2_CFD/include/numerics/scalar/scalar_sources.hpp @@ -1,8 +1,6 @@ /*! - * \file turb_sources.hpp - * \brief Delarations of numerics classes for integration of source - * terms in scalar problems. - * \author F. Palacios, T. Economon + * \file scalar_sources.hpp + * \brief Delarations of numerics classes for integration of source terms in scalar problems. * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 224cc118a8c0..002bb0dde089 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -37,7 +37,7 @@ * \brief Main class for defining a scalar solver. * \tparam TVariable - Class of C*Variable of the specific solver */ -template +template class CScalarSolver : public CSolver { protected: enum : size_t { MAXNDIM = 3 }; /*!< \brief Max number of space dimensions, used in some static arrays. */ @@ -147,10 +147,9 @@ class CScalarSolver : public CSolver { */ inline virtual void Viscous_Residual(unsigned long iEdge, CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { - /*--- Define an empty object for solver specific numerics contribution. In case there are none, this default *--- implementation will be called ---*/ - auto SolverSpecificNumerics = [&](unsigned long iPoint, unsigned long jPoint) { }; + auto SolverSpecificNumerics = [&](unsigned long iPoint, unsigned long jPoint) {}; /*--- Now instantiate the generic implementation with the functor above. ---*/ diff --git a/SU2_CFD/include/solvers/CScalarSolver.inl b/SU2_CFD/include/solvers/CScalarSolver.inl index d5e9d677bada..e584a306f4be 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.inl +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -24,15 +24,14 @@ * License along with SU2. If not, see . */ -#include "../../include/solvers/CScalarSolver.hpp" - #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" +#include "../../include/solvers/CScalarSolver.hpp" -template +template CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} -template +template CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) : CSolver(), Conservative(conservative) { nMarker = config->GetnMarker_All(); @@ -75,12 +74,14 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bo } } -template -CScalarSolver::~CScalarSolver() { delete nodes; } +template +CScalarSolver::~CScalarSolver() { + delete nodes; +} -template -void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, - CConfig* config, unsigned short iMesh) { +template +void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, + CNumerics** numerics_container, CConfig* config, unsigned short iMesh) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool muscl = config->GetMUSCL_Turb(); const bool limiter = (config->GetKind_SlopeLimit_Turb() != NO_LIMITER); @@ -239,7 +240,7 @@ void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** so } } -template +template void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { @@ -255,8 +256,9 @@ void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { END_SU2_OMP_FOR } -template -void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { +template +void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, + CConfig* config) { /*--- Complete residuals for periodic boundary conditions. We loop over the periodic BCs in matching pairs so that, in the event that there are adjacent periodic markers, the repeated points will have their residuals @@ -269,8 +271,9 @@ void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver } } -template -void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, + CConfig* config) { const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); /*--- Set shared residual variables to 0 and declare @@ -329,8 +332,9 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSo SetResidual_RMS(geometry, config); } -template -void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, + CConfig* config) { const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); @@ -376,8 +380,9 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CS CompleteComms(geometry, config, SOLUTION_EDDY); } -template -void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { +template +void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, + CConfig* config) { PrepareImplicitIteration(geometry, solver_container, config); /*--- Solve or smooth the linear system. ---*/ @@ -401,10 +406,10 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSol CompleteImplicitIteration(geometry, solver_container, config); } -template +template void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, - unsigned short iRKStep, unsigned short iMesh, - unsigned short RunTime_EqSystem) { + unsigned short iRKStep, unsigned short iMesh, + unsigned short RunTime_EqSystem) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool first_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST); const bool second_order = (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND); @@ -641,9 +646,9 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver } // end dynamic grid } -template +template void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, - bool val_update_geo) { + bool val_update_geo) { /*--- Restart the solution from file information ---*/ unsigned short iVar, iMesh; diff --git a/SU2_CFD/include/variables/CScalarVariable.hpp b/SU2_CFD/include/variables/CScalarVariable.hpp index b459f233883c..cb4db4f1c33b 100644 --- a/SU2_CFD/include/variables/CScalarVariable.hpp +++ b/SU2_CFD/include/variables/CScalarVariable.hpp @@ -79,7 +79,9 @@ class CScalarVariable : public CVariable { * \param[in] iVar - Index of the variable. * \param[in] source - Value of the harmonic balance source term. for the index iVar. */ - inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) final { HB_Source(iPoint,iVar) = source; } + inline void SetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar, su2double source) final { + HB_Source(iPoint, iVar) = source; + } /*! * \brief Get the harmonic balance source term. @@ -87,5 +89,7 @@ class CScalarVariable : public CVariable { * \param[in] iVar - Index of the variable. * \return Value of the harmonic balance source term for the index val_var. */ - inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const final { return HB_Source(iPoint,iVar); } + inline su2double GetHarmonicBalance_Source(unsigned long iPoint, unsigned long iVar) const final { + return HB_Source(iPoint, iVar); + } }; diff --git a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp index f07e8123917d..7afd5ebf10a8 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_convection.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_convection.cpp @@ -1,5 +1,5 @@ /*! - * \file turb_convection.cpp + * \file scalar_convection.cpp * \brief Implementation of numerics classes to compute convective * fluxes in scalar problems. * \author F. Palacios, T. Economon diff --git a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp index b3fc5d873a35..031a02f20030 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_diffusion.cpp @@ -1,5 +1,5 @@ /*! - * \file turb_diffusion.cpp + * \file scalar_diffusion.cpp * \brief Implementation of numerics classes to compute viscous * fluxes in scalar problems. * \author F. Palacios, T. Economon diff --git a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp index 9e4b637429ab..d8bfd0c0eba3 100644 --- a/SU2_CFD/src/numerics/scalar/scalar_sources.cpp +++ b/SU2_CFD/src/numerics/scalar/scalar_sources.cpp @@ -1,8 +1,6 @@ /*! - * \file turb_sources.cpp - * \brief Implementation of numerics classes for integration of - * scalar source-terms. - * \author F. Palacios, T. Economon + * \file scalar_sources.cpp + * \brief Implementation of numerics classes for integration of scalar source-terms. * \version 7.2.0 "Blackbird" * * SU2 Project Website: https://su2code.github.io From 58d3df3f8f9f7547263b9392d1ee87786cebd632 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 22 Sep 2021 14:44:53 +0200 Subject: [PATCH 44/48] Make Scalar LoadRestart pure virtual. And move current Turb specific impl to CTurbSolver. I.e. each Child of CscalarSolver has to implement its own LoadRestart. One has to make sure the correct Pre/Postprocessign routines are called in there which are consistent with the repective C(Fluid)Iteration. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- SU2_CFD/include/solvers/CScalarSolver.inl | 120 ---------------------- SU2_CFD/include/solvers/CTurbSolver.hpp | 10 ++ SU2_CFD/src/solvers/CTurbSolver.cpp | 119 +++++++++++++++++++++ 4 files changed, 130 insertions(+), 121 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index 002bb0dde089..b5b1f1bb2ab1 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -292,7 +292,7 @@ class CScalarSolver : public CSolver { * \param[in] val_iter - Current external iteration number. * \param[in] val_update_geo - Flag for updating coords and grid velocity. */ - void LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) final; + virtual void LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) override = 0; /*! * \brief Scalar solvers support OpenMP+MPI. diff --git a/SU2_CFD/include/solvers/CScalarSolver.inl b/SU2_CFD/include/solvers/CScalarSolver.inl index e584a306f4be..8c73ed905925 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.inl +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -645,123 +645,3 @@ void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver } // end dynamic grid } - -template -void CScalarSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, - bool val_update_geo) { - /*--- Restart the solution from file information ---*/ - - unsigned short iVar, iMesh; - unsigned long iPoint, index, iChildren, Point_Fine; - su2double Area_Children, Area_Parent; - const su2double* Solution_Fine = nullptr; - - string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter); - - /*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/ - SU2_OMP_MASTER { - /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ - - if (config->GetRead_Binary_Restart()) { - Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); - } else { - Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); - } - - /*--- Skip flow variables ---*/ - - unsigned short skipVars = nDim + solver[MESH_0][FLOW_SOL]->GetnVar(); - - /*--- Adjust the number of solution variables in the incompressible - restart. We always carry a space in nVar for the energy equation in the - mean flow solver, but we only write it to the restart if it is active. - Therefore, we must reduce skipVars here if energy is inactive so that - the turbulent variables are read correctly. ---*/ - - bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); - bool energy = config->GetEnergy_Equation(); - bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); - - if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; - - /*--- Load data from the restart into correct containers. ---*/ - - unsigned long counter = 0, iPoint_Global = 0; - for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { - /*--- Retrieve local index. If this node from the restart file lives - on the current processor, we will load and instantiate the vars. ---*/ - - auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); - - if (iPoint_Local > -1) { - /*--- We need to store this point's data, so jump to the correct - offset in the buffer of data from the restart file and load it. ---*/ - - index = counter * Restart_Vars[1] + skipVars; - for (iVar = 0; iVar < nVar; ++iVar) nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index + iVar]); - - /*--- Increment the overall counter for how many points have been loaded. ---*/ - counter++; - } - } - - /*--- Detect a wrong solution file ---*/ - - if (counter != nPointDomain) { - SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + - string("It could be empty lines at the end of the file."), - CURRENT_FUNCTION); - } - - } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. - END_SU2_OMP_MASTER - SU2_OMP_BARRIER - - /*--- MPI solution and compute the eddy viscosity ---*/ - - solver[MESH_0][TURB_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION); - solver[MESH_0][TURB_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION); - - solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, - RUNTIME_FLOW_SYS, false); - solver[MESH_0][TURB_SOL]->Postprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0); - - /*--- Interpolate the solution down to the coarse multigrid levels ---*/ - - for (iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) { - SU2_OMP_FOR_STAT(omp_chunk_size) - for (iPoint = 0; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) { - Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint); - su2double Solution_Coarse[MAXNVAR] = {0.0}; - for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) { - Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren); - Area_Children = geometry[iMesh - 1]->nodes->GetVolume(Point_Fine); - Solution_Fine = solver[iMesh - 1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); - for (iVar = 0; iVar < nVar; iVar++) { - Solution_Coarse[iVar] += Solution_Fine[iVar] * Area_Children / Area_Parent; - } - } - solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint, Solution_Coarse); - } - END_SU2_OMP_FOR - - solver[iMesh][TURB_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION); - solver[iMesh][TURB_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION); - - solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, - false); - solver[iMesh][TURB_SOL]->Postprocessing(geometry[iMesh], solver[iMesh], config, iMesh); - } - - /*--- Go back to single threaded execution. ---*/ - SU2_OMP_MASTER { - /*--- Delete the class memory that is used to load the restart. ---*/ - - delete[] Restart_Vars; - Restart_Vars = nullptr; - delete[] Restart_Data; - Restart_Data = nullptr; - } - END_SU2_OMP_MASTER - SU2_OMP_BARRIER -} diff --git a/SU2_CFD/include/solvers/CTurbSolver.hpp b/SU2_CFD/include/solvers/CTurbSolver.hpp index 1fcfbd07eab8..8f6dbe462455 100644 --- a/SU2_CFD/include/solvers/CTurbSolver.hpp +++ b/SU2_CFD/include/solvers/CTurbSolver.hpp @@ -126,6 +126,16 @@ class CTurbSolver : public CScalarSolver { CNumerics *visc_numerics, CConfig *config) final; + /*! + * \brief Load a solution from a restart file. + * \param[in] geometry - Geometrical definition of the problem. + * \param[in] solver - Container vector with all of the solvers. + * \param[in] config - Definition of the particular problem. + * \param[in] val_iter - Current external iteration number. + * \param[in] val_update_geo - Flag for updating coords and grid velocity. + */ + void LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, bool val_update_geo) final; + /*! * \brief Impose fixed values to turbulence quantities. * \details Turbulence quantities are set to far-field values in an upstream half-plane diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index 55d472b78d5e..cdf39bfdbc79 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -206,6 +206,125 @@ void CTurbSolver::BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_conta } +void CTurbSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter, + bool val_update_geo) { + /*--- Restart the solution from file information ---*/ + + unsigned short iVar, iMesh; + unsigned long iPoint, index, iChildren, Point_Fine; + su2double Area_Children, Area_Parent; + const su2double* Solution_Fine = nullptr; + + string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter); + + /*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/ + SU2_OMP_MASTER { + /*--- Read the restart data from either an ASCII or binary SU2 file. ---*/ + + if (config->GetRead_Binary_Restart()) { + Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename); + } else { + Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename); + } + + /*--- Skip flow variables ---*/ + + unsigned short skipVars = nDim + solver[MESH_0][FLOW_SOL]->GetnVar(); + + /*--- Adjust the number of solution variables in the incompressible + restart. We always carry a space in nVar for the energy equation in the + mean flow solver, but we only write it to the restart if it is active. + Therefore, we must reduce skipVars here if energy is inactive so that + the turbulent variables are read correctly. ---*/ + + bool incompressible = (config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE); + bool energy = config->GetEnergy_Equation(); + bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat(); + + if (incompressible && ((!energy) && (!weakly_coupled_heat))) skipVars--; + + /*--- Load data from the restart into correct containers. ---*/ + + unsigned long counter = 0, iPoint_Global = 0; + for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) { + /*--- Retrieve local index. If this node from the restart file lives + on the current processor, we will load and instantiate the vars. ---*/ + + auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global); + + if (iPoint_Local > -1) { + /*--- We need to store this point's data, so jump to the correct + offset in the buffer of data from the restart file and load it. ---*/ + + index = counter * Restart_Vars[1] + skipVars; + for (iVar = 0; iVar < nVar; ++iVar) nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index + iVar]); + + /*--- Increment the overall counter for how many points have been loaded. ---*/ + counter++; + } + } + + /*--- Detect a wrong solution file ---*/ + + if (counter != nPointDomain) { + SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") + + string("It could be empty lines at the end of the file."), + CURRENT_FUNCTION); + } + + } // end SU2_OMP_MASTER, pre and postprocessing are thread-safe. + END_SU2_OMP_MASTER + SU2_OMP_BARRIER + + /*--- MPI solution and compute the eddy viscosity ---*/ + + solver[MESH_0][TURB_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION); + solver[MESH_0][TURB_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION); + + solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, + RUNTIME_FLOW_SYS, false); + solver[MESH_0][TURB_SOL]->Postprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0); + + /*--- Interpolate the solution down to the coarse multigrid levels ---*/ + + for (iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) { + SU2_OMP_FOR_STAT(omp_chunk_size) + for (iPoint = 0; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) { + Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint); + su2double Solution_Coarse[MAXNVAR] = {0.0}; + for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) { + Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren); + Area_Children = geometry[iMesh - 1]->nodes->GetVolume(Point_Fine); + Solution_Fine = solver[iMesh - 1][TURB_SOL]->GetNodes()->GetSolution(Point_Fine); + for (iVar = 0; iVar < nVar; iVar++) { + Solution_Coarse[iVar] += Solution_Fine[iVar] * Area_Children / Area_Parent; + } + } + solver[iMesh][TURB_SOL]->GetNodes()->SetSolution(iPoint, Solution_Coarse); + } + END_SU2_OMP_FOR + + solver[iMesh][TURB_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION); + solver[iMesh][TURB_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION); + + solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, + false); + solver[iMesh][TURB_SOL]->Postprocessing(geometry[iMesh], solver[iMesh], config, iMesh); + } + + /*--- Go back to single threaded execution. ---*/ + SU2_OMP_MASTER { + /*--- Delete the class memory that is used to load the restart. ---*/ + + delete[] Restart_Vars; + Restart_Vars = nullptr; + delete[] Restart_Data; + Restart_Data = nullptr; + } + END_SU2_OMP_MASTER + SU2_OMP_BARRIER +} + void CTurbSolver::Impose_Fixed_Values(const CGeometry *geometry, const CConfig *config){ /*--- Check whether turbulence quantities are fixed to far-field values on a half-plane. ---*/ From 443190fa1baf7c506677c6963c887b4d2b1c0edb Mon Sep 17 00:00:00 2001 From: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com> Date: Wed, 22 Sep 2021 15:19:42 +0200 Subject: [PATCH 45/48] Rename to VariableType and Remove duplicate compilations due to templates Code suggestions by pcarruscag Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com> --- SU2_CFD/include/solvers/CScalarSolver.hpp | 4 ++-- SU2_CFD/src/solvers/CTransLMSolver.cpp | 5 ----- SU2_CFD/src/solvers/CTurbSASolver.cpp | 4 ---- SU2_CFD/src/solvers/CTurbSSTSolver.cpp | 4 ---- SU2_CFD/src/solvers/CTurbSolver.cpp | 3 +++ 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index b5b1f1bb2ab1..aa0173e3c229 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -35,7 +35,7 @@ /*! * \class CScalarSolver * \brief Main class for defining a scalar solver. - * \tparam TVariable - Class of C*Variable of the specific solver + * \tparam VariableType - Class of variable used by the solver inheriting from this template. */ template class CScalarSolver : public CSolver { @@ -74,7 +74,7 @@ class CScalarSolver : public CSolver { /*! * \brief The highest level in the variable hierarchy this solver can safely use. */ - TVariable* nodes = nullptr; + VariableType* nodes = nullptr; /*! * \brief Return nodes to allow CSolver::base_nodes to be set. diff --git a/SU2_CFD/src/solvers/CTransLMSolver.cpp b/SU2_CFD/src/solvers/CTransLMSolver.cpp index 9071e0e7a0bd..4de7b22533b4 100644 --- a/SU2_CFD/src/solvers/CTransLMSolver.cpp +++ b/SU2_CFD/src/solvers/CTransLMSolver.cpp @@ -25,15 +25,10 @@ * License along with SU2. If not, see . */ -#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTransLMSolver.hpp" #include "../../include/variables/CTransLMVariable.hpp" #include "../../include/variables/CTurbSAVariable.hpp" -/*--- Explicit instantiation of the parent class of CTurbSolver, - * to spread the compilation over multiple cpp files. ---*/ -template class CScalarSolver; - /*--- This is the implementation of the Langtry-Menter transition model. The main reference for this model is:Langtry, Menter, AIAA J. 47(12) 2009 DOI: https://doi.org/10.2514/1.42362 ---*/ diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 3ebed3710e1e..396d0412661b 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -25,15 +25,11 @@ * License along with SU2. If not, see . */ -#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTurbSASolver.hpp" #include "../../include/variables/CTurbSAVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -/*--- Explicit instantiation of the parent class of CTurbSolver, - * to spread the compilation over multiple cpp files. ---*/ -template class CScalarSolver; CTurbSASolver::CTurbSASolver(void) : CTurbSolver(false) { } diff --git a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp index 776b47fc94dd..3245a65e24ce 100644 --- a/SU2_CFD/src/solvers/CTurbSSTSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSSTSolver.cpp @@ -25,15 +25,11 @@ * License along with SU2. If not, see . */ -#include "../../include/solvers/CScalarSolver.inl" #include "../../include/solvers/CTurbSSTSolver.hpp" #include "../../include/variables/CTurbSSTVariable.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" -/*--- Explicit instantiation of the parent class of CTurbSolver, - * to spread the compilation over multiple cpp files. ---*/ -template class CScalarSolver; CTurbSSTSolver::CTurbSSTSolver(void) : CTurbSolver(true) { } diff --git a/SU2_CFD/src/solvers/CTurbSolver.cpp b/SU2_CFD/src/solvers/CTurbSolver.cpp index cdf39bfdbc79..09644642ec68 100644 --- a/SU2_CFD/src/solvers/CTurbSolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSolver.cpp @@ -28,7 +28,10 @@ #include "../../include/solvers/CTurbSolver.hpp" #include "../../../Common/include/parallelization/omp_structure.hpp" #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" +#include "../../include/solvers/CScalarSolver.inl" +/*--- Explicit instantiation of the parent class of CTurbSolver. ---*/ +template class CScalarSolver; CTurbSolver::CTurbSolver(bool conservative) : CScalarSolver(conservative) { } From b123fb5284fa4199e1a50ea55fea6cebfd4ef9f8 Mon Sep 17 00:00:00 2001 From: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com> Date: Wed, 22 Sep 2021 15:25:12 +0200 Subject: [PATCH 46/48] Change forgotten TVariable to VariableType --- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index aa0173e3c229..ce50d86a3fb9 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -37,7 +37,7 @@ * \brief Main class for defining a scalar solver. * \tparam VariableType - Class of variable used by the solver inheriting from this template. */ -template +template class CScalarSolver : public CSolver { protected: enum : size_t { MAXNDIM = 3 }; /*!< \brief Max number of space dimensions, used in some static arrays. */ From 2b18052650849eb6b5cca6de69633d5dd25f88c0 Mon Sep 17 00:00:00 2001 From: TobiKattmann <31306376+TobiKattmann@users.noreply.github.com> Date: Wed, 22 Sep 2021 15:26:44 +0200 Subject: [PATCH 47/48] Small changes. Added newline to eof and one comment change. --- SU2_CFD/src/solvers/CTransLMSolver.cpp | 3 ++- SU2_CFD/src/solvers/CTurbSASolver.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SU2_CFD/src/solvers/CTransLMSolver.cpp b/SU2_CFD/src/solvers/CTransLMSolver.cpp index 4de7b22533b4..779db2275138 100644 --- a/SU2_CFD/src/solvers/CTransLMSolver.cpp +++ b/SU2_CFD/src/solvers/CTransLMSolver.cpp @@ -33,7 +33,8 @@ The main reference for this model is:Langtry, Menter, AIAA J. 47(12) 2009 DOI: https://doi.org/10.2514/1.42362 ---*/ -CTransLMSolver::CTransLMSolver(void) : CTurbSolver(true) {} ///Note: TransLM seems to rho*gamma, rho*Re_sigma as Solution variables +// Note: TransLM seems to use rho*gamma, rho*Re_sigma as Solution variables, thus Conservative=true +CTransLMSolver::CTransLMSolver(void) : CTurbSolver(true) {} CTransLMSolver::CTransLMSolver(CGeometry *geometry, CConfig *config, unsigned short iMesh) : CTurbSolver(true) { unsigned short iVar, nLineLets; diff --git a/SU2_CFD/src/solvers/CTurbSASolver.cpp b/SU2_CFD/src/solvers/CTurbSASolver.cpp index 396d0412661b..7beab143042e 100644 --- a/SU2_CFD/src/solvers/CTurbSASolver.cpp +++ b/SU2_CFD/src/solvers/CTurbSASolver.cpp @@ -1641,4 +1641,4 @@ void CTurbSASolver::ComputeUnderRelaxationFactor(const CConfig *config) { } END_SU2_OMP_FOR -} \ No newline at end of file +} From 6f8e69a67d5e5bbb5f104cf3a4eb23846ea35f97 Mon Sep 17 00:00:00 2001 From: TobiKattmann Date: Wed, 22 Sep 2021 15:28:40 +0200 Subject: [PATCH 48/48] Rename TVariable to VariableType in CScalarSolver.inl. To stay consistent with the .hpp. One could also use a more concise as suggested by pcaruscag but I prefer to stay use the same name here. --- SU2_CFD/include/solvers/CScalarSolver.hpp | 2 +- SU2_CFD/include/solvers/CScalarSolver.inl | 40 +++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/SU2_CFD/include/solvers/CScalarSolver.hpp b/SU2_CFD/include/solvers/CScalarSolver.hpp index aa0173e3c229..ce50d86a3fb9 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.hpp +++ b/SU2_CFD/include/solvers/CScalarSolver.hpp @@ -37,7 +37,7 @@ * \brief Main class for defining a scalar solver. * \tparam VariableType - Class of variable used by the solver inheriting from this template. */ -template +template class CScalarSolver : public CSolver { protected: enum : size_t { MAXNDIM = 3 }; /*!< \brief Max number of space dimensions, used in some static arrays. */ diff --git a/SU2_CFD/include/solvers/CScalarSolver.inl b/SU2_CFD/include/solvers/CScalarSolver.inl index 8c73ed905925..31b1280bc5c0 100644 --- a/SU2_CFD/include/solvers/CScalarSolver.inl +++ b/SU2_CFD/include/solvers/CScalarSolver.inl @@ -28,11 +28,11 @@ #include "../../../Common/include/toolboxes/geometry_toolbox.hpp" #include "../../include/solvers/CScalarSolver.hpp" -template -CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} +template +CScalarSolver::CScalarSolver(bool conservative) : CSolver(), Conservative(conservative) {} -template -CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) +template +CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bool conservative) : CSolver(), Conservative(conservative) { nMarker = config->GetnMarker_All(); @@ -74,13 +74,13 @@ CScalarSolver::CScalarSolver(CGeometry* geometry, CConfig* config, bo } } -template -CScalarSolver::~CScalarSolver() { +template +CScalarSolver::~CScalarSolver() { delete nodes; } -template -void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, +template +void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config, unsigned short iMesh) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool muscl = config->GetMUSCL_Turb(); @@ -240,8 +240,8 @@ void CScalarSolver::Upwind_Residual(CGeometry* geometry, CSolver** so } } -template -void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { +template +void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { SU2_OMP_FOR_STAT(omp_chunk_size) for (unsigned long iPoint = 0; iPoint < nPoint; ++iPoint) { LinSysRes.SetBlock_Zero(iPoint); @@ -256,8 +256,8 @@ void CScalarSolver::SumEdgeFluxes(CGeometry* geometry) { END_SU2_OMP_FOR } -template -void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, +template +void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) { /*--- Complete residuals for periodic boundary conditions. We loop over the periodic BCs in matching pairs so that, in the event that there are @@ -271,8 +271,8 @@ void CScalarSolver::BC_Periodic(CGeometry* geometry, CSolver** solver } } -template -void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, +template +void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const auto flowNodes = solver_container[FLOW_SOL]->GetNodes(); @@ -332,8 +332,8 @@ void CScalarSolver::PrepareImplicitIteration(CGeometry* geometry, CSo SetResidual_RMS(geometry, config); } -template -void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, +template +void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { const bool compressible = (config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); @@ -380,8 +380,8 @@ void CScalarSolver::CompleteImplicitIteration(CGeometry* geometry, CS CompleteComms(geometry, config, SOLUTION_EDDY); } -template -void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, +template +void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSolver** solver_container, CConfig* config) { PrepareImplicitIteration(geometry, solver_container, config); @@ -406,8 +406,8 @@ void CScalarSolver::ImplicitEuler_Iteration(CGeometry* geometry, CSol CompleteImplicitIteration(geometry, solver_container, config); } -template -void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, +template +void CScalarSolver::SetResidual_DualTime(CGeometry* geometry, CSolver** solver_container, CConfig* config, unsigned short iRKStep, unsigned short iMesh, unsigned short RunTime_EqSystem) { const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT);