multiFieldValue.H
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) 2021-2022 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 Class
27  Foam::functionObjects::fieldValues::multiFieldValue
28 
29 Group
30  grpFieldFunctionObjects
31 
32 Description
33  Computes a selected operation between multiple function objects.
34 
35  The operation is applied to all results of each object.
36 
37 Note
38  Each object must generate the same number and type of results.
39 
40 Usage
41  Minimal example by using \c system/controlDict.functions:
42  \verbatim
43  multiFieldValue1
44  {
45  // Mandatory entries
46  type multiFieldValue;
47  libs (fieldFunctionObjects);
48  operation average;
49 
50  // List of fieldValue function objects as dictionaries
51  functions
52  {
53  region1
54  {
55  ...
56  // Optional
57  resultFields (field1 field2);
58  }
59  region2
60  {
61  ...
62  // Optional
63  resultFields (field1 field2);
64  }
65 
66  ...
67 
68  regionN
69  {
70  ...
71  // Optional
72  resultFields (field1 field2);
73  }
74  }
75 
76  // Inherited entries
77  ...
78  }
79  \endverbatim
80 
81  where the entries mean:
82  \table
83  Property | Description | Type | Reqd | Deflt
84  type | Type name: multiFieldValue | word | yes | -
85  libs | Library name: fieldFunctionObjects | word | yes | -
86  operation | Operation type to apply to values | word | yes | -
87  functions | List of function objects | dict | yes | -
88  \endtable
89 
90  Options for the \c operation entry:
91  \plaintable
92  sum | Sum of values
93  add | Add values (same as sum)
94  subtract | Subtract values from first entry
95  divide | Divide first entry by values
96  cmptDivide | Divide first entry by componentwise values
97  min | Minimum value
98  max | Maximum value
99  average | Average value
100  \endplaintable
101 
102  The \c resultFields entry can be used to set the name of the function object
103  result fields to process. If omitted, all available values are employed.
104 
105  The inherited entries are elaborated in:
106  - \link stateFunctionObject.H \endlink
107  - \link writeFile.H \endlink
108 
109 SourceFiles
110  multiFieldValue.C
111  multiFieldValueImpl.C
112 
113 \*---------------------------------------------------------------------------*/
114 
115 #ifndef Foam_functionObjects_multiFieldValue_H
116 #define Foam_functionObjects_multiFieldValue_H
117 
118 #include "stateFunctionObject.H"
119 #include "writeFile.H"
120 #include "Enum.H"
121 
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 
124 namespace Foam
125 {
126 namespace functionObjects
127 {
128 namespace fieldValues
129 {
130 
131 /*---------------------------------------------------------------------------*\
132  Class multiFieldValue Declaration
133 \*---------------------------------------------------------------------------*/
134 
135 class multiFieldValue
136 :
137  public functionObjects::stateFunctionObject,
138  public functionObjects::writeFile
139 {
140 public:
141 
142  // Public Data Types
143 
144  //- Operation type enumeration
145  enum operationType
146  {
147  opSum,
148  opAdd,
149  opSubtract,
150  opDivide,
151  opCmptDivide,
152  opMin,
153  opMax,
154  opAverage
155  };
156 
157  //- Operation type names
158  static const Enum<operationType> operationTypeNames_;
159 
160 
161 private:
162 
163  // Private Data
164 
165  //- Operation to apply to values
166  operationType operation_;
167 
168  //- List of function objects
169  PtrList<functionObject> functions_;
170 
171  //- List of result fields per function object
172  List<wordList> resultFields_;
173 
174 
175  // Private Member Functions
176 
177  //- Templated function to apply the operation.
178  // \return true if Type and resultType are correct
179  template<class Type>
180  bool applyOperation
181  (
182  const word& resultType,
183  const wordList& names,
184  const wordList& entryNames
185  );
186 
187 
188 protected:
189 
190  // Protected Member Functions
191 
192  //- Output file header information
193  virtual void writeFileHeader
194  (
195  const wordList& foNames,
196  const List<wordList>& entries,
197  const List<wordList>& types,
198  Ostream& os
199  ) const;
200 
201 
202 public:
203 
204  //- Run-time type information
205  TypeName("multiFieldValue");
208  // Constructors
210  //- Construct from Time and dictionary
212  (
213  const word& name,
214  const Time& runTime,
215  const dictionary& dict
216  );
217 
218  //- No copy construct
220 
221  //- No copy assignment
222  void operator=(const multiFieldValue&) = delete;
223 
224 
225  //- Destructor
226  virtual ~multiFieldValue() = default;
227 
228 
229  // Public Member Functions
230 
231  //- Read from dictionary
232  virtual bool read(const dictionary& dict);
233 
234  //- Do nothing
235  virtual bool execute();
236 
237  //- Calculate and write
238  virtual bool write();
239 };
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 } // End namespace fieldValues
245 } // End namespace functionObjects
246 } // End namespace Foam
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 #endif
251 
252 // ************************************************************************* //
dictionary dict
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
engineTime & runTime
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool read(const dictionary &dict)
Read from dictionary.
const word & name() const noexcept
Return the name of this functionObject.
virtual bool write()
Calculate and write.
A class for handling words, derived from Foam::string.
Definition: word.H:63
word resultType(const word &entryName) const
Retrieve the result type.
static const Enum< operationType > operationTypeNames_
Operation type names.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
TypeName("multiFieldValue")
Run-time type information.
OBJstream os(runTime.globalPath()/outputName)
void operator=(const multiFieldValue &)=delete
No copy assignment.
virtual ~multiFieldValue()=default
Destructor.
List< word > wordList
List of word.
Definition: fileName.H:59
virtual void writeFileHeader(const wordList &foNames, const List< wordList > &entries, const List< wordList > &types, Ostream &os) const
Output file header information.
multiFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Computes a selected operation between multiple function objects.
Namespace for OpenFOAM.