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-2020 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("weightFields", weightFieldNames_))
84  {
85  Info<< name() << " " << operationTypeNames_[operation_]
86  << " weight fields " << weightFieldNames_;
87  }
88  else if (dict.found("weightField"))
89  {
90  weightFieldNames_.setSize(1);
91  dict.lookup("weightField") >> weightFieldNames_[0];
92 
93  Info<< name() << " " << operationTypeNames_[operation_]
94  << " weight field " << weightFieldNames_[0];
95  }
96 
97  Info<< nl << endl;
98 }
99 
100 
102 (
103  const label i
104 )
105 {
107 
108  writeCommented(file(), "Time");
109 
110  forAll(fields_, fieldi)
111  {
112  file() << tab << operationTypeNames_[operation_] << "(";
113 
114  forAll(weightFieldNames_, i)
115  {
116  file() << weightFieldNames_[i] << ',';
117  }
118 
119  file() << fields_[fieldi] << ")";
120  }
121 
122  file() << endl;
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127 
129 (
130  const word& name,
131  const Time& runTime,
132  const dictionary& dict
133 )
134 :
135  fieldValue(name, runTime, dict, typeName),
137  operation_(operationTypeNames_.read(dict.lookup("operation")))
138 {
139  read(dict);
140 }
141 
142 
144 (
145  const word& name,
146  const objectRegistry& obr,
147  const dictionary& dict
148 )
149 :
150  fieldValue(name, obr, dict, typeName),
152  operation_(operationTypeNames_.read(dict.lookup("operation")))
153 {
154  read(dict);
155 }
156 
157 
158 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
159 
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
167 (
168  const dictionary& dict
169 )
170 {
171  fieldValue::read(dict);
172 
173  // No additional info to read
174  initialise(dict);
175 
176  return true;
177 }
178 
179 
181 {
183 
184  if (Pstream::master())
185  {
186  writeTime(file());
187  }
188 
189  forAll(fields_, i)
190  {
191  const word& fieldName = fields_[i];
192  bool processed = false;
193 
194  processed = processed || writeValues<scalar>(fieldName);
195  processed = processed || writeValues<vector>(fieldName);
196  processed = processed || writeValues<sphericalTensor>(fieldName);
197  processed = processed || writeValues<symmTensor>(fieldName);
198  processed = processed || writeValues<tensor>(fieldName);
199 
200  if (!processed)
201  {
203  << "Requested field " << fieldName
204  << " not found in database and not processed"
205  << endl;
206  }
207  }
208 
209  if (Pstream::master())
210  {
211  file()<< endl;
212  }
213 
214  Log << endl;
215 
216  return true;
217 }
218 
219 
220 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:667
#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:259
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:251
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:260
Volume (cell) region selection class.
Definition: volRegion.H:102
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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.
#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:812
virtual bool write()
Write.
Definition: fieldValue.C:112