refineBoundaryLayers.C 14 KB
Newer Older
1
2
/*---------------------------------------------------------------------------*\
  =========                 |
Tomislav Lugaric's avatar
Tomislav Lugaric committed
3
  \\      /  F ield         | cfMesh: A library for mesh generation
4
   \\    /   O peration     |
Tomislav Lugaric's avatar
Tomislav Lugaric committed
5
6
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7
8
-------------------------------------------------------------------------------
License
Tomislav Lugaric's avatar
Tomislav Lugaric committed
9
    This file is part of cfMesh.
10

Tomislav Lugaric's avatar
Tomislav Lugaric committed
11
    cfMesh is free software; you can redistribute it and/or modify it
12
    under the terms of the GNU General Public License as published by the
Tomislav Lugaric's avatar
Tomislav Lugaric committed
13
    Free Software Foundation; either version 3 of the License, or (at your
14
15
    option) any later version.

Tomislav Lugaric's avatar
Tomislav Lugaric committed
16
    cfMesh is distributed in the hope that it will be useful, but WITHOUT
17
18
19
20
21
    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
Tomislav Lugaric's avatar
Tomislav Lugaric committed
22
    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
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

Description

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

#include "refineBoundaryLayers.H"
#include "meshSurfaceEngine.H"
#include "demandDrivenData.H"

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

namespace Foam
{

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

const meshSurfaceEngine& refineBoundaryLayers::surfaceEngine() const
{
    if( !msePtr_ )
        msePtr_ = new meshSurfaceEngine(mesh_);

    return *msePtr_;
}

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

refineBoundaryLayers::refineBoundaryLayers(polyMeshGen& mesh)
:
    mesh_(mesh),
    msePtr_(NULL),
    globalNumLayers_(1),
    globalThicknessRatio_(1.0),
55
    globalMaxThicknessFirstLayer_(VGREAT),
56
57
58
59
    numLayersForPatch_(),
    thicknessRatioForPatch_(),
    maxThicknessForPatch_(),
    discontinuousLayersForPatch_(),
60
    cellSubsetName_(),
61
    done_(false),
62
    is2DMesh_(false),
63
    specialMode_(false),
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    nLayersAtBndFace_(),
    splitEdges_(),
    splitEdgesAtPoint_(),
    newVerticesForSplitEdge_(),
    facesFromFace_(),
    newFaces_()
{}

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

refineBoundaryLayers::~refineBoundaryLayers()
{
    deleteDemandDrivenData(msePtr_);
}

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

81
82
void refineBoundaryLayers::avoidRefinement()
{
83
84
85
86
87
88
89
90
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::avoidRefinement()"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

91
92
93
94
    globalNumLayers_ = 1;
    numLayersForPatch_.clear();
}

95
96
void refineBoundaryLayers::activate2DMode()
{
97
98
99
100
101
102
103
104
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::activate2DMode()"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

105
106
107
    is2DMesh_ = true;
}

108
109
void refineBoundaryLayers::setGlobalNumberOfLayers(const label nLayers)
{
110
111
112
113
114
115
116
117
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    if( nLayers < 2 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setGlobalNumberOfLayers(const label)"
        ) << "The specified global number of boundary layers is less than 2"
          << endl;

        return;
    }

    globalNumLayers_ = nLayers;
}

void refineBoundaryLayers::setGlobalThicknessRatio(const scalar thicknessRatio)
{
134
135
136
137
138
139
140
141
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    if( thicknessRatio < 1.0 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setGlobalThicknessRatio(const scalar)"
        ) << "The specified global thickness ratio is less than 1.0" << endl;

        return;
    }

    globalThicknessRatio_ = thicknessRatio;
}

void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer
(
    const scalar maxThickness
)
{
160
161
162
163
164
165
166
167
168
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
            "(const scalar)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    if( maxThickness <= 0.0 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
            "(const scalar)"
        ) << "The specified global maximum thickness of the first"
          << " boundary layer is negative!!" << endl;

        return;
    }

    globalMaxThicknessFirstLayer_ = maxThickness;
}

void refineBoundaryLayers::setNumberOfLayersForPatch
(
    const word& patchName,
    const label nLayers
)
{
190
191
192
193
194
195
196
197
198
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setNumberOfLayersForPatch"
            "(const word&, const label)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

199
200
201
202
203
204
205
    if( nLayers < 2 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setNumberOfLayersForPatch"
            "(const word&, const label)"
        ) << "The specified number of boundary layers for patch " << patchName
206
          << " is less than 2... boundary layers disabled for this patch!" << endl;
207
208
    }

Franjo's avatar
Franjo committed
209
    const labelList matchedIDs = mesh_.findPatches(patchName);
210
211
212
213
214

    forAll(matchedIDs, matchI)
    {
        numLayersForPatch_[mesh_.getPatchName(matchedIDs[matchI])] = nLayers;
    }
215
216
217
218
219
220
221
222
}

void refineBoundaryLayers::setThicknessRatioForPatch
(
    const word& patchName,
    const scalar thicknessRatio
)
{
223
224
225
226
227
228
229
230
231
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setThicknessRatioForPatch"
            "(const word&, const scalar)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

232
233
234
235
236
237
238
239
240
241
242
243
    if( thicknessRatio < 1.0 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setThicknessRatioForPatch"
            "(const word&, const scalar)"
        ) << "The specified thickness ratio for patch " << patchName
          << " is less than 1.0" << endl;

        return;
    }

Franjo's avatar
Franjo committed
244
    const labelList matchedIDs = mesh_.findPatches(patchName);
245
246
247

    forAll(matchedIDs, matchI)
    {
Franjo's avatar
Franjo committed
248
249
        const word pName = mesh_.getPatchName(matchedIDs[matchI]);
        thicknessRatioForPatch_[pName] = thicknessRatio;
250
    }
251
252
253
254
255
256
257
258
}

void refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch
(
    const word& patchName,
    const scalar maxThickness
)
{
259
260
261
262
263
264
265
266
267
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setMaxThicknessOfFirstLayerForPatch"
            "(const word&, const scalar)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

268
269
270
271
272
273
274
275
276
277
278
279
    if( maxThickness <= 0.0 )
    {
        WarningIn
        (
            "void refineBoundaryLayers::setGlobalMaxThicknessOfFirstLayer"
            "(const word&, const scalar)"
        ) << "The specified maximum thickness of the first boundary layer "
          << "for patch " << patchName << " is negative!!" << endl;

        return;
    }

Franjo's avatar
Franjo committed
280
    const labelList matchedIDs = mesh_.findPatches(patchName);
281
282
283

    forAll(matchedIDs, matchI)
    {
Franjo's avatar
Franjo committed
284
285
        const word pName = mesh_.getPatchName(matchedIDs[matchI]);
        maxThicknessForPatch_[pName] = maxThickness;
286
    }
287
288
289
290
}

void refineBoundaryLayers::setInteruptForPatch(const word& patchName)
{
291
292
293
294
295
296
297
298
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setInteruptForPatch(const word&)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

Franjo's avatar
Franjo committed
299
    const labelList matchedIDs = mesh_.findPatches(patchName);
300
301
302

    forAll(matchedIDs, matchI)
    {
Franjo's avatar
Franjo committed
303
304
        const word pName = mesh_.getPatchName(matchedIDs[matchI]);
        discontinuousLayersForPatch_.insert(pName);
305
    }
306
307
}

308
309
310
311
312
313
314
315
316
317
318
319
320
void refineBoundaryLayers::setCellSubset(const word subsetName)
{
    if( done_ )
    {
        FatalErrorIn
        (
            "void refineBoundaryLayers::setCellSubset(const word)"
        ) << "refineLayers is already executed" << exit(FatalError);
    }

    cellSubsetName_ = subsetName;
}

321
322
323
324
325
void refineBoundaryLayers::activateSpecialMode()
{
    specialMode_ = true;
}

326
327
void refineBoundaryLayers::refineLayers()
{
328
329
330
331
332
333
334
335
336
337
    bool refinePatch(false);
    for
    (
        std::map<word, label>::const_iterator it=numLayersForPatch_.begin();
        it!=numLayersForPatch_.end();
        ++it
    )
        if( it->second > 1 )
            refinePatch = true;

338
    if( (globalNumLayers_ < 2) && !refinePatch )
339
340
        return;

341
342
343
344
345
346
347
    Info << "Starting refining boundary layers" << endl;

    if( done_ )
    {
        WarningIn
        (
            "void refineBoundaryLayers::refineLayers()"
348
349
        ) << "Boundary layers are already refined! "
          << "Stopping refinement" << endl;
350
351
352
353

        return;
    }

354
    if( !analyseLayers() )
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    {
        WarningIn
        (
            "void refineBoundaryLayers::refineLayers()"
        ) << "Boundary layers do not exist in the mesh! Cannot refine" << endl;

        return;
    }

    generateNewVertices();

    generateNewFaces();

    generateNewCells();

    done_ = true;

    Info << "Finished refining boundary layers" << endl;
}

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
void refineBoundaryLayers::pointsInBndLayer(labelLongList& layerPoints)
{
    layerPoints.clear();

    boolList pointInLayer(mesh_.points().size(), false);

    forAll(newVerticesForSplitEdge_, seI)
    {
        forAllRow(newVerticesForSplitEdge_, seI, i)
            pointInLayer[newVerticesForSplitEdge_(seI, i)] = true;
    }

    forAll(pointInLayer, pointI)
        if( pointInLayer[pointI] )
            layerPoints.append(pointI);
}

void refineBoundaryLayers::pointsInBndLayer(const word subsetName)
{
    label sId = mesh_.pointSubsetIndex(subsetName);
    if( sId < 0 )
        sId = mesh_.addPointSubset(subsetName);

    forAll(newVerticesForSplitEdge_, seI)
    {
        forAllRow(newVerticesForSplitEdge_, seI, i)
            mesh_.addPointToSubset(sId, newVerticesForSplitEdge_(seI, i));
    }
}

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
void refineBoundaryLayers::readSettings
(
    const dictionary& meshDict,
    refineBoundaryLayers& refLayers
)
{
    if( meshDict.isDict("boundaryLayers") )
    {
        const dictionary& bndLayers = meshDict.subDict("boundaryLayers");

        //- read global properties
        if( bndLayers.found("nLayers") )
        {
            const label nLayers = readLabel(bndLayers.lookup("nLayers"));
            refLayers.setGlobalNumberOfLayers(nLayers);
        }
        if( bndLayers.found("thicknessRatio") )
        {
423
424
            const scalar ratio =
                readScalar(bndLayers.lookup("thicknessRatio"));
425
426
427
428
429
430
431
432
433
            refLayers.setGlobalThicknessRatio(ratio);
        }
        if( bndLayers.found("maxFirstLayerThickness") )
        {
            const scalar maxFirstThickness =
                readScalar(bndLayers.lookup("maxFirstLayerThickness"));
            refLayers.setGlobalMaxThicknessOfFirstLayer(maxFirstThickness);
        }

434
435
436
437
438
        //- consider specified patches for exclusion from boundary layer creation
        //- implemented by setting the number of layers to 1
        if( bndLayers.found("excludedPatches") )
        {
            const wordList patchNames(bndLayers.lookup("excludedPatches"));
Franjo's avatar
Franjo committed
439

440
441
442
443
444
445
446
447
            forAll(patchNames, patchI)
            {
                const word pName = patchNames[patchI];

                refLayers.setNumberOfLayersForPatch(pName, 1);
            }
        }

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
        //- patch-based properties
        if( bndLayers.isDict("patchBoundaryLayers") )
        {
            const dictionary& patchBndLayers =
                bndLayers.subDict("patchBoundaryLayers");
            const wordList patchNames = patchBndLayers.toc();

            forAll(patchNames, patchI)
            {
                const word pName = patchNames[patchI];

                if( patchBndLayers.isDict(pName) )
                {
                    const dictionary& patchDict =
                        patchBndLayers.subDict(pName);

                    if( patchDict.found("nLayers") )
                    {
                        const label nLayers =
                            readLabel(patchDict.lookup("nLayers"));
468

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
                        refLayers.setNumberOfLayersForPatch(pName, nLayers);
                    }
                    if( patchDict.found("thicknessRatio") )
                    {
                        const scalar ratio =
                            readScalar(patchDict.lookup("thicknessRatio"));
                        refLayers.setThicknessRatioForPatch(pName, ratio);
                    }
                    if( patchDict.found("maxFirstLayerThickness") )
                    {
                        const scalar maxFirstThickness =
                            readScalar
                            (
                                patchDict.lookup("maxFirstLayerThickness")
                            );
                        refLayers.setMaxThicknessOfFirstLayerForPatch
                        (
                            pName,
                            maxFirstThickness
                        );
                    }
                    if( patchDict.found("allowDiscontinuity") )
                    {
                        const bool allowDiscontinuity =
                            readBool(patchDict.lookup("allowDiscontinuity"));

                        if( allowDiscontinuity )
                            refLayers.setInteruptForPatch(pName);
                    }
                }
                else
                {
                    Warning << "Cannot refine layer for patch "
                        << patchNames[patchI] << endl;
                }
            }
        }
    }
    else
    {
        //- the layer will not be refined
        refLayers.avoidRefinement();
    }
}

514
515
516
517
518
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

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