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-2016 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,
85  const Xfer<labelList>& oldPatchStarts,
86  const Xfer<labelList>& oldPatchNMeshPoints,
87 
88  // how to subset pieces of mesh to send across
89  const Xfer<labelListList>& subPointMap,
90  const Xfer<labelListList>& subFaceMap,
91  const Xfer<labelListList>& subCellMap,
92  const Xfer<labelListList>& subPatchMap,
93 
94  // how to reconstruct received mesh
95  const Xfer<labelListList>& constructPointMap,
96  const Xfer<labelListList>& constructFaceMap,
97  const Xfer<labelListList>& constructCellMap,
98  const Xfer<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_(oldPatchStarts),
109  oldPatchNMeshPoints_(oldPatchNMeshPoints),
110  pointMap_(mesh.nPoints(), subPointMap, constructPointMap),
111  faceMap_
112  (
113  mesh.nFaces(),
114  subFaceMap,
115  constructFaceMap,
116  subFaceHasFlip,
117  constructFaceHasFlip
118  ),
119  cellMap_(mesh.nCells(), subCellMap, constructCellMap),
120  patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap)
121 {
122  calcPatchSizes();
123 }
124 
125 
127 (
128  // mesh before changes
129  const label nOldPoints,
130  const label nOldFaces,
131  const label nOldCells,
132  const Xfer<labelList>& oldPatchStarts,
133  const Xfer<labelList>& oldPatchNMeshPoints,
134 
135  // how to transfer pieces of mesh
136  const Xfer<mapDistribute>& pointMap,
137  const Xfer<mapDistribute>& faceMap,
138  const Xfer<mapDistribute>& cellMap,
139  const Xfer<mapDistribute>& patchMap
140 )
141 :
142  nOldPoints_(nOldPoints),
143  nOldFaces_(nOldFaces),
144  nOldCells_(nOldCells),
145  oldPatchSizes_(oldPatchStarts().size()),
146  oldPatchStarts_(oldPatchStarts),
147  oldPatchNMeshPoints_(oldPatchNMeshPoints),
148  pointMap_(pointMap),
149  faceMap_(faceMap),
150  cellMap_(cellMap),
151  patchMap_(patchMap)
152 {
153  calcPatchSizes();
154 }
155 
156 
158 (
159  const Xfer<mapDistributePolyMesh>& map
160 )
161 :
162  nOldPoints_(map().nOldPoints_),
163  nOldFaces_(map().nOldFaces_),
164  nOldCells_(map().nOldCells_),
165  oldPatchSizes_(map().oldPatchSizes_.xfer()),
166  oldPatchStarts_(map().oldPatchStarts_.xfer()),
167  oldPatchNMeshPoints_(map().oldPatchNMeshPoints_.xfer()),
168  pointMap_(map().pointMap_.xfer()),
169  faceMap_(map().faceMap_.xfer()),
170  cellMap_(map().cellMap_.xfer()),
171  patchMap_(map().patchMap_.xfer())
172 {}
173 
174 
176 {
177  is >> *this;
178 }
179 
180 
181 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182 
184 {
185  nOldPoints_ = rhs.nOldPoints_;
186  nOldFaces_ = rhs.nOldFaces_;
187  nOldCells_ = rhs.nOldCells_;
188  oldPatchSizes_.transfer(rhs.oldPatchSizes_);
189  oldPatchStarts_.transfer(rhs.oldPatchStarts_);
190  oldPatchNMeshPoints_.transfer(rhs.oldPatchNMeshPoints_);
191  pointMap_.transfer(rhs.pointMap_);
192  faceMap_.transfer(rhs.faceMap_);
193  cellMap_.transfer(rhs.cellMap_);
194  patchMap_.transfer(rhs.patchMap_);
195 }
196 
197 
199 {
200  return xferMove(*this);
201 }
202 
203 
205 {
206  // Construct boolList from selected elements
207  boolList isSelected
208  (
209  createWithValues<boolList>
210  (
211  nOldPoints(),
212  false,
213  lst,
214  true
215  )
216  );
217 
218  // Distribute
219  distributePointData(isSelected);
220 
221  // Collect selected elements
222  lst = findIndices(isSelected, true);
223 }
224 
225 
227 {
228  // Construct boolList from selected elements
229  boolList isSelected
230  (
231  createWithValues<boolList>
232  (
233  nOldFaces(),
234  false,
235  lst,
236  true
237  )
238  );
239 
240  // Distribute
241  distributeFaceData(isSelected);
242 
243  // Collect selected elements
244  lst = findIndices(isSelected, true);
245 }
246 
247 
249 {
250  // Construct boolList from selected elements
251  boolList isSelected
252  (
253  createWithValues<boolList>
254  (
255  nOldCells(),
256  false,
257  lst,
258  true
259  )
260  );
261 
262  // Distribute
263  distributeCellData(isSelected);
264 
265  // Collect selected elements
266  lst = findIndices(isSelected, true);
267 }
268 
269 
271 {
272  // Construct boolList from selected elements
273  boolList isSelected
274  (
275  createWithValues<boolList>
276  (
277  oldPatchStarts().size(), // nOldPatches
278  false,
279  lst,
280  true
281  )
282  );
283 
284  // Distribute
285  distributePatchData(isSelected);
286 
287  // Collect selected elements
288  lst = findIndices(isSelected, true);
289 }
290 
291 
292 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
293 
295 {
296  nOldPoints_ = rhs.nOldPoints_;
297  nOldFaces_ = rhs.nOldFaces_;
298  nOldCells_ = rhs.nOldCells_;
299  oldPatchSizes_ = rhs.oldPatchSizes_;
300  oldPatchStarts_ = rhs.oldPatchStarts_;
301  oldPatchNMeshPoints_ = rhs.oldPatchNMeshPoints_;
302  pointMap_ = rhs.pointMap_;
303  faceMap_ = rhs.faceMap_;
304  cellMap_ = rhs.cellMap_;
305  patchMap_ = rhs.patchMap_;
306 }
307 
308 
309 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
310 
312 {
313  is.fatalCheck("operator>>(Istream&, mapDistributePolyMesh&)");
314 
315  is >> map.nOldPoints_
316  >> map.nOldFaces_
317  >> map.nOldCells_
318  >> map.oldPatchSizes_
319  >> map.oldPatchStarts_
320  >> map.oldPatchNMeshPoints_
321  >> map.pointMap_
322  >> map.faceMap_
323  >> map.cellMap_
324  >> map.patchMap_;
325 
326  return is;
327 }
328 
329 
330 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
331 
333 {
334  os << map.nOldPoints_
335  << token::SPACE << map.nOldFaces_
336  << token::SPACE << map.nOldCells_ << token::NL
337  << map.oldPatchSizes_ << token::NL
338  << map.oldPatchStarts_ << token::NL
339  << map.oldPatchNMeshPoints_ << token::NL
340  << map.pointMap_ << token::NL
341  << map.faceMap_ << token::NL
342  << map.cellMap_ << token::NL
343  << map.patchMap_;
344 
345  return os;
346 }
347 
348 
349 // ************************************************************************* //
void operator=(const mapDistributePolyMesh &)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
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
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:177
label nFaces() const
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
label nCells() const
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurences 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.
Xfer< mapDistributePolyMesh > xfer()
Transfer contents to the Xfer container.
void distributeFaceData(List< T > &lst) const
Distribute list of face data.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Istream & operator>>(Istream &, directionInfo &)
const labelList & oldPatchStarts() const
List of the old patch start labels.
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:53
static const char nl
Definition: Ostream.H:262
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
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