Loading...
Searching...
No Matches
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-2025 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 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.db(),
64 ),
65 fld
66 );
67 regIOobject::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::listReduce(regionField, sumOp<Type>());
92 Pstream::listReduce(regionCount, sumOp<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// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
static void listReduce(UList< T > &values, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce list elements (list must be equal size on all ranks), applying bop to each list element.
const ObjectType * cfindObject(const word &fieldName) const
Return const pointer to the object (eg, a field) in the (sub) objectRegistry.
const objectRegistry & obr_
Reference to the region objectRegistry.
bool store()
Register object with its registry and transfer ownership to the registry.
List< label > labelList
A List of labels.
Definition List.H:62
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299