1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-drive/module-drive.cc,v 1.16 2017/01/12 14:50:32 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 "drive.h"
39 
40 class DummyDriveCaller : public DriveCaller {
41 private:
42 	doublereal dConst;
43 
44 public:
45 	DummyDriveCaller(const doublereal &d);
46 	virtual ~DummyDriveCaller(void);
47 
48 	/* Copia */
49 	virtual DriveCaller* pCopy(void) const;
50 
51 	/* Scrive il contributo del DriveCaller al file di restart */
52 	virtual std::ostream& Restart(std::ostream& out) const;
53 
54 	inline doublereal dGet(const doublereal& /* dVar */ ) const;
55 	inline doublereal dGet(void) const;
56 
57 	/* this is about drives that are differentiable */
58 	virtual bool bIsDifferentiable(void) const;
59 	virtual doublereal dGetP(const doublereal& dVar) const;
60 	virtual inline doublereal dGetP(void) const;
61 };
62 
DummyDriveCaller(const doublereal & d)63 DummyDriveCaller::DummyDriveCaller(const doublereal &d)
64 : DriveCaller(0),
65 dConst(d)
66 {
67 	NO_OP;
68 }
69 
~DummyDriveCaller(void)70 DummyDriveCaller::~DummyDriveCaller(void)
71 {
72 	NO_OP;
73 }
74 
75 DriveCaller *
pCopy(void) const76 DummyDriveCaller::pCopy(void) const
77 {
78 	return new DummyDriveCaller(dConst);
79 }
80 
81 std::ostream&
Restart(std::ostream & out) const82 DummyDriveCaller::Restart(std::ostream& out) const
83 {
84 	return out << "dummy, " << dConst;
85 }
86 
87 inline doublereal
dGet(const doublereal &) const88 DummyDriveCaller::dGet(const doublereal& /* dVar */ ) const
89 {
90 	return dConst;
91 }
92 
93 inline doublereal
dGet(void) const94 DummyDriveCaller::dGet(void) const
95 {
96 	return dConst;
97 }
98 
99 inline bool
bIsDifferentiable(void) const100 DummyDriveCaller::bIsDifferentiable(void) const
101 {
102 	return true;
103 }
104 
105 inline doublereal
dGetP(const doublereal &) const106 DummyDriveCaller::dGetP(const doublereal& /* dVar */ ) const
107 {
108 	return 0.;
109 }
110 
111 inline doublereal
dGetP(void) const112 DummyDriveCaller::dGetP(void) const
113 {
114 	return 0.;
115 }
116 
117 /* prototype of the functional object: reads a drive caller */
118 struct DummyDCR : public DriveCallerRead {
119 	virtual DriveCaller *
ReadDummyDCR120 	Read(const DataManager* pDM, MBDynParser& HP, bool bDeferred) {
121 		doublereal d = HP.GetReal();
122 		return new DummyDriveCaller(d);
123 	};
124 };
125 
126 extern "C" int
module_init(const char * module_name,void * pdm,void * php)127 module_init(const char *module_name, void *pdm, void *php)
128 {
129 #if 0
130 	DataManager	*pDM = (DataManager *)pdm;
131 	MBDynParser	*pHP = (MBDynParser *)php;
132 #endif
133 
134 	DriveCallerRead	*rf = new DummyDCR;
135 
136 	if (!SetDriveCallerData("dummy", rf)) {
137 		delete rf;
138 
139 		silent_cerr("DummyDrive: "
140 			"module_init(" << module_name << ") "
141 			"failed" << std::endl);
142 
143 		return -1;
144 	}
145 
146 	return 0;
147 }
148 
149