columnAverageTemplates.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) 2018-2020 OpenCFD Ltd.
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 "volFields.H"
29 #include "meshStructure.H"
30 #include "globalIndex.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
35 bool Foam::functionObjects::columnAverage::columnAverageField
36 (
37  const word& fieldName
38 )
39 {
40  typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
41 
42  const fieldType* fldPtr = cfindObject<fieldType>(fieldName);
43 
44  if (fldPtr)
45  {
46  const fieldType& fld = *fldPtr;
47 
48  const word resultName(averageName(fieldName));
49 
50  fieldType* resPtr = obr_.getObjectPtr<fieldType>(resultName);
51 
52  if (!resPtr)
53  {
54  resPtr = new fieldType
55  (
56  IOobject
57  (
58  resultName,
59  fld.mesh().time().timeName(),
60  fld.mesh(),
63  ),
64  fld
65  );
66  obr_.objectRegistry::store(resPtr);
67  }
68  fieldType& res = *resPtr;
69 
70  const meshStructure& ms = meshAddressing(fld.mesh());
71  if (globalFaces_().empty())
72  {
73  return false;
74  }
75 
76  const labelList& cellToPatchFace = ms.cellToPatchFaceAddressing();
77 
78  // Brute force: collect per-global-patchface on all processors
79  Field<Type> regionField(globalFaces_().size(), Zero);
80  labelList regionCount(globalFaces_().size(), 0);
81 
82  forAll(cellToPatchFace, celli)
83  {
84  const label regioni = cellToPatchFace[celli];
85  regionField[regioni] += fld[celli];
86  regionCount[regioni]++;
87  }
88 
89  // Global sum
90  Pstream::listCombineGather(regionField, plusEqOp<Type>());
91  Pstream::listCombineScatter(regionField);
92  Pstream::listCombineGather(regionCount, plusEqOp<label>());
93  Pstream::listCombineScatter(regionCount);
94 
95  forAll(regionField, regioni)
96  {
97  regionField[regioni] /= regionCount[regioni];
98  }
99 
100  // And send result back
101  forAll(cellToPatchFace, celli)
102  {
103  const label regioni = cellToPatchFace[celli];
104  res[celli] = regionField[regioni];
105  }
106  res.correctBoundaryConditions();
107 
108  return true;
109  }
110 
111  return false;
112 }
113 
114 
115 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
Foam::objectRegistry::getObjectPtr
Type * getObjectPtr(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:423
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:102
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
globalIndex.H
meshStructure.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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::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::IOobject::NO_READ
Definition: IOobject.H:188