MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
drvj.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/drvj.cc,v 1.30 2017/01/12 14:46:43 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 /* Giunti di velocita' imposta */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 #include "drvj.h"
37 
38 /* LinearVelocity - begin */
39 
40 /* Costruttore non banale */
42  const DofOwner* pDO,
43  const StructNode* pN,
44  const Vec3& TmpDir,
45  const DriveCaller* pDC,
46  flag fOut)
47 : Elem(uL, fOut),
48 Joint(uL, pDO, fOut),
49 DriveOwner(pDC),
50 pNode(pN), Dir(TmpDir), dF(0.)
51 {
52  NO_OP;
53 }
54 
55 
56 /* Distruttore */
58 {
59  NO_OP;
60 }
61 
62 /* Contributo al file di restart */
63 std::ostream& LinearVelocityJoint::Restart(std::ostream& out) const
64 {
65  Joint::Restart(out) << ", linear velocity, " << pNode->GetLabel()
66  << ", reference, global, ",
67  Dir.Write(out, ", ") << ", ";
68  return pGetDriveCaller()->Restart(out) << ';' << std::endl;
69 }
70 
71 /* dati privati */
72 unsigned int
74 {
75  return 1;
76 }
77 
78 unsigned int
80 {
81  ASSERT(s != NULL);
82 
83  if (strcmp(s, "v") == 0) {
84  return 1;
85  }
86 
87  return 0;
88 }
89 
91 LinearVelocityJoint::dGetPrivData(unsigned int i) const
92 {
93  ASSERT(i == 1);
94 
95  return dGet();
96 }
97 
100  doublereal /* dCoef */ ,
101  const VectorHandler& /* XCurr */ ,
102  const VectorHandler& /* XPrimeCurr */ )
103 {
104  DEBUGCOUT("Entering LinearVelocityJoint::AssJac()" << std::endl);
105 
106  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
107  WM.ResizeReset(6, 0);
108 
109  integer iFirstPositionIndex = pNode->iGetFirstPositionIndex();
110  integer iFirstMomentumIndex = pNode->iGetFirstMomentumIndex();
111  integer iFirstReactionIndex = iGetFirstIndex();
112 
113  for (int iCnt = 1; iCnt <= 3; iCnt++) {
114  doublereal d = Dir.dGet(iCnt);
115  WM.PutItem(iCnt, iFirstMomentumIndex+iCnt,
116  iFirstReactionIndex+1, d);
117  WM.PutItem(3+iCnt, iFirstReactionIndex+1,
118  iFirstPositionIndex+iCnt, d);
119  }
120 
121  return WorkMat;
122 }
123 
124 
127  doublereal /* dCoef */ ,
128  const VectorHandler& XCurr,
129  const VectorHandler& /* XPrimeCurr */ )
130 {
131  DEBUGCOUT("Entering LinearVelocityJoint::AssRes()" << std::endl);
132 
133  /* Dimensiona e resetta la matrice di lavoro */
134  integer iNumRows = 0;
135  integer iNumCols = 0;
136  this->WorkSpaceDim(&iNumRows, &iNumCols);
137  WorkVec.ResizeReset(iNumRows);
138 
139  /* Indici */
140  // integer iFirstPositionIndex = pNode->iGetFirstPositionIndex();
141  integer iFirstMomentumIndex = pNode->iGetFirstMomentumIndex();
142  integer iFirstReactionIndex = iGetFirstIndex();
143 
144  /* Indici del nodo */
145  for (int iCnt = 1; iCnt <= 3; iCnt++) {
146  WorkVec.PutRowIndex(iCnt, iFirstMomentumIndex+iCnt);
147  }
148 
149  WorkVec.PutRowIndex(4, iFirstReactionIndex+1);
150 
151  /* Aggiorna i dati propri */
152  dF = XCurr(iFirstReactionIndex+1);
153 
154  /* Recupera i dati */
155  Vec3 vNode(pNode->GetVCurr());
156 
157 
158  /* Equazioni di equilibrio, nodo 1 */
159  WorkVec.Add(1, -Dir*dF);
160 
161 
162  /* Equazione di vincolo di velocita' */
163  doublereal dv0 = dGet();
164  WorkVec.PutCoef(4, dv0-Dir.Dot(vNode));
165 
166  return WorkVec;
167 }
168 
169 
171 {
172  if (bToBeOutput()) {
173  Joint::Output(OH.Joints(), "LinearVelocity", GetLabel(),
174  Vec3(dF, 0., 0.), Zero3, Dir*dF, Zero3)
175  << " " << Dir << " " << dGet() << std::endl;
176  }
177 }
178 
179 
180 /* Contributo allo jacobiano durante l'assemblaggio iniziale */
183  const VectorHandler& /* XCurr */ )
184 {
185  DEBUGCOUT("Entering LinearVelocityJoint::InitialAssJac()" << std::endl);
186 
187  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
188  WM.ResizeReset(6, 0);
189 
190  integer iFirstVelocityIndex = pNode->iGetFirstPositionIndex()+6;
191  integer iFirstReactionIndex = iGetFirstIndex();
192 
193  for (int iCnt = 1; iCnt <= 3; iCnt++) {
194  doublereal d = Dir.dGet(iCnt);
195  WM.PutItem(iCnt, iFirstVelocityIndex+iCnt,
196  iFirstReactionIndex+1, d);
197  WM.PutItem(3+iCnt, iFirstReactionIndex+1,
198  iFirstVelocityIndex+iCnt, d);
199  }
200 
201  return WorkMat;
202 }
203 
204 
205 /* Contributo al residuo durante l'assemblaggio iniziale */
208  const VectorHandler& XCurr)
209 {
210  DEBUGCOUT("Entering LinearVelocityJoint::InitialAssRes()" << std::endl);
211 
212  /* Dimensiona e resetta la matrice di lavoro */
213  integer iNumRows = 0;
214  integer iNumCols = 0;
215  this->InitialWorkSpaceDim(&iNumRows, &iNumCols);
216  WorkVec.ResizeReset(iNumRows);
217 
218  /* Indici */
219  integer iFirstVelocityIndex = pNode->iGetFirstPositionIndex()+6;
220  integer iFirstReactionIndex = iGetFirstIndex();
221 
222  /* Indici del nodo */
223  for (int iCnt = 1; iCnt <= 3; iCnt++) {
224  WorkVec.PutRowIndex(iCnt, iFirstVelocityIndex+iCnt);
225  }
226 
227  WorkVec.PutRowIndex(4, iFirstReactionIndex+1);
228 
229  /* Aggiorna i dati propri */
230  dF = XCurr(iFirstReactionIndex+1);
231 
232  /* Recupera i dati */
233  Vec3 vNode(pNode->GetVCurr());
234 
235 
236  /* Equazioni di equilibrio, nodo 1 */
237  WorkVec.Add(1, -Dir*dF);
238 
239 
240  /* Equazione di vincolo di velocita' */
241  doublereal dv0 = dGet();
242  WorkVec.PutCoef(4, dv0-Dir.Dot(vNode));
243 
244  return WorkVec;
245 }
246 
247 /* LinearVelocity - end */
248 
249 
250 /* AngularVelocity - begin */
251 
252 /* Costruttore non banale */
254  const DofOwner* pDO,
255  const StructNode* pN,
256  const Vec3& TmpDir,
257  const DriveCaller* pDC,
258  flag fOut)
259 : Elem(uL, fOut),
260 Joint(uL, pDO, fOut),
261 DriveOwner(pDC),
262 pNode(pN), Dir(TmpDir), dM(0.)
263 {
264  NO_OP;
265 }
266 
267 
268 /* Distruttore */
270 {
271  NO_OP;
272 }
273 
274 
275 /* Contributo al file di restart */
276 std::ostream& AngularVelocityJoint::Restart(std::ostream& out) const
277 {
278  Joint::Restart(out) << ", angular velocity, "
279  << pNode->GetLabel() << ", reference, node, ",
280  Dir.Write(out, ", ") << ", ";
281  return pGetDriveCaller()->Restart(out) << ';' << std::endl;
282 }
283 
284 /* dati privati */
285 unsigned int
287 {
288  return 1;
289 }
290 
291 unsigned int
293 {
294  ASSERT(s != NULL);
295 
296  if (strcmp(s, "w") == 0) {
297  return 1;
298  }
299 
300  return 0;
301 }
302 
305 {
306  ASSERT(i == 1);
307 
308  return dGet();
309 }
310 
313  doublereal dCoef,
314  const VectorHandler& /* XCurr */ ,
315  const VectorHandler& /* XPrimeCurr */ )
316 {
317  DEBUGCOUT("Entering AngularVelocityJoint::AssJac()" << std::endl);
318 
319  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
320  WM.ResizeReset(12, 0);
321 
322  integer iFirstPositionIndex = pNode->iGetFirstPositionIndex()+3;
323  integer iFirstMomentumIndex = pNode->iGetFirstMomentumIndex()+3;
324  integer iFirstReactionIndex = iGetFirstIndex();
325 
326  Vec3 TmpDir(pNode->GetRRef()*Dir);
327 
328  for (int iCnt = 1; iCnt <= 3; iCnt++) {
329  doublereal d = TmpDir.dGet(iCnt);
330  WM.PutItem(iCnt, iFirstMomentumIndex+iCnt,
331  iFirstReactionIndex+1, d);
332  WM.PutItem(3+iCnt, iFirstReactionIndex+1,
333  iFirstPositionIndex+iCnt, d);
334  }
335 
336  WM.PutCross(7, iFirstMomentumIndex,
337  iFirstPositionIndex, TmpDir*(-dM*dCoef));
338 
339  return WorkMat;
340 }
341 
342 
345  doublereal /* dCoef */ ,
346  const VectorHandler& XCurr,
347  const VectorHandler& /* XPrimeCurr */ )
348 {
349  DEBUGCOUT("Entering AngularVelocityJoint::AssRes()" << std::endl);
350 
351  /* Dimensiona e resetta la matrice di lavoro */
352  integer iNumRows = 0;
353  integer iNumCols = 0;
354  this->WorkSpaceDim(&iNumRows, &iNumCols);
355  WorkVec.ResizeReset(iNumRows);
356 
357  /* Indici */
358  integer iFirstMomentumIndex = pNode->iGetFirstMomentumIndex()+3;
359  integer iFirstReactionIndex = iGetFirstIndex();
360 
361  /* Indici del nodo */
362  for (int iCnt = 1; iCnt <= 3; iCnt++) {
363  WorkVec.PutRowIndex(iCnt, iFirstMomentumIndex+iCnt);
364  }
365 
366  WorkVec.PutRowIndex(4, iFirstReactionIndex+1);
367 
368  /* Aggiorna i dati propri */
369  dM = XCurr(iFirstReactionIndex+1);
370 
371  /* Recupera i dati */
372  Vec3 Omega(pNode->GetWCurr());
373  Vec3 TmpDir(pNode->GetRCurr()*Dir);
374 
375  /* Equazioni di equilibrio, nodo 1 */
376  WorkVec.Add(1, TmpDir*(-dM));
377 
378 
379  /* Equazione di vincolo di velocita' */
380  doublereal dw0 = dGet();
381  WorkVec.PutCoef(4, dw0-TmpDir.Dot(Omega));
382 
383  return WorkVec;
384 }
385 
386 
388 {
389  if(bToBeOutput()) {
390  Vec3 Tmp(pNode->GetRCurr()*Dir);
391 
392  Joint::Output(OH.Joints(), "AngularVelocity", GetLabel(),
393  Zero3, Vec3(dM, 0., 0.), Zero3, Tmp*dM)
394  << " " << Tmp << " " << dGet() << std::endl;
395  }
396 }
397 
398 
399 /* Contributo allo jacobiano durante l'assemblaggio iniziale */
402  const VectorHandler& /* XCurr */ )
403 {
404  DEBUGCOUT("Entering AngularVelocityJoint::InitialAssJac()" << std::endl);
405 
406  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
407  WM.ResizeReset(15, 0);
408 
409  integer iFirstPositionIndex = pNode->iGetFirstPositionIndex()+3;
410  integer iFirstVelocityIndex = iFirstPositionIndex+6;
411  integer iFirstReactionIndex = iGetFirstIndex();
412 
413  Vec3 Tmp(Dir.Cross(pNode->GetWRef()));
414  for(int iCnt = 1; iCnt <= 3; iCnt++)
415  {
416  doublereal d = Dir.dGet(iCnt);
417  WM.PutItem(iCnt, iFirstVelocityIndex+iCnt,
418  iFirstReactionIndex+1, d);
419  WM.PutItem(3+iCnt, iFirstReactionIndex+1,
420  iFirstVelocityIndex+iCnt, d);
421  WM.PutItem(6+iCnt, iFirstReactionIndex+1,
422  iFirstPositionIndex+iCnt, Tmp.dGet(iCnt));
423  }
424 
425  WM.PutCross(10, iFirstVelocityIndex, iFirstPositionIndex, Dir*(-dM));
426 
427  return WorkMat;
428 }
429 
430 
431 /* Contributo al residuo durante l'assemblaggio iniziale */
434  const VectorHandler& XCurr)
435 {
436  DEBUGCOUT("Entering AngularVelocityJoint::InitialAssRes()" << std::endl);
437 
438  /* Dimensiona e resetta la matrice di lavoro */
439  integer iNumRows = 0;
440  integer iNumCols = 0;
441  this->InitialWorkSpaceDim(&iNumRows, &iNumCols);
442  WorkVec.ResizeReset(iNumRows);
443 
444  /* Indici */
445  integer iFirstVelocityIndex = pNode->iGetFirstPositionIndex()+9;
446  integer iFirstReactionIndex = iGetFirstIndex();
447 
448  /* Indici del nodo */
449  for(int iCnt = 1; iCnt <= 3; iCnt++)
450  {
451  WorkVec.PutRowIndex(iCnt, iFirstVelocityIndex+iCnt);
452  }
453 
454  WorkVec.PutRowIndex(4, iFirstReactionIndex+1);
455 
456  /* Aggiorna i dati propri */
457  dM = XCurr(iFirstReactionIndex+1);
458 
459  /* Recupera i dati */
460  Vec3 Omega(pNode->GetWCurr());
461 
462  /* Equazioni di equilibrio, nodo 1 */
463  WorkVec.Add(1, -Dir*dM);
464 
465  /* Equazione di vincolo di velocita' */
466  doublereal dw0 = dGet();
467  WorkVec.PutCoef(4, dw0-Dir.Dot(Omega));
468 
469  return WorkVec;
470 }
471 
472 /* AngularVelocity - end */
virtual unsigned int iGetNumPrivData(void) const
Definition: drvj.cc:73
const StructNode * pNode
Definition: drvj.h:46
AngularVelocityJoint(unsigned int uL, const DofOwner *pDO, const StructNode *pN, const Vec3 &TmpDir, const DriveCaller *pDC, flag fOut)
Definition: drvj.cc:253
virtual doublereal dGetPrivData(unsigned int i=0) const
Definition: drvj.cc:304
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: drvj.h:98
VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: drvj.cc:312
const Vec3 Zero3(0., 0., 0.)
Vec3 Cross(const Vec3 &v) const
Definition: matvec3.h:218
std::ostream & Write(std::ostream &out, const char *sFill=" ") const
Definition: matvec3.cc:738
doublereal dF
Definition: drvj.h:48
long int flag
Definition: mbdyn.h:43
virtual const Mat3x3 & GetRRef(void) const
Definition: strnode.h:1006
virtual bool bToBeOutput(void) const
Definition: output.cc:890
Definition: matvec3.h:98
virtual void ResizeReset(integer)
Definition: vh.cc:55
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
doublereal dGet(void) const
Definition: drive.cc:671
~LinearVelocityJoint(void)
Definition: drvj.cc:57
void ResizeReset(integer iNewRow, integer iNewCol)
Definition: submat.cc:1084
VariableSubMatrixHandler & InitialAssJac(VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
Definition: drvj.cc:182
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: drvj.h:191
virtual const Vec3 & GetWRef(void) const
Definition: strnode.h:1024
#define NO_OP
Definition: myassert.h:74
void PutCross(integer iSubIt, integer iFirstRow, integer iFirstCol, const Vec3 &v)
Definition: submat.cc:1236
virtual std::ostream & Restart(std::ostream &out) const =0
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: drvj.cc:292
virtual void PutRowIndex(integer iSubRow, integer iRow)=0
void PutItem(integer iSubIt, integer iRow, integer iCol, const doublereal &dCoef)
Definition: submat.h:997
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: drvj.h:169
virtual unsigned int iGetNumPrivData(void) const
Definition: drvj.cc:286
SubVectorHandler & InitialAssRes(SubVectorHandler &WorkVec, const VectorHandler &XCurr)
Definition: drvj.cc:433
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: drvj.h:79
virtual std::ostream & Restart(std::ostream &out) const
Definition: drvj.cc:63
LinearVelocityJoint(unsigned int uL, const DofOwner *pDO, const StructNode *pN, const Vec3 &TmpDir, const DriveCaller *pDC, flag fOut)
Definition: drvj.cc:41
const doublereal & dGet(unsigned short int iRow) const
Definition: matvec3.h:285
virtual doublereal dGetPrivData(unsigned int i=0) const
Definition: drvj.cc:91
#define DEBUGCOUT(msg)
Definition: myassert.h:232
~AngularVelocityJoint(void)
Definition: drvj.cc:269
virtual integer iGetFirstMomentumIndex(void) const =0
virtual integer iGetFirstPositionIndex(void) const
Definition: strnode.h:452
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
virtual std::ostream & Restart(std::ostream &out) const
Definition: joint.h:195
std::ostream & Joints(void) const
Definition: output.h:443
SubVectorHandler & InitialAssRes(SubVectorHandler &WorkVec, const VectorHandler &XCurr)
Definition: drvj.cc:207
virtual std::ostream & Restart(std::ostream &out) const
Definition: drvj.cc:276
#define ASSERT(expression)
Definition: colamd.c:977
virtual void PutCoef(integer iRow, const doublereal &dCoef)=0
DriveCaller * pGetDriveCaller(void) const
Definition: drive.cc:658
virtual void Add(integer iRow, const Vec3 &v)
Definition: vh.cc:63
VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: drvj.cc:99
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: drvj.cc:126
Definition: elem.h:75
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: drvj.cc:344
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322
doublereal dM
Definition: drvj.h:138
Definition: joint.h:50
SparseSubMatrixHandler & SetSparse(void)
Definition: submat.h:1178
virtual integer iGetFirstIndex(void) const
Definition: dofown.h:127
const StructNode * pNode
Definition: drvj.h:136
double doublereal
Definition: colamd.c:52
void Output(OutputHandler &OH) const
Definition: drvj.cc:170
std::ostream & Output(std::ostream &out, const char *sJointName, unsigned int uLabel, const Vec3 &FLocal, const Vec3 &MLocal, const Vec3 &FGlobal, const Vec3 &MGlobal) const
Definition: joint.cc:138
long int integer
Definition: colamd.c:51
unsigned int GetLabel(void) const
Definition: withlab.cc:62
VariableSubMatrixHandler & InitialAssJac(VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
Definition: drvj.cc:401
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: drvj.cc:79
void Output(OutputHandler &OH) const
Definition: drvj.cc:387