lagrangianFieldDecomposerCache.C
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) 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 \*---------------------------------------------------------------------------*/
27 
29 
30 #include "labelIOField.H"
31 #include "labelFieldIOField.H"
32 #include "scalarIOField.H"
33 #include "scalarFieldIOField.H"
34 #include "vectorIOField.H"
35 #include "vectorFieldIOField.H"
36 #include "sphericalTensorIOField.H"
38 #include "symmTensorIOField.H"
39 #include "symmTensorFieldIOField.H"
40 #include "tensorIOField.H"
41 #include "tensorFieldIOField.H"
42 
43 // * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // All lagrangian field/field-field types
49 class lagrangianFieldDecomposer::fieldsCache::privateCache
50 {
51 public:
52 
53  #undef declareField
54  #define declareField(Type) \
55  PtrList<PtrList<IOField<Type>>> Type##Fields_; \
56  PtrList<PtrList<CompactIOField<Field<Type>, Type>>> Type##FieldFields_;
57 
58  declareField(label);
59  declareField(scalar);
64  #undef declareField
65 
66  bool empty() const noexcept { return labelFields_.empty(); }
67 
68  label size() const noexcept { return labelFields_.size(); }
69 
70  void resize(const label len)
71  {
72  #undef doLocalCode
73  #define doLocalCode(Type) \
74  { \
75  Type##Fields_.resize(len); \
76  Type##FieldFields_.resize(len); \
77  }
78 
79  doLocalCode(label);
80  doLocalCode(scalar);
85 
86  #undef doLocalCode
87  }
88 
89  void readAll(const label cloudi, const IOobjectList& lagrangianObjects)
90  {
91  #undef doLocalCode
92  #define doLocalCode(Type) \
93  { \
94  lagrangianFieldDecomposer::readFields \
95  ( \
96  cloudi, \
97  lagrangianObjects, \
98  Type##Fields_ \
99  ); \
100  lagrangianFieldDecomposer::readFieldFields \
101  ( \
102  cloudi, \
103  lagrangianObjects, \
104  Type##FieldFields_ \
105  ); \
106  }
107 
108  doLocalCode(label);
109  doLocalCode(scalar);
114 
115  #undef doLocalCode
116  }
117 
118  void decomposeAll
119  (
120  const label cloudi,
121  const fileName& cloudDir,
122  const lagrangianFieldDecomposer& decomposer,
123  bool report /* unused */
124  ) const
125  {
126  #undef doLocalCode
127  #define doLocalCode(Type) \
128  { \
129  decomposer.decomposeFields \
130  ( \
131  cloudDir, \
132  Type##Fields_[cloudi] \
133  ); \
134  decomposer.decomposeFieldFields \
135  ( \
136  cloudDir, \
137  Type##FieldFields_[cloudi] \
138  ); \
139  }
140 
141  doLocalCode(label);
142  doLocalCode(scalar);
147 
148  #undef doLocalCode
149  }
150 };
151 
152 } // End namespace Foam
153 
154 
155 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
156 
158 :
159  cache_(new privateCache)
160 {}
161 
162 
164 (
165  const label nClouds
166 )
167 :
168  cache_(new privateCache)
169 {
170  cache_->resize(nClouds);
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
175 
176 // Destructor not in header (used incomplete type)
178 {}
179 
180 
181 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 {
185  return (!cache_ || cache_->empty());
186 }
187 
190 {
191  return (cache_ ? cache_->size() : label(0));
192 }
193 
194 
196 {
197  cache_.reset(new privateCache);
198 }
199 
200 
202 (
203  const label nClouds
204 )
205 {
206  if (cache_)
207  {
208  cache_->resize(nClouds);
209  }
210 }
211 
212 
214 (
215  const label cloudi,
216  const IOobjectList& lagrangianObjects
217 )
218 {
219  if (cache_)
220  {
221  cache_->readAll(cloudi, lagrangianObjects);
222  }
223 }
224 
225 
227 (
228  const label cloudi,
229  const fileName& cloudDir,
230  const lagrangianFieldDecomposer& decomposer,
231  bool report
232 ) const
233 {
234  if (cache_)
235  {
236  cache_->decomposeAll(cloudi, cloudDir, decomposer, report);
237  }
238 }
239 
240 
241 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:71
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
void decomposeAllFields(const label cloudi, const fileName &cloudDir, const lagrangianFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields and field-fields for given cloud.
void readAllFields(const label cloudi, const IOobjectList &lagrangianObjects)
Read all fields and field-fields for given cloud and objects.
void resize(const label nClouds)
Resize for the number of clouds.
void decomposeAll(const label cloudi, const fileName &cloudDir, const lagrangianFieldDecomposer &decomposer, bool report) const
#define doLocalCode(Type)
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
void readAll(const label cloudi, const IOobjectList &lagrangianObjects)
#define declareField(Type)
Tensor of scalars, i.e. Tensor<scalar>.
Namespace for OpenFOAM.
Lagrangian field decomposer.