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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::SubField
29 
30 Description
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 
35 SourceFiles
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 
48 namespace Foam
49 {
50 
51 // Forward Declarations
52 template<class Type> class SubField;
53 
54 /*---------------------------------------------------------------------------*\
55  Class SubField Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 template<class Type>
59 class SubField
60 :
61  public FieldBase,
62  public SubList<Type>
63 {
64 public:
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 
177 template<class Type>
179 Foam::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 
189 template<class Type>
191 Foam::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 
201 template<class Type>
204 {
205  return SubField<Type>(*this, range); // with range checking
206 }
207 
208 
209 template<class Type>
212 {
213  return SubField<Type>(*this, range); // with range checking
214 }
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 #endif
220 
221 // ************************************************************************* //
SubList.H
s
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))
Definition: gmvOutputSpray.H:25
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::SubField
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: Field.H:64
Foam::Field
Generic templated field type.
Definition: Field.H:63
Field.H
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
Foam::SubField::T
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: SubFieldI.H:129
Foam::SubField::component
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: SubFieldI.H:120
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::SubField::SubField
SubField() noexcept=default
Default construct, zero-sized and nullptr.
Foam::Field::slice
SubField< Type > slice(const label pos, label len=-1)
Return SubField slice (non-const access) - no range checking.
Definition: SubField.H:178
Foam::SubField::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: SubField.H:66
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177