MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-drive.cc
Go to the documentation of this file.
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:
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 
64 : DriveCaller(0),
65 dConst(d)
66 {
67  NO_OP;
68 }
69 
71 {
72  NO_OP;
73 }
74 
77 {
78  return new DummyDriveCaller(dConst);
79 }
80 
81 std::ostream&
82 DummyDriveCaller::Restart(std::ostream& out) const
83 {
84  return out << "dummy, " << dConst;
85 }
86 
87 inline doublereal
88 DummyDriveCaller::dGet(const doublereal& /* dVar */ ) const
89 {
90  return dConst;
91 }
92 
93 inline doublereal
95 {
96  return dConst;
97 }
98 
99 inline bool
101 {
102  return true;
103 }
104 
105 inline doublereal
106 DummyDriveCaller::dGetP(const doublereal& /* dVar */ ) const
107 {
108  return 0.;
109 }
110 
111 inline doublereal
113 {
114  return 0.;
115 }
116 
117 /* prototype of the functional object: reads a drive caller */
118 struct DummyDCR : public DriveCallerRead {
119  virtual DriveCaller *
120  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
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 
doublereal dConst
Definition: module-drive.cc:42
doublereal dGet(void) const
Definition: module-drive.cc:94
bool SetDriveCallerData(const char *name, DriveCallerRead *rf)
Definition: drive_.cc:1324
virtual ~DummyDriveCaller(void)
Definition: module-drive.cc:70
DummyDriveCaller(const doublereal &d)
Definition: module-drive.cc:63
virtual doublereal dGetP(void) const
#define NO_OP
Definition: myassert.h:74
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
virtual DriveCaller * pCopy(void) const
Definition: module-drive.cc:76
virtual DriveCaller * Read(const DataManager *pDM, MBDynParser &HP, bool bDeferred)
virtual bool bIsDifferentiable(void) const
double doublereal
Definition: colamd.c:52
static std::stack< const HighParser * > pHP
Definition: parser.cc:598
virtual std::ostream & Restart(std::ostream &out) const
Definition: module-drive.cc:82
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056