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 
51  Pstream::mapCombineGather(regionToSum, plusEqOp<Type>());
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 // ************************************************************************* //
regionSizeDistribution.H
volFields.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field
Generic templated field type.
Definition: Field.H:63
regionSplit.H
Foam::regionSplit
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:140
Foam::regionSplit::nRegions
label nRegions() const
Return total number of regions.
Definition: regionSplit.H:294
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::List< Type >
Foam::UList< label >
Foam::plusEqOp
Definition: ops.H:72
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114