multiFieldValueTemplates.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "FlatOutput.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class Type>
34 bool Foam::functionObjects::fieldValues::multiFieldValue::applyOperation
35 (
36  const word& resultType,
37  const wordList& names,
38  const wordList& entryNames
39 )
40 {
41  if (pTraits<Type>::typeName != resultType)
42  {
43  return false;
44  }
45 
46  Type result = Zero;
47 
48  Field<Type> values(names.size());
49  forAll(values, i)
50  {
51  values[i] = this->getObjectResult<Type>(names[i], entryNames[i]);
52  }
53 
54  const word& opName = operationTypeNames_[operation_];
55 
56  switch (operation_)
57  {
58  case opSum:
59  case opAdd:
60  {
61  result = sum(values);
62  break;
63  }
64  case opSubtract:
65  {
66  result = values[0];
67  for (label i = 1; i < values.size(); ++i)
68  {
69  result -= values[i];
70  }
71  break;
72  }
73  case opMin:
74  {
75  result = min(values);
76  break;
77  }
78  case opMax:
79  {
80  result = max(values);
81  break;
82  }
83  case opAverage:
84  {
85  result = average(values);
86  break;
87  }
88  default:
89  {
91  << "Unable to process operation "
92  << operationTypeNames_[operation_]
93  << abort(FatalError);
94  }
95  }
96 
97  OStringStream os;
98  os << opName << flatOutput(entryNames, FlatOutput::ParenComma{});
99  const word resultName(os.str());
100  Log << " " << resultName << " = " << result << endl;
101 
102  this->file()<< tab << result;
103 
104  // Write state/results information
105  this->setResult(resultName, result);
106 
107  return true;
108 }
109 
110 
111 // ************************************************************************* //
Log
#define Log
Definition: PDRblock.C:35
Foam::functionObjects::fieldValues::multiFieldValue::opSubtract
Subtract values from first entry.
Definition: multiFieldValue.H:196
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:236
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::stateFunctionObject::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: stateFunctionObject.C:130
Foam::functionObjects::fieldValues::multiFieldValue::operationTypeNames_
static const Enum< operationType > operationTypeNames_
Operation type names.
Definition: multiFieldValue.H:203
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::functionObjects::fieldValues::multiFieldValue::opMin
Minimum value.
Definition: multiFieldValue.H:197
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::functionObjects::fieldValues::multiFieldValue::opAdd
Add values (same as sum)
Definition: multiFieldValue.H:195
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::functionObjects::fieldValues::multiFieldValue::opMax
Maximum value.
Definition: multiFieldValue.H:198
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::tab
constexpr char tab
Definition: Ostream.H:403
Foam::functionObjects::fieldValues::multiFieldValue::opAverage
Average value.
Definition: multiFieldValue.H:199
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::functionObjects::fieldValues::multiFieldValue::opSum
Sum of values.
Definition: multiFieldValue.H:194
Foam::functionObjects::stateFunctionObject::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: stateFunctionObjectTemplates.C:108
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
FlatOutput.H
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:328