writeObjectsBase.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) 2016-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 "writeObjectsBase.H"
27 #include "Time.H"
28 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
33 (
34  const wordRe& name
35 )
36 {
37  writeObjectNames_.clear();
38  writeObjectNames_.append(name);
39 }
40 
41 
43 (
44  const wordReList& names
45 )
46 {
47  writeObjectNames_.clear();
48  writeObjectNames_.append(names);
49 }
50 
51 
53 {
54  DynamicList<word> allNames(writeObr_.toc().size());
56  {
58 
59  if (names.size())
60  {
61  allNames.append(names);
62  }
63  else
64  {
66  << "Object " << writeObjectNames_[i] << " not found in "
67  << "database. Available objects:" << nl << writeObr_.sortedToc()
68  << endl;
69  }
70  }
71 
72  return allNames;
73 }
74 
75 
77 (
78  const regIOobject& obj
79 )
80 {
81  if (log_) Info << " writing object " << obj.name() << endl;
82 
83  obj.write();
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
89 Foam::functionObjects::writeObjectsBase::writeObjectsBase
90 (
91  const objectRegistry& obr,
92  const Switch& log
93 )
94 :
95  writeObr_(obr),
96  log_(log)
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
101 
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
108 const Foam::wordReList&
110 {
111  return writeObjectNames_;
112 }
113 
114 
116 {
117  dict.lookup("objects") >> writeObjectNames_;
118 
119  return true;
120 }
121 
122 
124 {
125  wordList names(objectNames());
126 
127  if(!names.empty())
128  {
129  if (!writeObr_.time().writeTime())
130  {
132  }
133 
134  forAll(names, i)
135  {
136  const regIOobject& obj =
138 
139  writeObject(obj);
140  }
141  }
142 
143  return true;
144 }
145 
146 
147 // ************************************************************************* //
virtual bool write()
Write function.
dictionary dict
const objectRegistry & writeObr_
Reference to the region objectRegistry.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
const word & name() const
Return name.
Definition: IOobject.H:297
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
wordList names() const
Return the list of names of the IOobjects.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
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
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
void resetWriteObjectNames(const wordReList &names)
Reset the list of object names to be written.
virtual bool writeTimeDict() const
Write time dictionary to the <time>/uniform directory.
Definition: TimeIO.C:503
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
void resetWriteObjectName(const wordRe &name)
Reset the list of object names to be written to a single regular.
const Switch & log_
Reference to the inheriting function object&#39;s log variable.
wordReList writeObjectNames_
Object names requested by the user to be written.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
static const char nl
Definition: Ostream.H:265
const Time & time() const
Return time.
virtual void writeObject(const regIOobject &obj)
Write the requested registered IO object.
const wordReList & writeObjectNames() const
Return const access to the object names requested to be written.
#define WarningInFunction
Report a warning using Foam::Warning.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
messageStream Info
virtual wordList objectNames()
Get the list of field names to be written.
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
Registry of regIOobjects.
virtual bool write(const bool valid=true) const
Write using setting from DB.
virtual bool read(const dictionary &)
Read the list of objects to be written.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576