regIOobjectWrite.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) 2011-2021 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 Description
25  write function for regIOobjects
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "regIOobject.H"
30 #include "Time.H"
31 #include "OSspecific.H"
32 #include "OFstream.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
37 (
41  const bool write
42 ) const
43 {
44  if (!good())
45  {
47  << "bad object " << name()
48  << endl;
49 
50  return false;
51  }
52 
53  // If the instance is a time directory update to the current time
54  updateInstance();
55 
56  // Write global objects on master only
57  // Everyone check or just master
58  bool masterOnly =
59  globalFile()
60  && (
61  regIOobject::fileModificationChecking == timeStampMaster
62  || regIOobject::fileModificationChecking == inotifyMaster
63  );
64 
65  bool osGood = false;
66 
67  if (Pstream::master() || !masterOnly)
68  {
69  osGood = fileHandler().writeObject(*this, fmt, ver, cmp, write);
70  }
71  else
72  {
73  // Or scatter the master osGood?
74  osGood = true;
75  }
76 
77  if (OFstream::debug)
78  {
79  Pout<< " .... written" << endl;
80  }
81 
82  // Only update the lastModified_ time if this object is re-readable,
83  // i.e. lastModified_ is already set
84  if (watchIndices_.size())
85  {
86  fileHandler().setUnmodified(watchIndices_.last());
87  }
88 
89  return osGood;
90 }
91 
92 
93 bool Foam::regIOobject::write(const bool write) const
94 {
95  return writeObject
96  (
97  time().writeFormat(),
99  time().writeCompression(),
100  write
101  );
102 }
103 
104 
105 // ************************************************************************* //
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
const fileOperation & fileHandler()
Get current file handler.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool write=true) const
Writes a regIOobject (so header, contents and divider).
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
const Time & time() const
Return time.
Definition: IOobject.C:318
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Version number type.
Definition: IOstream.H:96
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
virtual bool write(const bool write=true) const
Write using setting from DB.