transformerI.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-2020 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 \*---------------------------------------------------------------------------*/
25 
26 #include "transformer.H"
27 #include "diagTensor.H"
28 
29 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
30 
32 {
33  return transformer(t, true, tensor::I, false, false);
34 }
35 
36 
38 {
39  return transformer(vector::zero, false, T, true, false);
40 }
41 
42 
44 {
45  return transformer(vector::zero, false, T, false, true);
46 }
47 
48 
49 // * * * * * * * * * * * * * * Private Constructors * * * * * * * * * * * * //
50 
52 (
53  const vector& t,
54  const bool translates,
55  const tensor& T,
56  const bool scales,
57  const bool rotates
58 )
59 :
60  t_(t),
61  translates_(translates),
62  T_(T),
63  scales_(scales),
64  rotates_(rotates)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 :
72  t_(Zero),
73  translates_(false),
74  T_(tensor::I),
75  scales_(false),
76  rotates_(false)
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 inline const Foam::vector& Foam::transformer::t() const
83 {
84  return t_;
85 }
86 
87 
88 inline bool Foam::transformer::translates() const
89 {
90  return translates_ && !transforms();
91 }
92 
93 
94 inline const Foam::tensor& Foam::transformer::T() const
95 {
96  return T_;
97 }
98 
99 
101 {
102  if (scales_ && rotates_)
103  {
104  return inv(T());
105  }
106  else if (scales_)
107  {
108  return inv(diag(T()));
109  }
110  else if (rotates_)
111  {
112  return T().T();
113  }
114  else
115  {
116  return tensor::I;
117  }
118 }
119 
120 
121 inline bool Foam::transformer::scales() const
122 {
123  return scales_ && !rotates_;
124 }
125 
126 
127 inline bool Foam::transformer::rotates() const
128 {
129  return !scales_ && rotates_;
130 }
131 
132 
133 inline bool Foam::transformer::transforms() const
134 {
135  return scales_ || rotates_;
136 }
137 
138 
139 template<typename Type>
140 inline bool Foam::transformer::transforms() const
141 {
142  return pTraits<Type>::rank != 0 && transforms();
143 }
144 
145 
147 {
148  return translates_ || transforms();
149 }
150 
151 
153 (
154  const vector& p
155 ) const
156 {
157  if (translates_ && !transforms())
158  {
159  return p + t();
160  }
161  else if (!translates_ && transforms())
162  {
163  return T() & p;
164  }
165  else if (translates_ && transforms())
166  {
167  return (T() & p) + t();
168  }
169  else
170  {
171  return p;
172  }
173 }
174 
175 
177 (
178  const vector& p
179 ) const
180 {
181  if (translates_ && !transforms())
182  {
183  return p - t();
184  }
185  else if (!translates_ && transforms())
186  {
187  return invT() & p;
188  }
189  else if (translates_ && transforms())
190  {
191  return invT() & (p - t());
192  }
193  else
194  {
195  return p;
196  }
197 }
198 
199 
200 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
201 
203 {
204  return transformer
205  (
206  tr.invT() & (-tr.t()),
207  tr.translates_,
208  tr.invT(),
209  tr.scales_,
210  tr.rotates_
211  );
212 }
213 
214 
215 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
216 
217 inline bool Foam::operator==(const transformer& tr1, const transformer& tr2)
218 {
219  return (tr1.t() == tr2.t() && tr1.T() == tr2.T());
220 }
221 
222 
223 inline bool Foam::operator!=(const transformer& tr1, const transformer& tr2)
224 {
225  return !operator==(tr1, tr2);
226 }
227 
228 
229 inline Foam::transformer Foam::operator&
230 (
231  const transformer& tr1,
232  const transformer& tr2
233 )
234 {
235  return transformer
236  (
237  (tr1.T() & tr2.t()) + tr1.t(),
238  tr1.translates_ || tr2.translates_,
239  tr1.T() & tr2.T(),
240  tr1.scales_ || tr2.scales_,
241  tr1.rotates_ || tr2.rotates_
242  );
243 }
244 
245 
246 // ************************************************************************* //
static transformer translation(const vector &t)
Construct a pure translation transformer.
Definition: transformerI.H:31
Vector-tensor class used to perform translations and rotations 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)
Tensor< Cmpt > T() const
Return transpose.
Definition: TensorI.H:331
Traits class for primitives.
Definition: pTraits.H:50
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
const vector & t() const
Return the translation vector.
Definition: transformerI.H:82
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
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 > &)
tensor invT() const
Return the inverse transformation tensor.
Definition: transformerI.H:100
static const zero Zero
Definition: zero.H:97
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
static const transformer I
Definition: transformer.H:125
const tensor & T() const
Return the transformation tensor.
Definition: transformerI.H:94
static const Tensor I
Definition: Tensor.H:83
transformer()
Construct null (i.e., no transformation)
Definition: transformerI.H:70
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
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
volScalarField & p
bool operator!=(const particle &, const particle &)
Definition: particle.C:1204
friend bool operator==(const transformer &tr1, const transformer &tr2)