fieldValueDelta.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-2020 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 "fieldValueDelta.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38 namespace fieldValues
39 {
42 }
43 }
44 }
45 
46 
47 const Foam::Enum
48 <
50 >
52 ({
53  { operationType::opAdd, "add" },
54  { operationType::opSubtract, "subtract" },
55  { operationType::opMin, "min" },
56  { operationType::opMax, "max" },
57  { operationType::opAverage, "average" },
58 });
59 
60 
61 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
62 
64 (
65  Ostream& os
66 ) const
67 {
68  const wordList& fields1 = region1Ptr_->fields();
69  const wordList& fields2 = region2Ptr_->fields();
70 
71  DynamicList<word> commonFields(fields1.size());
72  forAll(fields1, fieldi)
73  {
74  label index = fields2.find(fields1[fieldi]);
75  if (index != -1)
76  {
77  commonFields.append(fields1[fieldi]);
78  }
79  }
80 
81  writeHeaderValue(os, "Source1", region1Ptr_->name());
82  writeHeaderValue(os, "Source2", region2Ptr_->name());
83  writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
84  writeCommented(os, "Time");
85 
86  forAll(commonFields, i)
87  {
88  os << tab << commonFields[i];
89  }
90 
91  os << endl;
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const word& name,
100  const Time& runTime,
101  const dictionary& dict
102 )
103 :
105  writeFile(obr_, name, typeName, dict),
106  operation_(opSubtract),
107  region1Ptr_(nullptr),
108  region2Ptr_(nullptr)
109 {
110  read(dict);
111  writeFileHeader(file());
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 (
119  const dictionary& dict
120 )
121 {
124 
125  region1Ptr_.reset
126  (
128  (
129  name() + ".region1",
130  obr_,
131  dict.subDict("region1"),
132  false
133  ).ptr()
134  );
135  region2Ptr_.reset
136  (
138  (
139  name() + ".region2",
140  obr_,
141  dict.subDict("region2"),
142  false
143  ).ptr()
144  );
145 
146  operation_ = operationTypeNames_.get("operation", dict);
147 
148  return true;
149 }
150 
151 
153 {
154  region1Ptr_->write();
155  region2Ptr_->write();
156 
158 
159  Log << type() << " " << name() << " write:" << endl;
160 
161  const word& name1 = region1Ptr_->name();
162  const word& name2 = region2Ptr_->name();
163 
164  const wordList entries1 = objectResultEntries(name1);
165  const wordList entries2 = objectResultEntries(name2);
166 
167  if (entries1.size() != entries2.size())
168  {
170  << name() << ": objects must generate the same number of results"
171  << nl
172  << " " << name1 << " objects: " << entries1 << nl
173  << " " << name2 << " objects: " << entries2 << nl
174  << exit(FatalError);
175  }
176 
177  forAll(entries1, i)
178  {
179  const word& entry1(entries1[i]);
180  const word& entry2(entries2[i]);
181  const word type1 = objectResultType(name1, entry1);
182  const word type2 = objectResultType(name2, entry2);
183 
184  if (type1 != type2)
185  {
187  << name()
188  << ": input values for operation must be of the same type"
189  << nl
190  << " " << entry1 << ": " << type1 << nl
191  << " " << entry2 << ": " << type2 << nl
192  << exit(FatalError);
193  }
194 
195  bool found = false;
196 
197  applyOperation<scalar>(type1, name1, name2, entry1, entry2, found);
198  applyOperation<vector>(type1, name1, name2, entry1, entry2, found);
199  applyOperation<sphericalTensor>
200  (type1, name1, name2, entry1, entry2, found);
201  applyOperation<symmTensor>(type1, name1, name2, entry1, entry2, found);
202  applyOperation<tensor>(type1, name1, name2, entry1, entry2, found);
203 
204  if (!found)
205  {
206  Log << "Operation between "
207  << name1 << " with result " << entry1 << " and "
208  << name2 << " with result " << entry2 << " not applied"
209  << endl;
210  }
211  }
212 
213  Log << (entries1.empty() ? " none" : "") << endl;
214 
215  file()<< endl;
216 
217  return true;
218 }
219 
220 
222 {
223  return true;
224 }
225 
226 
227 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::writeFile::writeCurrentTime
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:309
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::fieldValues::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary)
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:237
Foam::DynamicList< word >
Foam::functionObjects::fieldValues::fieldValueDelta
Computes a selected operation between two fieldValue function objects.
Definition: fieldValueDelta.H:175
Foam::functionObjects::fieldValues::fieldValueDelta::execute
virtual bool execute()
Do nothing.
Definition: fieldValueDelta.C:221
Foam::functionObjects::fieldValues::defineTypeNameAndDebug
defineTypeNameAndDebug(fieldValueDelta, 0)
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:321
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::IOstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:39
fieldValueDelta.H
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::fieldValues::fieldValueDelta::write
virtual bool write()
Calculate and write.
Definition: fieldValueDelta.C:152
Foam::functionObjects::stateFunctionObject::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: stateFunctionObject.C:168
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::functionObjects::stateFunctionObject::objectResultEntries
List< word > objectResultEntries() const
Retrieve the result entries.
Definition: stateFunctionObject.C:201
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::tab
constexpr char tab
Definition: Ostream.H:384
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::functionObjects::fieldValues::fieldValueDelta::read
virtual bool read(const dictionary &)
Read from dictionary.
Definition: fieldValueDelta.C:118
Foam::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: fieldValueDelta.C:64
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::List< word >
Foam::functionObjects::fieldValues::fieldValueDelta::fieldValueDelta
fieldValueDelta(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: fieldValueDelta.C:98
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionObjects::fieldValues::fieldValueDelta::operationTypeNames_
static const Enum< operationType > operationTypeNames_
Operation type names.
Definition: fieldValueDelta.H:192
Foam::functionObjects::fieldValues::fieldValueDelta::operationType
operationType
Operation type enumeration.
Definition: fieldValueDelta.H:182