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 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  //- Return the field transpose (only defined for second rank tensors)
153  tmp<FieldField<Field, Type>> T() const;
154 
155 
156  // Member Operators
157 
158  //- Const or non-const access to a field
159  using PtrList<Field<Type>>::operator[];
160 
161  //- Const access to a single field element via (fieldi, elemi)
162  inline const Type& operator[](const labelPair& index) const;
163 
164  //- Non-const access to a single field element via (fieldi, elemi)
165  inline Type& operator[](const labelPair& index);
166 
167  //- Copy assignment
168  void operator=(const FieldField<Field, Type>&);
169 
170  //- Move assignment
171  void operator=(FieldField<Field, Type>&&);
172 
173  //- Move or clone assignment
174  void operator=(const tmp<FieldField<Field, Type>>&);
175 
176  //- Assign uniform value
177  void operator=(const Type& val);
178 
179  //- Assign uniform zero
180  void operator=(const Foam::zero);
181 
182  void operator+=(const FieldField<Field, Type>&);
183  void operator+=(const tmp<FieldField<Field, Type>>&);
184 
185  void operator-=(const FieldField<Field, Type>&);
186  void operator-=(const tmp<FieldField<Field, Type>>&);
187 
188  void operator*=(const FieldField<Field, scalar>&);
189  void operator*=(const tmp<FieldField<Field, scalar>>&);
190 
191  void operator/=(const FieldField<Field, scalar>&);
192  void operator/=(const tmp<FieldField<Field, scalar>>&);
193 
194  void operator+=(const Type&);
195  void operator-=(const Type&);
196 
197  void operator*=(const scalar&);
198  void operator/=(const scalar&);
199 
200 
201  // IOstream operators
202 
203  friend Ostream& operator<< <Field, Type>
204  (
205  Ostream&,
206  const FieldField<Field, Type>&
207  );
208 
209  friend Ostream& operator<< <Field, Type>
210  (
211  Ostream&,
212  const tmp<FieldField<Field, Type>>&
213  );
214 };
215 
216 
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 
219 } // End namespace Foam
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 #include "FieldFieldFunctions.H"
224 
225 #ifdef NoRepository
226  #include "FieldField.C"
227 #endif
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #endif
232 
233 // ************************************************************************* //
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 traits class, which is primarily used for primitives.
Definition: pTraits.H:50
void normalise()
Normalise this field. See notes in Field.
Definition: FieldField.C:222
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:752
void negate()
Negate this field. See notes in Field.
Definition: FieldField.C:212
Generic templated field type.
Definition: Field.H:61
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:99
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:55
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
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:279
friend Ostream & operator(Ostream &, const FieldField< Field, Type > &)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
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.