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-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::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 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 /*---------------------------------------------------------------------------*\
46  Class GeometricFieldListSlicer Declaration
47 \*---------------------------------------------------------------------------*/
48 
49 template<class Type>
51 {
52  // Private Data
53 
54  //- Pointers to the primitive fields
55  UPtrList<const Field<Type>> primitiveFields_;
56 
57  //- Pointers to the patch fields. Indexed by patch, then by field.
58  List<UPtrList<const Field<Type>>> patchFields_;
59 
60 
61 public:
62 
63  // Constructors
64 
65  //- Construct null. Set later.
67  {}
68 
69  //- Construct from a mesh and a list of fields
70  template<class GeoMesh, template<class> class PrimitiveField>
72  (
73  const GeoMesh& mesh,
75  geoFields
76  )
77  {
78  set(mesh, geoFields);
79  }
80 
81 
82  // Member Functions
83 
84  //- Set the field pointers
85  template<class GeoMesh, template<class> class PrimitiveField>
86  inline void set
87  (
88  const GeoMesh& mesh,
90  geoFields
91  )
92  {
93  primitiveFields_.resize(geoFields.size());
94 
95  patchFields_.resize(mesh.boundary().size(), primitiveFields_);
96 
97  forAll(geoFields, fieldi)
98  {
99  primitiveFields_.set
100  (
101  fieldi,
102  &geoFields[fieldi].primitiveField()
103  );
104 
105  forAll(geoFields[fieldi].boundaryField(), patchi)
106  {
107  patchFields_[patchi].set
108  (
109  fieldi,
110  &geoFields[fieldi].boundaryField()[patchi]
111  );
112  }
113  }
114  }
115 
116  //- Return a slice for an internal element
117  inline FieldListSlice<Type> slice(const label elementi) const
118  {
119  return FieldListSlice<Type>(primitiveFields_, elementi);
120  }
121 
122  //- Return a slice for a patch element
124  (
125  const label patchi,
126  const label patchElementi
127  ) const
128  {
129  return FieldListSlice<Type>(patchFields_[patchi], patchElementi);
130  }
131 };
132 
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Class to provide a list-like interface to a slice through a UPtrList of fields.
Class to provide list slices to different parts of a geometric field.
GeometricFieldListSlicer()
Construct null. Set later.
void set(const GeoMesh &mesh, const UPtrList< GeometricField< Type, GeoMesh, PrimitiveField >> &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.
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
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
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