fieldValueDelta.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-2021 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 "fieldValueDelta.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionObjects
34 {
35 namespace fieldValues
36 {
39 }
40 }
41 }
42 
43 template<>
44 const char* Foam::NamedEnum
45 <
47  5
48 >::names[] =
49 {
50  "add",
51  "subtract",
52  "min",
53  "max",
54  "average"
55 };
56 
57 const Foam::NamedEnum
58 <
60  5
62 
63 
64 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
65 
67 (
68  const label i
69 )
70 {
71  const wordList fields1 = region1Ptr_->fields();
72  const wordList fields2 = region2Ptr_->fields();
73 
74  DynamicList<word> commonFields(fields1.size());
75  forAll(fields1, fieldi)
76  {
77  label index = findIndex(fields2, fields1[fieldi]);
78  if (index != -1)
79  {
80  commonFields.append(fields1[fieldi]);
81  }
82  }
83 
84  Ostream& os = file();
85 
86  writeHeaderValue(os, "Source1", region1Ptr_->name());
87  writeHeaderValue(os, "Source2", region2Ptr_->name());
88  writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
89  writeCommented(os, "Time");
90 
91  forAll(commonFields, i)
92  {
93  os << tab << commonFields[i];
94  }
95 
96  os << endl;
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
103 (
104  const word& name,
105  const Time& runTime,
106  const dictionary& dict
107 )
108 :
109  regionFunctionObject(name, runTime, dict),
110  logFiles(obr_, name),
111  operation_(operationType::subtract),
112  region1Ptr_(nullptr),
113  region2Ptr_(nullptr)
114 {
115  read(dict);
116 }
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 (
129  const dictionary& dict
130 )
131 {
133 
134  region1Ptr_.reset
135  (
137  (
138  name() + ".region1",
139  obr_,
140  dict.subDict("region1"),
141  false
142  ).ptr()
143  );
144  region2Ptr_.reset
145  (
147  (
148  name() + ".region2",
149  obr_,
150  dict.subDict("region2"),
151  false
152  ).ptr()
153  );
154 
155  operation_ = operationTypeNames_.read(dict.lookup("operation"));
156 
157  resetName(typeName);
158 
159  return true;
160 }
161 
162 
165 {
166  return region1Ptr_->fields();
167 }
168 
169 
171 {
172  logFiles::write();
173 
174  region1Ptr_->write();
175  region2Ptr_->write();
176 
177  if (Pstream::master())
178  {
179  writeTime(file());
180  }
181 
182  Log << type() << " " << name() << " write:" << endl;
183 
184  bool found = false;
185  processFields<scalar>(found);
186  processFields<vector>(found);
187  processFields<sphericalTensor>(found);
188  processFields<symmTensor>(found);
189  processFields<tensor>(found);
190 
191  if (Pstream::master())
192  {
193  file()<< endl;
194  }
195 
196  if (!found)
197  {
198  Log << " none" << endl;
199  }
200  else
201  {
202  Log << endl;
203  }
204 
205  return true;
206 }
207 
208 
210 {
211  return true;
212 }
213 
214 
215 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:54
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Abstract base-class for Time/database functionObjects.
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:32
Provides a differencing option between two 'field value' function objects.
virtual wordList fields() const
Return the list of fields required.
static const NamedEnum< operationType, 5 > operationTypeNames_
Operation type names.
fieldValueDelta(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual void writeFileHeader(const label i)
Output file header information.
virtual bool read(const dictionary &)
Read from dictionary.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:107
virtual bool write()
Write function.
Definition: logFiles.C:167
Specialisation of Foam::functionObject for a region and providing a reference to the region Foam::obj...
virtual bool read(const dictionary &)
Read optional controls.
From the first field subtract the remaining fields in the list.
Definition: subtract.H:73
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
A class for handling words, derived from string.
Definition: word.H:62
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fieldValueDelta, 0)
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary)
Namespace for OpenFOAM.
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:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const char tab
Definition: Ostream.H:259
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict