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-2026 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 UPtrList of
29  fields
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef FieldListSlice_H
34 #define FieldListSlice_H
35 
36 #include "Field.H"
37 #include "UPtrList.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class FieldListSlice Declaration
46 \*---------------------------------------------------------------------------*/
47 
48 template<class Type>
49 class FieldListSlice
50 {
51  // Private Data
52 
53  //- Reference to the fields
54  const UPtrList<const Field<Type>>& fields_;
55 
56  //- Element index
57  const label elementi_;
58 
59 
60 public:
61 
62  // Constructors
63 
64  //- Construct from a list of fields and an element index
65  inline FieldListSlice
66  (
67  const UPtrList<const Field<Type>>& fields,
68  const label elementi
69  )
70  :
71  fields_(fields),
72  elementi_(elementi)
73  {}
74 
75  //- Construct from a list of fields and an element index
76  inline FieldListSlice
77  (
78  const UPtrList<Field<Type>>& fields,
79  const label elementi
80  )
81  :
83  (
84  reinterpret_cast<const UPtrList<const Field<Type>>&>(fields),
85  elementi
86  )
87  {}
88 
89 
90  // Member Functions
91 
92  //- Return the size of the slice
93  inline label size() const
94  {
95  return fields_.size();
96  }
97 
98 
99  // Member Operators
100 
101  //- Access an element
102  inline const Type& operator[](const label fieldi) const
103  {
104  return fields_[fieldi][elementi_];
105  }
106 };
107 
108 
109 //- Define scalarFieldListSlice, vectorFieldListSlice, etc...
110 #define typedefTypeFieldListSlice(Type, nullArg) \
111  typedef FieldListSlice<Type> Type##FieldListSlice;
113 #undef typedefTypeFieldListSlice
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 } // End namespace Foam
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 #endif
123 
124 // ************************************************************************* //
#define typedefTypeFieldListSlice(Type, nullArg)
Define scalarFieldListSlice, vectorFieldListSlice, etc...
Class to provide a list-like interface to a slice through a UPtrList 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
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:234
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(makeDimensionedPointFieldFunctions)