MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
module-nodedistdrive.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-nodedistdrive/module-nodedistdrive.cc,v 1.5 2017/01/12 14:55:48 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 /*
33  AUTHOR: Reinhard Resch <r.resch@secop.com>
34  Copyright (C) 2015(-2017) all rights reserved.
35 
36  The copyright of this code is transferred
37  to Pierangelo Masarati and Paolo Mantegazza
38  for use in the software MBDyn as described
39  in the GNU Public License version 2.1
40 */
41 
42 #ifdef HAVE_CONFIG_H
43 #include "mbconfig.h"
44 #endif
45 
46 #include <drive.h>
47 
48 #include <myassert.h>
49 #include <except.h>
50 
51 #include <strnode.h>
52 #include <elem.h>
53 #include <mynewmem.h>
54 #include <dataman.h>
55 
56 #include "module-nodedistdrive.h"
57 
59 {
60 public:
62  const StructNode* pNode1,
63  const Vec3& o1,
64  const StructNode* pNode2,
65  const Vec3& o2,
66  const Vec3& e1);
67  virtual ~NodeDistDriveCaller(void);
68 
69  /* Copia */
70  virtual DriveCaller* pCopy(void) const;
71 
72  virtual std::ostream& Restart(std::ostream& out) const;
73 
74  inline doublereal dGet(const doublereal& dVar) const;
75  inline doublereal dGet(void) const;
76  /* this is about drives that are differentiable */
77  virtual bool bIsDifferentiable(void) const;
78  inline virtual doublereal dGetP(void) const;
79  inline virtual doublereal dGetP(const doublereal& dVar) const;
80 
81 private:
82  const StructNode* const pNode1;
83  const Vec3 o1;
84  const StructNode* const pNode2;
85  const Vec3 o2;
86  const Vec3 e1;
87 };
88 
89 struct NodeDistDCR : public DriveCallerRead {
90  DriveCaller *
91  Read(const DataManager* pDM, MBDynParser& HP, bool bDeferred);
92 };
93 
95 NodeDistDCR::Read(const DataManager* pDM, MBDynParser& HP, bool bDeferred)
96 {
97  NeedDM(pDM, HP, bDeferred, "node distance");
98 
99  const DriveHandler* pDrvHdl = 0;
100 
101  if (pDM != 0) {
102  pDrvHdl = pDM->pGetDrvHdl();
103  }
104 
105  DriveCaller *pDC = 0;
106 
107  /* driver legato ad un grado di liberta' nodale */
108  if (pDM == 0) {
109  silent_cerr("sorry, since the driver is not owned by a DataManager" << std::endl
110  << "no DOF dependent drivers are allowed;" << std::endl
111  << "aborting..." << std::endl);
113  }
114 
115  if ( !HP.IsKeyWord("node1") )
116  {
117  silent_cerr("node distance drive caller: keyword \"node1\" expected at line " << HP.GetLineData() << std::endl);
119  }
120 
121  StructNode* const pNode1 = pDM->ReadNode<StructNode, StructDispNode, Node::STRUCTURAL>(HP);
122 
123  const Vec3 o1 = HP.IsKeyWord("offset") ? HP.GetPosRel(ReferenceFrame(pNode1)) : Zero3;
124 
125  if ( !HP.IsKeyWord("node2") )
126  {
127  silent_cerr("node distance drive caller: keyword \"node2\" expected at line " << HP.GetLineData() << std::endl);
129  }
130 
131  StructNode* const pNode2 = pDM->ReadNode<StructNode, StructDispNode, Node::STRUCTURAL>(HP);
132 
133  const Vec3 o2 = HP.IsKeyWord("offset") ? HP.GetPosRel(ReferenceFrame(pNode2)) : Zero3;
134 
135  if ( !HP.IsKeyWord("direction") )
136  {
137  silent_cerr("node distance drive caller: keyword \"direction\" expected at line " << HP.GetLineData() << std::endl);
139  }
140 
141  Vec3 e1 = HP.GetVecRel(ReferenceFrame(pNode2));
142 
143  e1 /= e1.Norm();
144 
145  /* allocazione e creazione */
148  NodeDistDriveCaller(pDrvHdl, pNode1, o1, pNode2, o2, e1));
149 
150  pDM->GetLogFile()
151  << "nodedistdrive: " << pDC->GetLabel()
152  << " (" << pDC->GetName() << ") "
153  << pNode1->GetLabel() << " "
154  << o1 << " "
155  << pNode2->GetLabel() << " "
156  << o2 << " "
157  << e1 << std::endl;
158 
159  return pDC;
160 }
161 
164 {
165  return dGetP();
166 }
167 
170 {
171  const Vec3& X1 = pNode1->GetXCurr();
172  const Mat3x3& R1 = pNode1->GetRCurr();
173  const Vec3& X2 = pNode2->GetXCurr();
174  const Mat3x3& R2 = pNode2->GetRCurr();
175 
176  const doublereal dX = e1.Dot(R2.MulTV(X2 - X1 - R1 * o1) + o2);
177 
178  return dX;
179 }
180 
182 {
183  return true;
184 }
185 
187 {
188  const Vec3& X1 = pNode1->GetXCurr();
189  const Vec3& X1Dot = pNode1->GetVCurr();
190  const Mat3x3& R1 = pNode1->GetRCurr();
191  const Vec3& omega1 = pNode1->GetWCurr();
192 
193  const Vec3& X2 = pNode2->GetXCurr();
194  const Vec3& X2Dot = pNode2->GetVCurr();
195  const Mat3x3& R2 = pNode2->GetRCurr();
196  const Vec3& omega2 = pNode2->GetWCurr();
197 
198  const doublereal dXP = e1.Dot(R2.MulTV(-omega2.Cross(X2 - X1 - R1 * o1) + X2Dot - X1Dot - omega1.Cross(R1 * o1)));
199 
200  return dXP;
201 }
202 
204 {
205  return dGetP();
206 }
207 
209  const DriveHandler* pDH,
210  const StructNode* pNode1Arg,
211  const Vec3& o1Arg,
212  const StructNode* pNode2Arg,
213  const Vec3& o2Arg,
214  const Vec3& e1Arg)
215 : DriveCaller(pDH),
216  pNode1(pNode1Arg), o1(o1Arg),
217  pNode2(pNode2Arg), o2(o2Arg),
218  e1(e1Arg)
219 {
220  NO_OP;
221 };
222 
224 {
225  NO_OP;
226 }
227 
228 /* Copia */
231 {
232  DriveCaller* pDC = NULL;
233 
237  pDrvHdl,
238  pNode1, o1,
239  pNode2, o2,
240  e1));
241 
242  return pDC;
243 }
244 
245 
246 /* Restart */
247 std::ostream&
248 NodeDistDriveCaller::Restart(std::ostream& out) const
249 {
250  out << "node distance,"
251  << pNode1->GetLabel() << ","
252  << o1 << ","
253  << pNode2->GetLabel() << ","
254  << o2 << ","
255  << e1;
256 
257  return out;
258 }
259 
261 {
262  DriveCallerRead *rf = new NodeDistDCR;
263 
264  if (!SetDriveCallerData("node" "distance", rf)) {
265  delete rf;
266  return false;
267  }
268 
269  return true;
270 }
271 
272 #ifndef STATIC_MODULES
273 
274 extern "C" int
275 module_init(const char *module_name, void *pdm, void *php)
276 {
277  if (!nodedistdrive_set()) {
278  silent_cerr("nodedistdrive: "
279  "module_init(" << module_name << ") "
280  "failed" << std::endl);
281  return -1;
282  }
283 
284  return 0;
285 }
286 
287 #endif // ! STATIC_MODULES
NodeDistDriveCaller(const DriveHandler *pDH, const StructNode *pNode1, const Vec3 &o1, const StructNode *pNode2, const Vec3 &o2, const Vec3 &e1)
bool SetDriveCallerData(const char *name, DriveCallerRead *rf)
Definition: drive_.cc:1324
const Vec3 Zero3(0., 0., 0.)
Vec3 Cross(const Vec3 &v) const
Definition: matvec3.h:218
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual std::ostream & Restart(std::ostream &out) const
doublereal dGet(void) const
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
const StructNode *const pNode2
DriveCaller * Read(const DataManager *pDM, MBDynParser &HP, bool bDeferred)
const DriveHandler * pGetDrvHdl(void) const
Definition: dataman.h:340
bool nodedistdrive_set()
#define NO_OP
Definition: myassert.h:74
virtual DriveCaller * pCopy(void) const
Vec3 MulTV(const Vec3 &v) const
Definition: matvec3.cc:482
virtual doublereal dGetP(void) const
virtual bool bIsDifferentiable(void) const
Vec3 GetPosRel(const ReferenceFrame &rf)
Definition: mbpar.cc:1331
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
DriveHandler * pDrvHdl
Definition: drive.h:444
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310
Vec3 GetVecRel(const ReferenceFrame &rf)
Definition: mbpar.cc:1584
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser.
std::ostream & GetLogFile(void) const
Definition: dataman.h:326
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322
void NeedDM(const DataManager *pDM, MBDynParser &HP, bool bDeferred, const char *const name)
Definition: drive_.cc:1354
const std::string & GetName(void) const
Definition: withlab.cc:68
double doublereal
Definition: colamd.c:52
virtual ~NodeDistDriveCaller(void)
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
unsigned int GetLabel(void) const
Definition: withlab.cc:62
Node * ReadNode(MBDynParser &HP, Node::Type type) const
Definition: dataman3.cc:2309
const StructNode *const pNode1