regionSizeDistributionTemplates.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) 2012-2018 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::functionObjects::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 template<class Type>
64 Foam::List<Type> Foam::functionObjects::regionSizeDistribution::extractData
65 (
66  const UList<label>& keys,
67  const Map<Type>& regionData
68 ) const
69 {
70  List<Type> sortedData(keys.size());
71 
72  forAll(keys, i)
73  {
74  sortedData[i] = regionData[keys[i]];
75  }
76  return sortedData;
77 }
78 
79 
80 // ************************************************************************* //
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:119
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
An STL-conforming iterator.
Definition: HashTable.H:426
Pre-declare SubField and related Field type.
Definition: Field.H:56
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
label nRegions() const
Return total number of regions.
Definition: regionSplit.H:201
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49