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 Foam::duplicatePoints::duplicatePoints(const polyMesh& mesh)
50 :
51  mesh_(mesh),
52  duplicates_(0)
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57 
59 (
61  polyTopoChange& meshMod
62 )
63 {
64  const Map<label>& meshPointMap = regionSide.meshPointMap();
65  const labelListList& pointRegions = regionSide.pointRegions();
66  const Map<label>& meshFaceMap = regionSide.meshFaceMap();
67  const faceList& faceRegions = regionSide.faceRegions();
68  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
69 
70  // Create duplicates for points. One for each region.
71  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72 
73  // Per point-to-be-duplicated, in order of the regions the point added.
74  duplicates_.setSize(meshPointMap.size());
75 
76  forAllConstIters(meshPointMap, iter)
77  {
78  const label pointi = iter.key();
79  const label localI = iter.val();
80  const labelList& regions = pointRegions[localI];
81 
82  duplicates_[localI].setSize(regions.size());
83  duplicates_[localI][0] = pointi;
84  for (label i = 1; i < regions.size(); i++)
85  {
86  duplicates_[localI][i] = meshMod.addPoint
87  (
88  mesh_.points()[pointi], // point
89  pointi, // master point
90  -1, // zone for point
91  true // supports a cell
92  );
93  }
94 
95  //Pout<< "For point:" << pointi << " coord:" << mesh_.points()[pointi]
96  // << endl;
97  //forAll(duplicates_[localI], i)
98  //{
99  // Pout<< " region:" << regions[i]
100  // << " addedpoint:" << duplicates_[localI][i]
101  // << endl;
102  //}
103  }
104 
105 
106 
107  // Modfify faces according to face region
108  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 
110  face newFace;
111 
112  forAllConstIters(meshFaceMap, iter)
113  {
114  const label facei = iter.key();
115  const label localI = iter.val();
116 
117  // Replace points with duplicated ones.
118  const face& fRegion = faceRegions[localI];
119  const face& f = mesh_.faces()[facei];
120 
121  newFace.setSize(f.size());
122  forAll(f, fp)
123  {
124  label pointi = f[fp];
125 
126  Map<label>::const_iterator iter = meshPointMap.find(pointi);
127 
128  if (iter != meshPointMap.end())
129  {
130  // Point has been duplicated. Find correct one for my
131  // region.
132 
133  // Get the regions and added points for this point
134  const labelList& regions = pointRegions[iter()];
135  const labelList& dupPoints = duplicates_[iter()];
136 
137  // Look up index of my region in the regions for this point
138  label index = regions.find(fRegion[fp]);
139  // Get the corresponding added point
140  newFace[fp] = dupPoints[index];
141  }
142  else
143  {
144  newFace[fp] = pointi;
145  }
146  }
147 
148  // Get current zone info
149  label zoneID = mesh_.faceZones().whichZone(facei);
150  bool zoneFlip = false;
151  if (zoneID >= 0)
152  {
153  const faceZone& fZone = mesh_.faceZones()[zoneID];
154  zoneFlip = fZone.flipMap()[fZone.whichFace(facei)];
155  }
156 
157 
158  if (mesh_.isInternalFace(facei))
159  {
160  meshMod.modifyFace
161  (
162  newFace, // modified face
163  facei, // label of face being modified
164  mesh_.faceOwner()[facei], // owner
165  mesh_.faceNeighbour()[facei], // neighbour
166  false, // face flip
167  -1, // patch for face
168  zoneID, // zone for face
169  zoneFlip // face flip in zone
170  );
171  }
172  else
173  {
174  meshMod.modifyFace
175  (
176  newFace, // modified face
177  facei, // label of face being modified
178  mesh_.faceOwner()[facei], // owner
179  -1, // neighbour
180  false, // face flip
181  patches.whichPatch(facei), // patch for face
182  zoneID, // zone for face
183  zoneFlip // face flip in zone
184  );
185  }
186  }
187 
188 
189  if (debug)
190  {
191  // Output duplicated points
192  {
193  OFstream str(mesh_.time().path()/"duplicatedPoints.obj");
194  forAllConstIters(meshPointMap, iter)
195  {
196  const label localI = iter.val();
197  const labelList& dups = duplicates_[localI];
198 
199  forAll(dups, i)
200  {
201  meshTools::writeOBJ(str, meshMod.points()[dups[i]]);
202  }
203  }
204  }
205  }
206 }
207 
208 
210 {
211  forAll(duplicates_, masterI)
212  {
213  inplaceRenumber(map.reversePointMap(), duplicates_[masterI]);
214  }
215 }
216 
217 
218 // ************************************************************************* //
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:209
Foam::faceZone::flipMap
const boolList & flipMap() const noexcept
Return face flip map.
Definition: faceZone.H:272
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::polyTopoChange::points
const DynamicList< point > & points() const
Points. Shrunk after constructing mesh (or calling of compact())
Definition: polyTopoChange.H:450
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:2610
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
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:296
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::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
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:2811
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:151
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:812
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:372
polyModifyFace.H
Foam::duplicatePoints::setRefinement
void setRefinement(const localPointRegion &regionSide, polyTopoChange &)
Play commands into polyTopoChange to duplicate points. Gets.
Definition: duplicatePoints.C:59
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
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:469
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:161
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)