1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
25 Performs point relocations in the mesh (smoothing) in order to
26 improve quality measures. It does not make the mesh invalied.
28 \*---------------------------------------------------------------------------*/
31 #include "objectRegistry.H"
33 #include "polyMeshGenModifier.H"
34 #include "meshOptimizer.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 int main(int argc, char *argv[])
42 argList::validArgs.clear();
44 argList::validOptions.insert("nLoops", "int");
45 argList::validOptions.insert("nIterations", "int");
46 argList::validOptions.insert("nSurfaceIterations", "int");
47 argList::validOptions.insert("qualityThreshold", "scalar");
48 argList::validOptions.insert("constrainedCellsSet", "word");
50 # include "setRootCase.H"
51 # include "createTime.H"
54 label nIterations(50);
56 label nSurfaceIterations(2);
57 scalar qualityThreshold(0.1);
59 if( args.options().found("nLoops") )
61 nLoops = readLabel(IStringStream(args.options()["nLoops"])());
65 Info << "Default number of loops is 10" << endl;
68 if( args.options().found("nIterations") )
71 readLabel(IStringStream(args.options()["nIterations"])());
75 Info << "Default number of iterations is 50" << endl;
78 if( args.options().found("nSurfaceIterations") )
81 readLabel(IStringStream(args.options()["nSurfaceIterations"])());
85 Info << "Default number of surface iterations is 2" << endl;
88 if( args.options().found("qualityThreshold") )
91 readScalar(IStringStream(args.options()["qualityThreshold"])());
95 Info << "Using default quality threshold 0.1" << endl;
98 word constrainedCellSet;
100 if( args.options().found("constrainedCellsSet") )
102 constrainedCellSet = args.options()["constrainedCellsSet"];
106 Info << "No constraints applied on the smoothing procedure" << endl;
109 //- load the mesh from disk
110 polyMeshGen pmg(runTime);
113 //- construct the smoother
114 meshOptimizer mOpt(pmg);
116 if( !constrainedCellSet.empty() )
118 //- lock cells in constrainedCellSet
119 mOpt.lockCellsInSubset(constrainedCellSet);
121 //- find boundary faces which shall be locked
122 labelLongList lockedBndFaces, selectedCells;
124 const label sId = pmg.cellSubsetIndex(constrainedCellSet);
125 pmg.cellsInSubset(sId, selectedCells);
127 boolList activeCell(pmg.cells().size(), false);
128 forAll(selectedCells, i)
129 activeCell[selectedCells[i]] = true;
132 //- clear geometry information before volume smoothing
133 pmg.clearAddressingData();
135 //- perform optimisation using the laplace smoother and
144 //- perform optimisation of worst quality faces
145 mOpt.optimizeMeshFVBestQuality(nLoops, qualityThreshold);
147 //- check the mesh again and untangl bad regions if any of them exist
148 mOpt.untangleMeshFV(nLoops, nIterations, nSurfaceIterations);
150 Info << "Writing mesh" << endl;
153 Info << "End\n" << endl;
157 // ************************************************************************* //