Fixed URL for libccmio-2.6.1 (bug report #5 by Thomas Oliveira)
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / surfaceTools / meshSurfaceEdgeExtractor2D / meshSurfaceEdgeExtractor2DDistributeFaces.C
blob76d04c219ec9dffc067aa182e6792e241e219a9c
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 "meshSurfaceEdgeExtractor2D.H"
30 #include "meshOctree.H"
31 #include "triSurf.H"
32 #include "meshSurfaceEngine.H"
33 #include "meshSurfaceMapper2D.H"
34 #include "polyMeshGen2DEngine.H"
35 #include "helperFunctions.H"
37 # ifdef USE_OMP
38 #include <omp.h>
39 # endif
41 //#define DEBUGMapping
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 void meshSurfaceEdgeExtractor2D::distributeBoundaryFaces()
52     polyMeshGen2DEngine mesh2DEngine(mesh_);
53     const boolList& activeFace = mesh2DEngine.activeFace();
54     const boolList& zMinPoint = mesh2DEngine.zMinPoints();
55     const boolList& zMaxPoint = mesh2DEngine.zMaxPoints();
57     const pointFieldPMG& points = mesh_.points();
58     const faceListPMG& faces = mesh_.faces();
59     const labelList& owner = mesh_.owner();
60     const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
62     const triSurf& surf = meshOctree_.surface();
63     const geometricSurfacePatchList& surfPatches = surf.patches();
65     //- copy boundary faces and their owner face
66     VRWGraph bndFaces;
67     labelLongList origFaceLabel;
69     forAll(boundaries, patchI)
70     {
71         const label start = boundaries[patchI].patchStart();
72         const label size = boundaries[patchI].patchSize();
74         for(label fI=0;fI<size;++fI)
75         {
76             const label faceI = start + fI;
77             const face& bf = faces[faceI];
79             bndFaces.appendList(bf);
80             origFaceLabel.append(faceI);
81         }
82     }
84     //- project face centres onto their nearest location on the surface mesh
85     wordList patchNames(surfPatches.size()+2);
86     wordList patchTypes(surfPatches.size()+2);
87     forAll(surfPatches, ptchI)
88     {
89         patchNames[ptchI] = surfPatches[ptchI].name();
90         patchTypes[ptchI] = surfPatches[ptchI].geometricType();
91     }
93     const label bottomEmptyId = patchNames.size() - 2;
94     const label topEmptyId = patchNames.size() - 1;
96     patchNames[bottomEmptyId] = "bottomEmptyFaces";
97     patchTypes[bottomEmptyId] = "empty";
98     patchNames[topEmptyId] = "topEmptyFaces";
99     patchTypes[topEmptyId] = "empty";
101     labelLongList bndFaceOwner(bndFaces.size());
102     labelLongList bndFacePatch(bndFaces.size());
104     # ifdef USE_OMP
105     # pragma omp parallel for schedule(dynamic, 50)
106     # endif
107     forAll(bndFaces, bfI)
108     {
109         const label faceI = origFaceLabel[bfI];
110         const face& f = faces[faceI];
112         bndFaceOwner[bfI] = owner[faceI];
114         if( !activeFace[faceI] )
115         {
116             if( zMinPoint[f[0]] )
117             {
118                 bndFacePatch[bfI] = bottomEmptyId;
119             }
120             else if( zMaxPoint[f[0]] )
121             {
122                 bndFacePatch[bfI] = topEmptyId;
123             }
124         }
125         else
126         {
127             //- this face is active
128             const point c = f.centre(points);
130             //- find the patch index of the nearest location on the surface mesh
131             point mapPoint;
132             scalar distSq;
133             label patchI, nt;
134             meshOctree_.findNearestSurfacePoint(mapPoint, distSq, nt, patchI, c);
136             bndFacePatch[bfI] = patchI;
137         }
138     }
140     //- replace the boundary
141     polyMeshGenModifier meshModifier(mesh_);
143     meshModifier.replaceBoundary
144     (
145         patchNames,
146         bndFaces,
147         bndFaceOwner,
148         bndFacePatch
149     );
151     //- set correct patch types
152     PtrList<boundaryPatch>& modBnd = meshModifier.boundariesAccess();
153     forAll(patchTypes, patchI)
154         modBnd[patchI].patchType() = patchTypes[patchI];
157 void meshSurfaceEdgeExtractor2D::remapBoundaryPoints()
159     meshSurfaceEngine mse(mesh_);
160     meshSurfaceMapper2D mapper(mse, meshOctree_);
162     mapper.adjustZCoordinates();
164     mapper.mapVerticesOntoSurfacePatches();
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 } // End namespace Foam
171 // ************************************************************************* //