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  auto* 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(),
64  ),
65  fld
66  );
67  obr_.objectRegistry::store(resPtr);
68  }
69  fieldType& res = *resPtr;
70 
71  const meshStructure& ms = meshAddressing(fld.mesh());
72  if (globalFaces_().empty())
73  {
74  return false;
75  }
76 
77  const labelList& cellToPatchFace = ms.cellToPatchFaceAddressing();
78 
79  // Brute force: collect per-global-patchface on all processors
80  Field<Type> regionField(globalFaces_().totalSize(), Zero);
81  labelList regionCount(globalFaces_().totalSize(), Zero);
82 
83  forAll(cellToPatchFace, celli)
84  {
85  const label regioni = cellToPatchFace[celli];
86  regionField[regioni] += fld[celli];
87  regionCount[regioni]++;
88  }
89 
90  // Global sum
91  Pstream::listCombineReduce(regionField, plusEqOp<Type>());
92  Pstream::listCombineReduce(regionCount, plusEqOp<label>());
93 
94  forAll(regionField, regioni)
95  {
96  regionField[regioni] /= regionCount[regioni];
97  }
98 
99  // And send result back
100  forAll(cellToPatchFace, celli)
101  {
102  const label regioni = cellToPatchFace[celli];
103  res[celli] = regionField[regioni];
104  }
105  res.correctBoundaryConditions();
106 
107  return true;
108  }
109 
110  return false;
111 }
112 
113 
114 // ************************************************************************* //
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
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))
const objectRegistry & obr_
Reference to the region objectRegistry.
Nothing to be read.
List< label > labelList
A List of labels.
Definition: List.H:62
Request registration (bool: true)
static void listCombineReduce(List< T > &values, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
After completion all processors have the same data.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127