yPlusRAS.C 7.59 KB
Newer Older
andy's avatar
andy committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2013 OpenFOAM Foundation
andy's avatar
andy committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
     \\/     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 "yPlusRAS.H"
#include "volFields.H"

#include "incompressible/RAS/RASModel/RASModel.H"
Henry's avatar
Henry committed
30
#include "nutWallFunction/nutWallFunctionFvPatchScalarField.H"
andy's avatar
andy committed
31
32

#include "compressible/RAS/RASModel/RASModel.H"
Henry's avatar
Henry committed
33
#include "mutWallFunction/mutWallFunctionFvPatchScalarField.H"
andy's avatar
andy committed
34
35
36
37
38

#include "wallDist.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

39
40
41
42
namespace Foam
{
defineTypeNameAndDebug(yPlusRAS, 0);
}
andy's avatar
andy committed
43
44
45
46


// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //

47
void Foam::yPlusRAS::writeFileHeader(const label i)
48
{
49
50
51
52
    file() << "# y+ (RAS)" << nl
        << "# time " << token::TAB << "patch" << token::TAB
        << "min" << token::TAB << "max" << token::TAB << "average"
        << endl;
53
54
55
}


andy's avatar
andy committed
56
57
58
59
void Foam::yPlusRAS::calcIncompressibleYPlus
(
    const fvMesh& mesh,
    volScalarField& yPlus
60
)
andy's avatar
andy committed
61
{
62
    typedef incompressible::nutWallFunctionFvPatchScalarField
andy's avatar
andy committed
63
64
65
66
67
68
69
70
71
        wallFunctionPatchField;

    const incompressible::RASModel& model =
        mesh.lookupObject<incompressible::RASModel>("RASProperties");

    const volScalarField nut(model.nut());
    const volScalarField::GeometricBoundaryField& nutPatches =
        nut.boundaryField();

andy's avatar
andy committed
72
    bool foundPatch = false;
73
    forAll(nutPatches, patchI)
andy's avatar
andy committed
74
    {
75
        if (isA<wallFunctionPatchField>(nutPatches[patchI]))
andy's avatar
andy committed
76
        {
andy's avatar
andy committed
77
            foundPatch = true;
andy's avatar
andy committed
78
79

            const wallFunctionPatchField& nutPw =
80
81
82
83
84
                dynamic_cast<const wallFunctionPatchField&>(nutPatches[patchI]);

            yPlus.boundaryField()[patchI] = nutPw.yPlus();
            const scalarField& Yp = yPlus.boundaryField()[patchI];

andy's avatar
andy committed
85
86
87
            scalar minYp = gMin(Yp);
            scalar maxYp = gMax(Yp);
            scalar avgYp = gAverage(Yp);
88
89
90
91
92
93
94
95
96
97

            if (log_)
            {
                Info<< "    patch " << nutPw.patch().name()
                    << " y+ : min = " << minYp << ", max = " << maxYp
                    << ", average = " << avgYp << nl;
            }

            if (Pstream::master())
            {
98
                file() << obr_.time().value() << token::TAB
99
100
101
102
                    << nutPw.patch().name() << token::TAB
                    << minYp << token::TAB << maxYp << token::TAB
                    << avgYp << endl;
            }
andy's avatar
andy committed
103
104
105
        }
    }

106
    if (log_ && !foundPatch)
andy's avatar
andy committed
107
108
109
110
111
112
113
114
115
116
117
    {
        Info<< "    no " << wallFunctionPatchField::typeName << " patches"
            << endl;
    }
}


