columnAverage.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-2021 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 "columnAverage.H"
29 #include "volFields.H"
31 #include "meshStructure.H"
32 #include "globalIndex.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40  defineTypeNameAndDebug(columnAverage, 0);
41  addToRunTimeSelectionTable(functionObject, columnAverage, dictionary);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 Foam::functionObjects::columnAverage::meshAddressing(const polyMesh& mesh) const
50 {
51  if (!meshStructurePtr_)
52  {
53  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
54 
55  // Count
56  label sz = 0;
57  for (const label patchi : patchIDs_)
58  {
59  sz += pbm[patchi].size();
60  }
61 
62  // Fill
63  labelList meshFaces(sz);
64  sz = 0;
65  for (const label patchi : patchIDs_)
66  {
67  label start = pbm[patchi].start();
68  label size = pbm[patchi].size();
69  for (label i = 0; i < size; ++i)
70  {
71  meshFaces[sz++] = start+i;
72  }
73  }
74 
75  if (sz == 0)
76  {
77  // TODO: If source patch is a cyclic it may have have been
78  // converted to a processorCyclic for parallel runs
79 
81  << "Requested patches have zero faces"
82  << endl;
83  }
84 
86  (
87  UIndirectList<face>(mesh.faces(), meshFaces),
88  mesh.points()
89  );
90 
91  globalFaces_.reset(new globalIndex(uip.size()));
92  globalEdges_.reset(new globalIndex(uip.nEdges()));
93  globalPoints_.reset(new globalIndex(uip.nPoints()));
94  meshStructurePtr_.reset
95  (
96  new meshStructure
97  (
98  mesh,
99  uip,
100  globalFaces_(),
101  globalEdges_(),
102  globalPoints_()
103  )
104  );
105  }
106 
107  return *meshStructurePtr_;
108 }
109 
110 
111 const Foam::word Foam::functionObjects::columnAverage::averageName
112 (
113  const word& fieldName
114 ) const
115 {
116  return scopedName("columnAverage(" + fieldName + ")");
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
123 (
124  const word& name,
125  const Time& runTime,
126  const dictionary& dict
127 )
128 :
130  patchIDs_(),
131  fieldSet_(mesh_)
132 {
133  read(dict);
134 }
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
140 {
142 
143  patchIDs_ =
144  mesh_.boundaryMesh().patchSet
145  (
146  dict.get<wordRes>("patches")
147  ).sortedToc();
148 
149  fieldSet_.read(dict);
150 
151  return true;
152 }
153 
154 
156 {
157  // Make fields up to date with current selection
158  fieldSet_.updateSelection();
159 
160  for (const word& fieldName : fieldSet_.selectionNames())
161  {
162  columnAverageField<scalar>(fieldName);
163  columnAverageField<vector>(fieldName);
164  columnAverageField<sphericalTensor>(fieldName);
165  columnAverageField<symmTensor>(fieldName);
166  columnAverageField<tensor>(fieldName);
167  }
168 
169  return true;
170 }
171 
172 
174 {
175  for (const word& fieldName : fieldSet_.selectionNames())
176  {
177  const word resultName("columnAverage(" + fieldName + ")");
178  const regIOobject* obj =
179  obr_.cfindObject<regIOobject>(averageName(fieldName));
180 
181  if (obj)
182  {
183  obj->write();
184  }
185  }
186 
187  return true;
188 }
189 
190 
191 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
globalIndex.H
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
meshStructure.H
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:132
Foam::functionObjects::columnAverage::write
virtual bool write()
Write the results.
Definition: columnAverage.C:173
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
columnAverage.H
Foam::meshStructure
Detect extruded mesh structure given a set of faces (uindirectPrimitivePatch).
Definition: meshStructure.H:61
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::uindirectPrimitivePatch
PrimitivePatch< UIndirectList< face >, const pointField & > uindirectPrimitivePatch
A PrimitivePatch with UIndirectList for the faces, const reference for the point field.
Definition: uindirectPrimitivePatch.H:49
Foam::functionObjects::columnAverage::read
virtual bool read(const dictionary &dict)
Read the settings.
Definition: columnAverage.C:139
Foam::functionObjects::columnAverage::execute
virtual bool execute()
Execute, currently does nothing.
Definition: columnAverage.C:155
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::functionObjects::columnAverage::columnAverage
columnAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: columnAverage.C:123