volFieldValue.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "volFieldValue.H"
27 #include "fvMesh.H"
28 #include "volFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37 namespace fieldValues
38 {
39  defineTypeNameAndDebug(volFieldValue, 0);
40  addToRunTimeSelectionTable(fieldValue, volFieldValue, dictionary);
41  addToRunTimeSelectionTable(functionObject, volFieldValue, dictionary);
42 }
43 }
44 }
45 
46 template<>
47 const char*
49 <
51  13
52 >::names[] =
53 {
54  "none",
55  "sum",
56  "weightedSum",
57  "sumMag",
58  "average",
59  "weightedAverage",
60  "volAverage",
61  "weightedVolAverage",
62  "volIntegrate",
63  "weightedVolIntegrate",
64  "min",
65  "max",
66  "CoV"
67 };
68 
69 const Foam::NamedEnum
70 <
72  13
74 
75 
76 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
77 
79 (
80  const dictionary& dict
81 )
82 {
83  if (dict.readIfPresent("weightField", weightFieldName_))
84  {
85  Info<< " weight field = " << weightFieldName_;
86  }
87 
88  Info<< nl << endl;
89 }
90 
91 
93 (
94  const label i
95 )
96 {
98 
99  writeCommented(file(), "Time");
100 
101  forAll(fields_, fieldi)
102  {
103  file()
104  << tab << operationTypeNames_[operation_]
105  << "(" << fields_[fieldi] << ")";
106  }
107 
108  file() << endl;
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113 
115 (
116  const word& name,
117  const Time& runTime,
118  const dictionary& dict
119 )
120 :
121  fieldValue(name, runTime, dict, typeName),
123  operation_(operationTypeNames_.read(dict.lookup("operation"))),
124  weightFieldName_("none")
125 {
126  read(dict);
127 }
128 
129 
131 (
132  const word& name,
133  const objectRegistry& obr,
134  const dictionary& dict
135 )
136 :
137  fieldValue(name, obr, dict, typeName),
139  operation_(operationTypeNames_.read(dict.lookup("operation"))),
140  weightFieldName_("none")
141 {
142  read(dict);
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 (
156  const dictionary& dict
157 )
158 {
159  fieldValue::read(dict);
160 
161  // No additional info to read
162  initialise(dict);
163 
164  return true;
165 }
166 
167 
169 {
171 
172  if (Pstream::master())
173  {
174  writeTime(file());
175  }
176 
177  forAll(fields_, i)
178  {
179  const word& fieldName = fields_[i];
180  bool processed = false;
181 
182  processed = processed || writeValues<scalar>(fieldName);
183  processed = processed || writeValues<vector>(fieldName);
184  processed = processed || writeValues<sphericalTensor>(fieldName);
185  processed = processed || writeValues<symmTensor>(fieldName);
186  processed = processed || writeValues<tensor>(fieldName);
187 
188  if (!processed)
189  {
191  << "Requested field " << fieldName
192  << " not found in database and not processed"
193  << endl;
194  }
195  }
196 
197  if (Pstream::master())
198  {
199  file()<< endl;
200  }
201 
202  Log << endl;
203 
204  return true;
205 }
206 
207 
208 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:59
static const NamedEnum< operationType, 13 > operationTypeNames_
Operation type names.
static const char tab
Definition: Ostream.H:264
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary)
void initialise(const dictionary &dict)
Initialise, e.g. cell addressing.
Definition: volFieldValue.C:79
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition: fieldValue.C:90
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
volFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
defineTypeNameAndDebug(fieldValueDelta, 0)
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const char nl
Definition: Ostream.H:265
Volume (cell) region selection class.
Definition: volRegion.H:102
void writeFileHeader(const writeFile &wf, Ostream &file)
Output file header information.
Definition: volRegion.C:58
virtual void writeFileHeader(const label i)
Output file header information.
Definition: volFieldValue.C:93
#define WarningInFunction
Report a warning using Foam::Warning.
#define Log
Report write to Foam::Info if the local log switch is true.
messageStream Info
Base class for field value -based function objects.
Definition: fieldValue.H:62
Registry of regIOobjects.
virtual bool write()
Calculate and write.
virtual bool read(const dictionary &)
Read from dictionary.
const fvMesh & mesh_
Reference to the fvMesh.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583
virtual bool write()
Write.
Definition: fieldValue.C:112