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 
164 {
165  logFiles::write();
166 
167  region1Ptr_->write();
168  region2Ptr_->write();
169 
170  if (Pstream::master())
171  {
172  writeTime(file());
173  }
174 
175  Log << type() << " " << name() << " write:" << endl;
176 
177  bool found = false;
178  processFields<scalar>(found);
179  processFields<vector>(found);
180  processFields<sphericalTensor>(found);
181  processFields<symmTensor>(found);
182  processFields<tensor>(found);
183 
184  if (Pstream::master())
185  {
186  file()<< endl;
187  }
188 
189  if (!found)
190  {
191  Log << " none" << endl;
192  }
193  else
194  {
195  Log << endl;
196  }
197 
198  return true;
199 }
200 
201 
203 {
204  return true;
205 }
206 
207 
208 // ************************************************************************* //
Specialisation of Foam::functionObject for a region and providing a reference to the region Foam::obj...
virtual void writeFileHeader(const label i)
Output file header information.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:167
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
static const char tab
Definition: Ostream.H:259
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary)
virtual bool read(const dictionary &)
Read from dictionary.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
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
static const NamedEnum< operationType, 5 > operationTypeNames_
Operation type names.
Abstract base-class for Time/database functionObjects.
Provides a differencing option between two &#39;field value&#39; function objects.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:982
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:294
defineTypeNameAndDebug(fieldValueDelta, 0)
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
fieldValueDelta(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
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
#define Log
Report write to Foam::Info if the local log switch is true.
virtual bool write()
Calculate and write.
bool found
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57