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-------------------------------------------------------------------------------
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 "volFields.H"
29#include "meshStructure.H"
30#include "globalIndex.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34template<class Type>
35bool 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_().totalSize(), Zero);
80 labelList regionCount(globalFaces_().totalSize(), Zero);
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::listCombineAllGather(regionField, plusEqOp<Type>());
91 Pstream::listCombineAllGather(regionCount, plusEqOp<label>());
92
93 forAll(regionField, regioni)
94 {
95 regionField[regioni] /= regionCount[regioni];
96 }
97
98 // And send result back
99 forAll(cellToPatchFace, celli)
100 {
101 const label regioni = cellToPatchFace[celli];
102 res[celli] = regionField[regioni];
103 }
104 res.correctBoundaryConditions();
105
106 return true;
107 }
108
109 return false;
110}
111
112
113// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
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.
const objectRegistry & obr_
Reference to the region objectRegistry.
Type * getObjectPtr(const word &name, const bool recursive=false) const
List< label > labelList
A List of labels.
Definition: List.H:66
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