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 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  // Calculate old patch sizes
37  for (label patchI = 0; patchI < oldPatchStarts_.size() - 1; patchI++)
38  {
39  oldPatchSizes_[patchI] =
40  oldPatchStarts_[patchI + 1] - oldPatchStarts_[patchI];
41  }
42 
43  // Set the last one by hand
44  const label lastPatchID = oldPatchStarts_.size() - 1;
45 
46  oldPatchSizes_[lastPatchID] = nOldFaces_ - oldPatchStarts_[lastPatchID];
47 
48  if (min(oldPatchSizes_) < 0)
49  {
50  FatalErrorIn("mapDistributePolyMesh::calcPatchSizes()")
51  << "Calculated negative old patch size:" << oldPatchSizes_ << nl
52  << "Error in mapping data" << abort(FatalError);
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
59 //- Construct from components
60 Foam::mapDistributePolyMesh::mapDistributePolyMesh
61 (
62  const polyMesh& mesh,
63 
64  // mesh before changes
65  const label nOldPoints,
66  const label nOldFaces,
67  const label nOldCells,
68  const Xfer<labelList>& oldPatchStarts,
69  const Xfer<labelList>& oldPatchNMeshPoints,
70 
71  // how to subset pieces of mesh to send across
72  const Xfer<labelListList>& subPointMap,
73  const Xfer<labelListList>& subFaceMap,
74  const Xfer<labelListList>& subCellMap,
75  const Xfer<labelListList>& subPatchMap,
76 
77  // how to reconstruct received mesh
78  const Xfer<labelListList>& constructPointMap,
79  const Xfer<labelListList>& constructFaceMap,
80  const Xfer<labelListList>& constructCellMap,
81  const Xfer<labelListList>& constructPatchMap
82 )
83 :
84  mesh_(mesh),
85  nOldPoints_(nOldPoints),
86  nOldFaces_(nOldFaces),
87  nOldCells_(nOldCells),
88  oldPatchSizes_(oldPatchStarts().size()),
89  oldPatchStarts_(oldPatchStarts),
90  oldPatchNMeshPoints_(oldPatchNMeshPoints),
91  pointMap_(mesh.nPoints(), subPointMap, constructPointMap),
92  faceMap_(mesh.nFaces(), subFaceMap, constructFaceMap),
93  cellMap_(mesh.nCells(), subCellMap, constructCellMap),
94  patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap)
95 {
96  calcPatchSizes();
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  // Construct boolList from selected elements
105  boolList isSelected
106  (
107  createWithValues<boolList>
108  (
109  nOldPoints(),
110  false,
111  lst,
112  true
113  )
114  );
115 
116  // Distribute
117  distributePointData(isSelected);
118 
119  // Collect selected elements
120  lst = findIndices(isSelected, true);
121 }
122 
123 
125 {
126  // Construct boolList from selected elements
127  boolList isSelected
128  (
129  createWithValues<boolList>
130  (
131  nOldFaces(),
132  false,
133  lst,
134  true
135  )
136  );
137 
138  // Distribute
139  distributeFaceData(isSelected);
140 
141  // Collect selected elements
142  lst = findIndices(isSelected, true);
143 }
144 
145 
147 {
148  // Construct boolList from selected elements
149  boolList isSelected
150  (
151  createWithValues<boolList>
152  (
153  nOldCells(),
154  false,
155  lst,
156  true
157  )
158  );
159 
160  // Distribute
161  distributeCellData(isSelected);
162 
163  // Collect selected elements
164  lst = findIndices(isSelected, true);
165 }
166 
167 
169 {
170  // Construct boolList from selected elements
171  boolList isSelected
172  (
173  createWithValues<boolList>
174  (
175  oldPatchStarts().size(), // nOldPatches
176  false,
177  lst,
178  true
179  )
180  );
181 
182  // Distribute
183  distributePatchData(isSelected);
184 
185  // Collect selected elements
186  lst = findIndices(isSelected, true);
187 }
188 
189 
190 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
191 
192 
193 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
194 
195 
196 // ************************************************************************* //
void distributeFaceIndices(labelList &faceIDs) const
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
label nFaces() const
label nOldPoints() const
Number of points in mesh before distribution.
const labelList & oldPatchStarts() const
List of the old patch start labels.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
label nOldCells() const
Number of cells in mesh before distribution.
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
void distributeCellIndices(labelList &cellIDs) const
label nCells() const
void distributePatchData(List< T > &lst) const
Distribute list of patch data.
static const char nl
Definition: Ostream.H:260
void setSize(const label)
Reset size of List.
Definition: List.C:318
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
void distributePointIndices(labelList &pointIDs) const
Distribute list of point/face/cell/patch indices.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
void distributePatchIndices(labelList &patchIDs) const
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void distributeFaceData(List< T > &lst) const
Distribute list of face data.
void distributeCellData(List< T > &lst) const
Distribute list of cell data.
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurences of given element. Linear search.
label nPoints() const
label nOldFaces() const
Number of faces in mesh before distribution.
void distributePointData(List< T > &lst) const
Distribute list of point data.