Fixed URL for libccmio-2.6.1 (bug report #5 by Thomas Oliveira)
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / surfaceTools / surfaceMorpherCells / surfaceMorpherCells.C
blob0ea511ecb3ed724ac4b9ec3642997d1870082e19
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 "surfaceMorpherCells.H"
29 #include "demandDrivenData.H"
31 //#define DEBUGMorph
33 # ifdef DEBUGMorph
34 #include <sstream>
35 #include "polyMeshGenAddressing.H"
36 # endif
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 void surfaceMorpherCells::replaceMeshBoundary()
47     wordList patchNames(1);
48     patchNames[0] = "defaultFaces";
50     polyMeshGenModifier(mesh_).replaceBoundary
51     (
52         patchNames,
53         newBoundaryFaces_,
54         newBoundaryOwners_,
55         newBoundaryPatches_
56     );
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 surfaceMorpherCells::surfaceMorpherCells
63     polyMeshGen& mesh
65     :
66     mesh_(mesh),
67     nIntFaces_(0),
68     boundaryVertex_(mesh.points().size()),
69     cellFlags_(mesh.cells().size()),
70     newBoundaryFaces_(),
71     newBoundaryOwners_(),
72     newBoundaryPatches_()
76 surfaceMorpherCells::~surfaceMorpherCells()
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 void surfaceMorpherCells::morphMesh()
83     //- perform surface morphing
84     bool changed;
86     # ifdef DEBUGMorph
87     label iter(0);
88     # endif
90     do
91     {
92         changed = false;
93         # ifdef DEBUGMorph
94         Info << "Iteration " << ++iter << endl;
95         # endif
97         findBoundaryVertices();
99         findBoundaryCells();
101         if( removeCellsWithAllVerticesAtTheBoundary() )
102         {
103             changed = true;
104             continue;
105         }
107         if( morphInternalFaces() )
108         {
109             changed = true;
110             continue;
111         }
113         if( morphBoundaryFaces() )
114         {
115             changed = true;
116             continue;
117         }
119         # ifdef DEBUGMorph
120         mesh_.write();
121         mesh_.addressingData().checkMesh(true);
122         fileName name("morphedMesh");
123         std::ostringstream ss;
124         ss << iter;
125         name += ss.str();
126         Info << "name " << name << endl;
127         ++iter;
129         const cellListPMG& cells = mesh_.cells();
130         const faceListPMG& faces = mesh_.faces();
131         forAll(cells, cellI)
132         {
133             const cell& c = cells[cellI];
135             const edgeList edges = c.edges(faces);
136             List<direction> nAppearances(edges.size(), direction(0));
138             forAll(c, fI)
139             {
140                 const edgeList fEdges = faces[c[fI]].edges();
142                 forAll(fEdges, eI)
143                     forAll(edges, eJ)
144                         if( fEdges[eI] == edges[eJ] )
145                         {
146                             ++nAppearances[eJ];
147                             break;
148                         }
149             }
151             bool closed(true);
152             forAll(nAppearances, eI)
153                 if( nAppearances[eI] != 2 )
154                 {
155                     closed = false;
156                     Info << "Edge " << edges[eI] << " appears "
157                         << label(nAppearances[eI]) << " times in cell "
158                         << cellI << endl;
159                 }
161             if( !closed )
162             {
163                 Info << "Cell " << cellI << " consists of faces " << c << endl;
164                 forAll(c, fI)
165                     Info << "Face " << c[fI] << " is " << faces[c[fI]] << endl;
166                 FatalErrorIn
167                 (
168                     "void surfaceMorpherCells::morphMesh()"
169                 ) << "Cell " << cellI << " is not topologically closed"
170                     << abort(FatalError);
171             }
172         }
173         # endif
175     } while( changed );
177     polyMeshGenModifier(mesh_).removeUnusedVertices();
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 } // End namespace Foam
184 // ************************************************************************* //