MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Rot.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/Rot.cc,v 1.32 2017/01/12 14:43:53 masarati Exp $ */
2 /*
3  * HmFe (C) is a FEM analysis code.
4  *
5  * Copyright (C) 1996-2017
6  *
7  * Marco Morandini <morandini@aero.polimi.it>
8  * Teodoro Merlini <merlini@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  */
20 /*
21  * MBDyn (C) is a multibody analysis code.
22  * http://www.mbdyn.org
23  *
24  * Copyright (C) 1996-2017
25  *
26  * This code is a partial merge of HmFe and MBDyn.
27  *
28  * Pierangelo Masarati <masarati@aero.polimi.it>
29  * Paolo Mantegazza <mantegazza@aero.polimi.it>
30  *
31  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
32  * via La Masa, 34 - 20156 Milano, Italy
33  * http://www.aero.polimi.it
34  *
35  * Changing this copyright notice is forbidden.
36  *
37  * This program is free software; you can redistribute it and/or modify
38  * it under the terms of the GNU General Public License as published by
39  * the Free Software Foundation (version 2 of the License).
40  *
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU General Public License for more details.
46  *
47  * You should have received a copy of the GNU General Public License
48  * along with this program; if not, write to the Free Software
49  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50  */
51 
52 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
53 
54 #include <iostream>
55 #include "mathtyp.h"
56 #include "matvecexp.h"
57 #include "RotCoeff.hh"
58 #include "Rot.hh"
59 
60 using namespace RotCoeff;
61 
62 Mat3x3 RotManip::Rot(const Vec3 & phi) {
63  doublereal coeff[COEFF_B];
64 
65  CoeffB(phi,phi,coeff);
66 
67  Mat3x3 Phi(1., phi*coeff[0]); /* I + c[0] * phi x */
68  Phi += Mat3x3(MatCrossCross, phi, phi*coeff[1]); /* += c[1] * phi x phi x */
69 
70  return Phi;
71 }
72 
73 
74 Mat3x3 RotManip::DRot(const Vec3 & phi) {
75  doublereal coeff[COEFF_C];
76 
77  CoeffC(phi,phi,coeff);
78 
79  Mat3x3 Ga(1., phi*coeff[1]); /* I + c[0] * phi x */
80  Ga += Mat3x3(MatCrossCross, phi, phi*coeff[2]); /* += c[1] * phi x phi x */
81 
82  return Ga;
83 }
84 
85 
86 void RotManip::RotAndDRot(const Vec3 & phi, Mat3x3 & Phi, Mat3x3 & Ga) {
87  doublereal coeff[COEFF_C];
88 
89  CoeffC(phi,phi,coeff);
90 
91  Phi = Mat3x3(1., phi*coeff[0]);
92  Phi += Mat3x3(MatCrossCross, phi, phi*coeff[1]);
93 
94  Ga = Mat3x3(1., phi*coeff[1]);
95  Ga += Mat3x3(MatCrossCross, phi, phi*coeff[2]);
96 
97  return;
98 }
99 
101  doublereal coeff[COEFF_D], coeffs[COEFF_C_STAR];
102 
103  CoeffCStar(phi,phi,coeff,coeffs);
104 
105  Mat3x3 GaIT(1., phi*.5);
106  GaIT += Mat3x3(MatCrossCross, phi, phi*coeffs[0]);
107 
108  return GaIT;
109 }
110 
112  doublereal coeff[COEFF_D], coeffs[COEFF_C_STAR];
113 
114  CoeffCStar(phi,phi,coeff,coeffs);
115 
116  Mat3x3 GaI(1., phi*(-.5));
117  GaI += Mat3x3(MatCrossCross, phi, phi*coeffs[0]);
118 
119  return GaI;
120 }
121 
122 void RotManip::RotAndDRot_IT(const Vec3 & phi, Mat3x3 & PhiIT, Mat3x3 & GaIT) {
123  doublereal coeff[COEFF_D], coeffs[COEFF_C_STAR];
124 
125  CoeffCStar(phi,phi,coeff,coeffs);
126 
127  PhiIT = Mat3x3(1., phi*coeff[0]);
128  PhiIT += Mat3x3(MatCrossCross, phi, phi*coeff[1]);
129 
130  GaIT = Mat3x3(1., phi*.5);
131  GaIT += Mat3x3(MatCrossCross, phi, phi*coeffs[0]);
132 
133  return;
134 }
135 
137  doublereal a, cosphi, sinphi;
138  Vec3 unit;
139 
140  // Modified from Appendix 2.4 of
141  //
142  // author = {Marco Borri and Lorenzo Trainelli and Carlo L. Bottasso},
143  // title = {On Representations and Parameterizations of Motion},
144  // journal = {Multibody System Dynamics},
145  // volume = {4},
146  // pages = {129--193},
147  // year = {2000}
148 
149  cosphi = (Phi.Trace() - 1.)/2.;
150  if (cosphi > 0.) {
151  unit = Phi.Ax();
152  sinphi = unit.Norm();
153  doublereal phi = atan2(sinphi, cosphi);
154  CoeffA(phi, Vec3(phi, 0., 0.), &a);
155  unit /= a;
156  } else {
157  // -1 <= cosphi <= 0
158  Mat3x3 eet(Phi.Symm());
159  eet(1, 1) -= cosphi;
160  eet(2, 2) -= cosphi;
161  eet(3, 3) -= cosphi;
162  // largest (abs) component of unit vector phi/|phi|
163  Int maxcol = 1;
164  if (eet(2, 2) > eet(1, 1)) {
165  maxcol = 2;
166  }
167  if (eet(3, 3) > eet(maxcol, maxcol)) {
168  maxcol = 3;
169  }
170  unit = (eet.GetVec(maxcol)/sqrt(eet(maxcol, maxcol)*(1. - cosphi)));
171  // sinphi = -(Mat3x3(unit)*Phi).Trace()/2.;
172  sinphi = -(unit.Cross(Phi)).Trace()/2.;
173  unit *= atan2(sinphi, cosphi);
174  }
175  return unit;
176 }
177 
179  (const Vec3 & phi,
180  const Vec3 & a) {
181  doublereal coeff[COEFF_E];
182  CoeffE(phi,phi,coeff);
183 
184  Mat3x3 L(MatCross, a*(-coeff[1]));
185  L -= Mat3x3(MatCrossCross, phi, a*coeff[2]);
186  L -= Mat3x3(MatCross, phi.Cross(a*coeff[2]));
187  L += (phi.Cross(a)).Tens(phi*coeff[3]);
188  L += (Mat3x3(MatCrossCross, phi, phi)*a).Tens(phi*coeff[4]);
189 
190  return L;
191 }
192 
194  (const VecExp & phi,
195  const VecExp & a) {
196  ScalExp coeff[COEFF_E];
197  CoeffE(phi,phi.GetVec(),coeff);
198 
199  MatExp L(a*(-coeff[1]));
200  L -= MatExp(phi,a*coeff[2]);
201  L -= MatExp(phi.Cross(a*coeff[2]));
202  L += (phi.Cross(a)).Tens(phi*coeff[3]);
203  L += (MatExp(phi,phi)*a).Tens(phi*coeff[4]);
204 
205  return L;
206 }
207 
209  ScalExp coeff[COEFF_B];
210 
211  CoeffB(phi,phi.GetVec(),coeff);
212 
213  MatExp Phi(1., phi*coeff[0]); /* I + c[0] * phi x */
214  Phi += MatExp(phi, phi*coeff[1]); /* += c[1] * phi x phi x */
215 
216  return Phi;
217 }
218 
220  ScalExp coeff[COEFF_C];
221 
222  CoeffC(phi,phi.GetVec(),coeff);
223 
224  MatExp Ga(1., phi*coeff[1]); /* I + c[0] * phi x */
225  Ga += MatExp(phi, phi*coeff[2]); /* += c[1] * phi x phi x */
226 
227  return Ga;
228 }
229 
230 void RoTrManip::RoTrAndDRoTr(const VecExp & phi, MatExp & Phi, MatExp & Ga) {
231  ScalExp coeff[COEFF_C];
232 
233  CoeffC(phi,phi.GetVec(),coeff);
234 
235  Phi = MatExp(1., phi*coeff[0]);
236  Phi += MatExp(phi, phi*coeff[1]);
237 
238  Ga = MatExp(1., phi*coeff[1]);
239  Ga += MatExp(phi, phi*coeff[2]);
240 
241  return;
242 }
243 
245  ScalExp coeff[COEFF_D], coeffs[COEFF_C_STAR];
246 
247  CoeffCStar(phi,phi.GetVec(),coeff,coeffs);
248 
249  MatExp GaIT(1., phi*.5);
250  GaIT += MatExp(phi, phi*coeffs[0]);
251 
252  return GaIT;
253 }
254 
256  ScalExp coeff[COEFF_D], coeffs[COEFF_C_STAR];
257 
258  CoeffCStar(phi,phi.GetVec(),coeff,coeffs);
259 
260  MatExp GaIT(1., phi*-.5);
261  GaIT += MatExp(phi, phi*coeffs[0]);
262 
263  return GaIT;
264 }
265 
267  MatExp & PhiIT,
268  MatExp & GaIT) {
269  ScalExp coeff[COEFF_D], coeffs[COEFF_C_STAR];
270 
271  CoeffCStar(phi,phi.GetVec(),coeff,coeffs);
272 
273  PhiIT = MatExp(1., phi*coeff[0]);
274  PhiIT += MatExp(phi, phi*coeff[1]);
275 
276  GaIT = MatExp(1., phi*.5);
277  GaIT += MatExp(phi, phi*coeffs[0]);
278 
279  return;
280 }
281 
283  Vec3 phi(RotManip::VecRot(H.GetVec()));
284  return VecExp(phi,
286  (H.GetMom()*(H.GetVec().Transpose())).Ax())
287  );
288 }
289 
290 namespace ER_Rot {
295 } // end of namespace ER_Rot
const Vec3 & GetVec(void) const
Definition: matvecexp.h:198
Vec3 Ax(void) const
Definition: matvec3.h:827
Mat3x3 DRot_IT(const Vec3 &phi)
Definition: Rot.cc:100
Vec3 Cross(const Vec3 &v) const
Definition: matvec3.h:218
const Mat3x3 & GetVec(void) const
Definition: matvecexp.h:356
MatrixExpression< TransposedMatrix< MatrixDirectExpr< Matrix< T, N_rows, N_cols > > >, N_cols, N_rows > Transpose(const Matrix< T, N_rows, N_cols > &A)
Definition: matvec.h:2206
Definition: matvec3.h:98
MatR_Manip MatR
Definition: Rot.cc:292
void CoeffC(const T1 &phi, const Vec3 &p, T2 *const coeff)
const MatCross_Manip MatCross
Definition: matvec3.cc:639
MatExp DRoTr_It(const VecExp &eta)
Definition: Rot.cc:244
doublereal Norm(void) const
Definition: matvec3.h:263
MatExp DRoTr_I(const VecExp &eta)
Definition: Rot.cc:255
Mat3x3 DRot(const Vec3 &phi)
Definition: Rot.cc:74
Param_Manip Param
Definition: Rot.cc:291
const Int COEFF_D
Definition: RotCoeff.hh:65
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
void RoTrAndDRoTr_It(const VecExp &eta, MatExp &HIt, MatExp &ThIt)
Definition: Rot.cc:266
const Int COEFF_E
Definition: RotCoeff.hh:66
VecExp Helix(const MatExp &H)
Definition: Rot.cc:282
void CoeffB(const T1 &phi, const Vec3 &p, T2 *const coeff)
doublereal Trace(void) const
Definition: matvec3.h:836
MatExp RoTr(const VecExp &eta)
Definition: Rot.cc:208
void CoeffCStar(const T1 &phi, const Vec3 &p, T2 *const coeff, T2 *const coeffs)
MatExp DRoTr(const VecExp &eta)
Definition: Rot.cc:219
Mat3x3 Rot(const Vec3 &phi)
Definition: Rot.cc:62
const Int COEFF_C_STAR
Definition: RotCoeff.hh:69
const Int COEFF_B
Definition: RotCoeff.hh:63
MatG_Manip MatG
Definition: Rot.cc:293
const Int COEFF_C
Definition: RotCoeff.hh:64
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
Mat3x3 Elle(const Vec3 &phi, const Vec3 &a)
Definition: Rot.cc:179
void CoeffA(const T1 &phi, const Vec3 &p, T2 *const coeff)
Mat3x3 Transpose(void) const
Definition: matvec3.h:816
const MatCrossCross_Manip MatCrossCross
Definition: matvec3.cc:640
Mat3x3 Symm(void) const
Definition: matvec3.h:840
void RotAndDRot(const Vec3 &phi, Mat3x3 &Phi, Mat3x3 &Ga)
Definition: Rot.cc:86
VecExp Cross(const VecExp &v) const
Definition: matvecexp.h:300
static const doublereal a
Definition: hfluid_.h:289
GradientExpression< BinaryExpr< FuncAtan2, LhsExpr, RhsExpr > > atan2(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2962
void CoeffE(const T1 &phi, const Vec3 &p, T2 *const coeff)
const Mat3x3 & GetMom(void) const
Definition: matvecexp.h:360
void RotAndDRot_IT(const Vec3 &phi, Mat3x3 &PhiIT, Mat3x3 &GaIT)
Definition: Rot.cc:122
MatGm1_Manip MatGm1
Definition: Rot.cc:294
void RoTrAndDRoTr(const VecExp &eta, MatExp &H, MatExp &Th)
Definition: Rot.cc:230
Mat3x3 DRot_I(const Vec3 &phi)
Definition: Rot.cc:111
MatExp Elle(const VecExp &phi, const VecExp &a)
Definition: Rot.cc:194