All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fieldValueDeltaTemplates.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) 2012-2018 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 "GeometricField.H"
27 #include "volMesh.H"
28 #include "surfaceMesh.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
33 Type Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
34 (
35  const Type& value1,
36  const Type& value2
37 ) const
38 {
39  Type result = Zero;
40 
41  switch (operation_)
42  {
43  case operationType::add:
44  {
45  result = value1 + value2;
46  break;
47  }
49  {
50  result = value1 - value2;
51  break;
52  }
53  case operationType::min:
54  {
55  result = min(value1, value2);
56  break;
57  }
58  case operationType::max:
59  {
60  result = max(value1, value2);
61  break;
62  }
64  {
65  result = 0.5*(value1 + value2);
66  break;
67  }
68  default:
69  {
71  << "Unable to process operation "
72  << operationTypeNames_[operation_]
73  << abort(FatalError);
74  }
75  }
76 
77  return result;
78 }
79 
80 
81 template<class Type>
82 void Foam::functionObjects::fieldValues::fieldValueDelta::processFields
83 (
84  bool& found
85 )
86 {
87  typedef GeometricField<Type, fvPatchField, volMesh> vf;
88  typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
89 
90  const wordList& fields1 = region1Ptr_->fields();
91 
92  const dictionary& results1 = region1Ptr_->resultDict();
93  const dictionary& results2 = region2Ptr_->resultDict();
94 
95  Type r1(Zero);
96  Type r2(Zero);
97 
98  forAll(fields1, i)
99  {
100  const word& fieldName = fields1[i];
101 
102  if
103  (
104  (obr_.foundObject<vf>(fieldName) || obr_.foundObject<sf>(fieldName))
105  && results2.found(fieldName)
106  )
107  {
108  results1.lookup(fieldName) >> r1;
109  results2.lookup(fieldName) >> r2;
110 
111  Type result = applyOperation(r1, r2);
112 
113  Log << " " << operationTypeNames_[operation_]
114  << "(" << fieldName << ") = " << result
115  << endl;
116 
117  if (Pstream::master())
118  {
119  file()<< tab << result;
120  }
121 
122  found = true;
123  }
124  }
125 }
126 
127 
128 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
static const char tab
Definition: Ostream.H:259
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
bool foundObject(const word &name) const
Is the named Type found?
static const NamedEnum< operationType, 5 > operationTypeNames_
Operation type names.
static const zero Zero
Definition: zero.H:97
errorManip< error > abort(error &err)
Definition: errorManip.H:131
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
volScalarField sf(fieldObject, mesh)
List< word > wordList
A List of words.
Definition: fileName.H:54
const objectRegistry & obr_
Reference to the region objectRegistry.
#define Log
Report write to Foam::Info if the local log switch is true.
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:107