duplicatePoints.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "duplicatePoints.H"
27 #include "localPointRegion.H"
28 #include "polyTopoChange.H"
29 #include "polyMesh.H"
30 #include "OFstream.H"
31 #include "meshTools.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
40 
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 // Construct from mesh
48 :
49  mesh_(mesh),
50  duplicates_(0)
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
57 (
58  const localPointRegion& regionSide,
59  polyTopoChange& meshMod
60 )
61 {
62  const Map<label>& meshPointMap = regionSide.meshPointMap();
63  const labelListList& pointRegions = regionSide.pointRegions();
64  const Map<label>& meshFaceMap = regionSide.meshFaceMap();
65  const faceList& faceRegions = regionSide.faceRegions();
66  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
67 
68  // Create duplicates for points. One for each region.
69  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70 
71  // Per point-to-be-duplicated, in order of the regions the point added.
72  duplicates_.setSize(meshPointMap.size());
73 
74  forAllConstIter(Map<label>, meshPointMap, iter)
75  {
76  label pointi = iter.key();
77  label localI = iter();
78  const labelList& regions = pointRegions[localI];
79 
80  duplicates_[localI].setSize(regions.size());
81  duplicates_[localI][0] = pointi;
82  for (label i = 1; i < regions.size(); i++)
83  {
84  duplicates_[localI][i] = meshMod.addPoint
85  (
86  mesh_.points()[pointi], // point
87  pointi, // master point
88  true // supports a cell
89  );
90  }
91 
92  // Pout<< "For point:" << pointi << " coord:" << mesh_.points()[pointi]
93  // << endl;
94  // forAll(duplicates_[localI], i)
95  //{
96  // Pout<< " region:" << regions[i]
97  // << " addedpoint:" << duplicates_[localI][i]
98  // << endl;
99  //}
100  }
101 
102 
103 
104  // Modify faces according to face region
105  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106 
107  face newFace;
108 
109  forAllConstIter(Map<label>, meshFaceMap, iter)
110  {
111  label facei = iter.key();
112  label localI = iter();
113 
114  // Replace points with duplicated ones.
115  const face& fRegion = faceRegions[localI];
116  const face& f = mesh_.faces()[facei];
117 
118  newFace.setSize(f.size());
119  forAll(f, fp)
120  {
121  label pointi = f[fp];
122 
123  Map<label>::const_iterator iter = meshPointMap.find(pointi);
124 
125  if (iter != meshPointMap.end())
126  {
127  // Point has been duplicated. Find correct one for my
128  // region.
129 
130  // Get the regions and added points for this point
131  const labelList& regions = pointRegions[iter()];
132  const labelList& dupPoints = duplicates_[iter()];
133 
134  // Look up index of my region in the regions for this point
135  label index = findIndex(regions, fRegion[fp]);
136  // Get the corresponding added point
137  newFace[fp] = dupPoints[index];
138  }
139  else
140  {
141  newFace[fp] = pointi;
142  }
143  }
144 
145  if (mesh_.isInternalFace(facei))
146  {
147  meshMod.modifyFace
148  (
149  newFace, // modified face
150  facei, // label of face being modified
151  mesh_.faceOwner()[facei], // owner
152  mesh_.faceNeighbour()[facei], // neighbour
153  false, // face flip
154  -1 // patch for face
155  );
156  }
157  else
158  {
159  meshMod.modifyFace
160  (
161  newFace, // modified face
162  facei, // label of face being modified
163  mesh_.faceOwner()[facei], // owner
164  -1, // neighbour
165  false, // face flip
166  patches.whichPatch(facei) // patch for face
167  );
168  }
169  }
170 
171 
172  if (debug)
173  {
174  // Output duplicated points
175  {
176  OFstream str(mesh_.time().path()/"duplicatedPoints.obj");
177  forAllConstIter(Map<label>, meshPointMap, iter)
178  {
179  label localI = iter();
180  const labelList& dups = duplicates_[localI];
181 
182  forAll(dups, i)
183  {
184  meshTools::writeOBJ(str, meshMod.points()[dups[i]]);
185  }
186  }
187  }
188  }
189 }
190 
191 
193 {
194  forAll(duplicates_, masterI)
195  {
196  inplaceRenumber(map.reversePointMap(), duplicates_[masterI]);
197  }
198 }
199 
200 
201 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
Output to file stream.
Definition: OFstream.H:86
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
Duplicate points.
void setRefinement(const localPointRegion &regionSide, polyTopoChange &)
Play commands into polyTopoChange to duplicate points. Gets.
void topoChange(const polyTopoChangeMap &)
Force recalculation of locally stored data on topological change.
duplicatePoints(const polyMesh &mesh)
Construct from mesh.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Takes mesh with 'baffles' (= boundary faces sharing points). Determines for selected points on bounda...
const Map< label > & meshPointMap() const
Per point that is to be duplicated the local index.
const faceList & faceRegions() const
Per face the region of its points.
const labelListList & pointRegions() const
Per local point the regions it is in.
const Map< label > & meshFaceMap() const
Per face that uses a duplicated point the local index.
Foam::polyBoundaryMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reversePointMap() const
Reverse point map.
Direct mesh changes based on v1.3 polyTopoChange syntax.
const DynamicList< point > & points() const
Points. Shrunk after constructing mesh (or calling of compact())
label addPoint(const point &, const label masterPointID, const bool inCell)
Add point and return new point index.
void modifyFace(const face &f, const label facei, const label own, const label nei, const bool flipFaceFlux, const label patchID)
Modify vertices or cell of face.
const fvPatchList & patches
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
Namespace for OpenFOAM.
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
defineTypeNameAndDebug(combustionModel, 0)
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
labelList f(nPoints)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112