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-2018 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  resetName(typeName);
117 }
118 
119 
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
121 
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127 
129 (
130  const dictionary& dict
131 )
132 {
134 
135  region1Ptr_.reset
136  (
138  (
139  name() + ".region1",
140  obr_,
141  dict.subDict("region1"),
142  false
143  ).ptr()
144  );
145  region2Ptr_.reset
146  (
148  (
149  name() + ".region2",
150  obr_,
151  dict.subDict("region2"),
152  false
153  ).ptr()
154  );
155 
156  operation_ = operationTypeNames_.read(dict.lookup("operation"));
157 
158  return true;
159 }
160 
161 
163 {
164  logFiles::write();
165 
166  region1Ptr_->write();
167  region2Ptr_->write();
168 
169  if (Pstream::master())
170  {
171  writeTime(file());
172  }
173 
174  Log << type() << " " << name() << " write:" << endl;
175 
176  bool found = false;
177  processFields<scalar>(found);
178  processFields<vector>(found);
179  processFields<sphericalTensor>(found);
180  processFields<symmTensor>(found);
181  processFields<tensor>(found);
182 
183  if (Pstream::master())
184  {
185  file()<< endl;
186  }
187 
188  if (!found)
189  {
190  Log << " none" << endl;
191  }
192  else
193  {
194  Log << endl;
195  }
196 
197  return true;
198 }
199 
200 
202 {
203  return true;
204 }
205 
206 
207 // ************************************************************************* //
Specialization 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:180
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:264
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
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 function objects.
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:699
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:297
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:53
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:583
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57