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-2023 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  //- Construct null
92  // Used for temporary fields which are initialised after construction
93  constexpr FieldField() noexcept;
94 
95  //- Construct given size
96  // Used for temporary fields which are initialised after construction
97  explicit FieldField(const label size);
98 
99  //- Clone construct with new type
100  FieldField(const word& type, const FieldField<Field, Type>& ff);
101 
102  //- Copy construct, cloning each element
103  FieldField(const FieldField<Field, Type>& ff);
104 
105  //- Move construct
106  FieldField(FieldField<Field, Type>&& ff);
107 
108  //- Construct as copy or re-use as specified.
109  FieldField(FieldField<Field, Type>& ff, bool reuse);
110 
111  //- Copy construct from PtrList
112  FieldField(const PtrList<Field<Type>>& list);
113 
114  //- Move construct from PtrList
115  FieldField(PtrList<Field<Type>>&& list);
116 
117  //- Move/copy construct from tmp<FieldField>
118  FieldField(const tmp<FieldField<Field, Type>>& tf);
119 
120  //- Construct from Istream
121  FieldField(Istream& is);
122 
123  //- Clone
124  tmp<FieldField<Field, Type>> clone() const;
125 
126  //- Return a pointer to a new calculatedFvPatchFieldField created on
127  // freestore without setting patchField values
128  template<class Type2>
129  static tmp<FieldField<Field, Type>> NewCalculatedType
130  (
131  const FieldField<Field, Type2>& ff
132  );
133 
134 
135  // Member Functions
136 
137  //- Negate this field. See notes in Field
138  void negate();
139 
140  //- Normalise this field. See notes in Field
141  void normalise();
142 
143  //- Return a component field of the field
145 
146  //- Replace a component field of the field
147  void replace(const direction, const FieldField<Field, cmptType>&);
148 
149  //- Replace a component field of the field
150  void replace(const direction, const cmptType&);
151 
152  //- Impose lower (floor) clamp on the field values (in-place)
153  void clamp_min(const Type& lower);
154 
155  //- Impose upper (ceiling) clamp on the field values (in-place)
156  void clamp_max(const Type& upper);
157 
158  //- Clamp field values (in-place) to the specified range.
159  // Does not check if range is valid or not.
160  void clamp_range(const Type& lower, const Type& upper);
161 
162  //- Clamp field values (in-place) to the specified range.
163  // Does not check if range is valid or not.
164  void clamp_range(const MinMax<Type>& range);
165 
166  //- Return the field transpose (only defined for second rank tensors)
167  tmp<FieldField<Field, Type>> T() const;
168 
169 
170  // Member Operators
171 
172  //- Const or non-const access to a field
173  using PtrList<Field<Type>>::operator[];
174 
175  //- Const access to a single field element via (fieldi, elemi)
176  inline const Type& operator[](const labelPair& index) const;
177 
178  //- Non-const access to a single field element via (fieldi, elemi)
179  inline Type& operator[](const labelPair& index);
180 
181  //- Copy assignment
182  void operator=(const FieldField<Field, Type>&);
183 
184  //- Move assignment
185  void operator=(FieldField<Field, Type>&&);
186 
187  //- Move or clone assignment
188  void operator=(const tmp<FieldField<Field, Type>>&);
189 
190  //- Assign uniform value
191  void operator=(const Type& val);
192 
193  //- Assign uniform zero
194  void operator=(const Foam::zero);
195 
196  void operator+=(const FieldField<Field, Type>&);
197  void operator+=(const tmp<FieldField<Field, Type>>&);
198 
199  void operator-=(const FieldField<Field, Type>&);
200  void operator-=(const tmp<FieldField<Field, Type>>&);
201 
202  void operator*=(const FieldField<Field, scalar>&);
203  void operator*=(const tmp<FieldField<Field, scalar>>&);
204 
205  void operator/=(const FieldField<Field, scalar>&);
206  void operator/=(const tmp<FieldField<Field, scalar>>&);
207 
208  void operator+=(const Type&);
209  void operator-=(const Type&);
210 
211  void operator*=(const scalar&);
212  void operator/=(const scalar&);
213 
214 
215  // IOstream operators
216 
217  friend Ostream& operator<< <Field, Type>
218  (
219  Ostream&,
220  const FieldField<Field, Type>&
221  );
222 
223  friend Ostream& operator<< <Field, Type>
224  (
225  Ostream&,
226  const tmp<FieldField<Field, Type>>&
227  );
228 };
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #include "FieldFieldFunctions.H"
238 
239 #ifdef NoRepository
240  #include "FieldField.C"
241 #endif
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 #endif
246 
247 // ************************************************************************* //
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:306
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
Definition: stringOps.C:1187
void normalise()
Normalise this field. See notes in Field.
Definition: FieldField.C:222
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:799
void negate()
Negate this field. See notes in Field.
Definition: FieldField.C:212
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
static tmp< FieldField< Field, Type > > NewCalculatedType(const FieldField< Field, Type2 > &ff)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: FieldField.C:191
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
tmp< FieldField< Field, cmptType > > component(const direction) const
Return a component field of the field.
Definition: FieldField.C:234
void replace(const direction, const FieldField< Field, cmptType > &)
Replace a component field of the field.
Definition: FieldField.C:252
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
string lower(const std::string &s)
Return string copy transformed with std::tolower on each character.
Definition: stringOps.C:1171
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
constexpr FieldField() noexcept
Construct null.
Definition: FieldField.C:101
tmp< FieldField< Field, Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: FieldField.C:336
friend Ostream & operator(Ostream &, const FieldField< Field, Type > &)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void clamp_max(const Type &upper)
Impose upper (ceiling) clamp on the field values (in-place)
Definition: FieldField.C:293
A non-counting (dummy) refCount.
Definition: refCount.H:55
tmp< FieldField< Field, Type > > clone() const
Clone.
Definition: FieldField.C:182
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:280