partTriMeshAddressing.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 
28 #include "demandDrivenData.H"
29 #include "meshSurfacePartitioner.H"
30 #include "partTriMesh.H"
31 #include "meshSurfaceEngine.H"
32 #include "triSurfModifier.H"
33 
34 //#define DEBUGSmooth
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
44 (
45  const List<direction>& useFace
46 )
47 {
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();
55 
56  meshSurfacePointLabelInTriMesh_.setSize(bPoints.size());
57  meshSurfacePointLabelInTriMesh_ = -1;
58  labelList nodeLabelForFace(bFaces.size(), -1);
59 
60  label nTriPoints(0);
61  forAll(bFaces, bfI)
62  {
63  if( useFace[bfI] )
64  {
65  const face& bf = bFaces[bfI];
66 
67  //- create a point in the face centre
68  if( bf.size() > 3 )
69  nodeLabelForFace[bfI] = nTriPoints++;
70 
71  //- create points at face points
72  forAll(bf, pI)
73  {
74  const label bpI = bp[bf[pI]];
75 
76  if( meshSurfacePointLabelInTriMesh_[bpI] == -1 )
77  meshSurfacePointLabelInTriMesh_[bpI] = nTriPoints++;
78  }
79 
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  );
93 
94  surf_.appendTriangle(tri);
95 
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  );
104 
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  );
118 
119  surf_.appendTriangle(tri);
120 
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  );
131 
132  surf_.appendTriangle(secondTri);
133  }
134  }
135  }
136  }
137 
138  //- add points
139  triSurfModifier sMod(surf_);
140  pointField& pts = sMod.pointsAccess();
141  pts.setSize(nTriPoints);
142 
143  pointType_.setSize(nTriPoints);
144  pointType_ = NONE;
145 
146  pointLabelInMeshSurface_.setSize(pts.size());
147  pointLabelInMeshSurface_ = -1;
148 
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  }
157 
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  }
165 
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;
170 
171  forAllConstIter(labelHashSet, mPart_.edgePoints(), it)
172  {
173  const label pI = meshSurfacePointLabelInTriMesh_[it.key()];
174  if( pI != -1 )
175  pointType_[pI] |= FEATUREEDGE;
176  }
177 
178  //- create addressing for parallel runs
179  if( Pstream::parRun() )
180  {
181  createParallelAddressing
182  (
183  meshSurfacePointLabelInTriMesh_,
184  nodeLabelForFace
185  );
186 
187  createBufferLayers();
188  }
189 
190  //- calculate point facets addressing
191  surf_.pointFacets();
192 }
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 } // End namespace Foam
197 
198 // ************************************************************************* //
Foam::meshSurfaceEngine::faceCentres
const vectorField & faceCentres() const
Definition: meshSurfaceEngineI.H:277
Foam::meshSurfaceEngine::bp
const labelList & bp() const
Definition: meshSurfaceEngineI.H:64
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.
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
triSurfModifier.H
Foam::triSurfModifier
Definition: triSurfModifier.H:48
Foam::HashSet< label, Hash< label > >
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::meshSurfaceEngine::boundaryFaces
const faceList::subList & boundaryFaces() const
Definition: meshSurfaceEngineI.H:103
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurfModifier::pointsAccess
pointField & pointsAccess()
non-const access to points
Definition: triSurfModifierI.H:37
Foam::meshSurfaceEngine::points
const pointFieldPMG & points() const
Definition: meshSurfaceEngineI.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::partTriMesh::createPointsAndTrias
void createPointsAndTrias(const List< direction > &)
create surface triangulation
Definition: partTriMeshAddressing.C:44
Foam::face::prevLabel
label prevLabel(const label i) const
Previous vertex on face.
Definition: faceI.H:124
Foam::face::nextLabel
label nextLabel(const label i) const
Next vertex on face.
Definition: faceI.H:117
Foam::List< direction >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::meshSurfaceEngine::boundaryPoints
const labelList & boundaryPoints() const
Definition: meshSurfaceEngineI.H:84
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
partTriMesh.H
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
meshSurfacePartitioner.H