GeometricFieldListSlicer.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::GeometricFieldListSlicer
26 
27 Description
28  Class to provide list slices to different parts of a geometric field
29 
30 See also
31  Foam::FieldListSlice
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef GeometricFieldListSlicer_H
36 #define GeometricFieldListSlicer_H
37 
38 #include "GeometricField.H"
39 #include "FieldListSlice.H"
40 #include "volFieldsFwd.H"
41 #include "surfaceFieldsFwd.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 /*---------------------------------------------------------------------------*\
48  Class GeometricFieldListSlicer Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class Type, template<class> class PatchField, class GeoMesh>
53 {
54  // Private Typedefs
55 
56  // Type of the geometric field
58 
59 
60  // Private Data
61 
62  //- Pointers to the internal fields
64 
65  //- Pointers to the patch fields. Indexed by patch, then by field.
66  List<UPtrList<const Field<Type>>> patchFields_;
67 
68 
69 public:
70 
71  // Constructors
72 
73  //- Construct null. Set later.
75  {}
76 
77  //- Construct from a mesh and a list of fields
79  (
80  const typename geoFieldType::Mesh& mesh,
81  const UPtrList<const geoFieldType>& geoFields
82  )
83  {
84  set(mesh, geoFields);
85  }
86 
87  //- Construct from a mesh and a list of fields
89  (
90  const typename geoFieldType::Mesh& mesh,
91  const UPtrList<geoFieldType>& geoFields
92  )
93  :
95  (
96  mesh,
97  reinterpret_cast<const UPtrList<const geoFieldType>&>(geoFields)
98  )
99  {}
100 
101 
102  // Member Functions
103 
104  //- Set the field pointers
105  inline void set
106  (
107  const typename geoFieldType::Mesh& mesh,
108  const UPtrList<const geoFieldType>& geoFields
109  )
110  {
111  fields_.resize(geoFields.size());
112 
113  patchFields_.resize(mesh.boundary().size(), fields_);
114 
115  forAll(geoFields, fieldi)
116  {
117  fields_.set
118  (
119  fieldi,
120  &geoFields[fieldi].primitiveField()
121  );
122 
123  forAll(geoFields[fieldi].boundaryField(), patchi)
124  {
125  patchFields_[patchi].set
126  (
127  fieldi,
128  &geoFields[fieldi].boundaryField()[patchi]
129  );
130  }
131  }
132  }
133 
134  //- Return a slice for an internal element
135  inline FieldListSlice<Type> slice(const label elementi) const
136  {
137  return FieldListSlice<Type>(fields_, elementi);
138  }
139 
140  //- Return a slice for a patch element
142  (
143  const label patchi,
144  const label patchElementi
145  ) const
146  {
147  return FieldListSlice<Type>(patchFields_[patchi], patchElementi);
148  }
149 };
150 
151 
152 //- Define volScalarFieldListSlicer, volVectorFieldListSlicer, etc...
153 #define typedefVolTypeFieldListSlicer(Type, nullArg) \
154  typedef GeometricFieldListSlicer<Type, fvPatchField, volMesh> \
155  CAT3(vol, CAPITALIZE(Type), FieldListSlicer);
157 #undef typedefVolTypeFieldListSlicer
158 
159 
160 //- Define surfaceScalarFieldListSlicer, surfaceVectorFieldListSlicer, etc...
161 #define typedefSurfaceTypeFieldListSlicer(Type, nullArg) \
162  typedef GeometricFieldListSlicer<Type, fvPatchField, surfaceMesh> \
163  CAT3(surface, CAPITALIZE(Type), FieldListSlicer);
165 #undef typedefSurfaceTypeFieldListSlicer
166 
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 } // End namespace Foam
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #endif
175 
176 // ************************************************************************* //
#define typedefSurfaceTypeFieldListSlicer(Type, nullArg)
Define surfaceScalarFieldListSlicer, surfaceVectorFieldListSlicer, etc...
#define typedefVolTypeFieldListSlicer(Type, nullArg)
Define volScalarFieldListSlicer, volVectorFieldListSlicer, etc...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
Class to provide list slices to different parts of a geometric field.
GeometricFieldListSlicer()
Construct null. Set later.
void set(const typename geoFieldType::Mesh &mesh, const UPtrList< const geoFieldType > &geoFields)
Set the field pointers.
FieldListSlice< Type > patchSlice(const label patchi, const label patchElementi) const
Return a slice for a patch element.
FieldListSlice< Type > slice(const label elementi) const
Return a slice for an internal element.
Generic GeometricField class.
GeoMesh::Mesh Mesh
Type of mesh on which this GeometricField is instantiated.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
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
label patchi
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)