Loading...
Searching...
No Matches
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 Foam_SubField_H
41#define Foam_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 a null SubField (reference to a nullObject).
73 //- Behaves like an empty SubField.
74 static const SubField<Type>& null() noexcept
75 {
77 }
78
79
80 // Constructors
81
82 //- Default construct, zero-sized and nullptr
83 SubField() noexcept = default;
85 //- Copy construct (shallow copy)
86 inline SubField(const SubField<Type>& fld);
87
88 //- Copy construct from SubList
89 inline SubField(const SubList<Type>& list);
90
91 //- Construct from UList, the entire size
92 inline explicit SubField(const UList<Type>& list) noexcept;
93
94 //- Construct from UList with a given sub-list size, start at 0
95 inline SubField
96 (
97 const UList<Type>& list,
98 const label len
99 );
100
101 //- Construct from UList, sub-list size and start index
102 inline SubField
103 (
104 const UList<Type>& list,
105 const label len,
106 const label start
107 );
108
109 //- Construct from UList and a (start,size) range.
110 // The range is subsetted with the list size itself to ensure that the
111 // result always addresses a valid section of the list.
112 inline SubField
113 (
114 const UList<Type>& list,
115 const labelRange& range
116 );
117
118 //- Construct from UList and a (start,size) range,
119 //- but bypassing run-time range checking.
120 inline SubField
121 (
122 const labelRange& range,
123 const UList<Type>& list
124 );
125
126
127 // Member Functions
128
129 //- Return a component field of the field
130 inline tmp<Field<cmptType>> component(const direction) const;
131
132 //- Return the field transpose (only defined for second rank tensors)
133 tmp<Field<Type>> T() const;
134
135
136 // Member Operators
137
138 //- Allow cast to a const Field<Type>&
139 // \note Marked as "strictly" deprecated.
140 // Currently (2025-04) code still depends on this cast.
141 FOAM_DEPRECATED_STRICTER(2025-04, "dereference as SubField, not Field?")
142 operator const Foam::Field<Type>&() const
143 {
144 return *reinterpret_cast<const Field<Type>*>(this);
145 }
146
147 //- Copy assign via UList operator. Takes linear time.
148 inline void operator=(const SubField<Type>&);
149
150 //- Copy assign via UList operator. Takes linear time.
151 inline void operator=(const Field<Type>&);
152
153 //- Assign all entries to the given value
154 inline void operator=(const Type& val);
155
156 //- Assign all entries to zero
157 inline void operator=(Foam::zero);
158
159 //- Copy assign via UList operator. Takes linear time.
160 template<class Form, direction Ncmpts>
162
163 //- Add value to each entry
164 inline void operator+=(const Type& val);
166 //- Subtract value from each entry
167 inline void operator-=(const Type& val);
168
169 //- Multiply each entry by value
170 inline void operator*=(const scalar& s);
171
172 //- Divide each entry by value
173 inline void operator/=(const scalar& s);
174};
175
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179} // End namespace Foam
180
181// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182
183#include "SubFieldI.H"
184
185// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * //
186
187template<class Type>
189Foam::Field<Type>::slice(const label pos, label len)
190{
191 if (len < 0)
192 {
193 len = (this->size() - pos);
194 }
195 return SubField<Type>(*this, len, pos);
196}
197
198
199template<class Type>
201Foam::Field<Type>::slice(const label pos, label len) const
202{
203 if (len < 0)
204 {
205 len = (this->size() - pos);
206 }
207 return SubField<Type>(*this, len, pos);
208}
209
210
211template<class Type>
213Foam::Field<Type>::slice(const labelRange& range)
214{
215 return SubField<Type>(*this, range); // with range checking
216}
217
218
219template<class Type>
221Foam::Field<Type>::slice(const labelRange& range) const
222{
223 return SubField<Type>(*this, range); // with range checking
224}
225
226
227// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228
229#endif
231// ************************************************************************* //
scalar range
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
constexpr FieldBase() noexcept
Default construct.
Definition Field.H:156
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
SubField< Type > slice(const label pos, label len=-1)
Return SubField slice (non-const access) - no range checking.
Definition SubField.H:230
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition SubField.H:58
void operator*=(const scalar &s)
Multiply each entry by value.
Definition SubFieldI.H:184
void operator=(const SubField< Type > &)
Copy assign via UList operator. Takes linear time.
Definition SubFieldI.H:122
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors).
Definition SubFieldI.H:113
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:104
pTraits< Type >::cmptType cmptType
Component type.
Definition SubField.H:64
void operator-=(const Type &val)
Subtract value from each entry.
Definition SubFieldI.H:174
void operator+=(const Type &val)
Add value to each entry.
Definition SubFieldI.H:164
void operator/=(const scalar &s)
Divide each entry by value.
Definition SubFieldI.H:194
static const SubField< Type > & null() noexcept
Return a null SubField (reference to a nullObject). Behaves like an empty SubField.
Definition SubField.H:73
SubList() noexcept=default
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:89
void size(const label n)
Definition UList.H:118
Templated vector space.
Definition VectorSpace.H:75
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
A class for managing temporary objects.
Definition tmp.H:75
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
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)
const T & NullObjectRef() noexcept
Const reference (of type T) to the nullObject.
Definition nullObject.H:228
uint8_t direction
Definition direction.H:49
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
#define FOAM_DEPRECATED_STRICTER(since, replacement)
Definition stdFoam.H:56