transformer.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::transformer
26 
27 Description
28  Vector-tensor class used to perform translations, rotations and scaling
29  operations in 3D space.
30 
31 SourceFiles
32  transformerI.H
33  transformer.C
34  transformerTemplates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef transformer_H
39 #define transformer_H
40 
41 #include "tensor.H"
42 #include "word.H"
43 #include "contiguous.H"
44 #include "pointField.H"
45 #include "transformField.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 class transformer;
55 Istream& operator>>(Istream& is, transformer&);
56 Ostream& operator<<(Ostream& os, const transformer& C);
57 
58 
59 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
60 
61 //- Return the inverse of the given transformer
62 inline transformer inv(const transformer& tr);
63 
64 
65 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
66 
67 inline bool operator==(const transformer& tr1, const transformer& tr2);
68 
69 inline bool operator!=(const transformer& tr1, const transformer& tr2);
70 
71 inline transformer operator+(const transformer& tr, const vector& t);
72 
73 inline transformer operator+(const vector& t, const transformer& tr);
74 
75 inline transformer operator-(const transformer& tr, const vector& t);
76 
77 inline transformer operator&(const transformer& tr1, const transformer& tr2);
78 
79 
80 /*---------------------------------------------------------------------------*\
81  Class transformer Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 class transformer
85 {
86  // Private data
87 
88  //- Translation vector
89  vector t_;
90 
91  //- True if the translation vector is non-zero
92  bool translates_;
93 
94  //- Transformation tensor
95  tensor T_;
96 
97  //- True if the transformation tensor has component vectors of
98  // differing magnitudes
99  bool scales_;
100 
101  //- True if the transformation tensor has off-diagonal terms
102  bool rotates_;
103 
104 
105  // Private constructors
106 
107  //- Construct given a translation vector and transformation tensor
108  inline transformer
109  (
110  const vector& t,
111  const bool translates,
112  const tensor& T,
113  const bool scales,
114  const bool rotates
115  );
116 
117 
118 public:
119 
120  // Static Data Members
122  static const char* const typeName;
124  static const transformer zero;
126  static const transformer I;
127 
128  //- Null transformer
129  static const transformer null;
130 
131 
132  // Static Member Functions
133 
134  //- Construct a pure translation transformer
135  inline static transformer translation(const vector& t);
136 
137  //- Construct a pure scaling transformer
138  inline static transformer scaling(const tensor& T);
139 
140  //- Construct a pure rotation transformer
141  inline static transformer rotation(const tensor& T);
142 
143 
144  // Constructors
145 
146  //- Construct null (i.e., no transformation)
147  inline transformer();
148 
149  //- Construct from Istream
151 
152 
153  // Member Functions
154 
155  // Access
156 
157  //- Return the translation vector
158  inline const vector& t() const;
159 
160  //- Return true if the transformer performs pure translation
161  // (i.e. the translation vector is non-zero and the transformation
162  // tensor is I)
163  inline bool translates() const;
164 
165  //- Return the transformation tensor
166  inline const tensor& T() const;
167 
168  //- Return the inverse transformation tensor
169  inline tensor invT() const;
170 
171  //- Return true if the transformer performs pure scaling
172  // (i.e. the transformation tensor is diagonal)
173  inline bool scales() const;
174 
175  //- Return true if the transformer performs pure rotation
176  // (i.e. the transformation tensor is orthogonal)
177  inline bool rotates() const;
178 
179  //- Return true if the transformer transforms a type
180  // (i.e. scales or rotates)
181  inline bool transforms() const;
182 
183  //- Return true if the transformer transforms the given type
184  // (i.e. scales or rotates)
185  template<typename Type>
186  inline bool transforms() const;
187 
188  //- Return true if the transformer transforms a point
189  // (i.e. translates or scales or rotates)
190  inline bool transformsPosition() const;
191 
192 
193  // Transform
194 
195  //- Transform the given position
196  inline vector transformPosition(const vector& v) const;
197 
198  //- Transform the given pointField
199  void transformPosition(pointField&, const pointField&) const;
200 
201  //- Transform the given pointField
203 
204  //- Inverse transform the given position
205  inline vector invTransformPosition(const vector& v) const;
206 
207  //- Inverse transform the given pointField
208  void invTransformPosition(pointField&, const pointField&) const;
209 
210  //- Inverse transform the given pointField
212 
213  //- Transform the given type
214  template<class Type>
215  Type transform(const Type&) const;
216 
217  //- Transform the given field
218  template<class Type>
219  void transform(Field<Type>&, const Field<Type>&) const;
220 
221  //- Transform the given field
222  template<class Type>
223  tmp<Field<Type>> transform(const Field<Type>&) const;
224 
225  //- Transform the given field
226  template<class Type>
227  tmp<Field<Type>> transform(const tmp<Field<Type>>&) const;
228 
229  //- Transform the given container
230  template<class Type, template<class> class Container>
231  void transformList(Container<Type>&) const;
232 
233  //- Inverse transform the given type
234  template<class Type>
235  Type invTransform(const Type&) const;
236 
237  //- Inverse transform the given field
238  template<class Type>
239  void invTransform(Field<Type>&, const Field<Type>&) const;
240 
241  //- Inverse transform the given field
242  template<class Type>
244 
245  //- Inverse transform the given field
246  template<class Type>
248 
249  //- Inverse transform the given container
250  template<class Type, template<class> class Container>
251  void invTransformList(Container<Type>&) const;
252 
253 
254  // Global Functions
255 
256  //- Return the inverse of the given transformer
257  friend inline transformer inv(const transformer& tr);
258 
259 
260  // Global Operators
261 
262  friend inline bool operator==
263  (
264  const transformer& tr1,
265  const transformer& tr2
266  );
267 
268  friend inline bool operator!=
269  (
270  const transformer& tr1,
271  const transformer& tr2
272  );
273 
274  friend inline transformer operator&
275  (
276  const transformer& tr1,
277  const transformer& tr2
278  );
279 
280 
281  // IOstream Operators
282 
283  friend Istream& operator>>(Istream& is, transformer&);
284 
285  friend Ostream& operator<<(Ostream& os, const transformer&);
286 };
287 
288 
289 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
290 
291 //- Return a string representation of a transformer
292 word name(const transformer&);
293 
294 //- Data associated with transformer type are contiguous
295 template<>
296 inline bool contiguous<transformer>() {return true;}
297 
298 // Template specialisations
299 
300 template<>
302 
303 template<>
305 
306 template<>
308 
309 template<>
311 
312 template<>
314 const;
315 
316 template<>
318 const;
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 } // End namespace Foam
324 
325 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 
327 #include "transformerI.H"
328 
329 #ifdef NoRepository
330  #include "transformerTemplates.C"
331 #endif
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #endif
336 
337 // ************************************************************************* //
void invTransformList(Container< Type > &) const
Inverse transform the given container.
static transformer translation(const vector &t)
Construct a pure translation transformer.
Definition: transformerI.H:31
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
static transformer rotation(const tensor &T)
Construct a pure rotation transformer.
Definition: transformerI.H:43
bool rotates() const
Return true if the transformer performs pure rotation.
Definition: transformerI.H:127
bool transforms() const
Return true if the transformer transforms a type.
Definition: transformerI.H:133
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const transformer null
Null transformer.
Definition: transformer.H:128
Template function to specify if the data of a type are contiguous.
static transformer scaling(const tensor &T)
Construct a pure scaling transformer.
Definition: transformerI.H:37
bool translates() const
Return true if the transformer performs pure translation.
Definition: transformerI.H:88
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
friend Ostream & operator<<(Ostream &os, const transformer &)
bool contiguous< transformer >()
Data associated with transformer type are contiguous.
Definition: transformer.H:295
const vector & t() const
Return the translation vector.
Definition: transformerI.H:82
tmp< GeometricField< Type, fvPatchField, volMesh > > operator &(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
void transformList(Container< Type > &) const
Transform the given container.
Spatial transformation functions for primitive fields.
vector invTransformPosition(const vector &v) const
Inverse transform the given position.
Definition: transformerI.H:177
friend transformer inv(const transformer &tr)
Return the inverse of the given transformer.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
tensor invT() const
Return the inverse transformation tensor.
Definition: transformerI.H:100
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
static const transformer I
Definition: transformer.H:125
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const tensor & T() const
Return the transformation tensor.
Definition: transformerI.H:94
static const char *const typeName
Definition: transformer.H:121
transformer()
Construct null (i.e., no transformation)
Definition: transformerI.H:70
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
bool transformsPosition() const
Return true if the transformer transforms a point.
Definition: transformerI.H:146
bool scales() const
Return true if the transformer performs pure scaling.
Definition: transformerI.H:121
Ostream & operator<<(Ostream &, const ensightPart &)
static const transformer zero
Definition: transformer.H:123
friend Istream & operator>>(Istream &is, transformer &)
Type transform(const Type &) const
Transform the given type.
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
A class for managing temporary objects.
Definition: PtrList.H:53
Type invTransform(const Type &) const
Inverse transform the given type.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1205
Namespace for OpenFOAM.