writeObjects.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) 2011-2016 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 "writeObjects.H"
27 #include "Time.H"
28 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(writeObjects, 0);
38 
40  (
41  functionObject,
42  writeObjects,
43  dictionary
44  );
45 }
46 }
47 
48 template<>
49 const char* Foam::NamedEnum
50 <
52  3
53 >::names[] =
54 {
55  "autoWrite",
56  "noWrite",
57  "anyWrite"
58 };
59 
60 const Foam::NamedEnum
61 <
63  3
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::functionObjects::writeObjects::writeObject
70 (
71  const regIOobject& obj
72 )
73 {
74  switch (writeOption_)
75  {
76  case AUTO_WRITE:
77  {
78  if(obj.writeOpt() != IOobject::AUTO_WRITE)
79  {
80  return;
81  }
82 
83  break;
84  }
85  case NO_WRITE:
86  {
87  if(obj.writeOpt() != IOobject::NO_WRITE)
88  {
89  return;
90  }
91 
92  break;
93  }
94  case ANY_WRITE:
95  {
96  break;
97  }
98  default:
99  {
101  << "Unknown writeOption "
102  << writeOptionNames_[writeOption_]
103  << ". Valid writeOption types are" << writeOptionNames_
104  << exit(FatalError);
105  }
106  }
107 
108  if
109  (
111  && writeObr_.time().writeTime()
112  )
113  {
114  Log << " automatically written object " << obj.name() << endl;
115  }
116  else
117  {
119  }
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
125 Foam::functionObjects::writeObjects::writeObjects
126 (
127  const word& name,
128  const Time& runTime,
129  const dictionary& dict
130 )
131 :
132  functionObject(name),
134  (
136  (
138  ),
139  log
140  ),
141  writeOption_(ANY_WRITE)
142 {
143  read(dict);
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148 
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
156 {
157  if (dict.found("field"))
158  {
159  writeObjectNames_.setSize(1);
160  dict.lookup("field") >> writeObjectNames_[0];
161  }
162  else if (dict.found("fields"))
163  {
164  dict.lookup("fields") >> writeObjectNames_;
165  }
166  else
167  {
169  }
170 
171  if (dict.found("writeOption"))
172  {
173  writeOption_ = writeOptionNames_.read(dict.lookup("writeOption"));
174  }
175  else
176  {
177  writeOption_ = ANY_WRITE;
178  }
179 
180  return functionObject::read(dict);
181 }
182 
183 
185 {
186  return true;
187 }
188 
189 
191 {
192  Info<< type() << " " << name() << " write:" << nl;
193 
195 
196  Log << endl;
197 
198  return true;
199 }
200 
201 
202 // ************************************************************************* //
virtual bool write()
Write function.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
const word & name() const
Return name.
Definition: IOobject.H:291
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool write()
Write the registered objects.
Definition: writeObjects.C:190
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static const NamedEnum< writeOption, 3 > writeOptionNames_
Definition: writeObjects.H:151
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Abstract base-class for Time/database function objects.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
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.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
writeOption
Re-enumeration defining the write options, based on the original.
Definition: writeObjects.H:144
virtual bool read(const dictionary &)
Read and set the function object if its data have changed.
static const char nl
Definition: Ostream.H:262
virtual void writeObject(const regIOobject &obj)
Write the requested registered IO object.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
writeOption writeOpt() const
Definition: IOobject.H:363
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
FunctionObject base class for writing a list of objects registered to the database, on behalf of the inheriting function object, on when those should be written to disk.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
#define Log
Report write to Foam::Info if the local log switch is true.
messageStream Info
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Registry of regIOobjects.
virtual bool execute()
Do nothing.
Definition: writeObjects.C:184
virtual ~writeObjects()
Destructor.
Definition: writeObjects.C:149
virtual bool read(const dictionary &)
Read the writeObjects data.
Definition: writeObjects.C:155
virtual bool read(const dictionary &)
Read the list of objects to be written.
addToRunTimeSelectionTable(functionObject, add, dictionary)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576