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-2025 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 const Foam::NamedEnum
44 <
46  5
48 {
49  "add",
50  "subtract",
51  "min",
52  "max",
53  "average"
54 };
55 
56 
57 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
58 
60 (
61  const label i
62 )
63 {
64  const wordList fields1 = region1Ptr_->fields();
65  const wordList fields2 = region2Ptr_->fields();
66 
67  DynamicList<word> commonFields(fields1.size());
68  forAll(fields1, fieldi)
69  {
70  label index = findIndex(fields2, fields1[fieldi]);
71  if (index != -1)
72  {
73  commonFields.append(fields1[fieldi]);
74  }
75  }
76 
77  Ostream& os = file();
78 
79  writeHeaderValue(os, "Source1", region1Ptr_->name());
80  writeHeaderValue(os, "Source2", region2Ptr_->name());
81  writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
82  writeCommented(os, "Time");
83 
84  forAll(commonFields, i)
85  {
86  os << tab << commonFields[i];
87  }
88 
89  os << endl;
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 
96 (
97  const word& name,
98  const Time& runTime,
99  const dictionary& dict
100 )
101 :
102  regionFunctionObject(name, runTime, dict),
103  logFiles(obr_, name),
104  operation_(operationType::subtract),
105  region1Ptr_(nullptr),
106  region2Ptr_(nullptr)
107 {
108  read(dict);
109 }
110 
111 
112 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
113 
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
121 (
122  const dictionary& dict
123 )
124 {
126 
127  region1Ptr_.reset
128  (
130  (
131  name() + ".region1",
132  obr_,
133  dict.subDict("region1"),
134  false
135  ).ptr()
136  );
137  region2Ptr_.reset
138  (
140  (
141  name() + ".region2",
142  obr_,
143  dict.subDict("region2"),
144  false
145  ).ptr()
146  );
147 
148  operation_ = operationTypeNames_.read(dict.lookup("operation"));
149 
150  resetName(typeName);
151 
152  return true;
153 }
154 
155 
158 {
159  return region1Ptr_->fields();
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 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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:55
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
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:113
virtual bool write()
Write function.
Definition: logFiles.C:173
virtual bool read(const dictionary &)
Read optional controls.
Specialisation of Foam::functionObject for a region.
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:258
static const char tab
Definition: Ostream.H:266
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
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