refineBoundaryLayers.H 13.7 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

Class
    refineBoundaryLayers

Description
    Refine existing boundary layers

SourceFiles
    refineBoundaryLayers.C
    refineBoundaryLayersFunctions.C

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

#ifndef refineBoundaryLayers_H
#define refineBoundaryLayers_H

Franjo's avatar
Franjo committed
39
40
#include "objectRegistry.H"
#include "Time.H"
41
42
43
#include "polyMeshGenModifier.H"
#include "meshSurfaceEngine.H"
#include "DynList.H"
44
#include "labelLongList.H"
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
#include "labelPair.H"

#include <map>
#include <set>

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

namespace Foam
{

// Forward declarations
class meshSurfaceEngine;

/*---------------------------------------------------------------------------*\
                Class refineBoundaryLayers Declaration
\*---------------------------------------------------------------------------*/

class refineBoundaryLayers
{
        //- Reference to the mesh
        polyMeshGen& mesh_;

        //- pointer to mesh surface engine
        mutable meshSurfaceEngine* msePtr_;

        //- global number of boundary layers
        label globalNumLayers_;

        //- global thickness ratio
        scalar globalThicknessRatio_;

        //- global maximum thickness of the first layer
        scalar globalMaxThicknessFirstLayer_;

        //- number of boundary layers for user-selected patches
        std::map<word, label> numLayersForPatch_;

        //- local thickness ratio for selected patches
        std::map<word, scalar> thicknessRatioForPatch_;

        //- local maximum layer thickness for selected patches
        std::map<word, scalar> maxThicknessForPatch_;

        //- allow discontinuous layers for patch
        std::set<word> discontinuousLayersForPatch_;

91
92
93
94
        //- the name of a subset which shall contain the indices
        //- of the cells in the boundary layer
        word cellSubsetName_;

95
96
97
        //- check whether the refinement is already executed
        bool done_;

98
99
100
        //- a flag whether a 2D mesh generation is active or not
        bool is2DMesh_;

101
102
103
104
        //- shall the layer be refined into two layers with the first one
        //- matching the thickness of the n-1 ones
        bool specialMode_;

105
106
        //- information about existing boundary layers at patches
        //- only available layers
Franjo's avatar
Franjo committed
107
        List<DynList<label> > layerAtPatch_;
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

        //- which patches are part of a single layer
        List<DynList<word> > patchesInLayer_;

        //- a containing the number of layers which shall be generated above
        //- a boundary face
        labelList nLayersAtBndFace_;

        //- a list of edges which shall be refined
        LongList<edge> splitEdges_;

        //- split edges at point
        VRWGraph splitEdgesAtPoint_;

        //- new vertices for on edges which shall be refined
        VRWGraph newVerticesForSplitEdge_;

        //- a graph containing information which new faces were generated
        //- from an existing face
        VRWGraph facesFromFace_;

        //- a graph containing faces after layer refinement
        VRWGraph newFaces_;

    // Private member functions
        //- Return reference to meshSurfaceEngine
        const meshSurfaceEngine& surfaceEngine() const;

        //- analyse layers to check their topology
137
        bool analyseLayers();
138

139
        //- generate new points on edges, faces and in cells
140
141
142
        void generateNewVertices();

        //- refine a given face and return the new faces
143
        //- generates new points at cross-split faces
144
145
146
147
        void refineFace
        (
            const face& f,
            const FixedList<label, 2>& nLayersInDirection,
148
            DynList<DynList<label, 4>, 128>& newFaces
149
150
        );

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        //- generate a matrix of points generated by splitting a face
        //- and return them in the local i, j system of the face
        void sortFacePoints
        (
            const label faceI,
            DynList<DynList<label> >& facePoints,
            const label transpose = false
        ) const;

        //- generate a matrix of faces generated by splitting a face
        //- and return them in the local i, j, system of the face
        void sortFaceFaces
        (
            const label faceI,
            DynList<DynList<label> >& faceFaces,
            const label transpose = false
        ) const;

169
170
171
172
173
174
175
        //- map split edges onto a cell
        void generateNewFaces();

        //- generate new cells for a prism with one boundary face
        void generateNewCellsPrism
        (
            const label cellI,
Franjo's avatar
Franjo committed
176
177
            DynList<DynList<DynList<label, 8>, 10>, 64>& cellsFromCell
        ) const;
178

179
180
181
        //- a helper function which stores faces generated from
        //- an existing face into new cells
        void storeFacesIntoCells
182
        (
183
184
185
186
187
188
189
            const label faceI,
            const bool reverseOrientation,
            const label normalDirection,
            const bool maxCoordinate,
            const label nLayersI,
            const label nLayersJ,
            const label nLayersK,
190
            DynList<DynList<DynList<label, 4>, 6>, 256>& cellsFromCell
191
        ) const;
192
193
194
195

        //- generate new cells and add them to the mesh
        void generateNewCells();

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
    // Nested classes
        class refineEdgeHexCell
        {
            // Private data
                //- label of cell
                const label cellI_;

                //- number of cells in local direction i
                label nLayersI_;

                //- number of cells in locatiol direction j
                label nLayersJ_;

                //- container for new cells
                DynList<DynList<DynList<label, 4>, 6>, 256> cellsFromCell_;

Franjo's avatar
Franjo committed
212
213
                //- const reference to the boundary layer class
                const refineBoundaryLayers& bndLayers_;
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

                //- faces sorted into directions of a hex shape
                FixedList<label, 6> faceInDirection_;

                //- information about orientation of faces
                //- false means the orientation as expected
                //- true means wrong orientation
                FixedList<bool, 6> faceOrientation_;

