Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / smoothers / geometry / meshOptimizer / boundaryLayerOptimisation / boundaryLayerOptimisation.C
blob5919474ff59979f15746f58a3a86fc60a671f26b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
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
13     Free Software Foundation; either version 3 of the License, or (at your
14     option) any later version.
16     cfMesh is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "boundaryLayerOptimisation.H"
29 #include "meshSurfacePartitioner.H"
31 // #define DEBUGSearch
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 boundaryLayerOptimisation::boundaryLayerOptimisation(polyMeshGen& mesh)
42     mesh_(mesh),
43     meshSurfacePtr_(new meshSurfaceEngine(mesh)),
44     deleteMeshSurface_(true),
45     partitionerPtr_(NULL),
46     hairEdges_(),
47     hairEdgesAtBndPoint_(),
48     hairEdgesNearHairEdge_(),
49     isBndLayerBase_(),
50     isExitFace_(),
51     hairEdgeType_(),
52     thinnedHairEdge_(),
53     maxNumIterations_(5),
54     nSmoothNormals_(5),
55     relThicknessTol_(0.1),
56     featureSizeFactor_(0.3),
57     reCalculateNormals_(true)
59     calculateHairEdges();
62 boundaryLayerOptimisation::boundaryLayerOptimisation
64     polyMeshGen& mesh,
65     const meshSurfaceEngine& mse
68     mesh_(mesh),
69     meshSurfacePtr_(&mse),
70     deleteMeshSurface_(false),
71     partitionerPtr_(NULL),
72     hairEdges_(),
73     hairEdgesAtBndPoint_(),
74     hairEdgesNearHairEdge_(),
75     isBndLayerBase_(),
76     isExitFace_(),
77     hairEdgeType_(),
78     thinnedHairEdge_(),
79     maxNumIterations_(5),
80     nSmoothNormals_(5),
81     relThicknessTol_(0.15),
82     featureSizeFactor_(0.3),
83     reCalculateNormals_(true)
85     calculateHairEdges();
88 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
90 boundaryLayerOptimisation::~boundaryLayerOptimisation()
92     deleteDemandDrivenData(partitionerPtr_);
94     if( deleteMeshSurface_ )
95         deleteDemandDrivenData(meshSurfacePtr_);
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 void boundaryLayerOptimisation::setMaxNumIterations
102     const label maxNumIterations
105     maxNumIterations_ = maxNumIterations;
108 void boundaryLayerOptimisation::setNumNormalsSmoothingIterations
110     const label nSmoothNormals
113     nSmoothNormals_ = nSmoothNormals;
116 void boundaryLayerOptimisation::recalculateNormals(const bool shallRecalculate)
118     reCalculateNormals_ = shallRecalculate;
121 void boundaryLayerOptimisation::setRelativeThicknessTolerance
123     const scalar relThicknessTol
126     relThicknessTol_ = relThicknessTol;
129 void boundaryLayerOptimisation::setFeatureSizeFactor
131     const scalar featureSizeFactor
134     featureSizeFactor_ = featureSizeFactor;
137 const edgeLongList& boundaryLayerOptimisation::hairEdges() const
139     return hairEdges_;
142 const VRWGraph& boundaryLayerOptimisation::hairEdgesAtBndPoint() const
144     return hairEdgesAtBndPoint_;
147 const boolList& boundaryLayerOptimisation::isBaseFace() const
149     return isBndLayerBase_;
152 const boolList& boundaryLayerOptimisation::isExitFace() const
154     return isExitFace_;
157 void boundaryLayerOptimisation::readSettings
159     const dictionary& meshDict,
160     boundaryLayerOptimisation& blOptimisation
163     if( meshDict.found("boundaryLayers") )
164     {
165         const dictionary& layersDict = meshDict.subDict("boundaryLayers");
167         if( layersDict.found("optimiseLayer") )
168         {
169             const bool smoothLayers =
170                 readBool(layersDict.lookup("optimiseLayer"));
172             if( !smoothLayers )
173                 return;
174         }
176         if( layersDict.found("optimisationParameters") )
177         {
178             const dictionary& optParams =
179                 layersDict.subDict("optimisationParameters");
181             if( optParams.found("recalculateNormals") )
182             {
183                 const bool recalculateNormals =
184                     readBool(optParams.lookup("recalculateNormals"));
186                 blOptimisation.recalculateNormals(recalculateNormals);
187             }
189             if( optParams.found("nSmoothNormals") )
190             {
191                 const label nSmoothNormals =
192                     readLabel(optParams.lookup("nSmoothNormals"));
194                 blOptimisation.setNumNormalsSmoothingIterations(nSmoothNormals);
195             }
197             if( optParams.found("featureSizeFactor") )
198             {
199                 const scalar featureSizeFactor =
200                     readScalar(optParams.lookup("featureSizeFactor"));
202                 if( featureSizeFactor >= 1.0 || featureSizeFactor < 0.0 )
203                     FatalErrorIn
204                     (
205                         "void boundaryLayerOptimisation::optimiseLayer"
206                         "(const dictionary&, boundaryLayerOptimisation&)"
207                     ) << "Feature size factor is out"
208                       << " of a valid range 0 to 1" << exit(FatalError);
210                 blOptimisation.setFeatureSizeFactor(featureSizeFactor);
211             }
213             if( optParams.found("relThicknessTol") )
214             {
215                 const scalar relThicknessTol =
216                     readScalar(optParams.lookup("relThicknessTol"));
218                 if( relThicknessTol >= 1.0 || relThicknessTol < 0.0 )
219                     FatalErrorIn
220                     (
221                         "void boundaryLayerOptimisation::optimiseLayer"
222                         "(const dictionary&, boundaryLayerOptimisation&)"
223                     ) << "Relative thickness tolerance is out"
224                       << " of a valid range 0 to 1" << exit(FatalError);
226                 blOptimisation.setRelativeThicknessTolerance(relThicknessTol);
227             }
229             if( optParams.found("maxNumIterations") )
230             {
231                 const label maxNumIterations =
232                     readLabel(optParams.lookup("maxNumIterations"));
234                 blOptimisation.setMaxNumIterations(maxNumIterations);
235             }
236         }
237     }
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 } // End namespace Foam
244 // ************************************************************************* //