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 | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
28 template<class Type>
30 (
31  const word& resultType,
32  const word& name1,
33  const word& name2,
34  const word& entryName1,
35  const word& entryName2,
36  bool& found
37 )
38 {
39  if (pTraits<Type>::typeName != resultType)
40  {
41  return;
42  }
43 
44  Type result = pTraits<Type>::zero;
45 
46  Type value1 = this->getObjectResult<Type>(name1, entryName1);
47  Type value2 = this->getObjectResult<Type>(name2, entryName2);
48 
49  const word& opName = operationTypeNames_[operation_];
50 
51  switch (operation_)
52  {
53  case opAdd:
54  {
55  result = value1 + value2;
56  break;
57  }
58  case opSubtract:
59  {
60  result = value1 - value2;
61  break;
62  }
63  case opMin:
64  {
65  result = min(value1, value2);
66  break;
67  }
68  case opMax:
69  {
70  result = max(value1, value2);
71  break;
72  }
73  case opAverage:
74  {
75  result = 0.5*(value1 + value2);
76  break;
77  }
78  default:
79  {
81  << "Unable to process operation "
82  << operationTypeNames_[operation_]
83  << abort(FatalError);
84  }
85  }
86 
87  const word resultName(opName + '(' + entryName1 + ',' + entryName2 + ')');
88 
89  if (log_) Info << " " << resultName << " = " << result << endl;
90 
91  this->file()<< tab << result;
92 
93  // Write state/results information
94  this->setResult(resultName, result);
95 
96  found = true;
97 }
98 
99 
100 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fieldValues::fieldValueDelta::apply
void apply(const word &resultType, const word &name1, const word &name2, const word &entryName1, const word &entryName2, bool &found)
Templated function to apply the operation.
Definition: fieldValueDeltaTemplates.C:30
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
found
bool found
Definition: TABSMDCalcMethod2.H:32
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::tab
static const char tab
Definition: Ostream.H:259
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)