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-2017 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 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 (
125  const dictionary& dict
126 )
127 {
130 
131  region1Ptr_.reset
132  (
134  (
135  name() + ".region1",
136  obr_,
137  dict.subDict("region1"),
138  false
139  ).ptr()
140  );
141  region2Ptr_.reset
142  (
144  (
145  name() + ".region2",
146  obr_,
147  dict.subDict("region2"),
148  false
149  ).ptr()
150  );
151 
152  operation_ = operationTypeNames_.get("operation", dict);
153 
154  return true;
155 }
156 
157 
159 {
160  region1Ptr_->write();
161  region2Ptr_->write();
162 
163  writeCurrentTime(file());
164 
165  Log << type() << " " << name() << " write:" << endl;
166 
167  const word& name1 = region1Ptr_->name();
168  const word& name2 = region2Ptr_->name();
169 
170  const wordList entries1 = objectResultEntries(name1);
171  const wordList entries2 = objectResultEntries(name2);
172 
173  if (entries1.size() != entries2.size())
174  {
176  << name() << ": objects must generate the same number of results"
177  << nl
178  << " " << name1 << " objects: " << entries1 << nl
179  << " " << name2 << " objects: " << entries2 << nl
180  << exit(FatalError);
181  }
182 
183  forAll(entries1, i)
184  {
185  const word& entry1(entries1[i]);
186  const word& entry2(entries2[i]);
187  const word type1 = objectResultType(name1, entry1);
188  const word type2 = objectResultType(name2, entry2);
189 
190  if (type1 != type2)
191  {
193  << name()
194  << ": input values for operation must be of the same type"
195  << nl
196  << " " << entry1 << ": " << type1 << nl
197  << " " << entry2 << ": " << type2 << nl
198  << exit(FatalError);
199  }
200 
201  bool found = false;
202 
203  applyOperation<scalar>(type1, name1, name2, entry1, entry2, found);
204  applyOperation<vector>(type1, name1, name2, entry1, entry2, found);
205  applyOperation<sphericalTensor>
206  (type1, name1, name2, entry1, entry2, found);
207  applyOperation<symmTensor>(type1, name1, name2, entry1, entry2, found);
208  applyOperation<tensor>(type1, name1, name2, entry1, entry2, found);
209 
210  if (!found)
211  {
212  Log << "Operation between "
213  << name1 << " with result " << entry1 << " and "
214  << name2 << " with result " << entry2 << " not applied"
215  << endl;
216  }
217  }
218 
219  Log << (entries1.empty() ? " none" : "") << endl;
220 
221  file()<< endl;
222 
223  return true;
224 }
225 
226 
228 {
229  return true;
230 }
231 
232 
233 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
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::DynamicList< word >
Foam::functionObjects::fieldValues::fieldValueDelta
Provides an operation between two 'field value' function objects.
Definition: fieldValueDelta.H:135
Foam::functionObjects::fieldValues::fieldValueDelta::execute
virtual bool execute()
Do nothing.
Definition: fieldValueDelta.C:227
Foam::functionObjects::fieldValues::fieldValueDelta::~fieldValueDelta
virtual ~fieldValueDelta()
Destructor.
Definition: fieldValueDelta.C:117
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:337
Foam::functionObjects::fieldValue::New
static autoPtr< fieldValue > New(const word &name, const objectRegistry &obr, const dictionary &dict, const bool output=true)
Return a reference to the selected fieldValue.
Definition: fieldValueNew.C:35
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:229
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:166
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:158
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
found
bool found
Definition: TABSMDCalcMethod2.H:32
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::tab
constexpr char tab
Definition: Ostream.H:371
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::functionObjects::fieldValues::fieldValueDelta::read
virtual bool read(const dictionary &)
Read from dictionary.
Definition: fieldValueDelta.C:124
Foam::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: fieldValueDelta.C:64
Foam::List< word >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
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
functionObject base class for writing single files
Definition: writeFile.H:59
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:152
Foam::functionObjects::fieldValues::fieldValueDelta::operationType
operationType
Operation type enumeration.
Definition: fieldValueDelta.H:142
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332