FieldListSlice.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::FieldListSlice
26 
27 Description
28  Class to provide a list-like interface to a slice through a PtrList of
29  fields
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef FieldListSlice_H
34 #define FieldListSlice_H
35 
36 #include "Field.H"
37 #include "fieldTypes.H"
38 #include "PtrList.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class FieldListSlice Declaration
47 \*---------------------------------------------------------------------------*/
48 
49 template<class Type>
50 class FieldListSlice
51 {
52  // Private Data
53 
54  //- Reference to the fields
55  const UPtrList<const Field<Type>>& fields_;
56 
57  //- Element index
58  const label elementi_;
59 
60 
61 public:
62 
63  // Constructors
64 
65  //- Construct from a list of fields and an element index
66  inline FieldListSlice
67  (
68  const UPtrList<const Field<Type>>& fields,
69  const label elementi
70  )
71  :
72  fields_(fields),
73  elementi_(elementi)
74  {}
75 
76  //- Construct from a list of fields and an element index
77  inline FieldListSlice
78  (
79  const UPtrList<Field<Type>>& fields,
80  const label elementi
81  )
82  :
84  (
85  reinterpret_cast<const UPtrList<const Field<Type>>&>(fields),
86  elementi
87  )
88  {}
89 
90 
91  // Member Functions
92 
93  //- Return the size of the slice
94  inline label size() const
95  {
96  return fields_.size();
97  }
98 
99 
100  // Member Operators
101 
102  //- Access an element
103  inline const Type& operator[](const label fieldi) const
104  {
105  return fields_[fieldi][elementi_];
106  }
107 };
108 
109 
110 //- Define scalarFieldListSlice, vectorFieldListSlice, etc...
111 #define typedefTypeFieldListSlice(Type, nullArg) \
112  typedef FieldListSlice<Type> Type##FieldListSlice;
114 #undef typedefTypeFieldListSlice
115 
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 } // End namespace Foam
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 #endif
124 
125 // ************************************************************************* //
#define typedefTypeFieldListSlice(Type, nullArg)
Define scalarFieldListSlice, vectorFieldListSlice, etc...
Class to provide a list-like interface to a slice through a PtrList of fields.
label size() const
Return the size of the slice.
const Type & operator[](const label fieldi) const
Access an element.
FieldListSlice(const UPtrList< const Field< Type >> &fields, const label elementi)
Construct from a list of fields and an element index.
Pre-declare SubField and related Field type.
Definition: Field.H:83
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
Include the header files for all the primitive types that Fields are instantiated for.
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:228
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)