meshSurfaceEdgeExtractor2DDistributeFaces.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"
30 #include "meshOctree.H"
31 #include "triSurf.H"
32 #include "meshSurfaceEngine.H"
33 #include "meshSurfaceMapper2D.H"
34 #include "polyMeshGen2DEngine.H"
35 #include "helperFunctions.H"
36 
37 # ifdef USE_OMP
38 #include <omp.h>
39 # endif
40 
41 //#define DEBUGMapping
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
51 {
52  polyMeshGen2DEngine mesh2DEngine(mesh_);
53  const boolList& activeFace = mesh2DEngine.activeFace();
54  const boolList& zMinPoint = mesh2DEngine.zMinPoints();
55  const boolList& zMaxPoint = mesh2DEngine.zMaxPoints();
56 
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();
61 
62  const triSurf& surf = meshOctree_.surface();
63  const geometricSurfacePatchList& surfPatches = surf.patches();
64 
65  //- copy boundary faces and their owner face
66  VRWGraph bndFaces;
67  labelLongList origFaceLabel;
68 
69  forAll(boundaries, patchI)
70  {
71  const label start = boundaries[patchI].patchStart();
72  const label size = boundaries[patchI].patchSize();
73 
74  for(label fI=0;fI<size;++fI)
75  {
76  const label faceI = start + fI;
77  const face& bf = faces[faceI];
78 
79  bndFaces.appendList(bf);
80  origFaceLabel.append(faceI);
81  }
82  }
83 
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  }
92 
93  const label bottomEmptyId = patchNames.size() - 2;
94  const label topEmptyId = patchNames.size() - 1;
95 
96  patchNames[bottomEmptyId] = "bottomEmptyFaces";
97  patchTypes[bottomEmptyId] = "empty";
98  patchNames[topEmptyId] = "topEmptyFaces";
99  patchTypes[topEmptyId] = "empty";
100 
101  labelLongList bndFaceOwner(bndFaces.size());
102  labelLongList bndFacePatch(bndFaces.size());
103 
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];
111 
112  bndFaceOwner[bfI] = owner[faceI];
113 
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);
129 
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);
135 
136  bndFacePatch[bfI] = patchI;
137  }
138  }
139 
140  //- replace the boundary
141  polyMeshGenModifier meshModifier(mesh_);
142 
143  meshModifier.replaceBoundary
144  (
145  patchNames,
146  bndFaces,
147  bndFaceOwner,
148  bndFacePatch
149  );
150 
151  //- set correct patch types
152  PtrList<boundaryPatch>& modBnd = meshModifier.boundariesAccess();
153  forAll(patchTypes, patchI)
154  modBnd[patchI].patchType() = patchTypes[patchI];
155 }
156 
158 {
160  meshSurfaceMapper2D mapper(mse, meshOctree_);
161 
162  mapper.adjustZCoordinates();
163 
165 }
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 } // End namespace Foam
170 
171 // ************************************************************************* //
Foam::polyMeshGenFaces::owner
const labelList & owner() const
owner and neighbour cells for faces
Definition: polyMeshGenFacesI.H:67
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
triSurf.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshSurfaceEdgeExtractor2D::mesh_
polyMeshGen & mesh_
mesh
Definition: meshSurfaceEdgeExtractor2D.H:57
Foam::polyMeshGen2DEngine::activeFace
const boolList & activeFace() const
const access to active faces
Definition: polyMeshGen2DEngineI.H:48
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOctree::findNearestSurfacePoint
void findNearestSurfacePoint(point &nearest, scalar &distSq, label &nearestTriangle, label &region, const point &p) const
find nearest surface point for vertex and its region
Definition: meshOctreeFindNearestSurfacePoint.C:44
Foam::polyMeshGenModifier::replaceBoundary
void replaceBoundary(const wordList &patchNames, const VRWGraph &boundaryFaces, const labelLongList &faceOwners, const labelLongList &facePatches)
replace the boundary with new boundary faces
Definition: polyMeshGenModifierReplaceBoundary.C:42
Foam::polyMeshGenPoints::points
const pointFieldPMG & points() const
access to points
Definition: polyMeshGenPointsI.H:44
Foam::polyMeshGen2DEngine::zMinPoints
const boolList & zMinPoints() const
Definition: polyMeshGen2DEngineI.H:64
meshOctree.H
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
patchTypes
wordList patchTypes(nPatches)
Foam::polyMeshGenModifier::boundariesAccess
PtrList< boundaryPatch > & boundariesAccess()
access to boundary data
Definition: polyMeshGenModifier.H:131
Foam::LongList< label >
meshSurfaceEdgeExtractor2D.H
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::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
Foam::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::meshSurfaceEdgeExtractor2D::remapBoundaryPoints
void remapBoundaryPoints()
re-map points after edges have been extracted
Definition: meshSurfaceEdgeExtractor2DDistributeFaces.C:157
patchNames
wordList patchNames(nPatches)
Foam::polyMeshGen2DEngine::zMaxPoints
const boolList & zMaxPoints() const
Definition: polyMeshGen2DEngineI.H:88
Foam::meshSurfaceMapper2D
Definition: meshSurfaceMapper2D.H:62
polyMeshGen2DEngine.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
meshSurfaceEngine.H
Foam::polyMeshGenModifier
Definition: polyMeshGenModifier.H:52
Foam::meshSurfaceMapper2D::mapVerticesOntoSurfacePatches
void mapVerticesOntoSurfacePatches()
Definition: meshSurfaceMapper2DMapVertices.C:490
Foam::polyMeshGen2DEngine
Definition: polyMeshGen2DEngine.H:51
helperFunctions.H
f
labelList f(nPoints)
Foam::VRWGraph::appendList
void appendList(const ListType &l)
Append a list as a row at the end of the graph.
Definition: VRWGraphI.H:286
Foam::Vector< scalar >
Foam::polyMeshGenFaces::boundaries
const PtrList< boundaryPatch > & boundaries() const
ordinary boundaries
Definition: polyMeshGenFacesI.H:111
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
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::meshOctree::surface
const triSurf & surface() const
return a reference to the surface
Definition: meshOctreeI.H:130
Foam::meshSurfaceEdgeExtractor2D::meshOctree_
const meshOctree & meshOctree_
octree
Definition: meshSurfaceEdgeExtractor2D.H:60
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::triSurf
Definition: triSurf.H:59
Foam::meshSurfaceEngine
Definition: meshSurfaceEngine.H:54
Foam::meshSurfaceMapper2D::adjustZCoordinates
void adjustZCoordinates()
adjust z coordinates of the mesh to the ones in the surface mesh
Definition: meshSurfaceMapper2DMapVertices.C:219
meshSurfaceMapper2D.H
Foam::meshSurfaceEdgeExtractor2D::distributeBoundaryFaces
void distributeBoundaryFaces()
distribute boundary faces into patches
Definition: meshSurfaceEdgeExtractor2DDistributeFaces.C:50