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-2020 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  {
57  if (regExp_)
58  {
60 
61  if (names.size())
62  {
63  allNames.append(names);
64  }
65  else
66  {
67  Warning
68  << "writeObjects: object " << writeObjectNames_[i]
69  << " not found in database. Available objects:"
70  << nl << writeObr_.sortedToc() << endl;
71  }
72  }
73  else
74  {
75  const word name(writeObjectNames_[i]);
76 
78  {
79  allNames.append(name);
80  }
81  else
82  {
83  Warning
84  << "writeObjects: object " << name
85  << " not found in database. Available objects:"
86  << nl << writeObr_.sortedToc() << endl;
87  }
88  }
89  }
90 
91  return move(allNames);
92 }
93 
94 
96 (
97  const regIOobject& obj
98 )
99 {
100  if (log_) Info << " writing object " << obj.name() << endl;
101 
102  obj.write();
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
109 (
110  const objectRegistry& obr,
111  const Switch& log
112 )
113 :
114  writeObr_(obr),
115  log_(log)
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
127 const Foam::wordReList&
129 {
130  return writeObjectNames_;
131 }
132 
133 
135 {
136  regExp_ = dict.lookupOrDefault<Switch>("regExp", true);
137 
138  if (regExp_)
139  {
140  dict.lookup("objects") >> writeObjectNames_;
141  }
142  else
143  {
144  const wordList objectNames(dict.lookup("objects"));
146  forAll(objectNames, i)
147  {
149  }
150  }
151 
152  return true;
153 }
154 
155 
157 {
158  wordList names(objectNames());
159 
160  if (!names.empty())
161  {
162  if (!writeObr_.time().writeTime())
163  {
165  }
166 
167  forAll(names, i)
168  {
170  }
171  }
172 
173  return true;
174 }
175 
176 
177 // ************************************************************************* //
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:434
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
const word & name() const
Return name.
Definition: IOobject.H:303
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
wordList names() const
Return the list of names of the IOobjects.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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/any.
Definition: Switch.H:60
bool foundObject(const word &name) const
Is the named Type found?
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:250
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
A class for handling words, derived from string.
Definition: word.H:59
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
Switch regExp_
Optional switch for regular expression support.
static const char nl
Definition: Ostream.H:260
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.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
messageStream Warning
void setSize(const label)
Reset size of List.
Definition: List.C:281
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
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:52
writeObjectsBase(const objectRegistry &obr, const Switch &logRef)
Construct from objectRegistry and inheriting function object.
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
virtual bool write(const bool write=true) const
Write using setting from DB.
Registry of regIOobjects.
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:844