mapDistributePolyMesh.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-2019 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 "mapDistributePolyMesh.H"
27 #include "polyMesh.H"
28 
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::mapDistributePolyMesh::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 (
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 
294 {
295  nOldPoints_ = rhs.nOldPoints_;
296  nOldFaces_ = rhs.nOldFaces_;
297  nOldCells_ = rhs.nOldCells_;
298  oldPatchSizes_ = rhs.oldPatchSizes_;
299  oldPatchStarts_ = rhs.oldPatchStarts_;
300  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
301  pointMap_ = rhs.pointMap_;
302  faceMap_ = rhs.faceMap_;
303  cellMap_ = rhs.cellMap_;
304  patchMap_ = rhs.patchMap_;
305 }
306 
307 
309 {
310  nOldPoints_ = rhs.nOldPoints_;
311  nOldFaces_ = rhs.nOldFaces_;
312  nOldCells_ = rhs.nOldCells_;
313  oldPatchSizes_ = move(rhs.oldPatchSizes_);
314  oldPatchStarts_ = move(rhs.oldPatchStarts_);
315  oldPatchNMeshPoints_ = move(rhs.oldPatchNMeshPoints_);
316  pointMap_ = move(rhs.pointMap_);
317  faceMap_ = move(rhs.faceMap_);
318  cellMap_ = move(rhs.cellMap_);
319  patchMap_ = move(rhs.patchMap_);
320 }
321 
322 
323 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
324 
326 {
327  is.fatalCheck("operator>>(Istream&, mapDistributePolyMesh&)");
328 
329  is >> map.nOldPoints_
330  >> map.nOldFaces_
331  >> map.nOldCells_
332  >> map.oldPatchSizes_
333  >> map.oldPatchStarts_
334  >> map.oldPatchNMeshPoints_
335  >> map.pointMap_
336  >> map.faceMap_
337  >> map.cellMap_
338  >> map.patchMap_;
339 
340  return is;
341 }
342 
343 
344 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
345 
347 {
348  os << map.nOldPoints_
349  << token::SPACE << map.nOldFaces_
350  << token::SPACE << map.nOldCells_ << token::NL
351  << map.oldPatchSizes_ << token::NL
352  << map.oldPatchStarts_ << token::NL
353  << map.oldPatchNMeshPoints_ << token::NL
354  << map.pointMap_ << token::NL
355  << map.faceMap_ << token::NL
356  << map.cellMap_ << token::NL
357  << map.patchMap_;
358 
359  return os;
360 }
361 
362 
363 // ************************************************************************* //
void operator=(const mapDistributePolyMesh &)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
void distributeCellIndices(labelList &cellIDs) const
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
const mapDistribute & pointMap() const
Point distribute map.
label nOldFaces() const
Number of faces in mesh before distribution.
void distributePointData(List< T > &lst) const
Distribute list of point data.
void distributePatchIndices(labelList &patchIDs) const
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const mapDistribute & cellMap() const
Cell distribute map.
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
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const mapDistribute & patchMap() const
Patch distribute map.
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurrences of given element. Linear search.
void transfer(mapDistribute &)
Transfer the contents of the argument and annul the argument.
mapDistributePolyMesh()
Construct null.
void distributeCellData(List< T > &lst) const
Distribute list of cell data.
void distributeFaceData(List< T > &lst) const
Distribute list of face data.
Istream & operator>>(Istream &, directionInfo &)
const labelList & oldPatchStarts() const
List of the old patch start labels.
const labelList & oldPatchNMeshPoints() const
List of numbers of mesh points per old patch.
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
const mapDistribute & faceMap() const
Face distribute map.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void distributeFaceIndices(labelList &faceIDs) const
void setSize(const label)
Reset size of List.
Definition: List.C:281
label nOldPoints() const
Number of points in mesh before distribution.
label nOldCells() const
Number of cells in mesh before distribution.
label patchi
Class containing processor-to-processor mapping information.
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
Ostream & operator<<(Ostream &, const ensightPart &)
void transfer(mapDistributePolyMesh &)
Transfer the contents of the argument and annul the argument.
label nPoints() const
void distributePatchData(List< T > &lst) const
Distribute list of patch data.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342