applyWallFunctionBoundaryConditions.C 9.31 KB
Newer Older
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
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
     \\/     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 2 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, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Application
    applyWallFunctionBounaryConditions

Description
29
    Updates OpenFOAM RAS cases to use the new (v1.6) wall function framework
30

31
32
    Attempts to determine whether case is compressible or incompressible, or
    can be supplied with -compressible command line argument
33
34
35
36
37
38
39

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "fvMesh.H"
#include "Time.H"
#include "volFields.H"
40
#include "surfaceFields.H"
41
42
43

#include "wallPolyPatch.H"

44
45
#include "incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H"
#include "incompressible/RAS/derivedFvPatchFields/wallFunctions/kqRWallFunctions/kqRWallFunction/kqRWallFunctionFvPatchField.H"
46
#include "incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutkWallFunction/nutkWallFunctionFvPatchScalarField.H"
47
48
49
50
#include "incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H"

#include "compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H"
#include "compressible/RAS/derivedFvPatchFields/wallFunctions/kqRWallFunctions/kqRWallFunction/kqRWallFunctionFvPatchField.H"
51
#include "compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutkWallFunction/mutkWallFunctionFvPatchScalarField.H"
52
53
#include "compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H"

54
55
56
57
using namespace Foam;

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

58
59
60
61
62
63
64
65
66
67
68
bool caseIsCompressible(const fvMesh& mesh)
{
    // Attempt flux field
    IOobject phiHeader
    (
        "phi",
        mesh.time().timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );
69

70
71
72
73
74
75
76
77
    if (phiHeader.headerOk())
    {
        surfaceScalarField phi(phiHeader, mesh);
        if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
        {
            return true;
        }
    }
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
    // Attempt density field
    IOobject rhoHeader
    (
        "rho",
        mesh.time().timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );

    if (rhoHeader.headerOk())
    {
        volScalarField rho(rhoHeader, mesh);
        if (rho.dimensions() == dimDensity)
        {
            return true;
        }
    }

    // Attempt pressure field
    IOobject pHeader
    (
        "p",
        mesh.time().timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );

    if (pHeader.headerOk())
    {
        volScalarField p(pHeader, mesh);
        if (p.dimensions() == dimMass/sqr(dimTime)/dimLength)
        {
            return true;
        }
    }

    // If none of the above are true, assume that the case is incompressible
    return false;
}


void createVolScalarField
(
    const fvMesh& mesh,
    const word& fieldName,
    const dimensionSet& dims
)
128
{
129
    IOobject fieldHeader
130
    (
131
        fieldName,
132
133
134
135
136
137
        mesh.time().timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );

138
    if (!fieldHeader.headerOk())
139
    {
140
        Info<< "Creating field " << fieldName << nl << endl;
141

142
        volScalarField field
143
144
145
        (
            IOobject
            (
146
                fieldName,
147
148
149
150
151
152
                mesh.time().timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
153
            dimensionedScalar("zero", dims, 0.0)
154
155
        );

156
        field.write();
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
    }
}


void replaceBoundaryType
(
    const fvMesh& mesh,
    const word& fieldName,
    const word& boundaryType,
    const string& boundaryValue
)
{
    IOobject header
    (
        fieldName,
        mesh.time().timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );

    if (!header.headerOk())
    {
        return;
    }

    Info<< "Updating boundary types for field " << header.name() << endl;

    const word oldTypeName = IOdictionary::typeName;
    const_cast<word&>(IOdictionary::typeName) = word::null;

    IOdictionary dict(header);

    const_cast<word&>(IOdictionary::typeName) = oldTypeName;
    const_cast<word&>(dict.type()) = dict.headerClassName();

193
194
195
196
197
198
    // Make a backup of the old file
    if (mvBak(dict.objectPath(), "old"))
    {
        Info<< "    Backup original file to "
            << (dict.objectPath() + ".old") << endl;
    }
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222

    // Loop through boundary patches and update
    const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
    dictionary& boundaryDict = dict.subDict("boundaryField");
    forAll(bMesh, patchI)
    {
        if (isType<wallPolyPatch>(bMesh[patchI]))
        {
            word patchName = bMesh[patchI].name();
            dictionary& oldPatch = boundaryDict.subDict(patchName);

            dictionary newPatch(dictionary::null);
            newPatch.add("type", boundaryType);
            newPatch.add("value", ("uniform " + boundaryValue).c_str());

            oldPatch = newPatch;
        }
    }

    Info<< "    writing updated " << dict.name() << nl << endl;
    dict.regIOobject::write();
}


223
void updateCompressibleCase(const fvMesh& mesh)
224
{
225
226
227
228
229
230
231
232
233
234
235
    Info<< "Case treated as compressible" << nl << endl;
    createVolScalarField
    (
        mesh,
        "mut",
        dimArea/dimTime*dimDensity
    );
    replaceBoundaryType
    (
        mesh,
        "mut",
236
        compressible::RASModels::mutkWallFunctionFvPatchScalarField::typeName,
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
282
283
284
285
286
287
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "epsilon",
        compressible::RASModels::epsilonWallFunctionFvPatchScalarField::
            typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "omega",
        compressible::RASModels::omegaWallFunctionFvPatchScalarField::typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "k",
        compressible::RASModels::kqRWallFunctionFvPatchField<scalar>::typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "q",
        compressible::RASModels::kqRWallFunctionFvPatchField<scalar>::typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "R",
        compressible::RASModels::kqRWallFunctionFvPatchField<symmTensor>::
            typeName,
        "(0 0 0 0 0 0)"
    );
}


void updateIncompressibleCase(const fvMesh& mesh)
{
    Info<< "Case treated as incompressible" << nl << endl;
    createVolScalarField(mesh, "nut", dimArea/dimTime);

    replaceBoundaryType
    (
        mesh,
        "nut",
288
        incompressible::RASModels::nutkWallFunctionFvPatchScalarField::typeName,
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "epsilon",
        incompressible::RASModels::epsilonWallFunctionFvPatchScalarField::
            typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "omega",
        incompressible::RASModels::omegaWallFunctionFvPatchScalarField::
            typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "k",
        incompressible::RASModels::kqRWallFunctionFvPatchField<scalar>::
            typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "q",
        incompressible::RASModels::kqRWallFunctionFvPatchField<scalar>::
            typeName,
        "0"
    );
    replaceBoundaryType
    (
        mesh,
        "R",
        incompressible::RASModels::kqRWallFunctionFvPatchField<symmTensor>::
            typeName,
        "(0 0 0 0 0 0)"
    );
}

333

334
335
336
int main(int argc, char *argv[])
{
    #include "addTimeOptions.H"
337
338
    argList::validOptions.insert("compressible", "");

339
340
341
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
342

343
    bool compressible = args.optionFound("compressible");
344

345
    Info<< "Updating turbulence fields to operate using new run time "
346
        << "selectable" << nl << "wall functions"
347
348
        << nl << endl;

349
350
    if (compressible || caseIsCompressible(mesh))
    {
351
        updateCompressibleCase(mesh);
352
353
354
    }
    else
    {
355
        updateIncompressibleCase(mesh);
356
    }
357
358
359
360
361
362
363
364

    Info<< "End\n" << endl;

    return 0;
}


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