polyDistributionMap.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-2022 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 "polyDistributionMap.H"
27 #include "polyMesh.H"
28 
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::polyDistributionMap::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  const polyMesh& mesh,
65 
66  // mesh before changes
67  const label nOldPoints,
68  const label nOldFaces,
69  const label nOldCells,
70  labelList&& oldPatchStarts,
71  labelList&& oldPatchNMeshPoints,
72 
73  // how to subset pieces of mesh to send across
74  labelListList&& subPointMap,
75  labelListList&& subFaceMap,
76  labelListList&& subCellMap,
77  labelListList&& subPatchMap,
78 
79  // how to reconstruct received mesh
80  labelListList&& constructPointMap,
81  labelListList&& constructFaceMap,
82  labelListList&& constructCellMap,
83  labelListList&& constructPatchMap,
84 
85  const bool subFaceHasFlip,
86  const bool constructFaceHasFlip
87 )
88 :
89  mesh_(mesh),
90  nOldPoints_(nOldPoints),
91  nOldFaces_(nOldFaces),
92  nOldCells_(nOldCells),
93  oldPatchSizes_(oldPatchStarts.size()),
94  oldPatchStarts_(move(oldPatchStarts)),
95  oldPatchNMeshPoints_(move(oldPatchNMeshPoints)),
96  pointMap_(mesh.nPoints(), move(subPointMap), move(constructPointMap)),
97  faceMap_
98  (
99  mesh.nFaces(),
100  move(subFaceMap),
101  move(constructFaceMap),
102  move(subFaceHasFlip),
103  constructFaceHasFlip
104  ),
105  cellMap_(mesh.nCells(), move(subCellMap), move(constructCellMap)),
106  patchMap_
107  (
108  mesh.boundaryMesh().size(),
109  move(subPatchMap),
110  move(constructPatchMap)
111  )
112 {
113  calcPatchSizes();
114 }
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  // Construct boolList from selected elements
122  boolList isSelected
123  (
124  createWithValues<boolList>
125  (
126  nOldPoints(),
127  false,
128  lst,
129  true
130  )
131  );
132 
133  // Distribute
134  distributePointData(isSelected);
135 
136  // Collect selected elements
137  lst = findIndices(isSelected, true);
138 }
139 
140 
142 {
143  // Construct boolList from selected elements
144  boolList isSelected
145  (
146  createWithValues<boolList>
147  (
148  nOldFaces(),
149  false,
150  lst,
151  true
152  )
153  );
154 
155  // Distribute
156  distributeFaceData(isSelected);
157 
158  // Collect selected elements
159  lst = findIndices(isSelected, true);
160 }
161 
162 
164 {
165  // Construct boolList from selected elements
166  boolList isSelected
167  (
168  createWithValues<boolList>
169  (
170  nOldCells(),
171  false,
172  lst,
173  true
174  )
175  );
176 
177  // Distribute
178  distributeCellData(isSelected);
179 
180  // Collect selected elements
181  lst = findIndices(isSelected, true);
182 }
183 
184 
186 {
187  // Construct boolList from selected elements
188  boolList isSelected
189  (
190  createWithValues<boolList>
191  (
192  oldPatchStarts().size(), // nOldPatches
193  false,
194  lst,
195  true
196  )
197  );
198 
199  // Distribute
200  distributePatchData(isSelected);
201 
202  // Collect selected elements
203  lst = findIndices(isSelected, true);
204 }
205 
206 
207 // ************************************************************************* //
void setSize(const label)
Reset size of List.
Definition: List.C:281
polyDistributionMap(const polyMesh &mesh, const label nOldPoints, const label nOldFaces, const label nOldCells, labelList &&oldPatchStarts, labelList &&oldPatchNMeshPoints, labelListList &&subPointMap, labelListList &&subFaceMap, labelListList &&subCellMap, labelListList &&subPatchMap, labelListList &&constructPointMap, labelListList &&constructFaceMap, labelListList &&constructCellMap, labelListList &&constructPatchMap, const bool subFaceHasFlip=false, const bool constructFaceHasFlip=false)
Move constructor from components.
void distributePatchIndices(labelList &patchIDs) const
Distribute list of patch indices.
void distributePointIndices(labelList &pointIDs) const
Distribute list of point indices.
void distributeFaceIndices(labelList &faceIDs) const
Distribute list of face indices.
void distributeCellIndices(labelList &cellIDs) const
Distribute list of cell indices.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
label nPoints
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
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurrences of given element. Linear search.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
error FatalError
static const char nl
Definition: Ostream.H:266