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-2023 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
121 
122  static const char* const typeName;
123 
124  static const transformer zero;
125  static const transformer I;
126 
127  //- Null transformer
128  static const transformer null;
129 
130 
131  // Static Member Functions
132 
133  //- Construct a pure translation transformer
134  inline static transformer translation(const vector& t);
135 
136  //- Construct a pure scaling transformer
137  inline static transformer scaling(const tensor& T);
138 
139  //- Construct a pure rotation transformer
140  inline static transformer rotation(const tensor& T);
141 
142 
143  // Constructors
144 
145  //- Construct null (i.e., no transformation)
146  inline transformer();
147 
148  //- Construct from Istream
150 
151 
152  // Member Functions
153 
154  // Access
155 
156  //- Return the translation vector
157  inline const vector& t() const;
158 
159  //- Return true if the transformer performs pure translation
160  // (i.e. the translation vector is non-zero and the transformation
161  // tensor is I)
162  inline bool translates() const;
163 
164  //- Return the transformation tensor
165  inline const tensor& T() const;
166 
167  //- Return the inverse transformation tensor
168  inline tensor invT() const;
169 
170  //- Return true if the transformer performs pure scaling
171  // (i.e. the transformation tensor is diagonal)
172  inline bool scales() const;
173 
174  //- Return true if the transformer performs pure rotation
175  // (i.e. the transformation tensor is orthogonal)
176  inline bool rotates() const;
177 
178  //- Return true if the transformer transforms a type
179  // (i.e. scales or rotates)
180  inline bool transforms() const;
181 
182  //- Return true if the transformer transforms the given type
183  // (i.e. scales or rotates)
184  template<typename Type>
185  inline bool transforms() const;
186 
187  //- Return true if the transformer transforms a point
188  // (i.e. translates or scales or rotates)
189  inline bool transformsPosition() const;
190 
191 
192  // Transform
193 
194  //- Transform the given position
195  inline vector transformPosition(const vector& v) const;
196 
197  //- Transform the given pointField
198  void transformPosition(pointField&, const pointField&) const;
199 
200  //- Transform the given pointField
202 
203  //- Inverse transform the given position
204  inline vector invTransformPosition(const vector& v) const;
205 
206  //- Inverse transform the given pointField
207  void invTransformPosition(pointField&, const pointField&) const;
208 
209  //- Inverse transform the given pointField
211 
212  //- Transform the given type
213  template<class Type>
214  Type transform(const Type&) const;
215 
216  //- Transform the given field
217  template<class Type>
218  void transform(Field<Type>&, const Field<Type>&) const;
219 
220  //- Transform the given field
221  template<class Type>
222  tmp<Field<Type>> transform(const Field<Type>&) const;
223 
224  //- Transform the given field
225  template<class Type>
226  tmp<Field<Type>> transform(const tmp<Field<Type>>&) const;
227 
228  //- Transform the given container
229  template<class Type, template<class> class Container>
230  void transformList(Container<Type>&) const;
231 
232  //- Inverse transform the given type
233  template<class Type>
234  Type invTransform(const Type&) const;
235 
236  //- Inverse transform the given field
237  template<class Type>
238  void invTransform(Field<Type>&, const Field<Type>&) const;
239 
240  //- Inverse transform the given field
241  template<class Type>
243 
244  //- Inverse transform the given field
245  template<class Type>
247 
248  //- Inverse transform the given container
249  template<class Type, template<class> class Container>
250  void invTransformList(Container<Type>&) const;
251 
252 
253  // Global Functions
254 
255  //- Return the inverse of the given transformer
256  friend inline transformer inv(const transformer& tr);
257 
258 
259  // Global Operators
260 
261  friend inline bool operator==
262  (
263  const transformer& tr1,
264  const transformer& tr2
265  );
266 
267  friend inline bool operator!=
268  (
269  const transformer& tr1,
270  const transformer& tr2
271  );
272 
273  friend inline transformer operator&
274  (
275  const transformer& tr1,
276  const transformer& tr2
277  );
278 
279 
280  // IOstream Operators
281 
282  friend Istream& operator>>(Istream& is, transformer&);
283 
284  friend Ostream& operator<<(Ostream& os, const transformer&);
285 };
286 
287 
288 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
289 
290 //- Return a string representation of a transformer
291 word name(const transformer&);
292 
293 //- Data associated with transformer type are contiguous
294 template<>
295 inline bool contiguous<transformer>() {return true;}
296 
297 // Template specialisations
298 
299 template<>
300 tmp<Field<bool>> transformer::transform(const Field<bool>&) const;
301 
302 template<>
303 tmp<Field<bool>> transformer::transform(const tmp<Field<bool>>&) const;
304 
305 template<>
306 tmp<Field<label>> transformer::transform(const Field<label>&) const;
307 
308 template<>
309 tmp<Field<label>> transformer::transform(const tmp<Field<label>>&) const;
310 
311 template<>
312 tmp<Field<scalar>> transformer::transform(const Field<scalar>&)
313 const;
314 
315 template<>
316 tmp<Field<scalar>> transformer::transform(const tmp<Field<scalar>>&)
317 const;
318 
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 } // End namespace Foam
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 #include "transformerI.H"
327 
328 #ifdef NoRepository
329  #include "transformerTemplates.C"
330 #endif
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 #endif
335 
336 // ************************************************************************* //
static const Foam::dimensionedScalar C("C", Foam::dimTemperature, 234.5)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for managing temporary objects.
Definition: tmp.H:55
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
friend Ostream & operator<<(Ostream &os, const transformer &)
tensor invT() const
Return the inverse transformation tensor.
Definition: transformerI.H:100
bool scales() const
Return true if the transformer performs pure scaling.
Definition: transformerI.H:121
static const transformer I
Definition: transformer.H:124
static transformer rotation(const tensor &T)
Construct a pure rotation transformer.
Definition: transformerI.H:43
transformer()
Construct null (i.e., no transformation)
Definition: transformerI.H:70
bool translates() const
Return true if the transformer performs pure translation.
Definition: transformerI.H:88
static transformer translation(const vector &t)
Construct a pure translation transformer.
Definition: transformerI.H:31
bool transformsPosition() const
Return true if the transformer transforms a point.
Definition: transformerI.H:146
void transformList(Container< Type > &) const
Transform the given container.
void invTransformList(Container< Type > &) const
Inverse transform the given container.
static transformer scaling(const tensor &T)
Construct a pure scaling transformer.
Definition: transformerI.H:37
friend Istream & operator>>(Istream &is, transformer &)
static const transformer zero
Definition: transformer.H:123
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.
Type invTransform(const Type &) const
Inverse transform the given type.
const vector & t() const
Return the translation vector.
Definition: transformerI.H:82
bool transforms() const
Return true if the transformer transforms a type.
Definition: transformerI.H:133
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
const tensor & T() const
Return the transformation tensor.
Definition: transformerI.H:94
Type transform(const Type &) const
Transform the given type.
bool rotates() const
Return true if the transformer performs pure rotation.
Definition: transformerI.H:127
static const char *const typeName
Definition: transformer.H:121
A class for handling words, derived from string.
Definition: word.H:62
Template function to specify if the data of a type are contiguous.
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1210
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Istream & operator>>(Istream &, pistonPointEdgeData &)
tmp< VolField< Type > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
bool contiguous< transformer >()
Data associated with transformer type are contiguous.
Definition: transformer.H:294
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
Spatial transformation functions for primitive fields.