duplicatePoints.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "duplicatePoints.H"
30 #include "localPointRegion.H"
31 #include "polyTopoChange.H"
32 #include "polyAddPoint.H"
33 #include "polyModifyFace.H"
34 #include "polyMesh.H"
35 #include "OFstream.H"
36 #include "meshTools.H"
37 #include "Time.H"
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(duplicatePoints, 0);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 // Construct from mesh
50 Foam::duplicatePoints::duplicatePoints(const polyMesh& mesh)
51 :
52  mesh_(mesh),
53  duplicates_(0)
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
60 (
62  polyTopoChange& meshMod
63 )
64 {
65  const Map<label>& meshPointMap = regionSide.meshPointMap();
66  const labelListList& pointRegions = regionSide.pointRegions();
67  const Map<label>& meshFaceMap = regionSide.meshFaceMap();
68  const faceList& faceRegions = regionSide.faceRegions();
69  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
70 
71  // Create duplicates for points. One for each region.
72  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 
74  // Per point-to-be-duplicated, in order of the regions the point added.
75  duplicates_.setSize(meshPointMap.size());
76 
77  forAllConstIters(meshPointMap, iter)
78  {
79  const label pointi = iter.key();
80  const label localI = iter.val();
81  const labelList& regions = pointRegions[localI];
82 
83  duplicates_[localI].setSize(regions.size());
84  duplicates_[localI][0] = pointi;
85  for (label i = 1; i < regions.size(); i++)
86  {
87  duplicates_[localI][i] = meshMod.addPoint
88  (
89  mesh_.points()[pointi], // point
90  pointi, // master point
91  -1, // zone for point
92  true // supports a cell
93  );
94  }
95 
96  //Pout<< "For point:" << pointi << " coord:" << mesh_.points()[pointi]
97  // << endl;
98  //forAll(duplicates_[localI], i)
99  //{
100  // Pout<< " region:" << regions[i]
101  // << " addedpoint:" << duplicates_[localI][i]
102  // << endl;
103  //}
104  }
105 
106 
107 
108  // Modfify faces according to face region
109  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 
111  face newFace;
112 
113  forAllConstIters(meshFaceMap, iter)
114  {
115  const label facei = iter.key();
116  const label localI = iter.val();
117 
118  // Replace points with duplicated ones.
119  const face& fRegion = faceRegions[localI];
120  const face& f = mesh_.faces()[facei];
121 
122  newFace.setSize(f.size());
123  forAll(f, fp)
124  {
125  label pointi = f[fp];
126 
127  Map<label>::const_iterator iter = meshPointMap.find(pointi);
128 
129  if (iter != meshPointMap.end())
130  {
131  // Point has been duplicated. Find correct one for my
132  // region.
133 
134  // Get the regions and added points for this point
135  const labelList& regions = pointRegions[iter()];
136  const labelList& dupPoints = duplicates_[iter()];
137 
138  // Look up index of my region in the regions for this point
139  label index = regions.find(fRegion[fp]);
140  // Get the corresponding added point
141  newFace[fp] = dupPoints[index];
142  }
143  else
144  {
145  newFace[fp] = pointi;
146  }
147  }
148 
149  // Get current zone info
150  label zoneID = mesh_.faceZones().whichZone(facei);
151  bool zoneFlip = false;
152  if (zoneID >= 0)
153  {
154  const faceZone& fZone = mesh_.faceZones()[zoneID];
155  zoneFlip = fZone.flipMap()[fZone.whichFace(facei)];
156  }
157 
158 
159  if (mesh_.isInternalFace(facei))
160  {
161  meshMod.modifyFace
162  (
163  newFace, // modified face
164  facei, // label of face being modified
165  mesh_.faceOwner()[facei], // owner
166  mesh_.faceNeighbour()[facei], // neighbour
167  false, // face flip
168  -1, // patch for face
169  zoneID, // zone for face
170  zoneFlip // face flip in zone
171  );
172  }
173  else
174  {
175  meshMod.modifyFace
176  (
177  newFace, // modified face
178  facei, // label of face being modified
179  mesh_.faceOwner()[facei], // owner
180  -1, // neighbour
181  false, // face flip
182  patches.whichPatch(facei), // patch for face
183  zoneID, // zone for face
184  zoneFlip // face flip in zone
185  );
186  }
187  }
188 
189 
190  if (debug)
191  {
192  // Output duplicated points
193  {
194  OFstream str(mesh_.time().path()/"duplicatedPoints.obj");
195  forAllConstIters(meshPointMap, iter)
196  {
197  const label localI = iter.val();
198  const labelList& dups = duplicates_[localI];
199 
200  forAll(dups, i)
201  {
202  meshTools::writeOBJ(str, meshMod.points()[dups[i]]);
203  }
204  }
205  }
206  }
207 }
208 
209 
211 {
212  forAll(duplicates_, masterI)
213  {
214  inplaceRenumber(map.reversePointMap(), duplicates_[masterI]);
215  }
216 }
217 
218 
219 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
meshTools.H
Foam::localPointRegion
Takes mesh with 'baffles' (= boundary faces sharing points). Determines for selected points on bounda...
Definition: localPointRegion.H:69
Foam::duplicatePoints::updateMesh
void updateMesh(const mapPolyMesh &)
Force recalculation of locally stored data on topological change.
Definition: duplicatePoints.C:210
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::polyTopoChange::points
const DynamicList< point > & points() const
Points. Shrunk after constructing mesh (or calling of compact())
Definition: polyTopoChange.H:448
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
polyTopoChange.H
localPointRegion.H
Foam::polyTopoChange::addPoint
label addPoint(const point &pt, const label masterPointID, const label zoneID, const bool inCell)
Add point. Return new point label.
Definition: polyTopoChange.C:2587
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:100
Foam::Map< label >
polyMesh.H
Foam::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
Definition: ListOpsTemplates.C:61
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
OFstream.H
duplicatePoints.H
Foam::regionSide
Determines the 'side' for every face and connected to a singly-connected (through edges) region of fa...
Definition: regionSide.H:63
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:62
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Foam::polyTopoChange::modifyFace
void modifyFace(const face &f, const label facei, const label own, const label nei, const bool flipFaceFlux, const label patchID, const label zoneID, const bool zoneFlip)
Modify vertices or cell of face.
Definition: polyTopoChange.C:2788
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrListI.H:108
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:805
polyAddPoint.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::faceZone::whichFace
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:388
polyModifyFace.H
Foam::duplicatePoints::setRefinement
void setRefinement(const localPointRegion &regionSide, polyTopoChange &)
Play commands into polyTopoChange to duplicate points. Gets.
Definition: duplicatePoints.C:60
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Time.H
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
f
labelList f(nPoints)
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:468
Foam::List< labelList >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::faceZone::flipMap
const boolList & flipMap() const
Return face flip map.
Definition: faceZone.H:271
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)