Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / boundaryLayers / triangulateNonPlanarBaseFaces / triangulateNonPlanarBaseFacesFunctions.C
blob4bc46cdb9a0ef84b51da07ef6ea2b757ed78d975
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 "triangulateNonPlanarBaseFaces.H"
29 #include "decomposeFaces.H"
30 #include "decomposeCells.H"
31 #include "helperFunctions.H"
32 #include "meshSurfacePartitioner.H"
33 #include "triangle.H"
35 # ifdef USE_OMP
36 #include <omp.h>
37 # endif
39 //#define DEBUGLayer
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 bool triangulateNonPlanarBaseFaces::findNonPlanarBoundaryFaces()
50     const pointFieldPMG& points = mesh_.points();
51     const label nInternalFaces = mesh_.nInternalFaces();
53     meshSurfacePartitioner mPart(mesh_);
54     const meshSurfaceEngine& mse = mPart.surfaceEngine();
55     const labelList& faceOwner = mse.faceOwners();
56     const faceList::subList& bFaces = mse.boundaryFaces();
58     bool hasInvalid(false);
60     # ifdef USE_OMP
61     # pragma omp parallel for schedule(dynamic, 50)
62     # endif
63     forAll(bFaces, bfI)
64     {
65         const face& bf = bFaces[bfI];
67         //- triangle shall not be decomposed, they are flat
68         if( bf.size() == 3 )
69             continue;
71         //- calculate min face diagonal
72         scalar minDist(VGREAT);
73         const point c = bf.centre(points);
74         forAll(bf, pI)
75         {
76             minDist = Foam::min(minDist, Foam::mag(c - points[bf[pI]]));
77         }
79         forAll(bf, eI)
80         {
81             triangle<point, point> tri
82             (
83                 points[bf[eI]],
84                 points[bf.nextLabel(eI)],
85                 c
86             );
88             const point triCentre = tri.centre();
89             vector n = tri.normal();
90             n /= (mag(n) + VSMALL);
92             forAll(bf, pI)
93             {
94                 const scalar d = (points[bf[pI]] - triCentre) & n;
96                 if( d > tol_ * minDist )
97                 {
98                     invertedCell_[faceOwner[bfI]] = true;
100                     decomposeFace_[nInternalFaces+bfI] = true;
101                     hasInvalid = true;
102                 }
103             }
104         }
105     }
107     reduce(hasInvalid, maxOp<bool>());
109     return hasInvalid;
112 void triangulateNonPlanarBaseFaces::decomposeBoundaryFaces()
114     //- decompose base faces into triangles
115     decomposeFaces triangulator(mesh_);
116     triangulator.decomposeMeshFaces(decomposeFace_);
117     const VRWGraph& newFacesFromFace = triangulator.newFacesForFace();
119     //- update face subsets
120     mesh_.updateFaceSubsets(newFacesFromFace);
123 void triangulateNonPlanarBaseFaces::decomposeCellsIntoPyramids()
125     decomposeCells sc(mesh_);
126     sc.decomposeMesh(invertedCell_);
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 } // End namespace Foam
133 // ************************************************************************* //