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-2020 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 
33  Thus it is itself unallocated so that no storage is allocated or
34  deallocated during its use. To achieve this behaviour, SubField is
35  derived from a SubList rather than a List.
36 
37 SourceFiles
38  SubFieldI.H
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef SubField_H
43 #define SubField_H
44 
45 #include "SubList.H"
46 #include "Field.H"
47 #include "VectorSpace.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declarations
55 template<class Type> class Field;
56 template<class Type> class SubField;
57 
58 /*---------------------------------------------------------------------------*\
59  Class SubField Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class Type>
63 class SubField
64 :
65  public refCount,
66  public SubList<Type>
67 {
68 
69 public:
70 
71  //- Component type
72  typedef typename pTraits<Type>::cmptType cmptType;
73 
74 
75  // Constructors
76 
77  //- Copy construct (shallow copy)
78  inline SubField(const SubField<Type>& sfield);
79 
80  //- Copy construct from SubList
81  inline SubField(const SubList<Type>& list);
82 
83  //- Construct from UList, the entire size
84  inline explicit SubField(const UList<Type>& list);
85 
86  //- Construct from UList with a given sub-list size, start at 0
87  inline SubField
88  (
89  const UList<Type>& list,
90  const label subSize
91  );
92 
93  //- Construct from UList with a given size and start index
94  inline SubField
95  (
96  const UList<Type>& list,
97  const label subSize,
98  const label startIndex
99  );
100 
101  //- Construct from UList and a (start,size) range.
102  // The range is subsetted with the list size itself to ensure that the
103  // result always addresses a valid section of the list.
104  inline SubField
105  (
106  const UList<Type>& list,
107  const labelRange& range
108  );
109 
110  //- Construct from UList and a (start,size) range, but bypassing
111  //- run-time range checking.
112  inline SubField
113  (
114  const labelRange& range,
115  const UList<Type>& list
116  );
117 
118 
119  // Member Functions
120 
121  //- Return a null SubField
122  static inline const SubField<Type>& null();
123 
124  //- Return a component field of the field
125  inline tmp<Field<cmptType>> component(const direction) const;
126 
127  //- Return the field transpose (only defined for second rank tensors)
128  tmp<Field<Type>> T() const;
129 
130 
131  // Member Operators
132 
133  //- Allow cast to a const Field<Type>&
134  inline operator const Foam::Field<Type>&() const;
135 
136  //- Copy assign via UList operator. Takes linear time.
137  inline void operator=(const SubField<Type>&);
138 
139  //- Copy assign via UList operator. Takes linear time.
140  inline void operator=(const Field<Type>&);
141 
142  //- Assign all entries to the given value
143  inline void operator=(const Type& val);
144 
145  //- Assign all entries to zero
146  inline void operator=(const Foam::zero);
147 
148  //- Copy assign via UList operator. Takes linear time.
149  template<class Form, direction Ncmpts>
150  inline void operator=(const VectorSpace<Form, Type, Ncmpts>& rhs);
151 
152  //- Add value to each entry
153  inline void operator+=(const Type& val);
154 
155  //- Subtract value from each entry
156  inline void operator-=(const Type& val);
157 
158  //- Multiply each entry by value
159  inline void operator*=(const scalar& s);
160 
161  //- Divide each entry by value
162  inline void operator/=(const scalar& s);
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #include "SubFieldI.H"
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #endif
177 
178 // ************************************************************************* //
VectorSpace.H
SubFieldI.H
SubList.H
Foam::SubField::operator/=
void operator/=(const scalar &s)
Divide each entry by value.
Definition: SubFieldI.H:215
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:53
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::SubField
SubField is a Field obtained as a section of another Field.
Definition: Field.H:64
Foam::SubField::operator*=
void operator*=(const scalar &s)
Multiply each entry by value.
Definition: SubFieldI.H:205
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:127
Foam::SubField::component
tmp< Field< cmptType > > component(const direction) const
Return a component field of the field.
Definition: SubFieldI.H:118
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SubField::operator=
void operator=(const SubField< Type > &)
Copy assign via UList operator. Takes linear time.
Definition: SubFieldI.H:143
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::SubField::operator-=
void operator-=(const Type &val)
Subtract value from each entry.
Definition: SubFieldI.H:195
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::UList< Type >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::SubField::operator+=
void operator+=(const Type &val)
Add value to each entry.
Definition: SubFieldI.H:185
Foam::SubField::SubField
SubField(const SubField< Type > &sfield)
Copy construct (shallow copy)
Definition: SubFieldI.H:33
Foam::SubField::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: SubField.H:71
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62