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  }
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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Pre-declare SubField and related Field type.
Definition: Field.H:83
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:167
A HashTable to objects of type <T> with a label key.
Definition: Map.H:52
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Scatter data. Reverse of combineGather.
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:118
label nRegions() const
Return total number of regions.
Definition: regionSplit.H:208
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
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
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:112