SubField.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) 2011-2024 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::SubField
26 
27 Description
28  SubField is a Field obtained as a section of another Field.
29 
30  Thus it is itself unallocated so that no storage is allocated or
31  deallocated during its use. To achieve this behaviour, SubField is
32  derived from a SubList rather than a List.
33 
34 SourceFiles
35  SubFieldI.H
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef SubField_H
40 #define SubField_H
41 
42 #include "SubList.H"
43 #include "Field.H"
44 #include "VectorSpace.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 //- Pre-declare SubField and related Field type
52 template<class Type> class Field;
53 template<class Type> class SubField;
54 
55 /*---------------------------------------------------------------------------*\
56  Class SubField Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type>
60 class SubField
61 :
62  public tmp<SubField<Type>>::refCount,
63  public SubList<Type>
64 {
65 
66 public:
67 
68  //- Component type
69  typedef typename pTraits<Type>::cmptType cmptType;
70 
71 
72  // Constructors
73 
74  //- Construct from a SubList
75  SubField(const SubList<Type>&);
76 
77  //- Construct from a UList<Type>, using the entire size
78  explicit SubField(const UList<Type>&);
79 
80  //- Construct from a UList<Type> with a given size
81  SubField(const UList<Type>& list, const label subSize);
82 
83  //- Construct from a UList<Type> with a given size and start index
84  SubField
85  (
86  const UList<Type>& list,
87  const label subSize,
88  const label startIndex
89  );
90 
91  //- Copy constructor
92  SubField(const SubField<Type>&);
93 
94  //- Copy constructor or reuse as specified
95  SubField(SubField<Type>&, bool reuse);
96 
97 
98  // Static Member Functions
99 
100  //- Return a null SubField
101  static inline const SubField<Type>& null()
102  {
103  return NullObjectRef<SubField<Type>>();
104  }
105 
106 
107  // Member Functions
108 
109  //- Return a component field of the field
111 
112  //- Return the field transpose (only defined for second rank tensors)
113  tmp<Field<Type>> T() const;
114 
115 
116  // Member Operators
117 
118  void operator=(const SubField<Type>&);
119  void operator=(const UList<Type>&);
120  void operator=(const tmp<Field<Type>>&);
121  void operator=(const Type&);
122  void operator=(const zero);
123 
124  template<class Form, direction Ncmpts>
126 
127  void operator+=(const UList<Type>&);
128  void operator+=(const tmp<Field<Type>>&);
129 
130  void operator-=(const UList<Type>&);
131  void operator-=(const tmp<Field<Type>>&);
132 
133  void operator*=(const UList<scalar>&);
134  void operator*=(const tmp<Field<scalar>>&);
135 
136  void operator/=(const UList<scalar>&);
137  void operator/=(const tmp<Field<scalar>>&);
138 
139  void operator+=(const Type&);
140  void operator-=(const Type&);
141 
142  void operator*=(const scalar&);
143  void operator/=(const scalar&);
144 
145  //- Allow cast to a const Field<Type>&
146  inline operator const Field<Type>&() const
147  {
148  return *reinterpret_cast<const Field<Type>*>(this);
149  }
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #ifdef NoRepository
160  #include "SubField.C"
161 #endif
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Pre-declare related SubField type.
Definition: SubField.H:63
void operator=(const SubField< Type > &)
Definition: SubField.C:119
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: SubField.C:110
SubField(const SubList< Type > &)
Construct from a SubList.
Definition: SubField.C:32
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: SubField.C:101
void operator+=(const UList< Type > &)
Definition: SubField.C:174
void operator-=(const UList< Type > &)
Definition: SubField.C:175
pTraits< Type >::cmptType cmptType
Component type.
Definition: SubField.H:68
void operator*=(const UList< scalar > &)
Definition: SubField.C:176
void operator/=(const UList< scalar > &)
Definition: SubField.C:177
A List obtained as a section of another List.
Definition: SubList.H:56
Templated vector space.
Definition: VectorSpace.H:85
Traits class for primitives.
Definition: pTraits.H:53
Reference counter for various OpenFOAM components.
Definition: refCount.H:50
A class for managing temporary objects.
Definition: tmp.H:55
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
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
uint8_t direction
Definition: direction.H:45