triSurfaceDetectFeatureEdgesFunctions.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "helperFunctions.H"
30 #include "demandDrivenData.H"
31 #include "labelPair.H"
32 
33 # ifdef USE_OMP
34 #include <omp.h>
35 # endif
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
46  const scalar tol = Foam::cos(angleTolerance_*M_PI/180.0);
47 
48  const vectorField& normals = surf_.facetNormals();
49 
50  const VRWGraph& edgeFaces = surf_.edgeFacets();
51 
52  # ifdef USE_OMP
53  # pragma omp parallel for schedule(dynamic, 40)
54  # endif
55  forAll(edgeFaces, edgeI)
56  {
57  const constRow eFaces = edgeFaces[edgeI];
58 
59  if( edgeFaces.sizeOfRow(edgeI) != 2 )
60  {
61  featureEdges_[edgeI] |= 8;
62  continue;
63  }
64 
65  scalar cosAngle =
66  (normals[eFaces[0]] & normals[eFaces[1]]) /
67  (mag(normals[eFaces[0]]) * mag(normals[eFaces[1]]) + VSMALL);
68 
69  //- check the orientation of triangles at this edge
70  //- check the sign of the angle if the orientation is not consistent
71  const labelledTri& tri0 = surf_[edgeFaces(edgeI, 0)];
72  const labelledTri& tri1 = surf_[edgeFaces(edgeI, 1)];
73  DynList<labelPair> sharedIndices;
74  forAll(tri0, i)
75  {
76  forAll(tri1, j)
77  {
78  if( tri0[i] == tri1[j] )
79  sharedIndices.append(labelPair(i, j));
80  }
81  }
82 
83  if( sharedIndices.size() == 2 )
84  {
85  const labelPair& pair0 = sharedIndices[0];
86  const labelPair& pair1 = sharedIndices[1];
87  if( ((pair0.first() + 1) % 3) == pair1.first() )
88  {
89  if( (pair0.second() + 1) % 3 == pair1.second() )
90  cosAngle *= -1.0;
91  }
92  else
93  {
94  if( (pair1.second() + 1) % 3 == pair0.second() )
95  cosAngle *= -1.0;
96  }
97  }
98 
99  if( cosAngle < tol )
100  featureEdges_[edgeI] |= 1;
101  }
102 }
103 
104 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 
106 } // End namespace Foam
107 
108 // ************************************************************************* //
Foam::triSurfAddressing::facetNormals
const vectorField & facetNormals() const
return normals of facets
Definition: triSurfAddressingI.H:170
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
triSurfaceDetectFeatureEdges.H
Foam::Pair::first
const Type & first() const
Return first.
Definition: Pair.H:87
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::triSurfaceDetectFeatureEdges::featureEdges_
List< direction > featureEdges_
detected feature edges
Definition: triSurfaceDetectFeatureEdges.H:57
Foam::triSurfaceDetectFeatureEdges::detectFeatureEdgesAngleCriterion
void detectFeatureEdgesAngleCriterion()
Definition: triSurfaceDetectFeatureEdgesFunctions.C:44
Foam::constRow
const typedef graphRow< const VRWGraph > constRow
Definition: graphRow.H:134
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Pair::second
const Type & second() const
Return second.
Definition: Pair.H:99
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList
Definition: DynList.H:53
Foam::triSurfaceDetectFeatureEdges::angleTolerance_
scalar angleTolerance_
angle tolerance
Definition: triSurfaceDetectFeatureEdges.H:60
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
helperFunctions.H
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::triSurfaceDetectFeatureEdges::surf_
triSurf & surf_
reference to triSurf
Definition: triSurfaceDetectFeatureEdges.H:54
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurfAddressing::edgeFacets
const VRWGraph & edgeFacets() const
return edge-facets addressing
Definition: triSurfAddressingI.H:97
Foam::labelPair
Pair< label > labelPair
Label pair.
Definition: labelPair.H:48
labelPair.H
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256