DimensionedFieldListSlicer.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) 2025 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::DimensionedFieldListSlicer
26 
27 Description
28  Class to provide list slices to different parts of a dimensioned field
29 
30 See also
31  Foam::FieldListSlice
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef DimensionedFieldListSlicer_H
36 #define DimensionedFieldListSlicer_H
37 
38 #include "DimensionedField.H"
39 #include "FieldListSlice.H"
40 #include "volFieldsFwd.H"
41 #include "surfaceFieldsFwd.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 /*---------------------------------------------------------------------------*\
48  Class DimensionedFieldListSlicer Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Type, class GeoMesh>
53 {
54  // Private Typedefs
55 
56  // Type of the dimensioned field
58 
59 
60  // Private Data
61 
62  //- Pointers to the primitive fields
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct null. Set later.
72  {}
73 
74  //- Construct from a list of fields
76  (
77  const UPtrList<const geoFieldType>& geoFields
78  )
79  {
80  set(geoFields);
81  }
82 
83  //- Construct from a list of fields
85  (
86  const UPtrList<geoFieldType>& geoFields
87  )
88  :
90  (
91  reinterpret_cast<const UPtrList<const geoFieldType>&>(geoFields)
92  )
93  {}
94 
95 
96  // Member Functions
97 
98  //- Set the field pointers
99  inline void set(const UPtrList<const geoFieldType>& geoFields)
100  {
101  fields_.resize(geoFields.size());
102 
103  forAll(geoFields, fieldi)
104  {
105  fields_.set
106  (
107  fieldi,
108  &geoFields[fieldi].primitiveField()
109  );
110  }
111  }
112 
113  //- Return a slice for an internal element
114  inline FieldListSlice<Type> slice(const label elementi) const
115  {
116  return FieldListSlice<Type>(fields_, elementi);
117  }
118 };
119 
120 
121 /*---------------------------------------------------------------------------*\
122  Class DimensionedFieldListAndSlicer Declaration
123 \*---------------------------------------------------------------------------*/
124 
125 template<class Type, class GeoMesh>
127 :
128  public PtrList<DimensionedField<Type, GeoMesh>>,
129  private DimensionedFieldListSlicer<Type, GeoMesh>
130 {
131  // Private Typedefs
132 
133  // Type of the dimensioned field
135 
136 
137 public:
138 
139  // Constructors
140 
141  //- Null Constructor
143  {}
144 
145  //- Construct with size specified
147  :
149  {}
150 
151  //- Construct from arguments
152  template<class ... Args>
154  :
155  PtrList<DimensionedField<Type, GeoMesh>>(args ...)
156  {
157  set();
158  }
159 
160 
161  // Member Functions
162 
163  //- Inherit the pointer list's set method
165 
166  //- Set the field pointers in the slicer
167  inline void set()
168  {
170  (
171  reinterpret_cast<const UPtrList<const geoFieldType>&>(*this)
172  );
173  }
174 
175  //- Return a slice for an internal element
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #endif
187 
188 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
void set()
Set the field pointers in the slicer.
Class to provide list slices to different parts of a dimensioned field.
DimensionedFieldListSlicer()
Construct null. Set later.
void set(const UPtrList< const geoFieldType > &geoFields)
Set the field pointers.
FieldListSlice< Type > slice(const label elementi) const
Return a slice for an internal element.
Class to provide a list-like interface to a slice through a PtrList of fields.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:47
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
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
bool set(const label) const
Is element set.
Definition: UPtrListI.H:87
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void resize(const label)
Reset size of UPtrList. This can only be used to set the size.
Definition: UPtrListI.H:71
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
Foam::argList args(argc, argv)