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-2022 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_.resize_nocopy(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 :
67 {}
68 
69 
71 :
72  nOldPoints_(0),
73  nOldFaces_(0),
74  nOldCells_(0),
75  oldPatchSizes_(),
76  oldPatchStarts_(),
77  oldPatchNMeshPoints_(),
78  pointMap_(comm),
79  faceMap_(comm),
80  cellMap_(comm),
81  patchMap_(comm)
82 {}
83 
84 
86 (
87  const mapDistributePolyMesh& map
88 )
89 :
91 {
92  deepCopy(map);
93 }
94 
95 
97 (
99 )
100 :
102 {
103  transfer(map);
104 }
105 
106 
108 (
110  bool reuse
111 )
112 :
114 {
115  if (reuse)
116  {
117  transfer(map);
118  }
119  else
120  {
121  deepCopy(map);
122  }
123 }
124 
125 
127 (
128  const polyMesh& mesh,
129 
130  // mesh before changes
131  const label nOldPoints,
132  const label nOldFaces,
133  const label nOldCells,
134  labelList&& oldPatchStarts,
135  labelList&& oldPatchNMeshPoints,
136 
137  // how to subset pieces of mesh to send across
138  labelListList&& subPointMap,
139  labelListList&& subFaceMap,
140  labelListList&& subCellMap,
141  labelListList&& subPatchMap,
142 
143  // how to reconstruct received mesh
144  labelListList&& constructPointMap,
145  labelListList&& constructFaceMap,
146  labelListList&& constructCellMap,
147  labelListList&& constructPatchMap,
148 
149  const bool subFaceHasFlip,
150  const bool constructFaceHasFlip
151 )
152 :
153  nOldPoints_(nOldPoints),
154  nOldFaces_(nOldFaces),
155  nOldCells_(nOldCells),
156  oldPatchSizes_(),
157  oldPatchStarts_(std::move(oldPatchStarts)),
158  oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
159  pointMap_
160  (
161  mesh.nPoints(),
162  std::move(subPointMap),
163  std::move(constructPointMap)
164  ),
165  faceMap_
166  (
167  mesh.nFaces(),
168  std::move(subFaceMap),
169  std::move(constructFaceMap),
170  subFaceHasFlip,
171  constructFaceHasFlip
172  ),
173  cellMap_
174  (
175  mesh.nCells(),
176  std::move(subCellMap),
177  std::move(constructCellMap)
178  ),
179  patchMap_
180  (
181  mesh.boundaryMesh().size(),
182  std::move(subPatchMap),
183  std::move(constructPatchMap)
184  )
185 {
186  calcPatchSizes();
187 }
188 
189 
191 (
192  // mesh before changes
193  const label nOldPoints,
194  const label nOldFaces,
195  const label nOldCells,
196  labelList&& oldPatchStarts,
197  labelList&& oldPatchNMeshPoints,
198 
199  // how to transfer pieces of mesh
200  mapDistribute&& pointMap,
202  mapDistribute&& cellMap,
203  mapDistribute&& patchMap
204 )
205 :
206  nOldPoints_(nOldPoints),
207  nOldFaces_(nOldFaces),
208  nOldCells_(nOldCells),
209  oldPatchSizes_(),
210  oldPatchStarts_(std::move(oldPatchStarts)),
211  oldPatchNMeshPoints_(std::move(oldPatchNMeshPoints)),
212  pointMap_(std::move(pointMap)),
213  faceMap_(std::move(faceMap)),
214  cellMap_(std::move(cellMap)),
215  patchMap_(std::move(patchMap))
216 {
217  calcPatchSizes();
218 }
219 
220 
221 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
222 
224 {
225  nOldPoints_ = 0;
226  nOldFaces_ = 0;
227  nOldCells_ = 0;
228  oldPatchSizes_.clear();
229  oldPatchStarts_.clear();
230  oldPatchNMeshPoints_.clear();
231  pointMap_.clear();
232  faceMap_.clear();
233  cellMap_.clear();
234  patchMap_.clear();
235 }
236 
237 
238 void Foam::mapDistributePolyMesh::deepCopy(const mapDistributePolyMesh& rhs)
239 {
240  if (this == &rhs)
241  {
242  // Self-assignment is a no-op
243  return;
244  }
245 
246  nOldPoints_ = rhs.nOldPoints_;
247  nOldFaces_ = rhs.nOldFaces_;
248  nOldCells_ = rhs.nOldCells_;
249  oldPatchSizes_ = rhs.oldPatchSizes_;
250  oldPatchStarts_ = rhs.oldPatchStarts_;
251  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
252  pointMap_ = rhs.pointMap_;
253  faceMap_ = rhs.faceMap_;
254  cellMap_ = rhs.cellMap_;
255  patchMap_ = rhs.patchMap_;
256 }
257 
258 
260 {
261  if (this == &rhs)
262  {
263  // Self-assignment is a no-op
264  return;
265  }
266 
267  nOldPoints_ = rhs.nOldPoints_;
268  nOldFaces_ = rhs.nOldFaces_;
269  nOldCells_ = rhs.nOldCells_;
270  oldPatchSizes_.transfer(rhs.oldPatchSizes_);
271  oldPatchStarts_.transfer(rhs.oldPatchStarts_);
272  oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_);
273  pointMap_.transfer(rhs.pointMap_);
274  faceMap_.transfer(rhs.faceMap_);
275  cellMap_.transfer(rhs.cellMap_);
276  patchMap_.transfer(rhs.patchMap_);
278  rhs.nOldPoints_ = 0;
279  rhs.nOldFaces_ = 0;
280  rhs.nOldCells_ = 0;
281 }
282 
283 
285 {
286  // Construct boolList from selected elements
287  boolList isSelected
288  (
289  ListOps::createWithValue<bool>(nOldPoints(), lst, true, false)
290  );
291 
292  // Distribute
293  distributePointData(isSelected);
294 
295  // Collect selected elements
296  lst = findIndices(isSelected, true);
297 }
298 
299 
301 {
302  // Construct boolList from selected elements
303  boolList isSelected
304  (
305  ListOps::createWithValue<bool>(nOldFaces(), lst, true, false)
306  );
307 
308  // Distribute
309  distributeFaceData(isSelected);
310 
311  // Collect selected elements
312  lst = findIndices(isSelected, true);
313 }
314 
315 
317 {
318  // Construct boolList from selected elements
319  boolList isSelected
320  (
321  ListOps::createWithValue<bool>(nOldCells(), lst, true, false)
322  );
323 
324  // Distribute
325  distributeCellData(isSelected);
326 
327  // Collect selected elements
328  lst = findIndices(isSelected, true);
329 }
330 
331 
333 {
334  // Construct boolList from selected elements
335  boolList isSelected
336  (
337  ListOps::createWithValue<bool>
338  (
339  oldPatchStarts().size(), // nOldPatches
340  lst,
341  true, // set value
342  false // default value
343  )
344  );
345 
346  // Distribute
347  distributePatchData(isSelected);
348 
349  // Collect selected elements
350  lst = findIndices(isSelected, true);
351 }
352 
353 
354 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
355 
357 {
358  if (this == &rhs)
359  {
360  // Self-assignment is a no-op
361  return;
362  }
363 
364  nOldPoints_ = rhs.nOldPoints_;
365  nOldFaces_ = rhs.nOldFaces_;
366  nOldCells_ = rhs.nOldCells_;
367  oldPatchSizes_ = rhs.oldPatchSizes_;
368  oldPatchStarts_ = rhs.oldPatchStarts_;
369  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
370  pointMap_ = rhs.pointMap_;
371  faceMap_ = rhs.faceMap_;
372  cellMap_ = rhs.cellMap_;
373  patchMap_ = rhs.patchMap_;
374 }
375 
376 
378 {
379  if (this != &rhs)
380  {
381  // Avoid self assignment
382  transfer(rhs);
383  }
384 }
385 
386 
387 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void distributeCellIndices(labelList &cellIDs) const
void distributePatchIndices(labelList &patchIDs) const
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
void operator=(const mapDistributePolyMesh &map)
Copy assignment.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
labelList findIndices(const ListType &input, typename ListType::const_reference val, label start=0)
Linear search to find all occurrences of given element.
void clear()
Reset to zero size, only retaining communicator(s)
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
mapDistributePolyMesh()
Default construct - uses worldComm.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
void transfer(mapDistributePolyMesh &map)
Transfer the contents of the argument and annul the argument.
dynamicFvMesh & mesh
label nPoints
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void distributeFaceIndices(labelList &faceIDs) const
Class containing processor-to-processor mapping information.
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
List< label > labelList
A List of labels.
Definition: List.H:62
Inter-processor communications stream.
Definition: UPstream.H:60