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
55 
56  // Write global objects on master only
57  // Everyone check or just master
58  bool masterOnly =
59  globalFile()
60  && (
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 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void updateInstance() const
If the instance is a time directory update to the current time.
Definition: IOobject.C:361
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:226
bool good() const
Definition: IOobject.H:471
const word & name() const
Return name.
Definition: IOobject.H:310
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
T & last()
Return the last element of the list.
Definition: UListI.H:128
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
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).
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
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.
virtual bool globalFile() const
Return true if object is global, i.e. same for all processors.
Definition: regIOobject.C:187
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
const fileOperation & fileHandler()
Get current file handler.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53