polyDistributionMap.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-2022 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 "polyDistributionMap.H"
27 #include "polyMesh.H"
28 
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::polyDistributionMap::calcPatchSizes()
33 {
34  oldPatchSizes_.setSize(oldPatchStarts_.size());
35 
36  if (oldPatchStarts_.size())
37  {
38  // Calculate old patch sizes
39  for (label patchi = 0; patchi < oldPatchStarts_.size() - 1; patchi++)
40  {
41  oldPatchSizes_[patchi] =
42  oldPatchStarts_[patchi + 1] - oldPatchStarts_[patchi];
43  }
44 
45  // Set the last one by hand
46  const label lastPatchID = oldPatchStarts_.size() - 1;
47 
48  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
49 
50  if (min(oldPatchSizes_) < 0)
51  {
53  << "Calculated negative old patch size:" << oldPatchSizes_ << nl
54  << "Error in mapping data" << abort(FatalError);
55  }
56  }
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 :
64  nOldPoints_(0),
65  nOldFaces_(0),
66  nOldCells_(0),
67  oldPatchSizes_(0),
68  oldPatchStarts_(0),
69  oldPatchNMeshPoints_(0),
70  pointMap_(),
71  faceMap_(),
72  cellMap_(),
73  patchMap_()
74 {}
75 
76 
78 (
79  const polyMesh& mesh,
80 
81  // mesh before changes
82  const label nOldPoints,
83  const label nOldFaces,
84  const label nOldCells,
87 
88  // how to subset pieces of mesh to send across
89  labelListList&& subPointMap,
90  labelListList&& subFaceMap,
91  labelListList&& subCellMap,
92  labelListList&& subPatchMap,
93 
94  // how to reconstruct received mesh
95  labelListList&& constructPointMap,
96  labelListList&& constructFaceMap,
97  labelListList&& constructCellMap,
98  labelListList&& constructPatchMap,
99 
100  const bool subFaceHasFlip,
101  const bool constructFaceHasFlip
102 )
103 :
104  nOldPoints_(nOldPoints),
105  nOldFaces_(nOldFaces),
106  nOldCells_(nOldCells),
107  oldPatchSizes_(oldPatchStarts.size()),
108  oldPatchStarts_(move(oldPatchStarts)),
109  oldPatchNMeshPoints_(move(oldPatchNMeshPoints)),
110  pointMap_(mesh.nPoints(), move(subPointMap), move(constructPointMap)),
111  faceMap_
112  (
113  mesh.nFaces(),
114  move(subFaceMap),
115  move(constructFaceMap),
116  move(subFaceHasFlip),
117  constructFaceHasFlip
118  ),
119  cellMap_(mesh.nCells(), move(subCellMap), move(constructCellMap)),
120  patchMap_
121  (
122  mesh.boundaryMesh().size(),
123  move(subPatchMap),
124  move(constructPatchMap)
125  )
126 {
127  calcPatchSizes();
128 }
129 
130 
132 (
133  // mesh before changes
134  const label nOldPoints,
135  const label nOldFaces,
136  const label nOldCells,
139 
140  // how to transfer pieces of mesh
145 )
146 :
147  nOldPoints_(nOldPoints),
148  nOldFaces_(nOldFaces),
149  nOldCells_(nOldCells),
150  oldPatchSizes_(oldPatchStarts.size()),
151  oldPatchStarts_(move(oldPatchStarts)),
152  oldPatchNMeshPoints_(move(oldPatchNMeshPoints)),
153  pointMap_(move(pointMap)),
154  faceMap_(move(faceMap)),
155  cellMap_(move(cellMap)),
156  patchMap_(move(patchMap))
157 {
158  calcPatchSizes();
159 }
160 
161 
163 (
164  polyDistributionMap&& map
165 )
166 :
167  nOldPoints_(map.nOldPoints_),
168  nOldFaces_(map.nOldFaces_),
169  nOldCells_(map.nOldCells_),
170  oldPatchSizes_(move(map.oldPatchSizes_)),
171  oldPatchStarts_(move(map.oldPatchStarts_)),
172  oldPatchNMeshPoints_(move(map.oldPatchNMeshPoints_)),
173  pointMap_(move(map.pointMap_)),
174  faceMap_(move(map.faceMap_)),
175  cellMap_(move(map.cellMap_)),
176  patchMap_(move(map.patchMap_))
177 {}
178 
179 
181 {
182  is >> *this;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 
189 {
190  nOldPoints_ = rhs.nOldPoints_;
191  nOldFaces_ = rhs.nOldFaces_;
192  nOldCells_ = rhs.nOldCells_;
193  oldPatchSizes_.transfer(rhs.oldPatchSizes_);
194  oldPatchStarts_.transfer(rhs.oldPatchStarts_);
195  oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_);
196  pointMap_.transfer(rhs.pointMap_);
197  faceMap_.transfer(rhs.faceMap_);
198  cellMap_.transfer(rhs.cellMap_);
199  patchMap_.transfer(rhs.patchMap_);
200 }
201 
202 
204 {
205  // Construct boolList from selected elements
206  boolList isSelected
207  (
208  createWithValues<boolList>
209  (
210  nOldPoints(),
211  false,
212  lst,
213  true
214  )
215  );
216 
217  // Distribute
218  distributePointData(isSelected);
219 
220  // Collect selected elements
221  lst = findIndices(isSelected, true);
222 }
223 
224 
226 {
227  // Construct boolList from selected elements
228  boolList isSelected
229  (
230  createWithValues<boolList>
231  (
232  nOldFaces(),
233  false,
234  lst,
235  true
236  )
237  );
238 
239  // Distribute
240  distributeFaceData(isSelected);
241 
242  // Collect selected elements
243  lst = findIndices(isSelected, true);
244 }
245 
246 
248 {
249  // Construct boolList from selected elements
250  boolList isSelected
251  (
252  createWithValues<boolList>
253  (
254  nOldCells(),
255  false,
256  lst,
257  true
258  )
259  );
260 
261  // Distribute
262  distributeCellData(isSelected);
263 
264  // Collect selected elements
265  lst = findIndices(isSelected, true);
266 }
267 
268 
270 {
271  // Construct boolList from selected elements
272  boolList isSelected
273  (
274  createWithValues<boolList>
275  (
276  oldPatchStarts().size(), // nOldPatches
277  false,
278  lst,
279  true
280  )
281  );
282 
283  // Distribute
284  distributePatchData(isSelected);
285 
286  // Collect selected elements
287  lst = findIndices(isSelected, true);
288 }
289 
290 
291 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
292 
293 void Foam::polyDistributionMap::operator=
294 (
295  const polyDistributionMap& rhs
296 )
297 {
298  nOldPoints_ = rhs.nOldPoints_;
299  nOldFaces_ = rhs.nOldFaces_;
300  nOldCells_ = rhs.nOldCells_;
301  oldPatchSizes_ = rhs.oldPatchSizes_;
302  oldPatchStarts_ = rhs.oldPatchStarts_;
303  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
304  pointMap_ = rhs.pointMap_;
305  faceMap_ = rhs.faceMap_;
306  cellMap_ = rhs.cellMap_;
307  patchMap_ = rhs.patchMap_;
308 }
309 
310 
312 {
313  nOldPoints_ = rhs.nOldPoints_;
314  nOldFaces_ = rhs.nOldFaces_;
315  nOldCells_ = rhs.nOldCells_;
316  oldPatchSizes_ = move(rhs.oldPatchSizes_);
317  oldPatchStarts_ = move(rhs.oldPatchStarts_);
318  oldPatchNMeshPoints_ = move(rhs.oldPatchNMeshPoints_);
319  pointMap_ = move(rhs.pointMap_);
320  faceMap_ = move(rhs.faceMap_);
321  cellMap_ = move(rhs.cellMap_);
322  patchMap_ = move(rhs.patchMap_);
323 }
324 
325 
326 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
327 
329 {
330  is.fatalCheck("operator>>(Istream&, polyDistributionMap&)");
331 
332  is >> map.nOldPoints_
333  >> map.nOldFaces_
334  >> map.nOldCells_
335  >> map.oldPatchSizes_
336  >> map.oldPatchStarts_
337  >> map.oldPatchNMeshPoints_
338  >> map.pointMap_
339  >> map.faceMap_
340  >> map.cellMap_
341  >> map.patchMap_;
342 
343  return is;
344 }
345 
346 
347 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
348 
350 {
351  os << map.nOldPoints_
352  << token::SPACE << map.nOldFaces_
353  << token::SPACE << map.nOldCells_ << token::NL
354  << map.oldPatchSizes_ << token::NL
355  << map.oldPatchStarts_ << token::NL
356  << map.oldPatchNMeshPoints_ << token::NL
357  << map.pointMap_ << token::NL
358  << map.faceMap_ << token::NL
359  << map.cellMap_ << token::NL
360  << map.patchMap_;
361 
362  return os;
363 }
364 
365 
366 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
void transfer(polyDistributionMap &)
Transfer the contents of the argument and annul the argument.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
polyDistributionMap()
Construct null.
const distributionMap & patchMap() const
Patch distribute map.
label nOldCells() const
Number of cells in mesh before distribution.
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
label nFaces() const
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nCells() const
const distributionMap & cellMap() const
Cell distribute map.
const distributionMap & faceMap() const
Face distribute map.
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurrences of given element. Linear search.
void transfer(distributionMap &)
Transfer the contents of the argument and annul the argument.
const labelList & oldPatchStarts() const
List of the old patch start labels.
Istream & operator>>(Istream &, directionInfo &)
label nOldPoints() const
Number of points in mesh before distribution.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
label nOldFaces() const
Number of faces in mesh before distribution.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
void distributeCellIndices(labelList &cellIDs) const
void distributePatchData(List< T > &lst) const
Distribute list of patch data.
void operator=(const polyDistributionMap &)
void distributeCellData(List< T > &lst) const
Distribute list of cell data.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void distributeFaceData(List< T > &lst) const
Distribute list of face data.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Class containing processor-to-processor mapping information.
label patchi
Ostream & operator<<(Ostream &, const ensightPart &)
void distributePointData(List< T > &lst) const
Distribute list of point data.
label nPoints() const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
const distributionMap & pointMap() const
Point distribute map.
void distributePatchIndices(labelList &patchIDs) const
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void distributeFaceIndices(labelList &faceIDs) const
const labelList & oldPatchNMeshPoints() const
List of numbers of mesh points per old patch.