SubField.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::SubField
29
30Description
31 SubField is a Field obtained as a section of another Field,
32 without its own allocation.
33 SubField is derived from a SubList rather than a List.
34
35SourceFiles
36 SubFieldI.H
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef SubField_H
41#define SubField_H
42
43#include "Field.H"
44#include "SubList.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51// Forward Declarations
52template<class Type> class SubField;
53
54/*---------------------------------------------------------------------------*\
55 Class SubField Declaration
56\*---------------------------------------------------------------------------*/
57
58template<class Type>
59class SubField
60:
61 public FieldBase,
62 public SubList<Type>
63{
64public:
65
66 //- Component type
67 typedef typename pTraits<Type>::cmptType cmptType;
68
69
70 // Static Member Functions
71
72 //- Return nullObject reference SubField
73 inline static const SubField<Type>& null();
74
75
76 // Constructors
77
78 //- Default construct, zero-sized and nullptr
79 SubField() noexcept = default;
80
81 //- Copy construct (shallow copy)
82 inline SubField(const SubField<Type>& sfield);
83
84 //- Copy construct from SubList
85 inline SubField(const SubList<Type>& list);
86
87 //- Construct from UList, the entire size
88 inline explicit SubField(const UList<Type>& list);
89
90 //- Construct from UList with a given sub-list size, start at 0
91 inline SubField
92 (
93 const UList<Type>& list,
94 const label subSize
95 );
96
97 //- Construct from UList with a given size and start index
98 inline SubField
99 (
100 const UList<Type>& list,
101 const label subSize,
102 const label startIndex
103 );
104
105 //- Construct from UList and a (start,size) range.
106 // The range is subsetted with the list size itself to ensure that the
107 // result always addresses a valid section of the list.
108 inline SubField
109 (
110 const UList<Type>& list,
111 const labelRange& range
112 );
113
114 //- Construct from UList and a (start,size) range, but bypassing
115 //- run-time range checking.
116 inline SubField
117 (
118 const labelRange& range,
119 const UList<Type>& list
120 );
121
122
123 // Member Functions
124
125 //- Return a component field of the field
126 inline tmp<Field<cmptType>> component(const direction) const;
127
128 //- Return the field transpose (only defined for second rank tensors)
129 tmp<Field<Type>> T() const;
130
131
132 // Member Operators
133
134 //- Allow cast to a const Field<Type>&
135 inline operator const Foam::Field<Type>&() const;
136
137 //- Copy assign via UList operator. Takes linear time.
138 inline void operator=(const SubField<Type>&);
139
140 //- Copy assign via UList operator. Takes linear time.
141 inline void operator=(const Field<Type>&);
142
143 //- Assign all entries to the given value
144 inline void operator=(const Type& val);
145
146 //- Assign all entries to zero
147 inline void operator=(const Foam::zero);
148
149 //- Copy assign via UList operator. Takes linear time.
150 template<class Form, direction Ncmpts>
151 inline void operator=(const VectorSpace<Form, Type, Ncmpts>& rhs);
152
153 //- Add value to each entry
154 inline void operator+=(const Type& val);
155
156 //- Subtract value from each entry
157 inline void operator-=(const Type& val);
158
159 //- Multiply each entry by value
160 inline void operator*=(const scalar& s);
161
162 //- Divide each entry by value
163 inline void operator/=(const scalar& s);
164};
165
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169} // End namespace Foam
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172
173#include "SubFieldI.H"
174
175// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176
177template<class Type>
179Foam::Field<Type>::slice(const label pos, label len)
180{
181 if (len < 0)
182 {
183 len = (this->size() - pos);
184 }
185 return SubField<Type>(*this, len, pos);
186}
187
188
189template<class Type>
191Foam::Field<Type>::slice(const label pos, label len) const
192{
193 if (len < 0)
194 {
195 len = (this->size() - pos);
196 }
197 return SubField<Type>(*this, len, pos);
198}
199
200
201template<class Type>
204{
205 return SubField<Type>(*this, range); // with range checking
206}
207
208
209template<class Type>
212{
213 return SubField<Type>(*this, range); // with range checking
214}
215
216
217// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218
219#endif
220
221// ************************************************************************* //
scalar range
Template invariant parts for Field and SubField.
Definition: FieldBase.H:53
Generic templated field type.
Definition: Field.H:82
SubField< Type > slice(const label pos, label len=-1)
Return SubField slice (non-const access) - no range checking.
Definition: SubField.H:178
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: SubField.H:62
static const SubField< Type > & null()
Return nullObject reference SubField.
Definition: SubFieldI.H:32
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: SubFieldI.H:129
SubField() noexcept=default
Default construct, zero-sized and nullptr.
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: SubFieldI.H:120
pTraits< Type >::cmptType cmptType
Component type.
Definition: SubField.H:66
A List obtained as a section of another List.
Definition: SubList.H:70
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
label size() const noexcept
The number of elements in the UList.
Definition: UListI.H:420
Templated vector space.
Definition: VectorSpace.H:79
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
A class for managing temporary objects.
Definition: tmp.H:65
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
uint8_t direction
Definition: direction.H:56
const direction noexcept
Definition: Scalar.H:223
A non-counting (dummy) refCount.
Definition: refCount.H:59