faFieldDecomposer.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-2017 Wikki Ltd
9  Copyright (C) 2021-2026 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::faFieldDecomposer
29 
30 Description
31  Finite Area area and edge field decomposer.
32 
33 Author
34  Zeljko Tukovic, FSB Zagreb
35  Hrvoje Jasak, Wikki Ltd.
36 
37 SourceFiles
38  faFieldDecomposer.cxx
39  faFieldDecomposer.txx
40  faFieldDecomposerCache.cxx
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_faFieldDecomposer_H
45 #define Foam_faFieldDecomposer_H
46 
47 #include "faMesh.H"
48 #include "faMeshSubset.H"
49 #include "faPatchFieldMapper.H"
50 #include "edgeFields.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class IOobjectList;
59 
60 /*---------------------------------------------------------------------------*\
61  Class faFieldDecomposer Declaration
62 \*---------------------------------------------------------------------------*/
63 
65 {
66 public:
67 
68  // Public Classes
69 
70  //- Patch field decomposer class
72  :
73  public faPatchFieldMapper
74  {
75  // Private Data
76 
77  label sizeBeforeMapping_;
78  labelList directAddressing_;
79 
80  public:
81 
82  // Constructors
83 
84  //- Construct given addressing
86  (
87  const label sizeBeforeMapping,
88  const labelUList& addressingSlice,
89  const label addressingOffset,
91  const bool noEdgeEncoding = false
92  );
93 
94 
95  // Member Functions
96 
97  label size() const noexcept
98  {
99  return directAddressing_.size();
100  }
102  virtual label sizeBeforeMapping() const
103  {
104  return sizeBeforeMapping_;
105  }
107  bool direct() const noexcept
108  {
109  return true;
110  }
112  virtual bool hasUnmapped() const
113  {
114  return false;
115  }
117  const labelUList& directAddressing() const noexcept
118  {
119  return directAddressing_;
120  }
121  };
122 
123 
124  //- Processor patch field decomposer class
125  class processorAreaPatchFieldDecomposer
126  :
127  public faPatchFieldMapper
128  {
129  // Private Data
130 
131  label sizeBeforeMapping_;
132  labelList directAddressing_;
133 
134  public:
135 
136  //- Construct addressing from details
138  (
139  const label nTotalFaces,
140  const labelUList& edgeOwner,
141  const labelUList& edgeNeigbour,
142  const labelUList& addressingSlice,
143  const bitSet& flip,
145  const bool noEdgeEncoding = false
146  );
147 
148 
149  // Member Functions
150 
151  label size() const noexcept
152  {
153  return directAddressing_.size();
154  }
155 
156  virtual label sizeBeforeMapping() const
157  {
158  return sizeBeforeMapping_;
159  }
160 
161  bool direct() const noexcept
162  {
163  return true;
164  }
165 
166  virtual bool hasUnmapped() const
167  {
168  return false;
169  }
170 
171  const labelUList& directAddressing() const noexcept
172  {
173  return directAddressing_;
174  }
175  };
176 
177 
178  //- Processor patch field decomposer class
179  class processorEdgePatchFieldDecomposer
180  :
181  public faPatchFieldMapper
182  {
183  label sizeBeforeMapping_;
184  labelListList addressing_;
185  scalarListList weights_;
186 
187  public:
188 
189  //- Construct given addressing
191  (
192  label sizeBeforeMapping,
193  const labelUList& addressingSlice,
195  const bool noEdgeEncoding = false
196  );
197 
198 
199  // Member Functions
200 
201  label size() const noexcept
202  {
203  return addressing_.size();
204  }
205 
206  virtual label sizeBeforeMapping() const
207  {
208  return sizeBeforeMapping_;
209  }
210 
211  bool direct() const noexcept
212  {
213  return false;
214  }
215 
216  virtual bool hasUnmapped() const
217  {
218  return false;
219  }
220 
221  const labelListList& addressing() const noexcept
222  {
223  return addressing_;
224  }
225 
226  const scalarListList& weights() const noexcept
227  {
228  return weights_;
229  }
230  };
231 
232 
233 private:
234 
235  // Private Data
236 
237  //- Reference to processor mesh
238  const faMesh& procMesh_;
239 
240  //- Reference to edge addressing
241  const labelUList& edgeAddressing_;
242 
243  //- Reference to face addressing
244  const labelUList& faceAddressing_;
245 
246  //- Reference to boundary addressing
247  const labelUList& boundaryAddressing_;
248 
249  //- List of patch field decomposers
250  PtrList<patchFieldDecomposer> patchFieldDecomposers_;
251 
252  //- Processor-patch field decomposers (area fields)
254  processorAreaPatchFieldDecomposers_;
255 
256  //- Processor-patch field decomposers (edge fields)
258  processorEdgePatchFieldDecomposers_;
259 
260  //- Processor-patch edge field flipping (as -1/+1 multipliers)
261  PtrList<scalarField> edgeSigns_;
262 
263  //- Has edgeProcAddressing without turning index (2512 and earlier)
264  bool noEdgeEncoding_;
265 
266 
267 public:
268 
269  // Public Classes
270  class fieldsCache;
271 
272  // Generated Methods
273 
274  //- No copy construct
275  faFieldDecomposer(const faFieldDecomposer&) = delete;
276 
277  //- No copy assignment
278  void operator=(const faFieldDecomposer&) = delete;
279 
280 
281  // Constructors
282 
283  //- Construct without mappers, added later with reset()
285  (
286  Foam::zero,
287  const faMesh& procMesh, // Target mesh
288  const labelUList& edgeAddressing,
289  const labelUList& faceAddressing,
290  const labelUList& boundaryAddressing,
292  const bool disableEdgeEncoding = false
293  );
294 
295  //- Construct from components using information from the complete mesh
297  (
298  const faMesh& completeMesh, // Source mesh
299  const faMesh& procMesh, // Target mesh
300  const labelUList& edgeAddressing,
301  const labelUList& faceAddressing,
302  const labelUList& boundaryAddressing,
304  const bool disableEdgeEncoding = false
305  );
306 
307  //- Construct from components without the complete mesh
309  (
310  // Information about the complete mesh
311  const label nTotalFaces,
312  const UList<labelRange>& boundaryRanges,
313  const labelUList& edgeOwner,
314  const labelUList& edgeNeigbour,
315 
316  // Addressing for processor mesh
317  const faMesh& procMesh, // Target mesh
318  const labelUList& edgeAddressing,
319  const labelUList& faceAddressing,
320  const labelUList& boundaryAddressing,
322  const bool disableEdgeEncoding = false
323  );
324 
325 
326  //- Destructor
327  ~faFieldDecomposer() = default;
328 
329 
330  // Member Functions
331 
332  //- True if no mappers have been allocated
333  bool empty() const noexcept;
334 
335  //- Remove all mappers
336  void clear();
337 
338  //- Reset mappers using information from the complete mesh
339  void reset(const faMesh& completeMesh);
340 
341  //- Reset mapper using information about the complete mesh
342  void reset
343  (
344  const label nTotalFaces,
345  const UList<labelRange>& boundaryRanges,
346  const labelUList& edgeOwner,
347  const labelUList& edgeNeigbour
348  );
349 
350  //- Is edge encoding disabled
351  bool noEdgeEncoding() const noexcept { return noEdgeEncoding_; }
352 
353  //- Change the edge encoding flag
354  bool noEdgeEncoding(bool on) noexcept
355  {
356  bool old(noEdgeEncoding_);
357  noEdgeEncoding_ = on;
358  return old;
359  }
360 
361  // Mapping
362 
363  //- Decompose area field
364  template<class Type>
367  (
369  ) const;
370 
371  //- Decompose surface field
372  template<class Type>
375  (
377  ) const;
378 
379  template<class GeoField>
380  void decomposeFields(const UPtrList<GeoField>& fields) const;
381 
382 
383  // Reading helpers
384 
385  //- Read the fields and store on the pointer list
386  template
387  <
388  class Type,
389  template<class> class PatchField,
390  class GeoMesh
391  >
392  static void readFields
393  (
394  const typename GeoMesh::Mesh& mesh,
395  const IOobjectList& objects,
397  const bool readOldTime
398  );
399 
400  //- Read fields and store on the pointer list
401  template<class Mesh, class GeoField>
402  static void readFields
403  (
404  const Mesh& mesh,
405  const IOobjectList& objects,
407  );
408 };
409 
410 
411 
412 /*---------------------------------------------------------------------------*\
413  Class faFieldDecomposer::fieldsCache Declaration
414 \*---------------------------------------------------------------------------*/
415 
417 {
418  // Private Data
419 
420  class privateCache;
421 
422  //- All field and field-field types for finiteArea
423  std::unique_ptr<privateCache> cache_;
424 
425 
426  // Private Member Functions
427 
428  //- No copy construct
429  fieldsCache(const fieldsCache&) = delete;
430 
431  //- No copy assignment
432  void operator=(const fieldsCache&) = delete;
433 
434 
435 public:
436 
437  // Constructors
438 
439  //- Default construct
440  fieldsCache();
441 
442 
443  //- Destructor
444  ~fieldsCache();
445 
446 
447  // Member Functions
448 
449  //- No fields
450  bool empty() const;
451 
452  //- Number of fields
453  label size() const;
454 
455  //- Clear out
456  void clear();
457 
458 
459  //- Read all fields given mesh and objects
460  void readAllFields
461  (
462  const faMesh& mesh,
463  const IOobjectList& objects
464  );
465 
466  //- Read all fields given mesh and objects.
467  //- Supports reading/sending fields
468  void readAllFields
469  (
470  const bitSet& haveMeshOnProc,
471  const faMeshSubset* subsetter,
472  const faMesh& mesh,
473  IOobjectList& objects
474  );
475 
476  //- Read all fields given mesh and objects.
477  //- Supports reading/sending fields
478  void readAllFields
479  (
480  const boolUList& haveMeshOnProc,
481  const faMeshSubset* subsetter,
482  const faMesh& mesh,
483  IOobjectList& objects
484  );
485 
486  //- Decompose and write all fields
487  void decomposeAllFields
488  (
489  const faFieldDecomposer& decomposer,
490  bool report = false
491  ) const;
492 };
493 
494 
495 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
496 
497 } // End namespace Foam
498 
499 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
500 
501 #ifdef NoRepository
502  #include "faFieldDecomposer.txx"
503 #endif
504 
505 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
506 
507 #endif
508 
509 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:133
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:119
const labelListList & addressing() const noexcept
Return the interpolation addressing.
virtual bool hasUnmapped() const
Any unmapped values?
rDeltaTY field()
label size() const noexcept
The size of the mapper.
Finite Area area and edge field decomposer.
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
~faFieldDecomposer()=default
Destructor.
bool direct() const noexcept
Is it a direct (non-interpolating) mapper?
void readAllFields(const faMesh &mesh, const IOobjectList &objects)
Read all fields given mesh and objects.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:63
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
Definition: faMeshSubset.H:61
Generic GeometricField class.
bool empty() const noexcept
True if no mappers have been allocated.
processorAreaPatchFieldDecomposer(const label nTotalFaces, const labelUList &edgeOwner, const labelUList &edgeNeigbour, const labelUList &addressingSlice, const bitSet &flip, const bool noEdgeEncoding=false)
Construct addressing from details.
patchFieldDecomposer(const label sizeBeforeMapping, const labelUList &addressingSlice, const label addressingOffset, const bool noEdgeEncoding=false)
Construct given addressing.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
virtual bool hasUnmapped() const
Any unmapped values?
bool noEdgeEncoding() const noexcept
Is edge encoding disabled.
virtual bool hasUnmapped() const
Any unmapped values?
const labelUList & directAddressing() const noexcept
Return the direct addressing values.
static void readFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh >> &fields, const bool readOldTime)
Read the fields and store on the pointer list.
void reset(const faMesh &completeMesh)
Reset mappers using information from the complete mesh.
dynamicFvMesh & mesh
label size() const
Number of fields.
const labelUList & directAddressing() const noexcept
Return the direct addressing values.
label size() const noexcept
The size of the mapper.
processorEdgePatchFieldDecomposer(label sizeBeforeMapping, const labelUList &addressingSlice, const bool noEdgeEncoding=false)
Construct given addressing.
label size() const noexcept
The size of the mapper.
bool direct() const noexcept
Is it a direct (non-interpolating) mapper?
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
const direction noexcept
Definition: scalarImpl.H:265
MESH Mesh
Definition: GeoMesh.H:61
void clear()
Remove all mappers.
const scalarListList & weights() const noexcept
Return the interpolation weights.
bool empty() const
No fields.
faFieldDecomposer(const faFieldDecomposer &)=delete
No copy construct.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:58
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: PtrList.H:56
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:45
void operator=(const faFieldDecomposer &)=delete
No copy assignment.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
bool direct() const noexcept
Is it a direct (non-interpolating) mapper?
A FieldMapper for finite-area patch fields.
void decomposeFields(const UPtrList< GeoField > &fields) const
tmp< GeometricField< Type, faPatchField, areaMesh > > decomposeField(const GeometricField< Type, faPatchField, areaMesh > &field) const
Decompose area field.
Namespace for OpenFOAM.
void decomposeAllFields(const faFieldDecomposer &decomposer, bool report=false) const
Decompose and write all fields.