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 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::functionObjects::writeObjects::writeObjects
52 (
53  const word& name,
54  const Time& runTime,
55  const dictionary& dict
56 )
57 :
58  functionObject(name),
59  obr_
60  (
62  (
64  )
65  ),
66  exclusiveWriting_(false),
67  objectNames_()
68 {
69  read(dict);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
82 {
83  if (dict.found("field"))
84  {
85  objectNames_.setSize(1);
86  dict.lookup("field") >> objectNames_[0];
87  }
88  else if (dict.found("fields"))
89  {
90  dict.lookup("fields") >> objectNames_;
91  }
92  else
93  {
94  dict.lookup("objects") >> objectNames_;
95  }
96 
97  dict.readIfPresent("exclusiveWriting", exclusiveWriting_);
98 
99  return true;
100 }
101 
102 
104 {
105  return true;
106 }
107 
108 
110 {
111  Info<< type() << " " << name() << " write:" << nl;
112 
113  if (!obr_.time().writeTime())
114  {
115  obr_.time().writeTimeDict();
116  }
117 
118  DynamicList<word> allNames(obr_.toc().size());
119  forAll(objectNames_, i)
120  {
121  wordList names(obr_.names<regIOobject>(objectNames_[i]));
122 
123  if (names.size())
124  {
125  allNames.append(names);
126  }
127  else
128  {
130  << "Object " << objectNames_[i] << " not found in "
131  << "database. Available objects:" << nl << obr_.sortedToc()
132  << endl;
133  }
134  }
135 
136  forAll(allNames, i)
137  {
138  regIOobject& obj = const_cast<regIOobject&>
139  (
140  obr_.lookupObject<regIOobject>(allNames[i])
141  );
142 
143  if (exclusiveWriting_)
144  {
145  // Switch off automatic writing to prevent double write
147  }
148 
149  Info<< " writing object " << obj.name() << endl;
150 
151  obj.write();
152  }
153 
154  return true;
155 }
156 
157 
158 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
virtual bool write()
Write the registered objects.
Definition: writeObjects.C:109
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:76
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Abstract base-class for Time/database function objects.
writeOption writeOpt() const
Definition: IOobject.H:314
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.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
static const char nl
Definition: Ostream.H:262
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
#define WarningInFunction
Report a warning using Foam::Warning.
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary)
virtual bool write() const
Write using setting from DB.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
messageStream Info
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Registry of regIOobjects.
virtual bool execute()
Do nothing.
Definition: writeObjects.C:103
virtual ~writeObjects()
Destructor.
Definition: writeObjects.C:75
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual bool read(const dictionary &)
Read the writeObjects data.
Definition: writeObjects.C:81
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451