channelIndexTemplates.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) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "channelIndex.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class T>
33 Foam::Field<T> Foam::channelIndex::regionSum(const Field<T>& cellField) const
34 {
35  Field<T> regionField(cellRegion_().nRegions(), Zero);
36 
37  forAll(cellRegion_(), celli)
38  {
39  regionField[cellRegion_()[celli]] += cellField[celli];
40  }
41 
42  // Global sum
43  Pstream::listCombineGather(regionField, plusEqOp<T>());
44  Pstream::listCombineScatter(regionField);
45 
46  return regionField;
47 }
48 
49 
50 template<class T>
52 (
53  const Field<T>& cellField,
54  const bool asymmetric
55 ) const
56 {
57  // Average and order
58  const Field<T> summedField(regionSum(cellField));
59 
60  Field<T> regionField
61  (
62  summedField
63  / regionCount_,
64  sortMap_
65  );
66 
67  // Symmetry?
68  if (symmetric_)
69  {
70  label nlb2 = cellRegion_().nRegions()/2;
71 
72  if (asymmetric)
73  {
74  for (label j=0; j<nlb2; j++)
75  {
76  regionField[j] =
77  0.5
78  * (
79  regionField[j]
80  - regionField[cellRegion_().nRegions() - j - 1]
81  );
82  }
83  }
84  else
85  {
86  for (label j=0; j<nlb2; j++)
87  {
88  regionField[j] =
89  0.5
90  * (
91  regionField[j]
92  + regionField[cellRegion_().nRegions() - j - 1]
93  );
94  }
95  }
96 
97  regionField.setSize(nlb2);
98  }
99 
100  return regionField;
101 }
102 
103 
104 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::channelIndex::collapse
Field< T > collapse(const Field< T > &vsf, const bool asymmetric=false) const
Collapse a field to a line.
Foam::Field< T >
channelIndex.H
Foam::Pstream::listCombineGather
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:290
Foam::Pstream::listCombineScatter
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Definition: combineGatherScatter.C:432
Foam::channelIndex::regionSum
Field< T > regionSum(const Field< T > &cellField) const
Sum field per region.