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-------------------------------------------------------------------------------
10License
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
32template<class T>
33Foam::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::listCombineAllGather(regionField, plusEqOp<T>());
44
45 return regionField;
46}
47
48
49template<class T>
51(
52 const Field<T>& cellField,
53 const bool asymmetric
54) const
55{
56 // Average and order
57 const Field<T> summedField(regionSum(cellField));
58
59 Field<T> regionField
60 (
61 summedField
62 / regionCount_,
63 sortMap_
64 );
65
66 // Symmetry?
67 if (symmetric_)
68 {
69 label nlb2 = cellRegion_().nRegions()/2;
70
71 if (asymmetric)
72 {
73 for (label j=0; j<nlb2; j++)
74 {
75 regionField[j] =
76 0.5
77 * (
78 regionField[j]
79 - regionField[cellRegion_().nRegions() - j - 1]
80 );
81 }
82 }
83 else
84 {
85 for (label j=0; j<nlb2; j++)
86 {
87 regionField[j] =
88 0.5
89 * (
90 regionField[j]
91 + regionField[cellRegion_().nRegions() - j - 1]
92 );
93 }
94 }
95
96 regionField.setSize(nlb2);
97 }
98
99 return regionField;
100}
101
102
103// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
static void listCombineAllGather(const List< commsStruct > &comms, List< T > &values, const CombineOp &cop, const int tag, const label comm)
After completion all processors have the same data.
void collapse()
Collapse shape to correct one after removing duplicate vertices.
Definition: cellShape.C:33
Field< T > regionSum(const Field< T > &cellField) const
Sum field per region.
static Map< Type > regionSum(const regionSplit &regions, const Field< Type > &fld)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333