MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
matvecexp.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/matvecexp.cc,v 1.25 2017/01/12 14:43:54 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * This code is a partial merge of HmFe and MBDyn.
9  *
10  * Pierangelo Masarati <masarati@aero.polimi.it>
11  * Paolo Mantegazza <mantegazza@aero.polimi.it>
12  *
13  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
14  * via La Masa, 34 - 20156 Milano, Italy
15  * http://www.aero.polimi.it
16  *
17  * Changing this copyright notice is forbidden.
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation (version 2 of the License).
22  *
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32  */
33 /*
34  * HmFe (C) is a FEM analysis code.
35  *
36  * Copyright (C) 1996-2017
37  *
38  * Marco Morandini <morandini@aero.polimi.it>
39  * Teodoro Merlini <merlini@aero.polimi.it>
40  *
41  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
42  * via La Masa, 34 - 20156 Milano, Italy
43  * http://www.aero.polimi.it
44  *
45  * Changing this copyright notice is forbidden.
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
49  *
50  */
51 
52 
53 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
54 
55 #include "matvecexp.h"
56 
57 // NOTE: do not use Zero3, Zero3x3 or mb_zero<>()
58 // because they might be not initialized yet
59 const VecExp ZeroExp(0., 0., 0., 0., 0., 0.);
60 const MatExp EyeExp(Mat3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.),
61  Mat3x3(0., 0., 0., 0., 0., 0., 0., 0., 0.));
62 
63 
64 
65 ScalExp
66 pow(const ScalExp &d, const doublereal &e)
67 {
68 #ifdef MBDYN_SINGLE_PRECISION
69  double p = d.GetVec();
70  return ScalExp(doublereal(pow(p, double(e))),
71  doublereal(d.GetMom()*(e*pow(p, double(e-1.)))));
72 #else /* ! MBDYN_SINGLE_PRECISION */
73  doublereal p = d.GetVec();
74  return ScalExp(pow(p, e), d.GetMom()*(e*pow(p, e-1.)));
75 #endif /* ! MBDYN_SINGLE_PRECISION */
76 };
77 
78 ScalExp
79 sqrt(const ScalExp &d)
80 {
81  doublereal p = sqrt(d.GetVec());
82  return ScalExp(p, d.GetMom()/(p*2.));
83 };
84 
85 ScalExp
86 sin(const ScalExp &d)
87 {
88  doublereal p = d.GetVec();
89  return ScalExp(sin(p), d.GetMom()*cos(p));
90 };
91 
92 ScalExp
93 cos(const ScalExp &d)
94 {
95  doublereal p = d.GetVec();
96  return ScalExp(cos(p), d.GetMom()*(-sin(p)));
97 };
98 
99 ScalExp
100 exp(const ScalExp &d)
101 {
102  doublereal p = exp(d.GetVec());
103  return ScalExp(p, d.GetMom()*p);
104 };
105 
106 
107 
108 
109 std::ostream&
110 ScalExp::Write(std::ostream& out, const char* sFill) const
111 {
112  return out
113  << GetVec() << sFill
114  << GetMom();
115 }
116 
117 //ScalExp
118 //operator - (const ScalExp& v)
119 //{
120 // return ScalExp(-v.GetVec(), -v.GetMom());
121 //}
122 //
123 
124 std::ostream&
125 operator << (std::ostream& out, const ScalExp& v)
126 {
127  return out
128  << v.GetVec() << " "
129  << v.GetMom();
130 }
131 
132 std::ostream&
133 Write(std::ostream& out, const ScalExp& v, const char* sFill)
134 {
135  return v.Write(out, sFill);
136 }
137 
138 std::ostream&
139 VecExp::Write(std::ostream& out, const char* sFill) const
140 {
141  return out
142  << vec.dGet(1) << sFill
143  << vec.dGet(2) << sFill
144  << vec.dGet(3) << sFill
145  << mom.dGet(1) << sFill
146  << mom.dGet(2) << sFill
147  << mom.dGet(3);
148 }
149 
150 VecExp
152 {
153  return VecExp(-v.GetVec(), -v.GetMom());
154 }
155 
156 std::ostream&
157 operator << (std::ostream& out, const VecExp& v)
158 {
159  const Vec3& vec = v.GetVec();
160  const Vec3& mom = v.GetMom();
161  return out
162  << vec.dGet(1) << " "
163  << vec.dGet(2) << " "
164  << vec.dGet(3) << " "
165  << mom.dGet(1) << " "
166  << mom.dGet(2) << " "
167  << mom.dGet(3);
168 }
169 
170 std::ostream&
171 Write(std::ostream& out, const VecExp& v, const char* sFill)
172 {
173  return v.Write(out, sFill);
174 }
175 
176 std::ostream&
177 MatExp::Write(std::ostream& out, const char* sFill, const char* sFill2) const
178 {
179  char* sF2 = (char*)sFill2;
180  if (sFill2 == NULL) {
181  sF2 = (char*)sFill;
182  }
183 
184  return out
185  << vec.dGet(1,1) << sFill
186  << vec.dGet(1,2) << sFill
187  << vec.dGet(1,3) << sFill
188  << mom.dGet(1,1) << sFill
189  << mom.dGet(1,2) << sFill
190  << mom.dGet(1,3) << sF2
191  << vec.dGet(2,1) << sFill
192  << vec.dGet(2,2) << sFill
193  << vec.dGet(2,3) << sFill
194  << mom.dGet(2,1) << sFill
195  << mom.dGet(2,2) << sFill
196  << mom.dGet(2,3) << sF2
197  << vec.dGet(3,1) << sFill
198  << vec.dGet(3,2) << sFill
199  << vec.dGet(3,3) << sFill
200  << mom.dGet(3,1) << sFill
201  << mom.dGet(3,2) << sFill
202  << mom.dGet(3,3) << sF2
203  << 0. << sFill
204  << 0. << sFill
205  << 0. << sFill
206  << vec.dGet(1,1) << sFill
207  << vec.dGet(1,2) << sFill
208  << vec.dGet(1,3) << sF2
209  << 0. << sFill
210  << 0. << sFill
211  << 0. << sFill
212  << vec.dGet(2,1) << sFill
213  << vec.dGet(2,2) << sFill
214  << vec.dGet(2,3) << sF2
215  << 0. << sFill
216  << 0. << sFill
217  << 0. << sFill
218  << vec.dGet(3,1) << sFill
219  << vec.dGet(3,2) << sFill
220  << vec.dGet(3,3);
221 }
222 
223 std::ostream&
224 operator << (std::ostream& out, const MatExp& m)
225 {
226  const Mat3x3& vec = m.GetVec();
227  const Mat3x3& mom = m.GetMom();
228  return out
229  << vec.dGet(1, 1) << " "
230  << vec.dGet(1, 2) << " "
231  << vec.dGet(1, 3) << " "
232  << mom.dGet(1, 1) << " "
233  << mom.dGet(1, 2) << " "
234  << mom.dGet(1, 3) << std::endl
235  << vec.dGet(2, 1) << " "
236  << vec.dGet(2, 2) << " "
237  << vec.dGet(2, 3) << " "
238  << mom.dGet(2, 1) << " "
239  << mom.dGet(2, 2) << " "
240  << mom.dGet(2, 3) << std::endl
241  << vec.dGet(3, 1) << " "
242  << vec.dGet(3, 2) << " "
243  << vec.dGet(3, 3) << " "
244  << mom.dGet(3, 1) << " "
245  << mom.dGet(3, 2) << " "
246  << mom.dGet(3, 3) << std::endl
247  << 0. << " "
248  << 0. << " "
249  << 0. << " "
250  << vec.dGet(1, 1) << " "
251  << vec.dGet(1, 2) << " "
252  << vec.dGet(1, 3) << std::endl
253  << 0. << " "
254  << 0. << " "
255  << 0. << " "
256  << vec.dGet(2, 1) << " "
257  << vec.dGet(2, 2) << " "
258  << vec.dGet(2, 3) << std::endl
259  << 0. << " "
260  << 0. << " "
261  << 0. << " "
262  << vec.dGet(3, 1) << " "
263  << vec.dGet(3, 2) << " "
264  << vec.dGet(3, 3);
265 }
266 
267 std::ostream&
268 Write(std::ostream& out, const MatExp& m, const char* sFill, const char* sFill2)
269 {
270  return m.Write(out, sFill, sFill2);
271 }
272 
273 #if 0
274 VecExp
275 MultRV(const VecExp& v, const Mat3x3& R)
276 {
277  return VecExp(R*v.GetVec(),R*v.GetMom());
278 }
279 
280 MatExp
281 MultRM(const MatExp& m, const Mat3x3& R)
282 {
283  return MatExp(R*m.GetVec(), R*m.GetMom());
284 }
285 
286 
287 MatExp
288 MultMRt(const MatExp& m, const Mat3x3& R)
289 {
290  Mat3x3 Rt = R.Transpose();
291  return MatExp(m.GetVec()*Rt, m.GetMom()*Rt);
292 }
293 
294 MatExp
295 MultRMRt(const MatExp& m, const Mat3x3& R)
296 {
297  Mat3x3 Rt = R.Transpose();
298  return MatExp(R*m.GetVec()*Rt, R*m.GetMom()*Rt);
299 }
300 #endif /* 0 */
301 
const Vec3 & GetVec(void) const
Definition: matvecexp.h:198
Mat3x3 MultRMRt(const Mat3x3 &m, const Mat3x3 &R)
Definition: matvec3.cc:1162
Mat3x3 MultRM(const Mat3x3 &m, const Mat3x3 &R)
Definition: matvec3.cc:1150
ScalExp cos(const ScalExp &d)
Definition: matvecexp.cc:93
const Mat3x3 & GetVec(void) const
Definition: matvecexp.h:356
Vec3 MultRV(const Vec3 &v, const Mat3x3 &R)
Definition: matvec3.cc:1144
const doublereal & dGet(unsigned short int iRow, unsigned short int iCol) const
Definition: matvec3.h:770
Definition: matvec3.h:98
Mat3x3 MultMRt(const Mat3x3 &m, const Mat3x3 &R)
Definition: matvec3.cc:1156
ScalExp pow(const ScalExp &d, const doublereal &e)
Definition: matvecexp.cc:66
std::ostream & Write(std::ostream &out, const ScalExp &v, const char *sFill)
Definition: matvecexp.cc:133
const Vec3 & GetMom(void) const
Definition: matvecexp.h:202
ScalExp sin(const ScalExp &d)
Definition: matvecexp.cc:86
std::ostream & Write(std::ostream &out, const char *sFill=" ") const
Definition: matvecexp.cc:139
Mat3x3 mom
Definition: matvecexp.h:321
std::ostream & Write(std::ostream &out, const char *sFill=" ") const
Definition: matvecexp.cc:110
ScalExp exp(const ScalExp &d)
Definition: matvecexp.cc:100
Mat3x3 vec
Definition: matvecexp.h:320
const doublereal & GetVec(void) const
Definition: matvecexp.h:90
std::ostream & operator<<(std::ostream &out, const ScalExp &v)
Definition: matvecexp.cc:125
const doublereal & GetMom(void) const
Definition: matvecexp.h:94
VecExp operator-(const VecExp &v)
Definition: matvecexp.cc:151
const VecExp ZeroExp(0., 0., 0., 0., 0., 0.)
const doublereal & dGet(unsigned short int iRow) const
Definition: matvec3.h:285
Vec3 mom
Definition: matvecexp.h:168
Mat3x3 Transpose(void) const
Definition: matvec3.h:816
const MatExp EyeExp(Mat3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), Mat3x3(0., 0., 0., 0., 0., 0., 0., 0., 0.))
std::ostream & Write(std::ostream &out, const char *sFill=" ", const char *sFill2=NULL) const
Definition: matvecexp.cc:177
Vec3 vec
Definition: matvecexp.h:167
double doublereal
Definition: colamd.c:52
ScalExp sqrt(const ScalExp &d)
Definition: matvecexp.cc:79
const Mat3x3 & GetMom(void) const
Definition: matvecexp.h:360
Mat3x3 R