FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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 labelList& oldPatchStarts,
69  const labelList& oldPatchNMeshPoints,
70 
71  // how to subset pieces of mesh to send across
72  const labelListList& subPointMap,
73  const labelListList& subFaceMap,
74  const labelListList& subCellMap,
75  const labelListList& subPatchMap,
76 
77  // how to reconstruct received mesh
78  const labelListList& constructPointMap,
79  const labelListList& constructFaceMap,
80  const labelListList& constructCellMap,
81  const 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 //- (optionally destructively) construct from components
101 Foam::mapDistributePolyMesh::mapDistributePolyMesh
102 (
103  const polyMesh& mesh,
104  const label nOldPoints,
105  const label nOldFaces,
106  const label nOldCells,
107  labelList& oldPatchStarts,
108  labelList& oldPatchNMeshPoints,
109 
110  labelListList& subPointMap,
111  labelListList& subFaceMap,
112  labelListList& subCellMap,
113  labelListList& subPatchMap,
114  labelListList& constructPointMap,
115  labelListList& constructFaceMap,
116  labelListList& constructCellMap,
117  labelListList& constructPatchMap,
118  const bool reUse // clone or reuse
119 )
120 :
121  mesh_(mesh),
122  nOldPoints_(nOldPoints),
123  nOldFaces_(nOldFaces),
124  nOldCells_(nOldCells),
125  oldPatchSizes_(oldPatchStarts.size()),
126  oldPatchStarts_(oldPatchStarts, reUse),
127  oldPatchNMeshPoints_(oldPatchNMeshPoints, reUse),
128 
129  pointMap_(mesh.nPoints(), subPointMap, constructPointMap, reUse),
130  faceMap_(mesh.nFaces(), subFaceMap, constructFaceMap, reUse),
131  cellMap_(mesh.nCells(), subCellMap, constructCellMap, reUse),
132  patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap, reUse)
133 {
134  calcPatchSizes();
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  // Construct boolList from selected elements
143  boolList isSelected
144  (
145  createWithValues<boolList>
146  (
147  nOldPoints(),
148  false,
149  lst,
150  true
151  )
152  );
153 
154  // Distribute
155  distributePointData(isSelected);
156 
157  // Collect selected elements
158  lst = findIndices(isSelected, true);
159 }
160 
161 
163 {
164  // Construct boolList from selected elements
165  boolList isSelected
166  (
167  createWithValues<boolList>
168  (
169  nOldFaces(),
170  false,
171  lst,
172  true
173  )
174  );
175 
176  // Distribute
177  distributeFaceData(isSelected);
178 
179  // Collect selected elements
180  lst = findIndices(isSelected, true);
181 }
182 
183 
185 {
186  // Construct boolList from selected elements
187  boolList isSelected
188  (
189  createWithValues<boolList>
190  (
191  nOldCells(),
192  false,
193  lst,
194  true
195  )
196  );
197 
198  // Distribute
199  distributeCellData(isSelected);
200 
201  // Collect selected elements
202  lst = findIndices(isSelected, true);
203 }
204 
205 
207 {
208  // Construct boolList from selected elements
209  boolList isSelected
210  (
211  createWithValues<boolList>
212  (
213  oldPatchStarts().size(), // nOldPatches
214  false,
215  lst,
216  true
217  )
218  );
219 
220  // Distribute
221  distributePatchData(isSelected);
222 
223  // Collect selected elements
224  lst = findIndices(isSelected, true);
225 }
226 
227 
228 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
229 
230 
231 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
232 
233 
234 // ************************ vim: set sw=4 sts=4 et: ************************ //