layerAverageTemplates.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-2023 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 "layerAverage.H"
27 #include "fvMesh.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class T>
32 T Foam::functionObjects::layerAverage::symmetricCoeff() const
33 {
34  return pTraits<T>::one;
35 }
36 
37 
38 template<class T>
39 Foam::tmp<Foam::Field<T>> Foam::functionObjects::layerAverage::sum
40 (
41  const VolInternalField<T>& cellField
42 ) const
43 {
44  tmp<Field<T>> tlayerField(new Field<T>(nLayers_, Zero));
45  Field<T>& layerField = tlayerField.ref();
46 
47  forAll(cellLayer_, celli)
48  {
49  if (cellLayer_[celli] != -1)
50  {
51  layerField[cellLayer_[celli]] += cellField[celli];
52  }
53  }
54 
56  Pstream::listCombineScatter(layerField);
57 
58  return tlayerField;
59 }
60 
61 
62 template<class T>
63 Foam::tmp<Foam::Field<T>> Foam::functionObjects::layerAverage::average
64 (
65  const tmp<VolInternalField<scalar>>& cellWeight,
66  const tmp<Field<scalar>>& layerWeight,
67  const VolInternalField<T>& cellField
68 ) const
69 {
70  tmp<Field<T>> tlayerField
71  (
72  cellWeight.valid()
73  ? sum<T>(mesh_.V()*cellWeight*cellField)/layerWeight
74  : sum<T>(mesh_.V()*cellField)/layerVolume_
75  );
76 
77  // Handle symmetry
78  if (symmetric_)
79  {
80  Field<T>& layerField = tlayerField.ref();
81 
82  const T coeff = symmetricCoeff<T>();
83 
84  for (label i=0; i<nLayers_/2; i++)
85  {
86  const label j = nLayers_ - i - 1;
87 
88  layerField[i] =
89  (layerField[i] + cmptMultiply(coeff, layerField[j]))/2;
90  }
91 
92  layerField.setSize(nLayers_/2);
93  }
94 
95  return tlayerField;
96 }
97 
98 
99 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void setSize(const label)
Reset size of List.
Definition: List.C:281
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
static const zero Zero
Definition: zero.H:97
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
typename VolField< Type >::Internal VolInternalField
Definition: volFieldsFwd.H:61
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)