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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "regionSizeDistribution.H"
30 #include "regionSplit.H"
31 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<class Type>
36 Foam::Map<Type> Foam::functionObjects::regionSizeDistribution::regionSum
37 (
38  const regionSplit& regions,
39  const Field<Type>& fld
40 ) const
41 {
42  // Per region the sum of fld
43  Map<Type> regionToSum(regions.nRegions()/Pstream::nProcs());
44 
45  forAll(fld, celli)
46  {
47  const label regioni = regions[celli];
48  regionToSum(regioni, Type(Zero)) += fld[celli];
49  }
50 
52  Pstream::mapCombineScatter(regionToSum);
53 
54  return regionToSum;
55 }
56 
57 
58 template<class Type>
59 Foam::List<Type> Foam::functionObjects::regionSizeDistribution::extractData
60 (
61  const labelUList& keys,
62  const Map<Type>& regionData
63 ) const
64 {
65  List<Type> sortedData(keys.size());
66 
67  forAll(keys, i)
68  {
69  sortedData[i] = regionData[keys[i]];
70  }
71  return sortedData;
72 }
73 
74 
75 // ************************************************************************* //
Foam::Pstream::mapCombineGather
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:545
regionSizeDistribution.H
volFields.H
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:65
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
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:136
Foam::regionSplit::nRegions
label nRegions() const
Definition: regionSplit.H:290
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::Pstream::mapCombineScatter
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Definition: combineGatherScatter.C:660
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:99
Foam::plusEqOp
Definition: ops.H:66
Foam::UList::size
void size(const label n)
Definition: UList.H:110
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Definition: UPstream.H:441