pointFieldDecomposerCache.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 
28 #include "pointFieldDecomposer.H"
29 #include "fieldsDistributor.H"
30 #include "pointFields.H"
31 #include "IOobjectList.H"
32 #include "PtrListOps.H"
33 
34 // * * * * * * * * * * * * * * * * Declarations * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // All point field types
40 class pointFieldDecomposer::fieldsCache::privateCache
41 {
42 public:
43 
44  #undef declareField
45  #define declareField(Type) \
46  PtrList<GeometricField<Type, pointPatchField, pointMesh>> Type##Fields_;
47 
48  declareField(scalar);
53  #undef declareField
54 
55  label size() const noexcept
56  {
57  label count = 0;
58 
59  #undef doLocalCode
60  #define doLocalCode(Type) \
61  { \
62  count += Type##Fields_.size(); \
63  }
64 
65  doLocalCode(scalar);
70  #undef doLocalCode
71 
72  return count;
73  }
74 
75  bool empty() const noexcept { return !size(); }
76 
77  void readAll(const pointMesh& mesh, const IOobjectList& objects)
78  {
79  #undef doLocalCode
80  #define doLocalCode(Type) \
81  { \
82  fieldsDistributor::readFields \
83  ( \
84  mesh, \
85  objects, \
86  Type##Fields_, \
87  false /* readOldTime = false */ \
88  ); \
89  }
90 
91  doLocalCode(scalar);
96 
97  #undef doLocalCode
98  }
99 
100  template<class GeoField>
101  static void decompose
102  (
103  const pointFieldDecomposer& decomposer,
104  const PtrList<GeoField>& fields,
105  bool report
106  )
107  {
108  if (!fields.empty())
109  {
110  if (report)
111  {
112  Info<< " "
114  << "s: "
116  }
117 
118  decomposer.decomposeFields(fields);
119  }
120  }
121 
122  void decomposeAll
123  (
124  const pointFieldDecomposer& decomposer,
125  bool report
126  ) const
127  {
128  #undef doLocalCode
129  #define doLocalCode(Type) \
130  { \
131  decompose(decomposer, Type##Fields_, report); \
132  }
133 
134  doLocalCode(scalar);
139 
140  #undef doLocalCode
141  }
142 };
143 
144 } // End namespace Foam
145 
146 
147 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 
150 :
151  cache_(new privateCache)
152 {}
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
157 // Destructor not in header (used incomplete type)
159 {}
160 
161 
162 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 {
166  return (!cache_ || cache_->empty());
167 }
168 
171 {
172  return (cache_ ? cache_->size() : label(0));
173 }
174 
175 
177 {
178  cache_.reset(new privateCache);
179 }
180 
181 
183 (
184  const pointMesh& mesh,
185  const IOobjectList& objects
186 )
187 {
188  if (cache_)
189  {
190  cache_->readAll(mesh, objects);
191  }
192 }
193 
194 
196 (
197  const pointFieldDecomposer& decomposer,
198  bool report
199 ) const
200 {
201  if (cache_)
202  {
203  cache_->decomposeAll(decomposer, report);
204  }
205 }
206 
207 
208 // ************************************************************************* //
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
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
static void decompose(const pointFieldDecomposer &decomposer, const PtrList< GeoField > &fields, bool report)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
#define declareField(Type)
void decomposeAll(const pointFieldDecomposer &decomposer, bool report) const
Functions to operate on Pointer Lists.
void readAllFields(const pointMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
dynamicFvMesh & mesh
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Point field decomposer.
void decomposeAllFields(const pointFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.
void readAll(const pointMesh &mesh, const IOobjectList &objects)
#define doLocalCode(Type)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
label size() const
Total number of fields.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Tensor of scalars, i.e. Tensor<scalar>.
Namespace for OpenFOAM.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
void decomposeFields(const PtrList< GeoField > &fields) const
Decompose list of fields.