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 | Copyright (C) 2012-2015 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"
27 #include "ListOps.H"
28 #include "Time.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  namespace fieldValues
37  {
38  defineTypeNameAndDebug(fieldValueDelta, 0);
39  }
40 
41  template<>
42  const char*
44  {
45  "add",
46  "subtract",
47  "min",
48  "max",
49  "average"
50  };
51 
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const objectRegistry& obr,
63  const dictionary& dict,
64  const bool loadFromFiles
65 )
66 :
67  functionObjectFile(obr, name, typeName),
68  name_(name),
69  obr_(obr),
70  loadFromFiles_(loadFromFiles),
71  log_(true),
72  operation_(opSubtract),
73  source1Ptr_(NULL),
74  source2Ptr_(NULL)
75 {
76  read(dict);
77 }
78 
79 
81 {
82  const wordList& fields1 = source1Ptr_->fields();
83  const wordList& fields2 = source2Ptr_->fields();
84 
85  DynamicList<word> commonFields(fields1.size());
86  forAll(fields1, i)
87  {
88  label index = findIndex(fields2, fields1[i]);
89  if (index != -1)
90  {
91  commonFields.append(fields1[i]);
92  }
93  }
94 
95  Ostream& os = file();
96 
97  writeHeaderValue(os, "Source1", source1Ptr_->name());
98  writeHeaderValue(os, "Source2", source2Ptr_->name());
99  writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
100  writeCommented(os, "Time");
101 
102  forAll(commonFields, i)
103  {
104  os << tab << commonFields[i];
105  }
106 
107  os << endl;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
112 
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  log_ = dict.lookupOrDefault<Switch>("log", true);
122  source1Ptr_.reset
123  (
125  (
126  name_ + ".source1",
127  obr_,
128  dict.subDict("source1"),
129  loadFromFiles_,
130  false
131  ).ptr()
132  );
133  source2Ptr_.reset
134  (
136  (
137  name_ + ".source2",
138  obr_,
139  dict.subDict("source2"),
140  loadFromFiles_,
141  false
142  ).ptr()
143  );
144 
145  operation_ = operationTypeNames_.read(dict.lookup("operation"));
146 }
147 
148 
150 {
152 
153  source1Ptr_->write();
154  source2Ptr_->write();
155 
156  if (Pstream::master())
157  {
158  file()<< obr_.time().value();
159  }
160 
161  if (log_) Info<< type() << " " << name_ << " output:" << endl;
162 
163  bool found = false;
164  processFields<scalar>(found);
165  processFields<vector>(found);
166  processFields<sphericalTensor>(found);
167  processFields<symmTensor>(found);
168  processFields<tensor>(found);
169 
170  if (Pstream::master())
171  {
172  file()<< endl;
173  }
174 
175  if (log_)
176  {
177  if (!found)
178  {
179  Info<< " none" << endl;
180  }
181  else
182  {
183  Info<< endl;
184  }
185  }
186 }
187 
188 
190 {
191  // Do nothing
192 }
193 
194 
196 {
197  // Do nothing
198 }
199 
200 
202 {
203  // Do nothing
204 }
205 
206 
208 {
209  // Do nothing
210 }
211 
212 
214 {
215  // Do nothing
216 }
217 
218 
219 // ************************************************************************* //
Foam::surfaceFields.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static autoPtr< fieldValue > New(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false, const bool output=true)
Return a reference to the selected fieldValue.
Definition: fieldValueNew.C:31
virtual void execute()
Execute.
A class for handling words, derived from string.
Definition: word.H:59
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
virtual void updateMesh(const mapPolyMesh &)
Update mesh.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Various functions to operate on Lists.
virtual void write()
Calculate and write.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
virtual void read(const dictionary &)
Read from dictionary.
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const NamedEnum< operationType, 5 > operationTypeNames_
Operation type names.
fieldValueDelta(const word &name, const objectRegistry &obr, const dictionary &dict, const bool loadFromFiles=false)
Construct from components.
#define forAll(list, i)
Definition: UList.H:421
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
bool found
virtual void write()
Write function.
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
static const char tab
Definition: Ostream.H:259
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Registry of regIOobjects.
defineTypeNameAndDebug(cellSource, 0)
virtual void movePoints(const polyMesh &)
Move points.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Base class for output file data handling.
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
virtual ~fieldValueDelta()
Destructor.
virtual void end()
Execute the at the final time-loop, currently does nothing.
virtual void writeFileHeader(const label i)
Output file header information.