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>
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>
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 // ************************************************************************* //
regionSizeDistribution.H
volFields.H
Foam::regionSizeDistribution::regionSum
Map< Type > regionSum(const regionSplit &, const Field< Type > &) const
Foam::HashTable::iterator
An STL-conforming iterator.
Definition: HashTable.H:415
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::label
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
Foam::Field< Type >
regionSplit.H
Foam::regionSplit
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:119
Foam::regionSplit::nRegions
label nRegions() const
Return total number of regions.
Definition: regionSplit.H:201
fld
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::plusEqOp
Definition: ops.H:71
Foam::List< Type >
Foam::UList
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
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::regionSizeDistribution::extractData
List< Type > extractData(const UList< label > &keys, const Map< Type > &) const
Get data in order.