channelIndexTemplates.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) 2011-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 "channelIndex.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
31 Foam::Field<T> Foam::channelIndex::regionSum(const Field<T>& cellField) const
32 {
33  Field<T> regionField(cellRegion_().nRegions(), Zero);
34 
35  forAll(cellRegion_(), celli)
36  {
37  regionField[cellRegion_()[celli]] += cellField[celli];
38  }
39 
40  // Global sum
41  Pstream::listCombineGather(regionField, plusEqOp<T>());
42  Pstream::listCombineScatter(regionField);
43 
44  return regionField;
45 }
46 
47 
48 template<class T>
50 (
51  const Field<T>& cellField,
52  const bool asymmetric
53 ) const
54 {
55  // Average and order
56  const Field<T> summedField(regionSum(cellField));
57 
58  Field<T> regionField
59  (
60  summedField
61  / regionCount_,
62  sortMap_
63  );
64 
65  // Symmetry?
66  if (symmetric_)
67  {
68  label nlb2 = cellRegion_().nRegions()/2;
69 
70  if (asymmetric)
71  {
72  for (label j=0; j<nlb2; j++)
73  {
74  regionField[j] =
75  0.5
76  * (
77  regionField[j]
78  - regionField[cellRegion_().nRegions() - j - 1]
79  );
80  }
81  }
82  else
83  {
84  for (label j=0; j<nlb2; j++)
85  {
86  regionField[j] =
87  0.5
88  * (
89  regionField[j]
90  + regionField[cellRegion_().nRegions() - j - 1]
91  );
92  }
93  }
94 
95  regionField.setSize(nlb2);
96  }
97 
98  return regionField;
99 }
100 
101 
102 // ************************************************************************* //
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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 void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
Field< T > regionSum(const Field< T > &cellField) const
Sum field per region.
static const zero Zero
Definition: zero.H:97
Field< T > collapse(const Field< T > &vsf, const bool asymmetric=false) const
Collapse a field to a line.