1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-eu2phi/module-eu2phi.cc,v 1.6 2017/01/12 14:51:03 masarati Exp $ */
2 /*
3 * MBDyn (C) is a multibody analysis code.
4 * http://www.mbdyn.org
5 *
6 * Copyright (C) 1996-2017
7 *
8 * Pierangelo Masarati <masarati@aero.polimi.it>
9 * Paolo Mantegazza <mantegazza@aero.polimi.it>
10 *
11 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12 * via La Masa, 34 - 20156 Milano, Italy
13 * http://www.aero.polimi.it
14 *
15 * Changing this copyright notice is forbidden.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation (version 2 of the License).
20 *
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33
34 #include <cmath>
35 #include <cfloat>
36
37 #include "dataman.h"
38 #include "tpldrive.h"
39 #include "Rot.hh"
40
41 class Eu2PhiWrap : public TplDriveCaller<Vec3> {
42 private:
43 TplDriveCaller<Vec3> *m_pDC;
44 OrientationDescription m_od;
45
46 public:
Eu2PhiWrap(TplDriveCaller<Vec3> * pDC,OrientationDescription od)47 Eu2PhiWrap(TplDriveCaller<Vec3>* pDC, OrientationDescription od) : m_pDC(pDC), m_od(od) {
48 NO_OP;
49 };
50
~Eu2PhiWrap(void)51 virtual ~Eu2PhiWrap(void) {
52 delete m_pDC;
53 };
54
55 /* copia */
pCopy(void) const56 virtual TplDriveCaller<Vec3>* pCopy(void) const {
57 return new Eu2PhiWrap(m_pDC->pCopy(), m_od);
58 };
59
60 /* Scrive il contributo del DriveCaller al file di restart */
Restart(std::ostream & out) const61 virtual std::ostream& Restart(std::ostream& out) const {
62 return out;
63 };
64
Restart_int(std::ostream & out) const65 virtual std::ostream& Restart_int(std::ostream& out) const {
66 return out;
67 };
68
69 /* Restituisce il valore del driver */
Get(const doublereal & dVar) const70 virtual Vec3 Get(const doublereal& dVar) const {
71 Vec3 E(m_pDC->Get(dVar));
72
73 Mat3x3 R;
74 switch (m_od) {
75 case EULER_123:
76 R = EulerAngles123_2MatR(E);
77 break;
78
79 case EULER_313:
80 R = EulerAngles313_2MatR(E);
81 break;
82
83 case EULER_321:
84 R = EulerAngles321_2MatR(E);
85 break;
86
87 default:
88 ASSERT(0);
89 }
90
91 return RotManip::VecRot(R);
92 };
93
Get(void) const94 virtual Vec3 Get(void) const {
95 return Get(0.);
96 };
97
98 /* this is about drives that are differentiable */
bIsDifferentiable(void) const99 virtual bool bIsDifferentiable(void) const {
100 return false;
101 };
GetP(void) const102 virtual Vec3 GetP(void) const {
103 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
104 };
105
getNDrives(void) const106 virtual int getNDrives(void) const {
107 return 1;
108 };
109 };
110
111 /* prototype of the functional object: reads a drive caller */
112 struct Eu2PhiDCR : public TplDriveCallerRead<Vec3> {
113 virtual TplDriveCaller<Vec3> *
ReadEu2PhiDCR114 Read(const DataManager* pDM, MBDynParser& HP) {
115 if (HP.IsKeyWord("help")) {
116 silent_cout(
117 "Eu2PhiWrap: converts a TplDriveCaller<Vec3> containing three Euler angles\n"
118 "into the corresponding Euler vector\n"
119 "\n"
120 "Syntax:\n"
121 " eu2phi ,\n"
122 " [ help , ]\n"
123 " [ format , { euler123 | euler313 | euler321 } , ]\n"
124 " (TplDriveCaller<Vec3>) <drive>\n");
125 }
126
127 OrientationDescription od(EULER_123);
128
129 if (HP.IsKeyWord("format")) {
130 od = ReadOrientationDescription(HP);
131 switch (od) {
132 case EULER_123:
133 case EULER_313:
134 case EULER_321:
135 break;
136
137 default:
138 silent_cerr("Eu2PhiWrap: unhandled format at line " << HP.GetLineData() << std::endl);
139 throw ErrGeneric(MBDYN_EXCEPT_ARGS);
140 }
141 }
142
143 return new Eu2PhiWrap(HP.GetTplDriveCaller<Vec3>(), od);
144 };
145 };
146
147 extern "C" int
module_init(const char * module_name,void * pdm,void * php)148 module_init(const char *module_name, void *pdm, void *php)
149 {
150 #if 0
151 DataManager *pDM = (DataManager *)pdm;
152 MBDynParser *pHP = (MBDynParser *)php;
153 #endif
154
155 TplDriveCallerRead<Vec3> *rf = new Eu2PhiDCR;
156
157 if (!SetDC3D("eu2phi", rf)) {
158 delete rf;
159
160 silent_cerr("Eu2PhiDCR: "
161 "module_init(" << module_name << ") "
162 "failed" << std::endl);
163
164 return -1;
165 }
166
167 return 0;
168 }
169
170