surfaceWriterCaching.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-2020 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::surfaceWriters::writerCaching
28 
29 Description
30  Information for surface 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  surfaceWriterCaching.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef surfaceWriters_writerCaching_H
42 #define surfaceWriters_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 surfaceWriters
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
110  {
111  return times_;
112  }
113 
114  //- Indices in times() when geometry (mesh) has been written
115  const bitSet& geometries() const
116  {
117  return geoms_;
118  }
119 
120  //- The most current time index
121  label latestTimeIndex() const
122  {
123  return max(0, times_.size()-1);
124  }
125 
126  //- The most current geometry index
127  label latestGeomIndex() const
128  {
129  return max(0, geoms_.find_last());
130  }
131 
132  //- Get or create the 'fields' information dictionary.
133  const dictionary& fieldsDict() const;
134 
135  //- Clear all values
136  void clear();
137 
138  //- Update time/geometry information and file cache.
139  //- This routine should only be called from the master process
140  // \return True if there is a state change, which is either a
141  // geometry change or a new time interval
142  bool update
143  (
144  const fileName& baseDir,
145  const scalar timeValue,
146  const bool geomChanged,
147  const word& fieldName,
148  const word& fieldType,
149  const word& varName = word::null
150  );
151 };
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace surfaceWriters
157 } // End namespace Foam
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 #endif
162 
163 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::DynamicList< scalar >
bitSet.H
Foam::surfaceWriters::writerCaching::fieldsDict
const dictionary & fieldsDict() const
Get or create the 'fields' information dictionary.
Definition: surfaceWriterCaching.C:78
scalarList.H
Foam::surfaceWriters::writerCaching::latestTimeIndex
label latestTimeIndex() const
The most current time index.
Definition: surfaceWriterCaching.H:120
Foam::surfaceWriters::writerCaching::~writerCaching
virtual ~writerCaching()=default
Destructor.
Foam::bitSet::find_last
label find_last() const
Locate the last bit set.
Definition: bitSetI.H:374
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::surfaceWriters::writerCaching::clear
void clear()
Clear all values.
Definition: surfaceWriterCaching.C:116
Foam::surfaceWriters::writerCaching::update
bool update(const fileName &baseDir, const scalar timeValue, const bool geomChanged, const word &fieldName, const word &fieldType, const word &varName=word::null)
Definition: surfaceWriterCaching.C:190
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::surfaceWriters::writerCaching::geometries
const bitSet & geometries() const
Indices in times() when geometry (mesh) has been written.
Definition: surfaceWriterCaching.H:114
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::surfaceWriters::writerCaching::latestGeomIndex
label latestGeomIndex() const
The most current geometry index.
Definition: surfaceWriterCaching.H:126
Foam::surfaceWriters::writerCaching::times
const scalarList & times() const
The output times for fields.
Definition: surfaceWriterCaching.H:108
Foam::List< scalar >
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
DynamicList.H
Foam::surfaceWriters::writerCaching
Information for surface writers with collated times.
Definition: surfaceWriterCaching.H:59
Foam::surfaceWriters::writerCaching::writerCaching
writerCaching(const word &cacheFileName)
Construct with specified cache name.
Definition: surfaceWriterCaching.C:70