DAkOmegaSSTFIML.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2 
3  DAFoam : Discrete Adjoint with OpenFOAM
4  Version : v3
5 
6  Description:
7  Child class for the kOmegaSST model with a betaFieldInversion field
8  multiplying to the omega transport equation. This betaFieldInversion term
9  can then be trained to improve the kOmegaSST model.
10 
11  This file is modified from OpenFOAM's source code
12  src/TurbulenceModels/turbulenceModels/RAS/kOmega/kOmega.H
13 
14  OpenFOAM: The Open Source CFD Toolbox
15 
16  Copyright (C): 2011-2016 OpenFOAM Foundation
17 
18  OpenFOAM License:
19 
20  OpenFOAM is free software: you can redistribute it and/or modify it
21  under the terms of the GNU General Public License as published by
22  the Free Software Foundation, either version 3 of the License, or
23  (at your option) any later version.
24 
25  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
26  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28  for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef DAkOmegaSSTFIML_H
36 #define DAkOmegaSSTFIML_H
37 
38 #include "DATurbulenceModel.H"
39 #include "addToRunTimeSelectionTable.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class DAkOmegaSSTFIML Declaration
47 \*---------------------------------------------------------------------------*/
48 
50  : public DATurbulenceModel
51 {
52 
53 protected:
55 
56  dimensionedScalar alphaK1_;
57  dimensionedScalar alphaK2_;
58 
59  dimensionedScalar alphaOmega1_;
60  dimensionedScalar alphaOmega2_;
61 
62  dimensionedScalar gamma1_;
63  dimensionedScalar gamma2_;
64 
65  dimensionedScalar beta1_;
66  dimensionedScalar beta2_;
67 
68  dimensionedScalar betaStar_;
69 
70  dimensionedScalar a1_;
71  dimensionedScalar b1_;
72  dimensionedScalar c1_;
73 
74  Switch F3_;
76 
78  scalar* inputs_ = new scalar[mesh_.nCells() * 9];
79  scalar* outputs_ = new scalar[mesh_.nCells()];
80 
81 #ifdef CODI_AD_FORWARD
82  double* inputsDouble_ = new double[mesh_.nCells() * 9];
83  double* outputsDouble_ = new double[mesh_.nCells()];
84 #endif
85 
87  void calcBetaField();
88 
90 
91  tmp<volScalarField> F1(const volScalarField& CDkOmega) const;
92  tmp<volScalarField> F2() const;
93  tmp<volScalarField> F3() const;
94  tmp<volScalarField> F23() const;
95 
96  tmp<volScalarField> blend(
97  const volScalarField& F1,
98  const dimensionedScalar& psi1,
99  const dimensionedScalar& psi2) const
100  {
101  return F1 * (psi1 - psi2) + psi2;
102  }
103 
104  tmp<volScalarField::Internal> blend(
105  const volScalarField::Internal& F1,
106  const dimensionedScalar& psi1,
107  const dimensionedScalar& psi2) const
108  {
109  return F1 * (psi1 - psi2) + psi2;
110  }
111 
112  tmp<volScalarField> alphaK(const volScalarField& F1) const
113  {
114  return blend(F1, alphaK1_, alphaK2_);
115  }
116 
117  tmp<volScalarField> alphaOmega(const volScalarField& F1) const
118  {
119  return blend(F1, alphaOmega1_, alphaOmega2_);
120  }
121 
122  tmp<volScalarField::Internal> beta(
123  const volScalarField::Internal& F1) const
124  {
125  return blend(F1, beta1_, beta2_);
126  }
127 
128  tmp<volScalarField::Internal> gamma(
129  const volScalarField::Internal& F1) const
130  {
131  return blend(F1, gamma1_, gamma2_);
132  }
133 
134  //- Return the effective diffusivity for k
135  tmp<volScalarField> DkEff(const volScalarField& F1) const
136  {
137  return tmp<volScalarField>(
138  new volScalarField("DkEff", alphaK(F1) * nut_ + this->nu()));
139  }
140 
141  //- Return the effective diffusivity for omega
142  tmp<volScalarField> DomegaEff(const volScalarField& F1) const
143  {
144  return tmp<volScalarField>(
145  new volScalarField(
146  "DomegaEff",
147  alphaOmega(F1) * nut_ + this->nu()));
148  }
149 
150  //- Return k production rate
151  tmp<volScalarField::Internal> Pk(
152  const volScalarField::Internal& G) const;
153 
154  //- Return epsilon/k which for standard RAS is betaStar*omega
155  tmp<volScalarField::Internal> epsilonByk(
156  const volScalarField& F1,
157  const volTensorField& gradU) const;
158 
159  //- Return G/nu
160  tmp<volScalarField::Internal> GbyNu(
161  const volScalarField::Internal& GbyNu0,
162  const volScalarField::Internal& F2,
163  const volScalarField::Internal& S2) const;
164 
165  tmp<fvScalarMatrix> kSource() const;
166 
167  tmp<fvScalarMatrix> omegaSource() const;
168 
169  tmp<fvScalarMatrix> Qsas(
170  const volScalarField::Internal& S2,
171  const volScalarField::Internal& gamma,
172  const volScalarField::Internal& beta) const;
174 
176 
177  volScalarField& omega_;
178  volScalarField omegaRes_;
179  volScalarField omegaResRef_;
180  volScalarField omegaResPartDeriv_;
181  volScalarField omegaRef_;
182  volScalarField& k_;
183  volScalarField kRes_;
184  volScalarField kResRef_;
185  volScalarField kResPartDeriv_;
186  volScalarField kRef_;
188 
189  // Field inversion and machine learning fields
190  volScalarField betaFieldInversion_;
191  volScalarField betaFieldInversionML_;
192  volScalarField QCriterion_;
193  volScalarField& p_;
194  volScalarField pGradAlongStream_;
195  volScalarField turbulenceIntensity_;
196  IOdictionary transportProperties_;
197  volScalarField ReT_;
198  volScalarField convectionTKE_;
199  volScalarField tauRatio_;
200  volScalarField pressureStress_;
201  volScalarField curvature_;
202  volScalarField UGradMisalignment_;
203 
208  //word eqnToModify_;
209 
211  //scalar betaFieldInversionWeight_;
212 
214  const volScalarField& y_;
215 
220  scalarList omegaNearWall_;
221 
223  label solveTurbState_ = 0;
224 
227 
228 public:
229  TypeName("kOmegaSSTFIML");
230  // Constructors
231 
232  //- Construct from components
234  const word modelType,
235  const fvMesh& mesh,
236  const DAOption& daOption);
237 
238  //- Destructor
240  {
241  delete[] inputs_;
242  delete[] outputs_;
243 #ifdef CODI_AD_FORWARD
244  delete[] inputsDouble_;
245  delete[] outputsDouble_;
246 #endif
247  }
248 
249  // Member functions
250 
252  virtual void correctModelStates(wordList& modelStates) const;
253 
255  virtual void correctNut();
256 
258  virtual void correctBoundaryConditions();
259 
261  virtual void updateIntermediateVariables();
262 
264  virtual void correctStateResidualModelCon(List<List<word>>& stateCon) const;
265 
267  virtual void addModelResidualCon(HashTable<List<List<word>>>& allCon) const;
268 
270  virtual void calcResiduals(const dictionary& options);
271 
273  virtual void correct();
274 
276  void saveOmegaNearWall();
277 
279  void setOmegaNearWall();
280 
283 
284 #ifdef CODI_AD_REVERSE
285 
287  static void betaCompute(
288  const double* x,
289  size_t n,
290  double* y,
291  size_t m,
292  codi::ExternalFunctionUserData* d)
293  {
295  }
296 
297  static void betaJacVecProd(
298  const double* x,
299  double* x_b,
300  size_t n,
301  const double* y,
302  const double* y_b,
303  size_t m,
304  codi::ExternalFunctionUserData* d)
305  {
307  }
308 #endif
309 };
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 } // End namespace Foam
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #endif
318 
319 // ************************************************************************* //
Foam::DAkOmegaSSTFIML::DAkOmegaSSTFIML
DAkOmegaSSTFIML(const word modelType, const fvMesh &mesh, const DAOption &daOption)
Definition: DAkOmegaSSTFIML.C:42
Foam::DAkOmegaSSTFIML::F3_
Switch F3_
Definition: DAkOmegaSSTFIML.H:74
Foam::DAkOmegaSSTFIML::epsilonByk
tmp< volScalarField::Internal > epsilonByk(const volScalarField &F1, const volTensorField &gradU) const
Definition: DAkOmegaSSTFIML.C:420
Foam::DAkOmegaSSTFIML::correctModelStates
virtual void correctModelStates(wordList &modelStates) const
update the turbulence state for DAStateInfo::regStates_
Definition: DAkOmegaSSTFIML.C:458
Foam::DAkOmegaSSTFIML::updateIntermediateVariables
virtual void updateIntermediateVariables()
update any intermediate variables that are dependent on state variables and are used in calcResiduals
Definition: DAkOmegaSSTFIML.C:605
Foam::DAkOmegaSSTFIML::DomegaEff
tmp< volScalarField > DomegaEff(const volScalarField &F1) const
Definition: DAkOmegaSSTFIML.H:142
Foam::DAUtility::pyCalcBetaJacVecProdInterface
static pyJacVecProdInterface pyCalcBetaJacVecProdInterface
Definition: DAUtility.H:133
Foam::DAkOmegaSSTFIML::tauRatio_
volScalarField tauRatio_
Definition: DAkOmegaSSTFIML.H:199
Foam::DAkOmegaSSTFIML::correctBoundaryConditions
virtual void correctBoundaryConditions()
update turbulence variable boundary values
Definition: DAkOmegaSSTFIML.C:516
Foam::DAkOmegaSSTFIML::b1_
dimensionedScalar b1_
Definition: DAkOmegaSSTFIML.H:71
Foam::DAUtility::pyCalcBeta
static void * pyCalcBeta
define a function pointer template for Python call back
Definition: DAUtility.H:129
Foam::DAkOmegaSSTFIML::alphaOmega
tmp< volScalarField > alphaOmega(const volScalarField &F1) const
Definition: DAkOmegaSSTFIML.H:117
Foam::DAkOmegaSSTFIML::alphaOmega1_
dimensionedScalar alphaOmega1_
Definition: DAkOmegaSSTFIML.H:59
Foam::DAUtility::pyCalcBetaInterface
static pyComputeInterface pyCalcBetaInterface
Definition: DAUtility.H:130
Foam::DAkOmegaSSTFIML::alphaK2_
dimensionedScalar alphaK2_
Definition: DAkOmegaSSTFIML.H:57
Foam::DAkOmegaSSTFIML::c1_
dimensionedScalar c1_
Definition: DAkOmegaSSTFIML.H:72
Foam::DAkOmegaSSTFIML::omegaSource
tmp< fvScalarMatrix > omegaSource() const
Definition: DAkOmegaSSTFIML.C:436
Foam::DAkOmegaSSTFIML::betaFieldInversion_
volScalarField betaFieldInversion_
Definition: DAkOmegaSSTFIML.H:190
Foam::DAkOmegaSSTFIML::blend
tmp< volScalarField::Internal > blend(const volScalarField::Internal &F1, const dimensionedScalar &psi1, const dimensionedScalar &psi2) const
Definition: DAkOmegaSSTFIML.H:104
Foam::DAkOmegaSSTFIML::kResPartDeriv_
volScalarField kResPartDeriv_
Definition: DAkOmegaSSTFIML.H:185
Foam::DAkOmegaSSTFIML::TypeName
TypeName("kOmegaSSTFIML")
Foam::DAkOmegaSSTFIML::blend
tmp< volScalarField > blend(const volScalarField &F1, const dimensionedScalar &psi1, const dimensionedScalar &psi2) const
Definition: DAkOmegaSSTFIML.H:96
Foam::DAkOmegaSSTFIML::convectionTKE_
volScalarField convectionTKE_
Definition: DAkOmegaSSTFIML.H:198
Foam::DAkOmegaSSTFIML::alphaK1_
dimensionedScalar alphaK1_
Definition: DAkOmegaSSTFIML.H:56
Foam::DAkOmegaSSTFIML::omega_
volScalarField & omega_
Definition: DAkOmegaSSTFIML.H:177
Foam::DAkOmegaSSTFIML::F3
tmp< volScalarField > F3() const
Definition: DAkOmegaSSTFIML.C:381
Foam::DAkOmegaSSTFIML::Pk
tmp< volScalarField::Internal > Pk(const volScalarField::Internal &G) const
Definition: DAkOmegaSSTFIML.C:414
Foam::DAOption
Definition: DAOption.H:29
Foam::DAkOmegaSSTFIML::curvature_
volScalarField curvature_
Definition: DAkOmegaSSTFIML.H:201
daOption
DAOption daOption(mesh, pyOptions_)
Foam::DAUtility::pyCalcBetaJacVecProd
static void * pyCalcBetaJacVecProd
Definition: DAUtility.H:132
Foam::DAkOmegaSSTFIML::correctStateResidualModelCon
virtual void correctStateResidualModelCon(List< List< word >> &stateCon) const
update the original variable connectivity for the adjoint state residuals in stateCon
Definition: DAkOmegaSSTFIML.C:616
Foam::DAkOmegaSSTFIML::outputs_
scalar * outputs_
Definition: DAkOmegaSSTFIML.H:79
Foam::DAkOmegaSSTFIML::addModelResidualCon
virtual void addModelResidualCon(HashTable< List< List< word >>> &allCon) const
add the model residual connectivity to stateCon
Definition: DAkOmegaSSTFIML.C:715
Foam::DAkOmegaSSTFIML::UGradMisalignment_
volScalarField UGradMisalignment_
Definition: DAkOmegaSSTFIML.H:202
Foam::DAkOmegaSSTFIML::~DAkOmegaSSTFIML
virtual ~DAkOmegaSSTFIML()
Definition: DAkOmegaSSTFIML.H:239
Foam::DAkOmegaSSTFIML::GbyNu
tmp< volScalarField::Internal > GbyNu(const volScalarField::Internal &GbyNu0, const volScalarField::Internal &F2, const volScalarField::Internal &S2) const
Definition: DAkOmegaSSTFIML.C:403
Foam::DAkOmegaSSTFIML::a1_
dimensionedScalar a1_
Definition: DAkOmegaSSTFIML.H:70
Foam::DAkOmegaSSTFIML::betaStar_
dimensionedScalar betaStar_
Definition: DAkOmegaSSTFIML.H:68
Foam::DAkOmegaSSTFIML::pGradAlongStream_
volScalarField pGradAlongStream_
Definition: DAkOmegaSSTFIML.H:194
Foam::DAkOmegaSSTFIML::omegaRef_
volScalarField omegaRef_
Definition: DAkOmegaSSTFIML.H:181
Foam::DAkOmegaSSTFIML::correct
virtual void correct()
solve the residual equations and update the state
Definition: DAkOmegaSSTFIML.C:807
Foam::DAkOmegaSSTFIML::Qsas
tmp< fvScalarMatrix > Qsas(const volScalarField::Internal &S2, const volScalarField::Internal &gamma, const volScalarField::Internal &beta) const
Definition: DAkOmegaSSTFIML.C:445
Foam::DAkOmegaSSTFIML::F2
tmp< volScalarField > F2() const
Definition: DAkOmegaSSTFIML.C:369
mesh
fvMesh & mesh
Definition: createRefsHeatTransfer.H:4
Foam::DAkOmegaSSTFIML::betaFieldInversionML_
volScalarField betaFieldInversionML_
Definition: DAkOmegaSSTFIML.H:191
Foam::DAkOmegaSSTFIML::calcResiduals
virtual void calcResiduals(const dictionary &options)
compute the turbulence residuals
Definition: DAkOmegaSSTFIML.C:972
Foam::DAkOmegaSSTFIML::alphaK
tmp< volScalarField > alphaK(const volScalarField &F1) const
Definition: DAkOmegaSSTFIML.H:112
Foam::DAkOmegaSSTFIML::QCriterion_
volScalarField QCriterion_
Definition: DAkOmegaSSTFIML.H:192
Foam::DAkOmegaSSTFIML::printInterval_
label printInterval_
time step interval to print residual
Definition: DAkOmegaSSTFIML.H:226
Foam::DAkOmegaSSTFIML::DkEff
tmp< volScalarField > DkEff(const volScalarField &F1) const
Definition: DAkOmegaSSTFIML.H:135
Foam::DAkOmegaSSTFIML::ReT_
volScalarField ReT_
Definition: DAkOmegaSSTFIML.H:197
Foam::DAkOmegaSSTFIML::F23
tmp< volScalarField > F23() const
Definition: DAkOmegaSSTFIML.C:391
Foam::DAkOmegaSSTFIML::calcBetaField
void calcBetaField()
calculate the beta field using the trained model
Definition: DAkOmegaSSTFIML.C:827
Foam::DAkOmegaSSTFIML::transportProperties_
IOdictionary transportProperties_
Definition: DAkOmegaSSTFIML.H:196
Foam::DATurbulenceModel::nut_
volScalarField & nut_
turbulence viscosity
Definition: DATurbulenceModel.H:83
Foam::DAkOmegaSSTFIML::kRef_
volScalarField kRef_
Definition: DAkOmegaSSTFIML.H:186
Foam::DAkOmegaSSTFIML::saveOmegaNearWall
void saveOmegaNearWall()
save near wall omega values to omegaNearWall_
Definition: DAkOmegaSSTFIML.C:555
Foam::DAkOmegaSSTFIML::correctNut
virtual void correctNut()
update nut based on other turbulence variables and update the BCs
Definition: DAkOmegaSSTFIML.C:494
Foam::DAkOmegaSSTFIML::alphaOmega2_
dimensionedScalar alphaOmega2_
Definition: DAkOmegaSSTFIML.H:60
Foam
Definition: multiFreqScalarFvPatchField.C:144
Foam::DAkOmegaSSTFIML::inputs_
scalar * inputs_
inputs and outputs for the beta calculation
Definition: DAkOmegaSSTFIML.H:78
Foam::DAkOmegaSSTFIML::omegaNearWall_
scalarList omegaNearWall_
Definition: DAkOmegaSSTFIML.H:220
Foam::DAkOmegaSSTFIML::omegaResRef_
volScalarField omegaResRef_
Definition: DAkOmegaSSTFIML.H:179
Foam::DAkOmegaSSTFIML::omegaResPartDeriv_
volScalarField omegaResPartDeriv_
Definition: DAkOmegaSSTFIML.H:180
Foam::DAkOmegaSSTFIML::turbulenceIntensity_
volScalarField turbulenceIntensity_
Definition: DAkOmegaSSTFIML.H:195
Foam::DATurbulenceModel::nu
tmp< volScalarField > nu() const
get the nu field
Definition: DATurbulenceModel.C:262
Foam::DAkOmegaSSTFIML::setOmegaNearWall
void setOmegaNearWall()
set omegaNearWall_ to near wall omega values
Definition: DAkOmegaSSTFIML.C:579
Foam::DAkOmegaSSTFIML::kRes_
volScalarField kRes_
Definition: DAkOmegaSSTFIML.H:183
Foam::DAkOmegaSSTFIML::k_
volScalarField & k_
Definition: DAkOmegaSSTFIML.H:182
Foam::DATurbulenceModel
Definition: DATurbulenceModel.H:61
Foam::DAkOmegaSSTFIML::gamma
tmp< volScalarField::Internal > gamma(const volScalarField::Internal &F1) const
Definition: DAkOmegaSSTFIML.H:128
Foam::DAkOmegaSSTFIML::pressureStress_
volScalarField pressureStress_
Definition: DAkOmegaSSTFIML.H:200
Foam::DAkOmegaSSTFIML::F1
tmp< volScalarField > F1(const volScalarField &CDkOmega) const
Definition: DAkOmegaSSTFIML.C:350
Foam::DAkOmegaSSTFIML::y_
const volScalarField & y_
Weight of betaFieldInversion for the turbulent transport equations if both are modified.
Definition: DAkOmegaSSTFIML.H:214
Foam::DATurbulenceModel::mesh_
const fvMesh & mesh_
fvMesh
Definition: DATurbulenceModel.H:74
Foam::DAkOmegaSSTFIML::p_
volScalarField & p_
Definition: DAkOmegaSSTFIML.H:193
Foam::DAkOmegaSSTFIML::solveTurbState_
label solveTurbState_
whether to solve for turb states
Definition: DAkOmegaSSTFIML.H:223
Foam::DAkOmegaSSTFIML::beta1_
dimensionedScalar beta1_
Definition: DAkOmegaSSTFIML.H:65
Foam::DAkOmegaSSTFIML::gamma2_
dimensionedScalar gamma2_
Definition: DAkOmegaSSTFIML.H:63
Foam::DAkOmegaSSTFIML::omegaRes_
volScalarField omegaRes_
Definition: DAkOmegaSSTFIML.H:178
Foam::DAkOmegaSSTFIML::kResRef_
volScalarField kResRef_
Definition: DAkOmegaSSTFIML.H:184
Foam::DAkOmegaSSTFIML::beta
tmp< volScalarField::Internal > beta(const volScalarField::Internal &F1) const
Definition: DAkOmegaSSTFIML.H:122
Foam::DAkOmegaSSTFIML::gamma1_
dimensionedScalar gamma1_
Definition: DAkOmegaSSTFIML.H:62
Foam::DAkOmegaSSTFIML::kSource
tmp< fvScalarMatrix > kSource() const
Definition: DAkOmegaSSTFIML.C:427
DATurbulenceModel.H
Foam::DAkOmegaSSTFIML
Definition: DAkOmegaSSTFIML.H:49
Foam::DAkOmegaSSTFIML::beta2_
dimensionedScalar beta2_
Definition: DAkOmegaSSTFIML.H:66
Foam::DAkOmegaSSTFIML::correctOmegaBoundaryConditions
void correctOmegaBoundaryConditions()
specially treatment to correct epsilon BC
Definition: DAkOmegaSSTFIML.C:528