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 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_.valid())
52  {
53  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
54  const labelList patchIDs(patchSet_.sortedToc());
55 
56  // Count
57  label sz = 0;
58  for (const label patchi : patchIDs)
59  {
60  sz += pbm[patchi].size();
61  }
62 
63  // Fill
64  labelList meshFaces(sz);
65  sz = 0;
66  for (const label patchi : patchIDs)
67  {
68  label start = pbm[patchi].start();
69  label size = pbm[patchi].size();
70  for (label i = 0; i < size; ++i)
71  {
72  meshFaces[sz++] = start+i;
73  }
74  }
75 
76  if (sz == 0)
77  {
78  // TODO: If source patch is a cyclic it may have have been
79  // converted to a processorCyclic for parallel runs
80 
82  << "Requested patches have zero faces"
83  << endl;
84  }
85 
87  (
88  UIndirectList<face>(mesh.faces(), meshFaces),
89  mesh.points()
90  );
91 
92  globalFaces_.set(new globalIndex(uip.size()));
93  globalEdges_.set(new globalIndex(uip.nEdges()));
94  globalPoints_.set(new globalIndex(uip.nPoints()));
95  meshStructurePtr_.set
96  (
97  new meshStructure
98  (
99  mesh,
100  uip,
101  globalFaces_(),
102  globalEdges_(),
103  globalPoints_()
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 name() + ":columnAverage(" + fieldName + ")";
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
123 (
124  const word& name,
125  const Time& runTime,
126  const dictionary& dict
127 )
128 :
130  patchSet_(),
131  fieldSet_(mesh_)
132 {
133  read(dict);
134 }
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
140 {
142 
143  patchSet_ = mesh_.boundaryMesh().patchSet(dict.get<wordRes>("patches"));
144 
145  fieldSet_.read(dict);
146 
147  return true;
148 }
149 
150 
152 {
153  // Make fields up to date with current selection
154  fieldSet_.updateSelection();
155 
156  for (const word& fieldName : fieldSet_.selectionNames())
157  {
158  columnAverageField<scalar>(fieldName);
159  columnAverageField<vector>(fieldName);
160  columnAverageField<sphericalTensor>(fieldName);
161  columnAverageField<symmTensor>(fieldName);
162  columnAverageField<tensor>(fieldName);
163  }
164 
165  return true;
166 }
167 
168 
170 {
171  for (const word& fieldName : fieldSet_.selectionNames())
172  {
173  const word resultName("columnAverage(" + fieldName + ")");
174  const regIOobject* obj =
175  obr_.lookupObjectPtr<regIOobject>(averageName(fieldName));
176 
177  if (obj)
178  {
179  obj->write();
180  }
181  }
182 
183  return true;
184 }
185 
186 
187 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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:62
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:337
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
meshStructure.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:170
Foam::functionObjects::columnAverage::read
virtual bool read(const dictionary &)
Read the settings.
Definition: columnAverage.C:139
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::functionObjects::columnAverage::write
virtual bool write()
Write the results.
Definition: columnAverage.C:169
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:121
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
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
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
columnAverage.H
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
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:67
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::uindirectPrimitivePatch
PrimitivePatch< face, UIndirectList, const pointField & > uindirectPrimitivePatch
A PrimitivePatch using a UIndirectList for the faces.
Definition: uindirectPrimitivePatch.H:47
Foam::functionObjects::columnAverage::columnAverage
columnAverage(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: columnAverage.C:123
Foam::functionObjects::columnAverage::execute
virtual bool execute()
Execute, currently does nothing.
Definition: columnAverage.C:151
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294