transform.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 | Copyright (C) 2011-2015 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 InNamespace
25  Foam
26 
27 Description
28  3D tensor transformation operations.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef transform_H
33 #define transform_H
34 
35 #include "tensor.H"
36 #include "mathematicalConstants.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
46 (
47  const vector& n1,
48  const vector& n2
49 )
50 {
51  const scalar s = n1 & n2;
52  const vector n3 = n1 ^ n2;
53  const scalar magSqrN3 = magSqr(n3);
54 
55  // n1 and n2 define a plane n3
56  if (magSqrN3 > SMALL)
57  {
58  // Return rotational transformation tensor in the n3-plane
59  return
60  s*I
61  + (1 - s)*sqr(n3)/magSqrN3
62  + (n2*n1 - n1*n2);
63  }
64  // n1 and n2 are contradirectional
65  else if (s < 0)
66  {
67  // Return mirror transformation tensor
68  return I + 2*n1*n2;
69  }
70  // n1 and n2 are codirectional
71  else
72  {
73  // Return null transformation tensor
74  return I;
75  }
76 }
77 
78 
79 inline label transform(const tensor&, const bool i)
80 {
81  return i;
82 }
83 
84 
85 inline label transform(const tensor&, const label i)
86 {
87  return i;
88 }
89 
90 
91 inline scalar transform(const tensor&, const scalar s)
92 {
93  return s;
94 }
95 
96 
97 template<class Cmpt>
98 inline Vector<Cmpt> transform(const tensor& tt, const Vector<Cmpt>& v)
99 {
100  return tt & v;
101 }
102 
103 
104 template<class Cmpt>
105 inline Tensor<Cmpt> transform(const tensor& tt, const Tensor<Cmpt>& t)
106 {
107  return Tensor<Cmpt>
108  (
109  (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.xx()
110  + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.xy()
111  + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.xz(),
112 
113  (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.yx()
114  + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.yy()
115  + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.yz(),
116 
117  (tt.xx()*t.xx() + tt.xy()*t.yx() + tt.xz()*t.zx())*tt.zx()
118  + (tt.xx()*t.xy() + tt.xy()*t.yy() + tt.xz()*t.zy())*tt.zy()
119  + (tt.xx()*t.xz() + tt.xy()*t.yz() + tt.xz()*t.zz())*tt.zz(),
120 
121  (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.xx()
122  + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.xy()
123  + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.xz(),
124 
125  (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.yx()
126  + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.yy()
127  + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.yz(),
128 
129  (tt.yx()*t.xx() + tt.yy()*t.yx() + tt.yz()*t.zx())*tt.zx()
130  + (tt.yx()*t.xy() + tt.yy()*t.yy() + tt.yz()*t.zy())*tt.zy()
131  + (tt.yx()*t.xz() + tt.yy()*t.yz() + tt.yz()*t.zz())*tt.zz(),
132 
133  (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.xx()
134  + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.xy()
135  + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.xz(),
136 
137  (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.yx()
138  + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.yy()
139  + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.yz(),
140 
141  (tt.zx()*t.xx() + tt.zy()*t.yx() + tt.zz()*t.zx())*tt.zx()
142  + (tt.zx()*t.xy() + tt.zy()*t.yy() + tt.zz()*t.zy())*tt.zy()
143  + (tt.zx()*t.xz() + tt.zy()*t.yz() + tt.zz()*t.zz())*tt.zz()
144  );
145 }
146 
147 
148 template<class Cmpt>
149 inline SphericalTensor<Cmpt> transform
150 (
151  const tensor& tt,
152  const SphericalTensor<Cmpt>& st
153 )
154 {
155  return st;
156 }
157 
158 
159 template<class Cmpt>
160 inline SymmTensor<Cmpt> transform(const tensor& tt, const SymmTensor<Cmpt>& st)
161 {
162  return SymmTensor<Cmpt>
163  (
164  (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.xx()
165  + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.xy()
166  + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.xz(),
167 
168  (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.yx()
169  + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.yy()
170  + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.yz(),
171 
172  (tt.xx()*st.xx() + tt.xy()*st.xy() + tt.xz()*st.xz())*tt.zx()
173  + (tt.xx()*st.xy() + tt.xy()*st.yy() + tt.xz()*st.yz())*tt.zy()
174  + (tt.xx()*st.xz() + tt.xy()*st.yz() + tt.xz()*st.zz())*tt.zz(),
175 
176  (tt.yx()*st.xx() + tt.yy()*st.xy() + tt.yz()*st.xz())*tt.yx()
177  + (tt.yx()*st.xy() + tt.yy()*st.yy() + tt.yz()*st.yz())*tt.yy()
178  + (tt.yx()*st.xz() + tt.yy()*st.yz() + tt.yz()*st.zz())*tt.yz(),
179 
180  (tt.yx()*st.xx() + tt.yy()*st.xy() + tt.yz()*st.xz())*tt.zx()
181  + (tt.yx()*st.xy() + tt.yy()*st.yy() + tt.yz()*st.yz())*tt.zy()
182  + (tt.yx()*st.xz() + tt.yy()*st.yz() + tt.yz()*st.zz())*tt.zz(),
183 
184  (tt.zx()*st.xx() + tt.zy()*st.xy() + tt.zz()*st.xz())*tt.zx()
185  + (tt.zx()*st.xy() + tt.zy()*st.yy() + tt.zz()*st.yz())*tt.zy()
186  + (tt.zx()*st.xz() + tt.zy()*st.yz() + tt.zz()*st.zz())*tt.zz()
187  );
188 }
189 
190 
191 template<class Type1, class Type2>
192 inline Type1 transformMask(const Type2& t)
193 {
194  return t;
195 }
196 
197 
198 template<>
200 {
201  return sph(t);
202 }
203 
204 
205 template<>
207 {
208  return symm(t);
209 }
210 
211 
212 //- Estimate angle of vec in coordinate system (e0, e1, e0^e1).
213 // Is guaranteed to return increasing number but is not correct
214 // angle. Used for sorting angles. All input vectors need to be normalized.
215 //
216 // Calculates scalar which increases with angle going from e0 to vec in
217 // the coordinate system e0, e1, e0^e1
218 //
219 // Jumps from 2*pi -> 0 at -SMALL so hopefully parallel vectors with small
220 // rounding errors should still get the same quadrant.
221 //
222 inline scalar pseudoAngle
223 (
224  const vector& e0,
225  const vector& e1,
226  const vector& vec
227 )
228 {
229  scalar cos = vec & e0;
230  scalar sin = vec & e1;
231 
232  if (sin < -SMALL)
233  {
234  return (3.0 + cos)*constant::mathematical::piByTwo;
235  }
236  else
237  {
238  return (1.0 - cos)*constant::mathematical::piByTwo;
239  }
240 }
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace Foam
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 #endif
250 
251 // ************************************************************************* //
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:82
mathematicalConstants.H
Foam::SymmTensor
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components,...
Definition: SymmTensor.H:53
Foam::Tensor::zx
const Cmpt & zx() const
Definition: TensorI.H:202
Foam::SymmTensor::zz
const Cmpt & zz() const
Definition: SymmTensorI.H:115
Foam::SymmTensor::xy
const Cmpt & xy() const
Definition: SymmTensorI.H:91
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:255
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Foam::transformMask< symmTensor >
symmTensor transformMask< symmTensor >(const symmTensor &st)
Definition: symmTransform.H:157
Foam::Tensor::yx
const Cmpt & yx() const
Definition: TensorI.H:181
tensor.H
Foam::transform
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
Foam::Tensor::xz
const Cmpt & xz() const
Definition: TensorI.H:174
Foam::Tensor::yz
const Cmpt & yz() const
Definition: TensorI.H:195
Foam::SymmTensor::yz
const Cmpt & yz() const
Definition: SymmTensorI.H:109
Foam::constant::mathematical::piByTwo
const scalar piByTwo(0.5 *pi)
Foam::Tensor::zy
const Cmpt & zy() const
Definition: TensorI.H:209
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Tensor::yy
const Cmpt & yy() const
Definition: TensorI.H:188
Foam::SymmTensor::xx
const Cmpt & xx() const
Definition: SymmTensorI.H:85
Foam::Tensor::zz
const Cmpt & zz() const
Definition: TensorI.H:216
Foam::sph
SphericalTensor< Cmpt > sph(const DiagTensor< Cmpt > &dt)
Return the spherical part of a diagonal tensor.
Definition: DiagTensorI.H:281
Foam::I
static const sphericalTensor I(1)
Foam::Tensor::xy
const Cmpt & xy() const
Definition: TensorI.H:167
Foam::pseudoAngle
scalar pseudoAngle(const vector &e0, const vector &e1, const vector &vec)
Estimate angle of vec in coordinate system (e0, e1, e0^e1).
Definition: transform.H:223
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::SphericalTensor
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor.H:51
Foam::Tensor::xx
const Cmpt & xx() const
Definition: TensorI.H:160
Foam::transformMask
Type1 transformMask(const Type2 &t)
Definition: transform.H:192
Foam::transformMask< sphericalTensor >
sphericalTensor transformMask< sphericalTensor >(const symmTensor &st)
Definition: symmTransform.H:150
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::Vector< scalar >
Foam::SymmTensor::yy
const Cmpt & yy() const
Definition: SymmTensorI.H:103
Foam::SymmTensor::xz
const Cmpt & xz() const
Definition: SymmTensorI.H:97
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Definition: transform.H:46
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256