Forward compatibility: flex
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / meshes / partTriMesh / partTriMeshAddressing.C
blob6c81efe97df07738a21dbc64fd30f47bc6bb5d5f
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 "meshSurfacePartitioner.H"
30 #include "partTriMesh.H"
31 #include "meshSurfaceEngine.H"
32 #include "triSurfModifier.H"
34 //#define DEBUGSmooth
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 void partTriMesh::createPointsAndTrias
45     const List<direction>& useFace
48     const labelList& facePatch = mPart_.boundaryFacePatches();
49     const meshSurfaceEngine& meshSurface = mPart_.surfaceEngine();
50     const pointFieldPMG& points = meshSurface.points();
51     const vectorField& faceCentres = meshSurface.faceCentres();
52     const labelList& bPoints = meshSurface.boundaryPoints();
53     const labelList& bp = meshSurface.bp();
54     const faceList::subList& bFaces = meshSurface.boundaryFaces();
56     meshSurfacePointLabelInTriMesh_.setSize(bPoints.size());
57     meshSurfacePointLabelInTriMesh_ = -1;
58     labelList nodeLabelForFace(bFaces.size(), -1);
60     label nTriPoints(0);
61     forAll(bFaces, bfI)
62     {
63         if( useFace[bfI] )
64         {
65             const face& bf = bFaces[bfI];
67             //- create a point in the face centre
68             if( bf.size() > 3 )
69                 nodeLabelForFace[bfI] = nTriPoints++;
71             //- create points at face points
72             forAll(bf, pI)
73             {
74                 const label bpI = bp[bf[pI]];
76                 if( meshSurfacePointLabelInTriMesh_[bpI] == -1 )
77                     meshSurfacePointLabelInTriMesh_[bpI] = nTriPoints++;
78             }
80             //- create triangles
81             if( bf.size() > 3 )
82             {
83                 forAll(bf, eI)
84                 {
85                     //- add a triangle connected to face centre
86                     labelledTri tri
87                     (
88                         meshSurfacePointLabelInTriMesh_[bp[bf[eI]]],
89                         meshSurfacePointLabelInTriMesh_[bp[bf.nextLabel(eI)]],
90                         nodeLabelForFace[bfI],
91                         facePatch[bfI]
92                     );
94                     surf_.appendTriangle(tri);
96                     //- add a triangle for shape
97                     labelledTri secondTri
98                     (
99                         meshSurfacePointLabelInTriMesh_[bp[bf[eI]]],
100                         meshSurfacePointLabelInTriMesh_[bp[bf.nextLabel(eI)]],
101                         meshSurfacePointLabelInTriMesh_[bp[bf.prevLabel(eI)]],
102                         facePatch[bfI]
103                     );
105                     surf_.appendTriangle(secondTri);
106                 }
107             }
108             else
109             {
110                 //- face is a triangle
111                 labelledTri tri
112                 (
113                     meshSurfacePointLabelInTriMesh_[bp[bf[0]]],
114                     meshSurfacePointLabelInTriMesh_[bp[bf[1]]],
115                     meshSurfacePointLabelInTriMesh_[bp[bf[2]]],
116                     facePatch[bfI]
117                 );
119                 surf_.appendTriangle(tri);
121                 //- add a triangle for shape
122                 forAll(bf, eI)
123                 {
124                     labelledTri secondTri
125                     (
126                         meshSurfacePointLabelInTriMesh_[bp[bf[eI]]],
127                         meshSurfacePointLabelInTriMesh_[bp[bf.nextLabel(eI)]],
128                         meshSurfacePointLabelInTriMesh_[bp[bf.prevLabel(eI)]],
129                         facePatch[bfI]
130                     );
132                     surf_.appendTriangle(secondTri);
133                 }
134             }
135         }
136     }
138     //- add points
139     triSurfModifier sMod(surf_);
140     pointField& pts = sMod.pointsAccess();
141     pts.setSize(nTriPoints);
143     pointType_.setSize(nTriPoints);
144     pointType_ = NONE;
146     pointLabelInMeshSurface_.setSize(pts.size());
147     pointLabelInMeshSurface_ = -1;
149     forAll(meshSurfacePointLabelInTriMesh_, bpI)
150         if( meshSurfacePointLabelInTriMesh_[bpI] != -1 )
151         {
152             const label npI = meshSurfacePointLabelInTriMesh_[bpI];
153             pointLabelInMeshSurface_[npI] = bpI;
154             pts[npI] = points[bPoints[bpI]];
155             pointType_[npI] |= SMOOTH;
156         }
158     forAll(nodeLabelForFace, bfI)
159         if( nodeLabelForFace[bfI] != -1 )
160         {
161             const label npI = nodeLabelForFace[bfI];
162             pts[npI] = faceCentres[bfI];
163             pointType_[npI] = FACECENTRE;
164         }
166     //- set CORNER and FEATUREEDGE flags to surface points
167     forAllConstIter(labelHashSet, mPart_.corners(), it)
168         if( meshSurfacePointLabelInTriMesh_[it.key()] != -1 )
169             pointType_[meshSurfacePointLabelInTriMesh_[it.key()]] |= CORNER;
171     forAllConstIter(labelHashSet, mPart_.edgePoints(), it)
172     {
173         const label pI = meshSurfacePointLabelInTriMesh_[it.key()];
174         if( pI != -1 )
175             pointType_[pI] |= FEATUREEDGE;
176     }
178     //- create addressing for parallel runs
179     if( Pstream::parRun() )
180     {
181         createParallelAddressing
182         (
183             meshSurfacePointLabelInTriMesh_,
184             nodeLabelForFace
185         );
187         createBufferLayers();
188     }
190     //- calculate point facets addressing
191     surf_.pointFacets();
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 } // End namespace Foam
198 // ************************************************************************* //