stateModel.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) 2025 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 "stateModel.H"
27 #include "Time.H"
28 #include "timeIOdictionary.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(stateModel::stateModelWriter, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
39 
40 Foam::IOobject Foam::stateModel::io
41 (
42  const word& name,
43  const objectRegistry& db,
44  const bool processor,
45  const bool write
46 )
47 {
48  return
49  IOobject
50  (
51  name + "State",
52  db.time().name(),
53  processor ? "processorUniform" : "uniform",
54  db,
57  false
58  );
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 Foam::stateModel::stateModelWriter::stateModelWriter
65 (
66  const stateModel& model,
67  const bool processor
68 )
69 :
70  regIOobject(io(model.name(), model.db(), processor, true)),
71  model_(model),
72  processor_(processor)
73 {}
74 
75 
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
83 {}
84 
85 
86 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
87 
89 {
90  if (!processor_)
91  {
92  model_.writeState(os);
93  }
94 
95  if (processor_ == Pstream::parRun())
96  {
97  model_.writeProcessorState(os);
98  }
99 
100  return os.good();
101 }
102 
103 
104 bool Foam::stateModel::writeState(const bool write) const
105 {
106  if (write)
107  {
108  bool allOk = true;
109 
110  const bool ok = stateModel::stateModelWriter(*this, false).write();
111  allOk = allOk && ok;
112 
113  if (Pstream::parRun())
114  {
115  const bool ok = stateModel::stateModelWriter(*this, true).write();
116  allOk = allOk && ok;
117  }
118 
119  return allOk;
120  }
121  else
122  {
123  return false;
124  }
125 }
126 
127 
129 {}
130 
131 
133 {}
134 
135 
137 (
138  const word& name,
139  const objectRegistry& db
140 )
141 {
142  timeIOdictionary stateDict(io(name, db, false, false));
143 
144  if (Pstream::parRun())
145  {
146  stateDict.merge(timeIOdictionary(io(name, db, true, false)));
147  }
148 
149  return stateDict;
150 }
151 
152 
153 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1314
const word & name() const
Return const reference to name.
Registry of regIOobjects.
const Time & time() const
Return time.
virtual const word & name() const =0
Return the model name.
bool writeState(const bool write) const
Write state.
Definition: stateModel.C:104
static dictionary stateDict(const word &name, const objectRegistry &db)
Construct and return the state dictionary for reading.
Definition: stateModel.C:137
virtual ~stateModel()
Destructor.
Definition: stateModel.C:82
stateModel()
Construct null.
Definition: stateModel.C:76
virtual const objectRegistry & db() const =0
Return the model's database.
virtual void writeProcessorState(Ostream &os) const
Write processor state.
Definition: stateModel.C:132
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
A class for handling words, derived from string.
Definition: word.H:62
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
defineTypeNameAndDebug(combustionModel, 0)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
const bool writeData(readBool(pdfDictionary.lookup("writeData")))