                //- points on cross-split faces
                FixedList<DynList<DynList<label> >, 2> cellPoints_;

            // Private member functions
                //- populate faceInDirection_nad wrongFaceOrientation_
                void determineFacesInDirections();

                //- populate new cells with new faces generated from already
                //- existing faces
                void populateExistingFaces();

                //- generate new internal faces and tore them to new cells
                void generateMissingFaces();

        public:

            // Constructor
                //- construct from cell label and the refineBoundaryLayers
Franjo's avatar
Franjo committed
241
242
243
244
245
                refineEdgeHexCell
                (
                    const label cellI,
                    const refineBoundaryLayers& ref
                );
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

            // Public member functions
                inline const DynList<DynList<DynList<label, 4>, 6>, 256>&
                newCells() const
                {
                    return cellsFromCell_;
                }
        };

        class refineCornerHexCell
        {
            // Private data
                //- label of cell
                const label cellI_;

                //- number of cells in local direction i
                label nLayersI_;

                //- number of cells in local direction j
                label nLayersJ_;

                //- number of cells in local direction k
                label nLayersK_;

                //- split edge in directions
                FixedList<label, 3> splitEdgeInDirection_;

                //- container for new cells
                DynList<DynList<DynList<label, 4>, 6>, 256> cellsFromCell_;

                //- reference to the boundary layer class
Franjo's avatar
Franjo committed
277
                const refineBoundaryLayers& bndLayers_;
278
279
280
281
282
283
284
285
286
287
288
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

                //- faces sorted into directions of a hex shape
                FixedList<label, 6> faceInDirection_;

                //- information about orientation of faces
                //- false means the orientation as expected
                //- true means wrong orientation
                FixedList<bool, 6> faceOrientation_;

                //- points on cross-split faces
                FixedList<DynList<DynList<label> >, 6> facePoints_;

                //- points inside the cell
                DynList<DynList<DynList<label> > > cellPoints_;

            // Private member functions
                //- populate faceInDirection_nad wrongFaceOrientation_
                void determineFacesInDirections();

                //- populate new cells with new faces generated from already
                //- existing faces
                void populateExistingFaces();

                //- generate missing points inside the cell
                void generateNewPoints();

                //- generate new internal faces and tore them to new cells
                void generateMissingFaces();

        public:

            // Constructor
                //- construct from cell label and the refineBoundaryLayers
                refineCornerHexCell
                (
                    const label cellI,
Franjo's avatar
Franjo committed
314
                    const refineBoundaryLayers& ref
315
316
317
318
319
320
321
322
323
324
325
326
                );

            // Public member functions
                inline const DynList<DynList<DynList<label, 4>, 6>, 256>&
                newCells() const
                {
                    return cellsFromCell_;
                }
        };

    // Private member functions

327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
        //- Disallow bitwise copy construct
        refineBoundaryLayers(const refineBoundaryLayers&);

        //- Disallow bitwise assignment
        void operator=(const refineBoundaryLayers&);

public:

    // Constructors

        //- Construct from mesh reference
        refineBoundaryLayers(polyMeshGen& mesh);

    // Destructor
        ~refineBoundaryLayers();

    // Public member functions
Franjo's avatar
Franjo committed
344
345

        // Settings
346
347
348
        //- set no refinement flag
        void avoidRefinement();

349
350
351
        //- activate 2D layer refinement
        void activate2DMode();

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
        //- set the global number of boundary layers
        void setGlobalNumberOfLayers(const label nLayers);

        //- set the global thickness ratio (default is 1)
        void setGlobalThicknessRatio(const scalar thicknessRatio);

        //- set the maximum thickness of the first boundary layer
        void setGlobalMaxThicknessOfFirstLayer(const scalar maxThickness);

        //- set the number of layers for a patch
        //- the settings override the global settings
        void setNumberOfLayersForPatch
        (
            const word& patchName,
            const label nLayers
        );

        //- set the thickness ratio for a patch
        //- it overrides the global settings
        void setThicknessRatioForPatch
        (
            const word& patchName,
            const scalar thicknessRatio
        );

        //- set the maximum thickness of the first layer for a patch
        void setMaxThicknessOfFirstLayerForPatch
        (
            const word& patchName,
            const scalar maxThickness
        );

        //- set whether the settings for a given patch are valid for the
        //- patch only, or whether they extend over th whole sheet
        //- the selected patch belongs to
        //- the default behaviour is to apply the patch settings to the whole
        //- sheet
        void setInteruptForPatch(const word& patchName);

391
        //- set the flag to store the boundary layer cells in a subset
392
393
        void setCellSubset(const word subsetName = "layerCells");

394
395
396
397
398
399
        //- this flag refinement of a layer into a single one matching
        //- the thickness of the n layers. This functionality is intended to
        //- create additional layer that shall be improved by the boundary
        //- layer smoother in order to leave the inside points intact
        void activateSpecialMode();

Franjo's avatar
Franjo committed
400
    // Worker
401
402
403
        //- performs refinement based on the given settings
        void refineLayers();

404
405
406
407
408
409
410
    // Post information
        //- provide the list of points in the boundary layer
        void pointsInBndLayer(labelLongList&);

        //- create a subset containing points in the boundary layer
        void pointsInBndLayer(const word subsetName="pointsInBndLayer");

411
    // Static member functions
412
413
414
        //- read the settings from dictionary
        static void readSettings(const dictionary&, refineBoundaryLayers&);
};
415
416
417
418
419
420
421
422
423
424

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

} // End namespace Foam

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

#endif

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