-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManhartWallFunctionFvPatchScalarField.C
executable file
·281 lines (210 loc) · 10.3 KB
/
ManhartWallFunctionFvPatchScalarField.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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 General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "ManhartWallFunctionFvPatchScalarField.H"
#include "LESModel.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace incompressible
{
namespace LESModels
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// A patch is a list of labels that address the faces in the global face list
ManhartWallFunctionFvPatchScalarField::
ManhartWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(p, iF),
kappa_(0.41),
E_(9.8)
{}
ManhartWallFunctionFvPatchScalarField::
ManhartWallFunctionFvPatchScalarField
(
const ManhartWallFunctionFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchScalarField(ptf, p, iF, mapper),
kappa_(ptf.kappa_),
E_(ptf.E_)
{}
ManhartWallFunctionFvPatchScalarField::
ManhartWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchScalarField(p, iF, dict),
kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
E_(dict.lookupOrDefault<scalar>("E", 9.8))
{}
ManhartWallFunctionFvPatchScalarField::
ManhartWallFunctionFvPatchScalarField
(
const ManhartWallFunctionFvPatchScalarField& nwfpsf
)
:
fixedValueFvPatchScalarField(nwfpsf),
kappa_(nwfpsf.kappa_),
E_(nwfpsf.E_)
{}
ManhartWallFunctionFvPatchScalarField::
ManhartWallFunctionFvPatchScalarField
(
const ManhartWallFunctionFvPatchScalarField& nwfpsf,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(nwfpsf, iF),
kappa_(nwfpsf.kappa_),
E_(nwfpsf.E_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void ManhartWallFunctionFvPatchScalarField::evaluate
(
const Pstream::commsTypes
)
{
// Refer fvPatch.C for boundaryField,DeltaCoeffs etc.
// Refer lesModel.H and .C
// DeltaCoeffs: Return the face - cell distance coefficient except for coupled patches for which the cell-centre to coupled-cell-centre
// distance coefficient is returned
const LESModel& lesModel = db().lookupObject<LESModel>("LESProperties"); // Read LES model information from LES properties file
const label patchi = patch().index(); //- Return the index of this patch in the fvBoundaryMesh, and name the function as a label "patchi"
const fvPatchVectorField& U = lesModel.U().boundaryField()[patchi]; //Define "U" as a pointer to a velocity field array as a type
// given by "fvPatchVectorField" , and the ID of the patch is given by patchi
const scalarField nuw = lesModel.nu()().boundaryField()[patchi]; // Same array as above, but for viscosity
const volScalarField& pr = this->db().lookupObject<volScalarField>("p"); // Read "Pressure" from the database structure -WHATS ITS ARRAY SIZE? = COMPLETE FIELD
const scalarField& ry = patch().deltaCoeffs(); // Create an array having the reciprocal of the "y" distance values of boundary cells
// from wall with LES Delta Coefficient values for all cells in the patch
const scalarField magUp(mag(U.patchInternalField() - U)); // U(Cells Adjacent to boundary Field) - U(boundary field) -- WHY??
scalarField& nuSgsw = *this; // Consider value of nuSgs in "this" (the current) instance. Using *this operator. nuSGS is calc. by LES model
// and its value is modified in this code to suit velocity profile
const scalarField magFaceGradU(mag(U.snGrad())); // Calc. Surface Normal Gradient of the boundary field
volVectorField gradp = fvc::grad(pr);
const fvPatchVectorField Gbpr = gradp.boundaryField()[patchi];
// const fvPatchScalarField& bpr = pr.boundaryField()[patchi];
// volVectorField Gbpr = fvc::grad(bpr);
const scalarField GradP = Gbpr.component(0);
forAll(nuSgsw, facei) // facei for how many faces ? = boundary field?
{
scalar magUpara = magUp[facei]; // Wall Parallel "U" velocity at the cell adjacent to the wall
scalar Pgrad = GradP[facei];
/* if (Pgrad > -100 && Pgrad < 100)
{ Pgrad = GradP[facei]; }
else
{ Pgrad = -25;} */
std::cout << "\n";
std::cout << "magUpara is \t" << magUpara ;
scalar tau = (nuSgsw[facei] + nuw[facei])*magFaceGradU[facei]; // Wall shear stress (tau) definition.
// scalar utau = sqrt((nuSgsw[facei] + nuw[facei])*magFaceGradU[facei]);
std::cout << "magFaceGradU[facei] is \t" << magFaceGradU[facei];
scalar utau = sqrt(mag(tau)); // Friction Velocity (Utau) definition.
scalar uP = pow(mag(( nuSgsw[facei] + nuw[facei])*Pgrad),(1.0/3.0)); // Defining streamwise pressure based velocity (nuw or nusgs?)
std::cout << "GradP[facei] is \t" << Pgrad << "\n"; //DEBUG
std::cout << "nuSgsw is \t" << nuSgsw[facei] << "\t and nuw is \t" << nuw[facei]; // DEBUG
scalar utauP = sqrt(sqr(utau) + sqr(uP));
std::cout << "utauP is \t" << utauP << "\n"; //DEBUG
std::cout << "utau is" << utau << "\t and uP is \t" << uP << "\n" ; // DEBUG
// scalar alpha = sqr(utau)/sqr(utauP);
// std::cout << "Alpha is \t" << alpha << "\n";
/* scalar Ustar = magUpara/utauP;
scalar ystar = utauP/(ry[facei]*nuw[facei]); */
std::cout << " Newton Raphson Loop Start " << "\n";
if (utau > VSMALL)
{
int iter = 0;
scalar err = GREAT;
do
{ //Newton-Raphson Solution
scalar YoverNu = 1.0/(ry[facei]*nuw[facei]);
scalar utauPsqr = sqr(utau) + sqr(uP);
scalar alpha = sqr(utau)/utauPsqr;
scalar ystar = sqrt(utauPsqr)*YoverNu;
scalar Ustar = magUpara/sqrt(utauPsqr);
// F
/* scalar f = sign(tau)*(sqr(utau)/sqrt(utauPsqr))*YoverNu
+ sign(Pgrad)*0.5*(pow(uP,3)/sqrt(utauPsqr))*sqr(YoverNu)
- magUpara/sqrt(utauPsqr); */
scalar f = sign(Pgrad)*(0.5*pow((1-alpha),1.5))*pow(ystar,2) + sign(tau)*alpha*ystar - Ustar ;
// DEBUG
std::cout << "Alpha is \t" << alpha << "\n";
std::cout << " The new uP is" << uP << "\n";
std::cout << "The prev. iteration utauP is" << sqrt(utauPsqr) << "\t The prev. iter utau is" << utau << "\n"; //DEBUG
std::cout << "YoverNu is \t" << YoverNu << "\n"; //DEBUG
// F DERIVATIVE
scalar df = sign(tau)*(2*utau/sqrt(utauPsqr) - pow(utau,3)/pow(utauPsqr,1.5))*YoverNu
+ magUpara*(utau/pow(utauPsqr,1.5))
- sign(Pgrad)*0.5*(pow(uP,3)*(1.0/pow(utauPsqr,1.5))*utau)*sqr(YoverNu);
//DEBUG
std::cout << " NR Values " << "\n"; //DEBUG
std::cout << " the 'f' is " << f << "\n";
std::cout << " the 'df' is " << df << "\n";
// correction
scalar utauNew = utau - f/df;
err = mag((utau - utauNew)/utau);
utau = utauNew;
std::cout << "utauNew is" << utau << "\n";
std::cout << "Error is" << err << "\n";
tau = sqr(utau); // sqr(max(utau,0));
} while (utau > VSMALL && err > 0.01 && ++iter < 10); // Setting tolerance criteria for Utau and max limit of NR iterations
std::cout << " New tau is \t" << tau; //DEBUG
std::cout << " The new magFaceGradU is \t" << magFaceGradU[facei];
std::cout << " The new nuSgs is \t" << nuSgsw[facei] << " \t and the new nuw[facei] \t" << nuw[facei];
scalar nuCorr = (tau/magFaceGradU[facei])*(1 + (nuSgsw[facei]/nuw[facei])) - nuw[facei] - nuSgsw[facei];
std::cout << "nuCorr is \t" << nuCorr; //DEBUG
nuSgsw[facei] = nuSgsw[facei] + nuCorr; // Updating new value of nuSgs
}
else
{
nuSgsw[facei] = 0; //Seting SGS viscosity to 0 if Wall Shear stress is lesser than the VSMALL value set in OpenFOAM
}
}
fixedValueFvPatchScalarField::evaluate();
}
void ManhartWallFunctionFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField
(
fvPatchScalarField,
ManhartWallFunctionFvPatchScalarField
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace LESModels
} // End namespace incompressible
} // End namespace Foam
// ************************************************************************* //