Fixed URL for libccmio-2.6.1 (bug report #5 by Thomas Oliveira)
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / surfaceTools / meshSurfaceEdgeExtractor / meshSurfaceEdgeCreateEdgeVertices.C
blobb2bbf41337f443a2847ff07b099077460be2128f
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 "demandDrivenData.H"
29 #include "polyMeshGenAddressing.H"
30 #include "meshSurfaceEdgeExtractor.H"
31 #include "meshOctree.H"
32 #include "Map.H"
34 #define DEBUGMapping
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 void meshSurfaceEdgeExtractor::createEdgeVertices()
45     pointFieldPMG& points = mesh_.points();
46     const faceListPMG& faces = mesh_.faces();
48     const edgeList& edges = mesh_.addressingData().edges();
49     const VRWGraph& faceEdges = mesh_.addressingData().faceEdges();
51     Map<label> newEdgePoint;
53     const label nIntFaces = mesh_.nInternalFaces();
54     const label nFaces = faces.size();
56     nPoints_ = points.size();
58     for(label faceI=nIntFaces;faceI<nFaces;++faceI)
59     {
60         const face& f = faces[faceI];
62         forAll(f, pI)
63         {
64             const label edgeI = faceEdges(faceI, pI);
66             if( newEdgePoint.found(edgeI) ) continue;
68             const label s = f[pI];
69             const label e = f.nextLabel(pI);
71             if( !pointRegions_.sizeOfRow(s) || !pointRegions_.sizeOfRow(e) )
72             {
73                 Warning << "Boundary vertices " << s << " and " << e
74                     << " are not mapped to the boundary!" << endl;
76                 continue;
77             }
79             if( pointRegions_(s, 0) != pointRegions_(e, 0) )
80             {
81                 point newP;
82                 scalar distSq;
83                 label nse;
85                 FixedList<point, 2> edgePoints;
86                 FixedList<label, 2> patches;
88                 edgePoints[0] = points[s];
89                 edgePoints[1] = points[e];
90                 patches[0] = pointRegions_(s, 0);
91                 patches[1] = pointRegions_(e, 0);
93                 const bool found =
94                 meshOctree_.findNearestPointToEdge
95                 (
96                     newP,
97                     distSq,
98                     nse,
99                     edgePoints,
100                     patches
101                 );
103                 if( found )
104                 {
105                     points.append(newP);
106                 }
107                 else
108                 {
109                     points.append
110                     (
111                         edges[faceEdges(faceI, pI)].centre(points)
112                     );
113                 }
115                 pointRegions_.appendList(patches);
117                 newEdgePoint.insert(edgeI, nPoints_);
118                 ++nPoints_;
119             }
120         }
121     }
123     points.setSize(nPoints_);
125     //- create new faces
126     DynList<label> newF;
127     forAll(faces, faceI)
128     {
129         const face& f = faces[faceI];
131         newF.clear();
133         forAll(f, eI)
134         {
135             newF.append(f[eI]);
136             if( newEdgePoint.found(faceEdges(faceI, eI)) )
137                 newF.append(newEdgePoint[faceEdges(faceI, eI)]);
138         }
140         if( newF.size() > f.size() )
141         {
142             //- face must be changed
143             face& mf = const_cast<face&>(f);
144             mf.setSize(newF.size());
145             forAll(mf, pI)
146                 mf[pI] = newF[pI];
147         }
148     }
150     mesh_.clearAddressingData();
152     Info << "Finished creating mesh edges" << endl;
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 } // End namespace Foam
159 // ************************************************************************* //