MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
accj.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/struct/accj.cc,v 1.35 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 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 #include <limits>
35 
36 #include "accj.h"
37 
38 /* LinearAccelerationJoint - 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),
51 Dir(TmpDir),
52 dF(0.)
53 {
54  ASSERT(pNode != NULL);
55  ASSERT(Dir.Norm() > std::numeric_limits<doublereal>::epsilon());
56  Dir /= Dir.Norm();
57 }
58 
59 
60 /* Distruttore */
62 {
63  NO_OP;
64 }
65 
66 
67 /* Tipo di Joint */
69 {
71 }
72 
73 
74 /* Contributo al file di restart */
75 std::ostream& LinearAccelerationJoint::Restart(std::ostream& out) const
76 {
77  return out << "Not implemented yet!" << std::endl;
78 }
79 
80 
81 unsigned int LinearAccelerationJoint::iGetNumDof(void) const
82 {
83  return 2;
84 }
85 
86 
88 {
89  ASSERT(i == 0 || i == 1);
90  switch (i) {
91  case 0:
93  case 1:
94  return DofOrder::ALGEBRAIC;
95  default:
96  silent_cerr("invalid dof number" << std::endl);
98  }
99 }
100 
101 
103  integer* piNumCols) const
104 {
105  *piNumRows = 5;
106  *piNumCols = 5;
107 }
108 
109 
112  doublereal dCoef,
113  const VectorHandler& /* XCurr */ ,
114  const VectorHandler& /* XPrimeCurr */ )
115 {
116  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
117  WM.Resize(8, 0);
118 
119  integer iNodeRowIndex = pNode->iGetFirstRowIndex();
120  integer iNodeColIndex = pNode->iGetFirstColIndex();
121  integer iIndex = iGetFirstIndex();
122 
123  doublereal d = Dir.dGet(1);
124  WorkMat.PutItem(1, iIndex+1, iNodeColIndex+1, d);
125  WorkMat.PutItem(2, iNodeRowIndex+1, iIndex+2, d);
126  d = Dir.dGet(2);
127  WorkMat.PutItem(3, iIndex+1, iNodeColIndex+2, d);
128  WorkMat.PutItem(4, iNodeRowIndex+2, iIndex+2, d);
129  d = Dir.dGet(3);
130  WorkMat.PutItem(5, iIndex+1, iNodeColIndex+3, d);
131  WorkMat.PutItem(6, iNodeRowIndex+3, iIndex+2, d);
132 
133  WorkMat.PutItem(7, iIndex+1, iIndex+1, -dCoef);
134  WorkMat.PutItem(8, iIndex+2, iIndex+1, 1.);
135 
136  return WorkMat;
137 }
138 
139 
142  doublereal /* dCoef */ ,
143  const VectorHandler& XCurr,
144  const VectorHandler& XPrimeCurr)
145 {
146  WorkVec.Resize(5);
147 
148  integer iNodeRowIndex = pNode->iGetFirstRowIndex();
149  integer iIndex = iGetFirstIndex();
150 
151  doublereal dQ = XCurr(iIndex+1);
152  doublereal dQP = XPrimeCurr(iIndex+1);
153  dF = XCurr(iIndex+2);
154 
155  Vec3 V = pNode->GetVCurr();
156 
157  WorkVec.PutItem(1, iNodeRowIndex+1, -dF*Dir.dGet(1));
158  WorkVec.PutItem(2, iNodeRowIndex+2, -dF*Dir.dGet(2));
159  WorkVec.PutItem(3, iNodeRowIndex+3, -dF*Dir.dGet(3));
160  WorkVec.PutItem(4, iIndex+1, dQ-Dir.Dot(V));
161  WorkVec.PutItem(5, iIndex+2, dGet()-dQP);
162 
163  return WorkVec;
164 }
165 
166 
168 {
169  Joint::Output(OH.Joints(), "LinearAcc", GetLabel(),
170  Vec3(dF, 0., 0.), Zero3, Dir*dF, Zero3)
171  << " " << dGet() << std::endl;
172 }
173 
174 void
176  VectorHandler& X, VectorHandler& /* Xp */ ,
178 {
179  // TODO: hints (e.g. get drive, get orientation)
180  integer iIndex = iGetFirstIndex();
181 
182  // inherit initial velocity from node's
183  const Vec3& V(pNode->GetVCurr());
184  X(iIndex + 1) = Dir*V;
185 }
186 
187 /* funzioni usate nell'assemblaggio iniziale */
188 
190 {
191  return 0;
192 }
193 
194 
196  integer* piNumCols) const
197 {
198  *piNumRows = 0;
199  *piNumCols = 0;
200 }
201 
202 
203 /* Contributo allo jacobiano durante l'assemblaggio iniziale */
206  const VectorHandler& /* XCurr */ )
207 {
208  WorkMat.SetNullMatrix();
209  return WorkMat;
210 }
211 
212 
213 /* Contributo al residuo durante l'assemblaggio iniziale */
216  const VectorHandler& /* XCurr */ )
217 {
218  WorkVec.Resize(0);
219  return WorkVec;
220 }
221 
222 /* Dati privati */
223 unsigned int
225 {
226  return 2;
227 }
228 
229 /* Dati privati */
230 unsigned int
232 {
233  ASSERT(s != NULL);
234 
235  if (strcmp(s, "F") == 0) {
236  return 1;
237  }
238 
239  if (strcmp(s, "a") == 0) {
240  return 2;
241  }
242 
243  return 0;
244 }
245 
248 {
249  switch (i) {
250  case 1:
251  return dF;
252  case 2:
253  return dGet();
254  default:
256  }
257 }
258 
259 /* LinearAccelerationJoint - end */
260 
261 
262 /* AngularAccelerationJoint - begin */
263 
264 /* Costruttore non banale */
266  const DofOwner* pDO,
267  const StructNode* pN,
268  const Vec3& TmpDir,
269  const DriveCaller* pDC,
270  flag fOut)
271 : Elem(uL, fOut),
272 Joint(uL, pDO, fOut),
273 DriveOwner(pDC),
274 pNode(pN),
275 Dir(TmpDir),
276 dM(0.)
277 {
278  ASSERT(pNode != NULL);
279  ASSERT(Dir.Norm() > std::numeric_limits<doublereal>::epsilon());
280  Dir /= Dir.Norm();
281 }
282 
283 
284 /* Distruttore */
286 {
287  NO_OP;
288 }
289 
290 
291 /* Tipo di Joint */
293 {
295 }
296 
297 
298 /* Contributo al file di restart */
299 std::ostream& AngularAccelerationJoint::Restart(std::ostream& out) const
300 {
301  return out << "Not implemented yet!" << std::endl;
302 }
303 
304 
305 unsigned int AngularAccelerationJoint::iGetNumDof(void) const
306 {
307  return 2;
308 }
309 
310 
312 {
313  ASSERT(i == 0 || i == 1);
314  switch (i) {
315  case 0:
316  return DofOrder::DIFFERENTIAL;
317  case 1:
318  return DofOrder::ALGEBRAIC;
319  default:
320  silent_cerr("invalid dof number" << std::endl);
322  }
323 }
324 
325 
327  integer* piNumCols) const
328 {
329  *piNumRows = 5;
330  *piNumCols = 5;
331 }
332 
333 
336  doublereal dCoef,
337  const VectorHandler& /* XCurr */ ,
338  const VectorHandler& /* XPrimeCurr */ )
339 {
340  SparseSubMatrixHandler& WM = WorkMat.SetSparse();
341  WM.Resize(8, 0);
342 
343  integer iNodeRowIndex = pNode->iGetFirstRowIndex();
344  integer iNodeColIndex = pNode->iGetFirstColIndex();
345  integer iIndex = iGetFirstIndex();
346 
347  Vec3 TmpDir = pNode->GetRRef()*Dir;
348 
349  doublereal d = TmpDir.dGet(1);
350  WorkMat.PutItem(1, iIndex+1, iNodeColIndex+4, d);
351  WorkMat.PutItem(2, iNodeRowIndex+4, iIndex+2, d);
352  d = TmpDir.dGet(2);
353  WorkMat.PutItem(3, iIndex+1, iNodeColIndex+5, d);
354  WorkMat.PutItem(4, iNodeRowIndex+5, iIndex+2, d);
355  d = TmpDir.dGet(3);
356  WorkMat.PutItem(5, iIndex+1, iNodeColIndex+6, d);
357  WorkMat.PutItem(6, iNodeRowIndex+6, iIndex+2, d);
358 
359  WorkMat.PutItem(7, iIndex+1, iIndex+1, -dCoef);
360  WorkMat.PutItem(8, iIndex+2, iIndex+1, 1.);
361 
362  return WorkMat;
363 }
364 
365 
368  doublereal /* dCoef */ ,
369  const VectorHandler& XCurr,
370  const VectorHandler& XPrimeCurr)
371 {
372  WorkVec.Resize(5);
373 
374  integer iNodeRowIndex = pNode->iGetFirstRowIndex();
375  integer iIndex = iGetFirstIndex();
376 
377  doublereal dQ = XCurr(iIndex+1);
378  doublereal dQP = XPrimeCurr(iIndex+1);
379  dM = XCurr(iIndex+2);
380 
381  Vec3 W = pNode->GetWCurr();
382  Vec3 TmpDir = pNode->GetRCurr()*Dir;
383 
384  WorkVec.PutItem(1, iNodeRowIndex+4, -dM*TmpDir.dGet(1));
385  WorkVec.PutItem(2, iNodeRowIndex+5, -dM*TmpDir.dGet(2));
386  WorkVec.PutItem(3, iNodeRowIndex+6, -dM*TmpDir.dGet(3));
387  WorkVec.PutItem(4, iIndex+1, dQ-TmpDir.Dot(W));
388  WorkVec.PutItem(5, iIndex+2, dGet()-dQP);
389 
390  return WorkVec;
391 }
392 
393 
395 {
396  Joint::Output(OH.Joints(), "AngularAcc", GetLabel(),
397  Vec3(dM, 0., 0.), Zero3, Dir*dM, Zero3)
398  << " " << dGet() << std::endl;
399 }
400 
401 void
403  VectorHandler& X, VectorHandler& /* Xp */ ,
405 {
406  // TODO: hints (e.g. get drive, get orientation)
407  integer iIndex = iGetFirstIndex();
408 
409  // inherit initial angular velocity from node's
410  const Vec3& W(pNode->GetWCurr());
411  Vec3 TmpDir(pNode->GetRCurr()*Dir);
412  X(iIndex + 1) = TmpDir*W;
413 }
414 
415 /* funzioni usate nell'assemblaggio iniziale */
417 {
418  return 0;
419 }
420 
421 
423  integer* piNumCols) const
424 {
425  *piNumRows = 0;
426  *piNumCols = 0;
427 }
428 
429 
430 /* Contributo allo jacobiano durante l'assemblaggio iniziale */
433  const VectorHandler& /* XCurr */ )
434 {
435  WorkMat.SetNullMatrix();
436  return WorkMat;
437 }
438 
439 
440 /* Contributo al residuo durante l'assemblaggio iniziale */
443  const VectorHandler& /* XCurr */ )
444 {
445  WorkVec.Resize(0);
446  return WorkVec;
447 }
448 
449 /* Dati privati */
450 unsigned int
452 {
453  return 2;
454 }
455 
456 /* Dati privati */
457 unsigned int
459 {
460  ASSERT(s != NULL);
461 
462  if (strcmp(s, "M") == 0) {
463  return 1;
464  }
465 
466  if (strcmp(s, "wp") == 0) {
467  return 2;
468  }
469 
470  return 0;
471 }
472 
475 {
476  switch (i) {
477  case 1:
478  return dM;
479  case 2:
480  return dGet();
481  default:
483  }
484 }
485 
486 /* AngularAccelerationJoint - end */
DofOrder::Order GetDofType(unsigned int i) const
Definition: accj.cc:311
virtual unsigned int iGetNumPrivData(void) const
Definition: accj.cc:451
virtual std::ostream & Restart(std::ostream &out) const
Definition: accj.cc:299
Type
Definition: joint.h:66
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: accj.cc:102
const Vec3 Zero3(0., 0., 0.)
virtual void SetValue(DataManager *pDM, VectorHandler &, VectorHandler &, SimulationEntity::Hints *ph=0)
Definition: accj.cc:402
long int flag
Definition: mbdyn.h:43
virtual const Mat3x3 & GetRRef(void) const
Definition: strnode.h:1006
virtual unsigned int iGetNumPrivData(void) const
Definition: accj.cc:224
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal dF
Definition: accj.h:48
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: accj.cc:458
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
doublereal Norm(void) const
Definition: matvec3.h:263
virtual doublereal dGetPrivData(unsigned int i) const
Definition: accj.cc:474
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: accj.cc:195
doublereal dGet(void) const
Definition: drive.cc:671
VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: accj.cc:335
#define NO_OP
Definition: myassert.h:74
std::vector< Hint * > Hints
Definition: simentity.h:89
const StructNode * pNode
Definition: accj.h:46
virtual Joint::Type GetJointType(void) const
Definition: accj.cc:68
virtual void PutItem(integer iSubRow, integer iRow, const doublereal &dCoef)
Definition: submat.h:1445
void Resize(integer iNewRow, integer iNewCol)
Definition: submat.cc:1053
void WorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: accj.cc:326
virtual Joint::Type GetJointType(void) const
Definition: accj.cc:292
virtual unsigned int iGetNumDof(void) const
Definition: accj.cc:81
VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: accj.cc:111
void PutItem(integer iSubIt, integer iRow, integer iCol, const doublereal &dCoef)
Definition: submat.h:997
~LinearAccelerationJoint(void)
Definition: accj.cc:61
virtual doublereal dGetPrivData(unsigned int i) const
Definition: accj.cc:247
const StructNode * pNode
Definition: accj.h:126
virtual unsigned int iGetNumDof(void) const
Definition: accj.cc:305
void SetNullMatrix(void)
Definition: submat.h:1159
DofOrder::Order GetDofType(unsigned int i) const
Definition: accj.cc:87
const doublereal & dGet(unsigned short int iRow) const
Definition: matvec3.h:285
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: accj.cc:141
SubVectorHandler & InitialAssRes(SubVectorHandler &WorkVec, const VectorHandler &XCurr)
Definition: accj.cc:442
virtual integer iGetFirstRowIndex(void) const
Definition: node.cc:82
virtual unsigned int iGetInitialNumDof(void) const
Definition: accj.cc:416
~AngularAccelerationJoint(void)
Definition: accj.cc:285
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
virtual unsigned int iGetInitialNumDof(void) const
Definition: accj.cc:189
virtual void SetValue(DataManager *pDM, VectorHandler &, VectorHandler &, SimulationEntity::Hints *ph=0)
Definition: accj.cc:175
std::ostream & Joints(void) const
Definition: output.h:443
#define ASSERT(expression)
Definition: colamd.c:977
virtual void InitialWorkSpaceDim(integer *piNumRows, integer *piNumCols) const
Definition: accj.cc:422
void Output(OutputHandler &OH) const
Definition: accj.cc:394
Definition: elem.h:75
virtual std::ostream & Restart(std::ostream &out) const
Definition: accj.cc:75
void Output(OutputHandler &OH) const
Definition: accj.cc:167
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: accj.cc:231
Definition: joint.h:50
VariableSubMatrixHandler & InitialAssJac(VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
Definition: accj.cc:432
SparseSubMatrixHandler & SetSparse(void)
Definition: submat.h:1178
AngularAccelerationJoint(unsigned int uL, const DofOwner *pDO, const StructNode *pN, const Vec3 &TmpDir, const DriveCaller *pDC, flag fOut)
Definition: accj.cc:265
virtual integer iGetFirstIndex(void) const
Definition: dofown.h:127
SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &XCurr, const VectorHandler &XPrimeCurr)
Definition: accj.cc:367
double doublereal
Definition: colamd.c:52
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
LinearAccelerationJoint(unsigned int uL, const DofOwner *pDO, const StructNode *pN, const Vec3 &TmpDir, const DriveCaller *pDC, flag fOut)
Definition: accj.cc:41
SubVectorHandler & InitialAssRes(SubVectorHandler &WorkVec, const VectorHandler &XCurr)
Definition: accj.cc:215
long int integer
Definition: colamd.c:51
unsigned int GetLabel(void) const
Definition: withlab.cc:62
VariableSubMatrixHandler & InitialAssJac(VariableSubMatrixHandler &WorkMat, const VectorHandler &XCurr)
Definition: accj.cc:205
virtual void Resize(integer iNewSize)=0
virtual integer iGetFirstColIndex(void) const
Definition: node.cc:88