regionSizeDistributionTemplates.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) 2012 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 "regionSizeDistribution.H"
27 #include "regionSplit.H"
28 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
33 Foam::Map<Type> Foam::regionSizeDistribution::regionSum
34 (
35  const regionSplit& regions,
36  const Field<Type>& fld
37 ) const
38 {
39  // Per region the sum of fld
40  Map<Type> regionToSum(regions.nRegions()/Pstream::nProcs());
41 
42  forAll(fld, cellI)
43  {
44  label regionI = regions[cellI];
45 
46  typename Map<Type>::iterator fnd = regionToSum.find(regionI);
47  if (fnd == regionToSum.end())
48  {
49  regionToSum.insert(regionI, fld[cellI]);
50  }
51  else
52  {
53  fnd() += fld[cellI];
54  }
55  }
56  Pstream::mapCombineGather(regionToSum, plusEqOp<Type>());
57  Pstream::mapCombineScatter(regionToSum);
58 
59  return regionToSum;
60 }
61 
62 
63 // Get data in sortedToc order
64 template<class Type>
65 Foam::List<Type> Foam::regionSizeDistribution::extractData
66 (
67  const UList<label>& keys,
68  const Map<Type>& regionData
69 ) const
70 {
71  List<Type> sortedData(keys.size());
72 
73  forAll(keys, i)
74  {
75  sortedData[i] = regionData[keys[i]];
76  }
77  return sortedData;
78 }
79 
80 
81 // ************************************************************************* //
label nRegions() const
Return total number of regions.
Definition: regionSplit.H:218
An STL-conforming iterator.
Definition: HashTable.H:415
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49
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
#define forAll(list, i)
Definition: UList.H:421
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Pre-declare SubField and related Field type.
Definition: Field.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:116