MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
tpldrive_impl.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/tpldrive_impl.h,v 1.19 2017/01/12 14:46:11 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 #ifndef TPLDRIVE_IMPL_H
33 #define TPLDRIVE_IMPL_H
34 
35 #include <typeinfo>
36 #include "tpldrive.h"
37 #include "mbpar.h"
38 
39 /* ZeroTplDriveCaller - begin */
40 
41 template <class T>
43 public:
45  NO_OP;
46  };
47 
49  NO_OP;
50  };
51 
52  /* copia */
53  virtual TplDriveCaller<T>* pCopy(void) const {
54  typedef ZeroTplDriveCaller<T> dc;
55  TplDriveCaller<T>* pDC = 0;
56 
57  SAFENEW(pDC, dc);
58 
59  return pDC;
60  };
61 
62  /* Scrive il contributo del DriveCaller al file di restart */
63  virtual std::ostream& Restart(std::ostream& out) const {
64  return out << "zero";
65  };
66 
67  virtual std::ostream& Restart_int(std::ostream& out) const {
68  return out;
69  };
70 
71  inline T Get(const doublereal& dVar) const {
72  return mb_zero<T>();
73  };
74 
75  inline T Get(void) const {
76  return mb_zero<T>();
77  };
78 
79  /* this is about drives that are differentiable */
80  inline bool bIsDifferentiable(void) const {
81  return true;
82  };
83 
84  inline T GetP(void) const {
85  return mb_zero<T>();
86  };
87 
88  inline int getNDrives(void) const {
89  return 0;
90  };
91 };
92 
93 /* ZeroTplDriveCaller - end */
94 
95 /* SingleTplDriveCaller - begin */
96 
97 template <class T>
98 class SingleTplDriveCaller : public TplDriveCaller<T>, public DriveOwner {
99 protected:
100  T t;
101 
102 public:
103  SingleTplDriveCaller(const DriveCaller* pDC, const T& x)
104  : DriveOwner(pDC), t(const_cast<T&>(x)) {
105  NO_OP;
106  };
107 
109  NO_OP;
110  };
111 
112  /* copia */
113  virtual TplDriveCaller<T>* pCopy(void) const {
114  typedef SingleTplDriveCaller<T> dc;
115  TplDriveCaller<T>* pDC = 0;
116 
117  SAFENEWWITHCONSTRUCTOR(pDC, dc, dc(pGetDriveCaller()->pCopy(), t));
118 
119  return pDC;
120  };
121 
122  /* Scrive il contributo del DriveCaller al file di restart */
123  virtual std::ostream& Restart(std::ostream& out) const {
124  out << "single, ",
125  Write(out, t, ", ") << ", ";
126  return pGetDriveCaller()->Restart(out);
127  };
128 
129  virtual std::ostream& Restart_int(std::ostream& out) const {
130  Write(out, t, ", ") << ", ";
131  return pGetDriveCaller()->Restart(out);
132  };
133 
134  inline T Get(const doublereal& dVar) const {
135  return t*dGet(dVar);
136  };
137 
138  inline T Get(void) const {
139  return t*dGet();
140  };
141 
142  /* this is about drives that are differentiable */
143  inline bool bIsDifferentiable(void) const {
145  };
146 
147  inline T GetP(void) const {
148  return t*dGetP();
149  };
150 
151  inline int getNDrives(void) const {
152  return 1;
153  };
154 };
155 
156 /* Nota: in caso scalare, viene semplificata la classe in modo da
157  * usare solo il drive senza pesatura che viene assunta unitaria */
158 
159 template<>
161 : public TplDriveCaller<doublereal>, public DriveOwner {
162 public:
163  SingleTplDriveCaller(const DriveCaller* pDC, const doublereal& = 0.)
164  : DriveOwner(pDC) {
165  NO_OP;
166  };
167 
169  NO_OP;
170  };
171 
172  /* copia */
173  virtual TplDriveCaller<doublereal>* pCopy(void) const {
175 
177  SAFENEWWITHCONSTRUCTOR(pDC, dc, dc(pGetDriveCaller()->pCopy()));
178 
179  return pDC;
180  };
181 
182  /* Scrive il contributo del DriveCaller al file di restart */
183  virtual std::ostream& Restart(std::ostream& out) const {
184  out << "single, ";
185  return pGetDriveCaller()->Restart(out);
186  };
187 
188  virtual std::ostream& Restart_int(std::ostream& out) const {
189  return pGetDriveCaller()->Restart(out);
190  };
191 
192  inline doublereal Get(const doublereal& dVar) const {
193  return dGet(dVar);
194  };
195 
196  inline doublereal Get(void) const {
197  return dGet();
198  };
199 
200  inline bool bIsDifferentiable(void) const {
202  };
203 
204  inline doublereal GetP(void) const {
205  return dGetP();
206  };
207 
208  inline int getNDrives(void) const {
209  return 1;
210  };
211 };
212 
213 template <class T>
215 DC2TDC(DriveCaller *pDC, T& t)
216 {
217  typedef SingleTplDriveCaller<T> STDC;
218 
219  TplDriveCaller<T> *p = 0;
220  SAFENEWWITHCONSTRUCTOR(p, STDC, STDC(pDC, t));
221  return p;
222 }
223 
224 
225 /* SingleTplDriveCaller - end */
226 
227 #endif // TPLDRIVE_IMPL_H
228 
virtual std::ostream & Restart_int(std::ostream &out) const
virtual TplDriveCaller< T > * pCopy(void) const
virtual std::ostream & Restart_int(std::ostream &out) const
Definition: tpldrive_impl.h:67
T GetP(void) const
bool bIsDifferentiable(void) const
Definition: tpldrive_impl.h:80
std::ostream & Write(std::ostream &out, const FullMatrixHandler &m, const char *s, const char *s2)
Definition: fullmh.cc:376
T Get(void) const
Definition: tpldrive_impl.h:75
doublereal dGet(void) const
Definition: drive.cc:671
T Get(void) const
#define NO_OP
Definition: myassert.h:74
T GetP(void) const
Definition: tpldrive_impl.h:84
bool bIsDifferentiable(void) const
Definition: drive.cc:677
virtual std::ostream & Restart(std::ostream &out) const =0
SingleTplDriveCaller(const DriveCaller *pDC, const doublereal &=0.)
doublereal dGetP(void) const
Definition: drive.cc:690
SingleTplDriveCaller(const DriveCaller *pDC, const T &x)
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
T Get(const doublereal &dVar) const
Definition: tpldrive_impl.h:71
virtual std::ostream & Restart_int(std::ostream &out) const
T Get(const doublereal &dVar) const
TplDriveCaller< T > * DC2TDC(DriveCaller *pDC, T &t)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
DriveCaller * pGetDriveCaller(void) const
Definition: drive.cc:658
virtual TplDriveCaller< doublereal > * pCopy(void) const
int getNDrives(void) const
Definition: tpldrive_impl.h:88
int getNDrives(void) const
virtual TplDriveCaller< T > * pCopy(void) const
Definition: tpldrive_impl.h:53
virtual std::ostream & Restart(std::ostream &out) const
doublereal GetP(void) const
double doublereal
Definition: colamd.c:52
doublereal Get(void) const
virtual std::ostream & Restart(std::ostream &out) const
Definition: tpldrive_impl.h:63
virtual std::ostream & Restart(std::ostream &out) const
doublereal Get(const doublereal &dVar) const
bool bIsDifferentiable(void) const