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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
32 {
34 
35  if (oldPatchStarts_.size())
36  {
37  // Calculate old patch sizes
38  for (label patchI = 0; patchI < oldPatchStarts_.size() - 1; patchI++)
39  {
40  oldPatchSizes_[patchI] =
41  oldPatchStarts_[patchI + 1] - oldPatchStarts_[patchI];
42  }
43 
44  // Set the last one by hand
45  const label lastPatchID = oldPatchStarts_.size() - 1;
46 
47  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
48 
49  if (min(oldPatchSizes_) < 0)
50  {
52  << "Calculated negative old patch size:" << oldPatchSizes_ << nl
53  << "Error in mapping data" << abort(FatalError);
54  }
55  }
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 :
63  nOldPoints_(0),
64  nOldFaces_(0),
65  nOldCells_(0),
66  oldPatchSizes_(0),
67  oldPatchStarts_(0),
68  oldPatchNMeshPoints_(0),
69  pointMap_(),
70  faceMap_(),
71  cellMap_(),
72  patchMap_()
73 {}
74 
75 
77 (
78  const polyMesh& mesh,
79 
80  // mesh before changes
81  const label nOldPoints,
82  const label nOldFaces,
83  const label nOldCells,
84  const Xfer<labelList>& oldPatchStarts,
85  const Xfer<labelList>& oldPatchNMeshPoints,
86 
87  // how to subset pieces of mesh to send across
88  const Xfer<labelListList>& subPointMap,
89  const Xfer<labelListList>& subFaceMap,
90  const Xfer<labelListList>& subCellMap,
91  const Xfer<labelListList>& subPatchMap,
92 
93  // how to reconstruct received mesh
94  const Xfer<labelListList>& constructPointMap,
95  const Xfer<labelListList>& constructFaceMap,
96  const Xfer<labelListList>& constructCellMap,
97  const Xfer<labelListList>& constructPatchMap,
98 
99  const bool subFaceHasFlip,
100  const bool constructFaceHasFlip
101 )
102 :
103  nOldPoints_(nOldPoints),
104  nOldFaces_(nOldFaces),
105  nOldCells_(nOldCells),
106  oldPatchSizes_(oldPatchStarts().size()),
107  oldPatchStarts_(oldPatchStarts),
108  oldPatchNMeshPoints_(oldPatchNMeshPoints),
109  pointMap_(mesh.nPoints(), subPointMap, constructPointMap),
110  faceMap_
111  (
112  mesh.nFaces(),
113  subFaceMap,
114  constructFaceMap,
115  subFaceHasFlip,
116  constructFaceHasFlip
117  ),
118  cellMap_(mesh.nCells(), subCellMap, constructCellMap),
119  patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap)
120 {
121  calcPatchSizes();
122 }
123 
124 
126 (
127  // mesh before changes
128  const label nOldPoints,
129  const label nOldFaces,
130  const label nOldCells,
131  const Xfer<labelList>& oldPatchStarts,
132  const Xfer<labelList>& oldPatchNMeshPoints,
133 
134  // how to transfer pieces of mesh
135  const Xfer<mapDistribute>& pointMap,
137  const Xfer<mapDistribute>& cellMap,
138  const Xfer<mapDistribute>& patchMap
139 )
140 :
141  nOldPoints_(nOldPoints),
142  nOldFaces_(nOldFaces),
143  nOldCells_(nOldCells),
144  oldPatchSizes_(oldPatchStarts().size()),
145  oldPatchStarts_(oldPatchStarts),
146  oldPatchNMeshPoints_(oldPatchNMeshPoints),
147  pointMap_(pointMap),
148  faceMap_(faceMap),
149  cellMap_(cellMap),
150  patchMap_(patchMap)
151 {
152  calcPatchSizes();
153 }
154 
155 
157 (
158  const Xfer<mapDistributePolyMesh>& map
159 )
160 :
161  nOldPoints_(map().nOldPoints_),
162  nOldFaces_(map().nOldFaces_),
163  nOldCells_(map().nOldCells_),
164  oldPatchSizes_(map().oldPatchSizes_.xfer()),
165  oldPatchStarts_(map().oldPatchStarts_.xfer()),
166  oldPatchNMeshPoints_(map().oldPatchNMeshPoints_.xfer()),
167  pointMap_(map().pointMap_.xfer()),
168  faceMap_(map().faceMap_.xfer()),
169  cellMap_(map().cellMap_.xfer()),
170  patchMap_(map().patchMap_.xfer())
171 {}
172 
173 
175 {
176  is >> *this;
177 }
178 
179 
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 
183 {
184  nOldPoints_ = rhs.nOldPoints_;
185  nOldFaces_ = rhs.nOldFaces_;
186  nOldCells_ = rhs.nOldCells_;
187  oldPatchSizes_.transfer(rhs.oldPatchSizes_);
188  oldPatchStarts_.transfer(rhs.oldPatchStarts_);
189  oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_);
190  pointMap_.transfer(rhs.pointMap_);
191  faceMap_.transfer(rhs.faceMap_);
192  cellMap_.transfer(rhs.cellMap_);
193  patchMap_.transfer(rhs.patchMap_);
194 }
195 
196 
198 {
199  return xferMove(*this);
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 
308 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
309 
311 {
312  is.fatalCheck("operator>>(Istream&, mapDistributePolyMesh&)");
313 
314  is >> map.nOldPoints_
315  >> map.nOldFaces_
316  >> map.nOldCells_
317  >> map.oldPatchSizes_
318  >> map.oldPatchStarts_
319  >> map.oldPatchNMeshPoints_
320  >> map.pointMap_
321  >> map.faceMap_
322  >> map.cellMap_
323  >> map.patchMap_;
324 
325  return is;
326 }
327 
328 
329 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
330 
331 Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map)
332 {
333  os << map.nOldPoints_
334  << token::SPACE << map.nOldFaces_
335  << token::SPACE << map.nOldCells_ << token::NL
336  << map.oldPatchSizes_ << token::NL
337  << map.oldPatchStarts_ << token::NL
338  << map.oldPatchNMeshPoints_ << token::NL
339  << map.pointMap_ << token::NL
340  << map.faceMap_ << token::NL
341  << map.cellMap_ << token::NL
342  << map.patchMap_;
343 
344  return os;
345 }
346 
347 
348 // ************************************************************************* //
Foam::mapDistributePolyMesh::distributePointIndices
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
Definition: mapDistributePolyMesh.C:203
Foam::mapDistributePolyMesh::pointMap_
mapDistribute pointMap_
Point distribute map.
Definition: mapDistributePolyMesh.H:81
Foam::IOstream::fatalCheck
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:105
Foam::mapDistributePolyMesh::nOldCells_
label nOldCells_
Number of old live cells.
Definition: mapDistributePolyMesh.H:68
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::mapDistributePolyMesh::cellMap_
mapDistribute cellMap_
Cell distribute map.
Definition: mapDistributePolyMesh.H:87
Foam::mapDistributePolyMesh::mapDistributePolyMesh
mapDistributePolyMesh()
Construct null.
Definition: mapDistributePolyMesh.C:61
Foam::mapDistributePolyMesh::operator=
void operator=(const mapDistributePolyMesh &)
Definition: mapDistributePolyMesh.C:293
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
polyMesh.H
Foam::token::NL
@ NL
Definition: token.H:97
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
mapDistributePolyMesh.H
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::mapDistributePolyMesh::nOldFaces_
label nOldFaces_
Number of old live faces.
Definition: mapDistributePolyMesh.H:65
Foam::label
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
Foam::mapDistributePolyMesh::patchMap_
mapDistribute patchMap_
Patch distribute map.
Definition: mapDistributePolyMesh.H:90
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::mapDistributePolyMesh::oldPatchSizes_
labelList oldPatchSizes_
List of the old patch sizes.
Definition: mapDistributePolyMesh.H:71
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::mapDistributePolyMesh::distributeFaceIndices
void distributeFaceIndices(labelList &faceIDs) const
Definition: mapDistributePolyMesh.C:225
Foam::FatalError
error FatalError
Foam::mapDistributePolyMesh::oldPatchStarts_
labelList oldPatchStarts_
List of the old patch start labels.
Definition: mapDistributePolyMesh.H:74
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::mapDistributePolyMesh::xfer
Xfer< mapDistributePolyMesh > xfer()
Transfer contents to the Xfer container.
Definition: mapDistributePolyMesh.C:197
Foam::mapDistributePolyMesh::transfer
void transfer(mapDistributePolyMesh &)
Transfer the contents of the argument and annul the argument.
Definition: mapDistributePolyMesh.C:182
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::PtrList::size
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::mapDistributePolyMesh::nOldPoints_
label nOldPoints_
Number of old live points.
Definition: mapDistributePolyMesh.H:62
Foam::mapDistributePolyMesh::distributeCellIndices
void distributeCellIndices(labelList &cellIDs) const
Definition: mapDistributePolyMesh.C:247
Foam::mapDistributePolyMesh::oldPatchNMeshPoints_
labelList oldPatchNMeshPoints_
List of numbers of mesh points per old patch.
Definition: mapDistributePolyMesh.H:77
Foam::mapDistributePolyMesh::distributePatchIndices
void distributePatchIndices(labelList &patchIDs) const
Definition: mapDistributePolyMesh.C:269
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:57
Foam::mapDistributePolyMesh::calcPatchSizes
void calcPatchSizes()
Definition: mapDistributePolyMesh.C:31
Foam::findIndices
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurences of given element. Linear search.
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::mapDistributePolyMesh::faceMap_
mapDistribute faceMap_
Face distribute map.
Definition: mapDistributePolyMesh.H:84
Foam::token::SPACE
@ SPACE
Definition: token.H:95