fieldValueDeltaTemplates.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-2016 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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
32 void Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
33 (
34  const word& resultType,
35  const word& name1,
36  const word& name2,
37  const word& entryName1,
38  const word& entryName2,
39  bool& found
40 )
41 {
42  if (pTraits<Type>::typeName != resultType)
43  {
44  return;
45  }
46 
47  Type result = Zero;
48 
49  Type value1 = this->getObjectResult<Type>(name1, entryName1);
50  Type value2 = this->getObjectResult<Type>(name2, entryName2);
51 
52  const word& opName = operationTypeNames_[operation_];
53 
54  switch (operation_)
55  {
56  case opAdd:
57  {
58  result = value1 + value2;
59  break;
60  }
61  case opSubtract:
62  {
63  result = value1 - value2;
64  break;
65  }
66  case opMin:
67  {
68  result = min(value1, value2);
69  break;
70  }
71  case opMax:
72  {
73  result = max(value1, value2);
74  break;
75  }
76  case opAverage:
77  {
78  result = 0.5*(value1 + value2);
79  break;
80  }
81  default:
82  {
84  << "Unable to process operation "
85  << operationTypeNames_[operation_]
86  << abort(FatalError);
87  }
88  }
89 
90  const word resultName(opName + '(' + entryName1 + ',' + entryName2 + ')');
91 
92  Log << " " << resultName << " = " << result << endl;
93 
94  this->file()<< tab << result;
95 
96  // Write state/results information
97  this->setResult(resultName, result);
98 
99  found = true;
100 }
101 
102 
103 // ************************************************************************* //
Log
#define Log
Definition: PDRblock.C:35
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:237
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::functionObjects::stateFunctionObject::resultType
word resultType(const word &entryName) const
Retrieve the result type.
Definition: stateFunctionObject.C:159
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
Foam::functionObjects::fieldValues::fieldValueDelta::opSubtract
Subtract.
Definition: fieldValueDelta.H:185
Foam::functionObjects::fieldValues::fieldValueDelta::opAdd
Add.
Definition: fieldValueDelta.H:184
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
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::functionObjects::fieldValues::fieldValueDelta::opMin
Minimum.
Definition: fieldValueDelta.H:186
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::functionObjects::fieldValues::fieldValueDelta::opAverage
Average.
Definition: fieldValueDelta.H:188
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::tab
constexpr char tab
Definition: Ostream.H:384
Foam::functionObjects::fieldValues::fieldValueDelta::opMax
Maximum.
Definition: fieldValueDelta.H:187
Foam::functionObjects::stateFunctionObject::setResult
void setResult(const word &entryName, const Type &value)
Add result.
Definition: stateFunctionObjectTemplates.C:124
Foam::functionObjects::fieldValues::fieldValueDelta::operationTypeNames_
static const Enum< operationType > operationTypeNames_
Operation type names.
Definition: fieldValueDelta.H:192