vectorTensorTransformI.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 :
32  t_(Zero),
33  R_(sphericalTensor::I),
34  hasR_(false)
35 {}
36 
37 
39 (
40  const vector& t,
41  const tensor& R,
42  bool hasR
43 )
44 :
45  t_(t),
46  R_(R),
47  hasR_(hasR)
48 {}
49 
50 
52 :
53  t_(t),
54  R_(sphericalTensor::I),
55  hasR_(false)
56 {}
57 
58 
60 :
61  t_(Zero),
62  R_(R),
63  hasR_(true)
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 inline const Foam::vector& Foam::vectorTensorTransform::t() const
70 {
71  return t_;
72 }
73 
74 
75 inline const Foam::tensor& Foam::vectorTensorTransform::R() const
76 {
77  return R_;
78 }
79 
80 
81 inline bool Foam::vectorTensorTransform::hasR() const
82 {
83  return hasR_;
84 }
85 
86 
88 {
89  return t_;
90 }
91 
92 
94 {
95  // Assume that non-const access to R changes it from I, so set
96  // hasR to true
97 
98  hasR_ = true;
99 
100  return R_;
101 }
102 
103 
105 (
106  const vector& v
107 ) const
108 {
109  if (hasR_)
110  {
111  return t() + (R() & v);
112  }
113  else
114  {
115  return t() + v;
116  }
117 }
118 
119 
121 (
122  const pointField& pts
123 ) const
124 {
125  tmp<pointField> tfld;
126 
127  if (hasR_)
128  {
129  tfld = t() + (R() & pts);
130  }
131  else
132  {
133  tfld = t() + pts;
134  }
135  return tfld();
136 }
137 
138 
140 (
141  const vector& v
142 ) const
143 {
144  if (hasR_)
145  {
146  return (R().T() & (v - t()));
147  }
148  else
149  {
150  return v - t();
151  }
152 }
153 
154 
156 (
157  const pointField& pts
158 ) const
159 {
160  tmp<pointField> tfld;
161 
162  if (hasR_)
163  {
164  tfld = (R().T() & (pts - t()));
165  }
166  else
167  {
168  tfld = pts - t();
169  }
170  return tfld();
171 }
172 
173 
174 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
175 
176 inline void Foam::vectorTensorTransform::operator&=
177 (
178  const vectorTensorTransform& tr
179 )
180 {
181  t_ += tr.t_;
182  R_ = tr.R_ & R_;
184  // If either of the two objects has hasR_ as true, then inherit
185  // it, otherwise, these should both be I tensors.
186  hasR_ = tr.hasR_ || hasR_;
187 }
188 
191 {
192  t_ = t;
193 }
194 
197 {
198  t_ += t;
199 }
200 
203 {
204  t_ -= t;
205 }
206 
207 
209 {
210  hasR_ = true;
211 
212  R_ = R;
213 }
214 
215 
217 {
218  hasR_ = true;
220  R_ = R & R_;
221 }
222 
223 
224 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
225 
226 inline Foam::vectorTensorTransform Foam::inv(const vectorTensorTransform& tr)
227 {
228  return vectorTensorTransform(-tr.t(), tr.R().T(), tr.hasR());
229 }
230 
231 
232 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
233 
234 inline bool Foam::operator==
235 (
236  const vectorTensorTransform& tr1,
237  const vectorTensorTransform& tr2
238 )
239 {
240  return (tr1.t() == tr2.t() && tr1.R() == tr2.R());
241 }
242 
243 
244 inline bool Foam::operator!=
245 (
246  const vectorTensorTransform& tr1,
247  const vectorTensorTransform& tr2
248 )
249 {
250  return !operator==(tr1, tr2);
251 }
252 
253 
254 inline Foam::vectorTensorTransform Foam::operator+
255 (
256  const vectorTensorTransform& tr,
257  const vector& t
258 )
259 {
260  return vectorTensorTransform(tr.t() + t, tr.R(), tr.hasR());
261 }
262 
263 
264 inline Foam::vectorTensorTransform Foam::operator+
265 (
266  const vector& t,
267  const vectorTensorTransform& tr
268 )
269 {
270  return vectorTensorTransform(t + tr.t(), tr.R(), tr.hasR());
271 }
272 
273 
274 inline Foam::vectorTensorTransform Foam::operator-
275 (
276  const vectorTensorTransform& tr,
277  const vector& t
278 )
279 {
280  return vectorTensorTransform(tr.t() - t, tr.R(), tr.hasR());
281 }
282 
283 
284 inline Foam::vectorTensorTransform Foam::operator&
285 (
286  const vectorTensorTransform& tr1,
287  const vectorTensorTransform& tr2
288 )
289 {
290  return vectorTensorTransform
291  (
292  tr1.t() + tr2.t(),
293  tr1.R() & tr2.R(),
294  (tr1.hasR() || tr2.hasR())
295  );
296 }
297 
298 
299 // ************************************************************************* //
vectorTensorTransform & operator=(const vectorTensorTransform &)=default
Copy assignment.
Vector-tensor class used to perform translations and rotations in 3D space.
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
vector invTransformPosition(const vector &v) const
Inverse transform the given position.
Tensor< scalar > tensor
Definition: symmTensor.H:57
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
static const Identity< scalar > I
Definition: Identity.H:100
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Vector< scalar > vector
Definition: vector.H:57
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
dimensioned< Type > T() const
Return transpose.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define R(A, B, C, D, E, F, K, M)
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
vector transformPosition(const vector &v) const
Transform the given position.
Tensor of scalars, i.e. Tensor<scalar>.
void operator &=(const vectorTensorTransform &)
vectorTensorTransform()
Default construct - no translation, identity rotation.
const pointField & pts
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127