ensightWriterCaching.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::ensightOutput::writerCaching
28 
29 Description
30  State information for writers with collated times.
31 
32  The class maintains an internal list of the known times
33  as well as a file-cached version with the field information.
34  The information is used for restarts.
35 
36 SourceFiles
37  ensightWriterCaching.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_ensightOutput_writerCaching_H
42 #define Foam_ensightOutput_writerCaching_H
43 
44 #include "bitSet.H"
45 #include "dictionary.H"
46 #include "scalarList.H"
47 #include "DynamicList.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 namespace ensightOutput
54 {
55 
56 /*---------------------------------------------------------------------------*\
57  Class writerCaching Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class writerCaching
61 {
62  // Private Data
63 
64  //- Cache dictionary file name
65  word dictName_;
66 
67  //- The output times
68  DynamicList<scalar> times_;
69 
70  //- Indices in times_ when geometry (mesh) has been written
71  bitSet geoms_;
72 
73  //- Cached information for geometry, times, fields
74  dictionary cache_;
75 
76 
77  // Private Member Functions
78 
79  //- Read time information from dictFileName.
80  // Returns timeIndex corresponding to timeValue
81  label readPreviousTimes
82  (
83  const fileName& dictFile,
84  const scalar timeValue
85  );
86 
87  //- Get or create a sub-dictionary for named field
88  dictionary& fieldDict(const word& fieldName);
89 
90  //- Remove named field
91  bool remove(const word& fieldName);
92 
93 
94 public:
95 
96  // Constructors
97 
98  //- Construct with specified cache name
99  explicit writerCaching(const word& cacheFileName);
100 
101 
102  //- Destructor
103  virtual ~writerCaching() = default;
104 
105 
106  // Member Functions
107 
108  //- The output times for fields
109  const scalarList& times() const noexcept
110  {
111  return times_;
112  }
113 
114  //- Indices in times() when geometry (mesh) has been written
115  const bitSet& geometries() const noexcept
116  {
117  return geoms_;
118  }
119 
120  //- The most current time index
121  label latestTimeIndex() const;
122 
123  //- The most current geometry index
124  label latestGeomIndex() const;
126  //- Expected timeset for the geometry.
127  // Can be any of the following:
128  //
129  // 0: constant/static
130  // 1: moving, with the same frequency as the data
131  // 2: moving, with different frequency as the data
132  int geometryTimeset() const;
134  //- Get or create the 'fields' information dictionary.
135  const dictionary& fieldsDict() const;
136 
137  //- Clear all values
138  void clear();
139 
140  //- Update time/geometry information and file cache.
141  //- This routine should only be called from the master process
142  // \return True if there is a state change, which is either a
143  // geometry change or a new time interval
144  bool update
145  (
146  const fileName& baseDir,
147  const scalar timeValue,
148  const bool geomChanged,
149  const word& fieldName,
150  const word& fieldType,
151  const word& varName = word::null
152  );
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace ensightOutput
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
bool update(const fileName &baseDir, const scalar timeValue, const bool geomChanged, const word &fieldName, const word &fieldType, const word &varName=word::null)
Update time/geometry information and file cache. This routine should only be called from the master p...
A class for handling file names.
Definition: fileName.H:71
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
State information for writers with collated times.
const dictionary & fieldsDict() const
Get or create the &#39;fields&#39; information dictionary.
virtual ~writerCaching()=default
Destructor.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const scalarList & times() const noexcept
The output times for fields.
static const word null
An empty word.
Definition: word.H:84
const direction noexcept
Definition: Scalar.H:258
int geometryTimeset() const
Expected timeset for the geometry.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
label latestGeomIndex() const
The most current geometry index.
const bitSet & geometries() const noexcept
Indices in times() when geometry (mesh) has been written.
writerCaching(const word &cacheFileName)
Construct with specified cache name.
label latestTimeIndex() const
The most current time index.
Namespace for OpenFOAM.