writeObjects.H
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) 2011-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 Class
25  Foam::functionObjects::writeObjects
26 
27 Description
28  Allows specification of different writing frequency of objects registered
29  to the database.
30 
31  It has similar functionality as the main time database through the
32  \c writeControl setting:
33  - timeStep
34  - writeTime
35  - adjustableRunTime
36  - runTime
37  - clockTime
38  - cpuTime
39 
40  It also has the ability to write the selected objects that were defined
41  with the respective write mode for the requested \c writeOption, namely:
42  \vartable
43  autoWrite | objects set to write at output time
44  noWrite | objects set to not write by default
45  anyWrite | any option of the previous two
46  \endvartable
47 
48  Example of function object specification:
49  \verbatim
50  writeObjects1
51  {
52  type writeObjects;
53 
54  libs ("libutilityFunctionObjects.so");
55 
56  objects (obj1 obj2);
57  writeOption anyWrite;
58  }
59  \endverbatim
60 
61 Usage
62  \table
63  Property | Description | Required | Default value
64  type | type name: writeObjects | yes |
65  objects, fields or field | objects to write | yes |
66  writeOption | only those with this write option | no | anyWrite
67  \endtable
68 
69  The objects to be written can either be specified by the \c objects,
70  \c fields or \c field entry, the latter two for backwards compatibility
71  and to provide a more logical, obvious and readable interface when
72  writing fields. Regular expressions can also be used when specifying
73  multiple \c objects or \c fields.
74 
75 See also
76  Foam::functionObject
77  Foam::functionObjects::writeObjectsBase
78  Foam::functionObjects::timeControl
79 
80 SourceFiles
81  writeObjects.C
82 
83 \*---------------------------------------------------------------------------*/
84 
85 #ifndef writeObjects_functionObject_H
86 #define writeObjects_functionObject_H
87 
88 #include "functionObject.H"
89 #include "writeObjectsBase.H"
90 #include "NamedEnum.H"
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
94 namespace Foam
95 {
96 
97 namespace functionObjects
98 {
99 
100 /*---------------------------------------------------------------------------*\
101  Class writeObjects Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 class writeObjects
105 :
106  public functionObject,
107  public writeObjectsBase
108 {
109 public:
110 
111  // Public data types
112 
113  //- Re-enumeration defining the write options, based on the original
114  // ones at IOobject::writeOption
115  enum class writeOption
116  {
117  AUTO_WRITE,
118  NO_WRITE,
119  ANY_WRITE
120  };
121 
122  static const NamedEnum<writeOption, 3> writeOptionNames_;
123 
124 
125 private:
126 
127  // Private Data
128 
129  //- To only write objects of defined writeOption
130  writeOption writeOption_;
131 
132 
133  // Private Member Functions
134 
135  //- Write the requested registered IO object
136  virtual void writeObject(const regIOobject& obj);
137 
138 
139 public:
140 
141  //- Runtime type information
142  TypeName("writeObjects");
143 
144 
145  // Constructors
146 
147  //- Construct from Time and dictionary
149  (
150  const word& name,
151  const Time& runTime,
152  const dictionary& dict
153  );
154 
155  //- Disallow default bitwise copy construction
156  writeObjects(const writeObjects&) = delete;
157 
158 
159  //- Destructor
160  virtual ~writeObjects();
161 
162 
163  // Member Functions
164 
165  //- Read the writeObjects data
166  virtual bool read(const dictionary&);
167 
168  //- Return the list of fields required
169  virtual wordList fields() const
170  {
171  return wordList::null();
172  }
173 
174  //- Do nothing
175  virtual bool execute();
176 
177  //- Write the registered objects
178  virtual bool write();
179 
180 
181  // Member Operators
182 
183  //- Disallow default bitwise assignment
184  void operator=(const writeObjects&) = delete;
185 };
186 
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 } // End namespace functionObjects
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
static const List< word > & null()
Return a null List.
Definition: ListI.H:118
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
Allows specification of different writing frequency of objects registered to the database.
Definition: writeObjects.H:139
virtual wordList fields() const
Return the list of fields required.
Definition: writeObjects.H:200
virtual ~writeObjects()
Destructor.
Definition: writeObjects.C:146
void operator=(const writeObjects &)=delete
Disallow default bitwise assignment.
static const NamedEnum< writeOption, 3 > writeOptionNames_
Definition: writeObjects.H:153
TypeName("writeObjects")
Runtime type information.
writeOption
Re-enumeration defining the write options, based on the original.
Definition: writeObjects.H:147
virtual bool execute()
Do nothing.
Definition: writeObjects.C:183
writeObjects(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: writeObjects.C:123
virtual bool write()
Write the registered objects.
Definition: writeObjects.C:189
virtual bool read(const dictionary &)
Read the writeObjects data.
Definition: writeObjects.C:152
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
dictionary dict