mapDistributePolyMesh.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) 2015-2018 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 "mapDistributePolyMesh.H"
30 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::mapDistributePolyMesh::calcPatchSizes()
35 {
36  oldPatchSizes_.setSize(oldPatchStarts_.size());
37 
38  if (oldPatchStarts_.size())
39  {
40  // Calculate old patch sizes
41  for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++)
42  {
43  oldPatchSizes_[patchi] =
44  oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi];
45  }
46 
47  // Set the last one by hand
48  const label lastPatchID = oldPatchStarts_.size() - 1;
49 
50  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
51 
52  if (min(oldPatchSizes_) < 0)
53  {
55  << "Calculated negative old patch size:" << oldPatchSizes_ << nl
56  << "Error in mapping data" << abort(FatalError);
57  }
58  }
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
65 :
66  nOldPoints_(0),
67  nOldFaces_(0),
68  nOldCells_(0),
69  oldPatchSizes_(0),
70  oldPatchStarts_(0),
71  oldPatchNMeshPoints_(0),
72  pointMap_(),
73  faceMap_(),
74  cellMap_(),
75  patchMap_()
76 {}
77 
78 
80 (
82 )
83 :
85 {
86  transfer(map);
87 }
88 
89 
91 (
92  const polyMesh& mesh,
93 
94  // mesh before changes
95  const label nOldPoints,
96  const label nOldFaces,
97  const label nOldCells,
98  labelList&& oldPatchStarts,
99  labelList&& oldPatchNMeshPoints,
100 
101  // how to subset pieces of mesh to send across
102  labelListList&& subPointMap,
103  labelListList&& subFaceMap,
104  labelListList&& subCellMap,
105  labelListList&& subPatchMap,
106 
107  // how to reconstruct received mesh
108  labelListList&& constructPointMap,
109  labelListList&& constructFaceMap,
110  labelListList&& constructCellMap,
111  labelListList&& constructPatchMap,
112 
113  const bool subFaceHasFlip,
114  const bool constructFaceHasFlip
115 )
116 :
117  nOldPoints_(nOldPoints),
118  nOldFaces_(nOldFaces),
119  nOldCells_(nOldCells),
120  oldPatchSizes_(oldPatchStarts.size()),
121  oldPatchStarts_(std::move(oldPatchStarts)),
122  oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
123  pointMap_
124  (
125  mesh.nPoints(),
126  std::move(subPointMap),
127  std::move(constructPointMap)
128  ),
129  faceMap_
130  (
131  mesh.nFaces(),
132  std::move(subFaceMap),
133  std::move(constructFaceMap),
134  subFaceHasFlip,
135  constructFaceHasFlip
136  ),
137  cellMap_
138  (
139  mesh.nCells(),
140  std::move(subCellMap),
141  std::move(constructCellMap)
142  ),
143  patchMap_
144  (
145  mesh.boundaryMesh().size(),
146  std::move(subPatchMap),
147  std::move(constructPatchMap)
148  )
149 {
150  calcPatchSizes();
151 }
152 
153 
155 (
156  // mesh before changes
157  const label nOldPoints,
158  const label nOldFaces,
159  const label nOldCells,
160  labelList&& oldPatchStarts,
161  labelList&& oldPatchNMeshPoints,
162 
163  // how to transfer pieces of mesh
164  mapDistribute&& pointMap,
166  mapDistribute&& cellMap,
167  mapDistribute&& patchMap
168 )
169 :
170  nOldPoints_(nOldPoints),
171  nOldFaces_(nOldFaces),
172  nOldCells_(nOldCells),
173  oldPatchSizes_(oldPatchStarts.size()),
174  oldPatchStarts_(std::move(oldPatchStarts)),
175  oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
176  pointMap_(std::move(pointMap)),
177  faceMap_(std::move(faceMap)),
178  cellMap_(std::move(cellMap)),
179  patchMap_(std::move(patchMap))
180 {
181  calcPatchSizes();
182 }
183 
184 
186 {
187  is >> *this;
188 }
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
194 {
195  nOldPoints_ = rhs.nOldPoints_;
196  nOldFaces_ = rhs.nOldFaces_;
197  nOldCells_ = rhs.nOldCells_;
198  oldPatchSizes_.transfer(rhs.oldPatchSizes_);
199  oldPatchStarts_.transfer(rhs.oldPatchStarts_);
200  oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_);
201  pointMap_.transfer(rhs.pointMap_);
202  faceMap_.transfer(rhs.faceMap_);
203  cellMap_.transfer(rhs.cellMap_);
204  patchMap_.transfer(rhs.patchMap_);
205 
206  rhs.nOldPoints_ = 0;
207  rhs.nOldFaces_ = 0;
208  rhs.nOldCells_ = 0;
209 }
210 
211 
213 {
214  // Construct boolList from selected elements
215  boolList isSelected
216  (
217  ListOps::createWithValue<bool>(nOldPoints(), lst, true, false)
218  );
219 
220  // Distribute
221  distributePointData(isSelected);
222 
223  // Collect selected elements
224  lst = findIndices(isSelected, true);
225 }
226 
227 
229 {
230  // Construct boolList from selected elements
231  boolList isSelected
232  (
233  ListOps::createWithValue<bool>(nOldFaces(), lst, true, false)
234  );
235 
236  // Distribute
237  distributeFaceData(isSelected);
238 
239  // Collect selected elements
240  lst = findIndices(isSelected, true);
241 }
242 
243 
245 {
246  // Construct boolList from selected elements
247  boolList isSelected
248  (
249  ListOps::createWithValue<bool>(nOldCells(), lst, true, false)
250  );
251 
252  // Distribute
253  distributeCellData(isSelected);
254 
255  // Collect selected elements
256  lst = findIndices(isSelected, true);
257 }
258 
259 
261 {
262  // Construct boolList from selected elements
263  boolList isSelected
264  (
265  ListOps::createWithValue<bool>
266  (
267  oldPatchStarts().size(), // nOldPatches
268  lst,
269  true, // set value
270  false // default value
271  )
272  );
273 
274  // Distribute
275  distributePatchData(isSelected);
276 
277  // Collect selected elements
278  lst = findIndices(isSelected, true);
279 }
280 
281 
282 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
283 
285 {
286  nOldPoints_ = rhs.nOldPoints_;
287  nOldFaces_ = rhs.nOldFaces_;
288  nOldCells_ = rhs.nOldCells_;
289  oldPatchSizes_ = rhs.oldPatchSizes_;
290  oldPatchStarts_ = rhs.oldPatchStarts_;
291  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
292  pointMap_ = rhs.pointMap_;
293  faceMap_ = rhs.faceMap_;
294  cellMap_ = rhs.cellMap_;
295  patchMap_ = rhs.patchMap_;
296 }
297 
298 
300 {
301  transfer(rhs);
302 }
303 
304 
305 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
306 
308 {
310 
311  is >> map.nOldPoints_
312  >> map.nOldFaces_
313  >> map.nOldCells_
314  >> map.oldPatchSizes_
315  >> map.oldPatchStarts_
316  >> map.oldPatchNMeshPoints_
317  >> map.pointMap_
318  >> map.faceMap_
319  >> map.cellMap_
320  >> map.patchMap_;
321 
322  return is;
323 }
324 
325 
326 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
327 
329 {
330  os << map.nOldPoints_
331  << token::SPACE << map.nOldFaces_
332  << token::SPACE << map.nOldCells_ << token::NL
333  << map.oldPatchSizes_ << token::NL
334  << map.oldPatchStarts_ << token::NL
335  << map.oldPatchNMeshPoints_ << token::NL
336  << map.pointMap_ << token::NL
337  << map.faceMap_ << token::NL
338  << map.cellMap_ << token::NL
339  << map.patchMap_;
340 
341  return os;
342 }
343 
344 
345 // ************************************************************************* //
Foam::mapDistributePolyMesh::distributePointIndices
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
Definition: mapDistributePolyMesh.C:212
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::mapDistributePolyMesh::mapDistributePolyMesh
mapDistributePolyMesh()
Construct null.
Definition: mapDistributePolyMesh.C:64
Foam::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
Foam::mapDistributePolyMesh::transfer
void transfer(mapDistributePolyMesh &map)
Transfer the contents of the argument and annul the argument.
Definition: mapDistributePolyMesh.C:193
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
polyMesh.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
Foam::mapDistributePolyMesh::operator=
void operator=(const mapDistributePolyMesh &map)
Copy assignment.
Definition: mapDistributePolyMesh.C:284
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
mapDistributePolyMesh.H
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
Foam::mapDistributePolyMesh::distributeFaceIndices
void distributeFaceIndices(labelList &faceIDs) const
Definition: mapDistributePolyMesh.C:228
Foam::token::NL
Newline [isspace].
Definition: token.H:124
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::mapDistributePolyMesh::distributeCellIndices
void distributeCellIndices(labelList &cellIDs) const
Definition: mapDistributePolyMesh.C:244
Foam::findIndices
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
Foam::primitiveMesh::nFaces
label nFaces() const noexcept
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::mapDistributePolyMesh::distributePatchIndices
void distributePatchIndices(labelList &patchIDs) const
Definition: mapDistributePolyMesh.C:260
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:66