FieldField.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) 2022-2026 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::FieldField
29 
30 Description
31  A field of fields is a PtrList of fields with reference counting.
32 
33 SourceFiles
34  FieldField.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_FieldField_H
39 #define Foam_FieldField_H
40 
41 #include "tmp.H"
42 #include "Pair.H"
43 #include "PtrList.H"
44 #include "scalar.H"
45 #include "direction.H"
46 #include "VectorSpace.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 
55 template<template<class> class Field, class Type>
56 class FieldField;
57 
58 template<template<class> class Field, class Type>
59 Ostream& operator<<
60 (
61  Ostream&,
63 );
64 
65 template<template<class> class Field, class Type>
66 Ostream& operator<<
67 (
68  Ostream&,
70 );
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class FieldField Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<template<class> class Field, class Type>
78 class FieldField
79 :
80  public refCount,
81  public PtrList<Field<Type>>
82 {
83 public:
84 
85  //- Component type
86  typedef typename pTraits<Type>::cmptType cmptType;
87 
88 
89  // Constructors
90 
91  //- Default construct.
92  //- Used for temporary fields that are initialised after construction
93  constexpr FieldField() noexcept;
94 
95  //- Construct given size.
96  //- Used for temporary fields that are initialised after construction
97  explicit FieldField(label len);
98 
99  //- Clone construct with new type
100  FieldField(const word& type, const FieldField& ff);
101 
102  //- Copy construct, cloning each element
103  FieldField(const FieldField& ff);
104 
105  //- Copy construct, cloning each element with arguments
106  template<class CloneArg, class... CloneArgs>
107  FieldField(const FieldField&, const CloneArg&, CloneArgs&&...);
108 
109  //- Move construct
111 
112  //- Construct as copy or re-use as specified.
113  FieldField(FieldField& ff, bool reuse);
114 
115  //- Copy construct from PtrList
116  FieldField(const PtrList<Field<Type>>& list);
117 
118  //- Move construct from PtrList
119  FieldField(PtrList<Field<Type>>&& list);
120 
121  //- Move/copy construct from tmp<FieldField>
122  FieldField(const tmp<FieldField<Field, Type>>& tf);
123 
124  //- Construct from Istream
125  FieldField(Istream& is);
126 
127  //- Clone, forwarding optional arguments to clone of each element
128  template<class... Args>
129  tmp<FieldField<Field, Type>> clone(Args&&... args) const;
130 
131  //- Return a pointer to a new calculated patchField created on
132  //- freestore without setting patchField values
133  template<class Type2>
134  static tmp<FieldField<Field, Type>> NewCalculatedType
135  (
136  const FieldField<Field, Type2>& ff
137  );
138 
139 
140  // Member Functions
141 
142  //- Negate this field. See notes in Field
143  void negate();
144 
145  //- Normalise this field. See notes in Field
146  void normalise();
147 
148  //- Return a component field of the field
150 
151  //- Replace a component field of the field
152  void replace(const direction, const FieldField<Field, cmptType>&);
153 
154  //- Replace a component field of the field
155  void replace(const direction, const cmptType&);
156 
157  //- Impose lower (floor) clamp on the field values (in-place)
158  void clamp_min(const Type& lower);
159 
160  //- Impose lower (floor) clamp on the field values (in-place)
161  void clamp_min(const FieldField<Field, Type>& lower);
162 
163  //- Impose upper (ceiling) clamp on the field values (in-place)
164  void clamp_max(const Type& upper);
165 
166  //- Impose upper (ceiling) clamp on the field values (in-place)
167  void clamp_max(const FieldField<Field, Type>& upper);
168 
169  //- Clamp field values (in-place) to the specified range.
170  // Does not check if range is valid or not.
171  void clamp_range(const Type& lower, const Type& upper);
172 
173  //- Clamp field values (in-place) to the specified range.
174  // Does not check if range is valid or not.
175  void clamp_range(const MinMax<Type>& range);
176 
177  //- Return the field transpose (only defined for second rank tensors)
178  tmp<FieldField<Field, Type>> T() const;
179 
180 
181  // Member Operators
182 
183  //- Const or non-const access to a field
184  using PtrList<Field<Type>>::operator[];
185 
186  //- Const access to a single field element via (fieldi, elemi)
187  inline const Type& operator[](const labelPair& index) const;
188 
189  //- Non-const access to a single field element via (fieldi, elemi)
190  inline Type& operator[](const labelPair& index);
191 
192  //- Copy assignment
193  void operator=(const FieldField<Field, Type>&);
194 
195  //- Move assignment
196  void operator=(FieldField<Field, Type>&&);
197 
198  //- Move or clone assignment
199  void operator=(const tmp<FieldField<Field, Type>>&);
200 
201  //- Assign uniform value
202  void operator=(const Type& val);
203 
204  //- Assign uniform zero
205  void operator=(Foam::zero);
206 
207  void operator+=(const FieldField<Field, Type>&);
208  void operator+=(const tmp<FieldField<Field, Type>>&);
209 
210  void operator-=(const FieldField<Field, Type>&);
211  void operator-=(const tmp<FieldField<Field, Type>>&);
212 
213  void operator*=(const FieldField<Field, scalar>&);
214  void operator*=(const tmp<FieldField<Field, scalar>>&);
215 
216  void operator/=(const FieldField<Field, scalar>&);
217  void operator/=(const tmp<FieldField<Field, scalar>>&);
218 
219  void operator+=(const Type&);
220  void operator-=(const Type&);
221 
222  void operator*=(const scalar&);
223  void operator/=(const scalar&);
224 
225 
226  // IOstream operators
227 
228  friend Ostream& operator<< <Field, Type>
229  (
230  Ostream&,
231  const FieldField<Field, Type>&
232  );
233 
234  friend Ostream& operator<< <Field, Type>
235  (
236  Ostream&,
237  const tmp<FieldField<Field, Type>>&
238  );
239 };
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 } // End namespace Foam
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #include "FieldFieldFunctions.H"
249 
250 #ifdef NoRepository
251  #include "FieldField.C"
252 #endif
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #endif
257 
258 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
Reference counter for various OpenFOAM components.
Definition: refCount.H:44
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A min/max value pair with additional methods. In addition to conveniently storing values...
Definition: HashSet.H:72
void clamp_range(const Type &lower, const Type &upper)
Clamp field values (in-place) to the specified range.
Definition: FieldField.C:356
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:63
void normalise()
Normalise this field. See notes in Field.
Definition: FieldField.C:242
scalar range
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:805
void negate()
Negate this field. See notes in Field.
Definition: FieldField.C:232
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition: Field.H:69
A class for handling words, derived from Foam::string.
Definition: word.H:63
tmp< FieldField< Field, Type > > clone(Args &&... args) const
Clone, forwarding optional arguments to clone of each element.
Definition: FieldField.C:197
static tmp< FieldField< Field, Type > > NewCalculatedType(const FieldField< Field, Type2 > &ff)
Return a pointer to a new calculated patchField created on freestore without setting patchField value...
Definition: FieldField.C:211
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:265
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
tmp< FieldField< Field, cmptType > > component(const direction) const
Return a component field of the field.
Definition: FieldField.C:254
void replace(const direction, const FieldField< Field, cmptType > &)
Replace a component field of the field.
Definition: FieldField.C:272
Direction is an 8-bit unsigned integer type used to represent Cartesian directions, components etc.
pTraits< Type >::cmptType cmptType
Component type.
Definition: FieldField.H:83
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: PtrList.H:56
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
constexpr FieldField() noexcept
Default construct. Used for temporary fields that are initialised after construction.
Definition: FieldField.C:101
tmp< FieldField< Field, Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: FieldField.C:386
friend Ostream & operator(Ostream &, const FieldField< Field, Type > &)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Foam::argList args(argc, argv)
void clamp_max(const Type &upper)
Impose upper (ceiling) clamp on the field values (in-place)
Definition: FieldField.C:313
A non-counting (dummy) refCount.
Definition: refCount.H:55
const FieldField< fvPatchField, Type > & ff(const FieldField< fvPatchField, Type > &bf)
Namespace for OpenFOAM.
void clamp_min(const Type &lower)
Impose lower (floor) clamp on the field values (in-place)
Definition: FieldField.C:300