void Foam::yPlusRAS::calcCompressibleYPlus
(
    const fvMesh& mesh,
    volScalarField& yPlus
118
)
andy's avatar
andy committed
119
{
120
    typedef compressible::mutWallFunctionFvPatchScalarField
andy's avatar
andy committed
121
122
123
124
125
126
127
128
129
        wallFunctionPatchField;

    const compressible::RASModel& model =
        mesh.lookupObject<compressible::RASModel>("RASProperties");

    const volScalarField mut(model.mut());
    const volScalarField::GeometricBoundaryField& mutPatches =
        mut.boundaryField();

andy's avatar
andy committed
130
    bool foundPatch = false;
131
    forAll(mutPatches, patchI)
andy's avatar
andy committed
132
    {
133
        if (isA<wallFunctionPatchField>(mutPatches[patchI]))
andy's avatar
andy committed
134
        {
andy's avatar
andy committed
135
            foundPatch = true;
andy's avatar
andy committed
136
137

            const wallFunctionPatchField& mutPw =
138
139
140
141
142
                dynamic_cast<const wallFunctionPatchField&>(mutPatches[patchI]);

            yPlus.boundaryField()[patchI] = mutPw.yPlus();
            const scalarField& Yp = yPlus.boundaryField()[patchI];

andy's avatar
andy committed
143
144
145
            scalar minYp = gMin(Yp);
            scalar maxYp = gMax(Yp);
            scalar avgYp = gAverage(Yp);
146
147
148
149
150
151
152
153
154
155

            if (log_)
            {
                Info<< "    patch " << mutPw.patch().name()
                    << " y+ : min = " << minYp << ", max = " << maxYp
                    << ", average = " << avgYp << nl;
            }

            if (Pstream::master())
            {
156
                file() << obr_.time().value() << token::TAB
157
158
159
160
                    << mutPw.patch().name() << token::TAB
                    << minYp << token::TAB << maxYp << token::TAB
                    << avgYp << endl;
            }
andy's avatar
andy committed
161
162
163
        }
    }

164
    if (log_ && !foundPatch)
andy's avatar
andy committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
    {
        Info<< "    no " << wallFunctionPatchField::typeName << " patches"
            << endl;
    }
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::yPlusRAS::yPlusRAS
(
    const word& name,
    const objectRegistry& obr,
    const dictionary& dict,
    const bool loadFromFiles
)
:
182
    functionObjectFile(obr, name, typeName),
andy's avatar
andy committed
183
184
185
    name_(name),
    obr_(obr),
    active_(true),
186
    log_(false),
187
    phiName_("phi")
andy's avatar
andy committed
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
{
    // Check if the available mesh is an fvMesh, otherwise deactivate
    if (!isA<fvMesh>(obr_))
    {
        active_ = false;
        WarningIn
        (
            "yPlusRAS::yPlusRAS"
            "("
                "const word&, "
                "const objectRegistry&, "
                "const dictionary&, "
                "const bool"
            ")"
        )   << "No fvMesh available, deactivating." << nl
            << endl;
    }
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::yPlusRAS::~yPlusRAS()
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::yPlusRAS::read(const dictionary& dict)
{
    if (active_)
    {
220
        log_ = dict.lookupOrDefault<Switch>("log", false);
andy's avatar
andy committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
        phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
    }
}


void Foam::yPlusRAS::execute()
{
    // Do nothing - only valid on write
}


void Foam::yPlusRAS::end()
{
    // Do nothing - only valid on write
}
236
237
238
239
240
241


void Foam::yPlusRAS::timeSet()
{
    // Do nothing - only valid on write
}
andy's avatar
andy committed
242
243
244
245
246
247


void Foam::yPlusRAS::write()
{
    if (active_)
    {
248
249
        functionObjectFile::write();

andy's avatar
andy committed
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
        const surfaceScalarField& phi =
            obr_.lookupObject<surfaceScalarField>(phiName_);

        const fvMesh& mesh = refCast<const fvMesh>(obr_);

        volScalarField yPlusRAS
        (
            IOobject
            (
                "yPlusRAS",
                mesh.time().timeName(),
                mesh,
                IOobject::NO_READ
            ),
            mesh,
            dimensionedScalar("0", dimless, 0.0)
        );

268
269
        if (log_)
        {
270
            Info<< type() << " " << name_ << " output:" << nl;
271
272
        }

andy's avatar
andy committed
273
274
275
276
277
278
279
280
281
        if (phi.dimensions() == dimMass/dimTime)
        {
            calcCompressibleYPlus(mesh, yPlusRAS);
        }
        else
        {
            calcIncompressibleYPlus(mesh, yPlusRAS);
        }

282
283
        if (log_)
        {
284
285
            Info<< "    writing field " << yPlusRAS.name() << nl
                << endl;
286
        }
andy's avatar
andy committed
287
288
289
290
291
292
293

        yPlusRAS.write();
    }
}


// ************************************************************************* //