FreeFOAM The Cross-Platform CFD Toolkit
EulerCoordinateRotation.C
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) 1991-2010 OpenCFD Ltd.
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 
27 
28 #include <OpenFOAM/Switch.H>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(EulerCoordinateRotation, 0);
38  (
39  coordinateRotation,
40  EulerCoordinateRotation,
41  dictionary
42  );
43 }
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::EulerCoordinateRotation::calcTransform
48 (
49  const scalar phiAngle,
50  const scalar thetaAngle,
51  const scalar psiAngle,
52  const bool inDegrees
53 )
54 {
55  scalar phi = phiAngle;
56  scalar theta = thetaAngle;
57  scalar psi = psiAngle;
58 
59  if (inDegrees)
60  {
61  phi *= mathematicalConstant::pi/180.0;
62  theta *= mathematicalConstant::pi/180.0;
63  psi *= mathematicalConstant::pi/180.0;
64  }
65 
67  (
68  tensor
69  (
70  cos(phi)*cos(psi) - sin(phi)*sin(psi)*cos(theta),
71  -sin(phi)*cos(psi)*cos(theta) - cos(phi)*sin(psi),
72  sin(phi)*sin(theta),
73 
74  cos(phi)*sin(psi)*cos(theta) + sin(phi)*cos(psi),
75  cos(phi)*cos(psi)*cos(theta) - sin(phi)*sin(psi),
76  -cos(phi)*sin(theta),
77 
78  sin(psi)*sin(theta),
79  cos(psi)*sin(theta),
80  cos(theta)
81  )
82  );
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
89 :
91 {}
92 
93 
95 (
96  const vector& phiThetaPsi,
97  const bool inDegrees
98 )
99 :
101 {
102  calcTransform
103  (
104  phiThetaPsi.component(vector::X),
105  phiThetaPsi.component(vector::Y),
106  phiThetaPsi.component(vector::Z),
107  inDegrees
108  );
109 }
110 
111 
113 (
114  const scalar phiAngle,
115  const scalar thetaAngle,
116  const scalar psiAngle,
117  const bool inDegrees
118 )
119 :
121 {
122  calcTransform(phiAngle, thetaAngle, psiAngle, inDegrees);
123 }
124 
125 
127 (
128  const dictionary& dict
129 )
130 :
132 {
133  vector rotation(dict.lookup("rotation"));
134 
135  calcTransform
136  (
137  rotation.component(vector::X),
138  rotation.component(vector::Y),
139  rotation.component(vector::Z),
140  dict.lookupOrDefault<Switch>("degrees", true)
141  );
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //