MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
modelns.cc File Reference
#include "mbconfig.h"
#include <limits>
#include <cfloat>
#include "modelns.h"
#include "strnode.h"
#include "matvecexp.h"
#include "Rot.hh"
Include dependency graph for modelns.cc:

Go to the source code of this file.

Enumerations

enum  IDX_t {
  IDX1 = 1, IDX2 = 2, IDX3 = 3, NORM,
  SQUARE
}
 
enum  when_t { CURR = 0, PREV = 1 }
 

Functions

static const char * IDX2str (IDX_t IDX)
 
static const char * when2str (when_t when)
 
template<IDX_t IDX, when_t when>
static int position (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int distance (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int unitvec (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int angle (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int anglerel (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int velocity (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int vrel (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int angvel (const MathParser::MathArgs &args)
 
template<IDX_t IDX, when_t when>
static int angvrel (const MathParser::MathArgs &args)
 
template<bool p>
static int drive (const MathParser::MathArgs &args)
 
static int model_sf (const MathParser::MathArgs &args)
 
static int model_node (const MathParser::MathArgs &args)
 
template<bool unique>
static int model_elem (const MathParser::MathArgs &args)
 
static int model_curr (const MathParser::MathArgs &args)
 

Enumeration Type Documentation

enum IDX_t
Enumerator
IDX1 
IDX2 
IDX3 
NORM 
SQUARE 

Definition at line 43 of file modelns.cc.

43  {
44  IDX1 = 1,
45  IDX2 = 2,
46  IDX3 = 3,
47  NORM,
48  SQUARE
49 };
Definition: modelns.cc:47
Definition: modelns.cc:45
Definition: modelns.cc:46
Definition: modelns.cc:44
enum when_t
Enumerator
CURR 
PREV 

Definition at line 74 of file modelns.cc.

74  {
75  CURR = 0,
76  PREV = 1
77 };
Definition: modelns.cc:75
Definition: modelns.cc:76

Function Documentation

template<IDX_t IDX, when_t when>
static int angle ( const MathParser::MathArgs args)
static

Definition at line 313 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, StructNode::GetRCurr(), StructNode::GetRPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, RotManip::VecRot(), and when2str().

314 {
315  ASSERT(args.size() == 1 + 1 + 1);
316  ASSERT(args[0]->Type() == MathParser::AT_REAL);
317  ASSERT(args[1]->Type() == MathParser::AT_INT);
318  ASSERT(args[2]->Type() == MathParser::AT_PRIVATE);
319 
320  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
321  ASSERT(out != 0);
322 
323  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
324  ASSERT(arg1 != 0);
325  ASSERT((*arg1)() >= 0);
326 
327  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[2]);
328  ASSERT(dm != 0);
329 
330  unsigned uLabel = unsigned((*arg1)());
331 
332  const StructNode *pNode = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel);
333  if (pNode == 0) {
334  silent_cerr("model::angle" << when2str(when) << IDX2str(IDX)
335  << "(" << uLabel << "): "
336  "unable to find StructNode(" << uLabel << ")"
337  << std::endl);
339  }
340 
341  Vec3 phi;
342  switch (when) {
343  case CURR:
344  phi = RotManip::VecRot(pNode->GetRCurr());
345  break;
346 
347  case PREV:
348  phi = RotManip::VecRot(pNode->GetRPrev());
349  break;
350  }
351 
352  switch (IDX) {
353  case NORM:
354  *out = phi.Norm();
355  break;
356 
357  default:
358  *out = phi(IDX);
359  break;
360  }
361 
362  return 0;
363 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
doublereal Norm(void) const
Definition: matvec3.h:263
Definition: modelns.cc:75
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Mat3x3 & GetRPrev(void) const
Definition: strnode.h:1000
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int anglerel ( const MathParser::MathArgs args)
static

Definition at line 370 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, StructNode::GetRCurr(), StructNode::GetRPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, Mat3x3::MulTM(), NORM, Vec3::Norm(), PREV, RotManip::VecRot(), and when2str().

371 {
372  ASSERT(args.size() == 1 + 2 + 1);
373  ASSERT(args[0]->Type() == MathParser::AT_REAL);
374  ASSERT(args[1]->Type() == MathParser::AT_INT);
375  ASSERT(args[2]->Type() == MathParser::AT_INT);
376  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
377 
378  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
379  ASSERT(out != 0);
380 
381  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
382  ASSERT(arg1 != 0);
383  ASSERT((*arg1)() >= 0);
384 
385  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
386  ASSERT(arg2 != 0);
387  ASSERT((*arg2)() >= 0);
388 
389  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[3]);
390  ASSERT(dm != 0);
391 
392  unsigned uLabel1 = unsigned((*arg1)());
393  unsigned uLabel2 = unsigned((*arg2)());
394 
395  const StructNode *pNode1 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel1);
396  if (pNode1 == 0) {
397  silent_cerr("model::anglerel" << when2str(when) << IDX2str(IDX)
398  << "(" << uLabel1 << "," << uLabel2 << "): "
399  "unable to find StructNode(" << uLabel1 << ")"
400  << std::endl);
402  }
403 
404  const StructNode *pNode2 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel2);
405  if (pNode2 == 0) {
406  silent_cerr("model::anglerel" << when2str(when) << IDX2str(IDX)
407  << "(" << uLabel1 << "," << uLabel2 << "): "
408  "unable to find StructNode(" << uLabel2 << ")"
409  << std::endl);
411  }
412 
413  Vec3 phi;
414  switch (when) {
415  case CURR:
416  phi = RotManip::VecRot(pNode1->GetRCurr().MulTM(pNode2->GetRCurr()));
417  break;
418 
419  case PREV:
420  phi = RotManip::VecRot(pNode1->GetRPrev().MulTM(pNode2->GetRPrev()));
421  break;
422  }
423 
424  switch (IDX) {
425  case NORM:
426  *out = phi.Norm();
427  break;
428 
429  default:
430  *out = phi(IDX);
431  break;
432  }
433 
434  return 0;
435 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
virtual const Mat3x3 & GetRCurr(void) const
Definition: strnode.h:1012
doublereal Norm(void) const
Definition: matvec3.h:263
Definition: modelns.cc:75
Vec3 VecRot(const Mat3x3 &Phi)
Definition: Rot.cc:136
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Mat3x3 & GetRPrev(void) const
Definition: strnode.h:1000
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
Mat3x3 MulTM(const Mat3x3 &m) const
Definition: matvec3.cc:500

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int angvel ( const MathParser::MathArgs args)
static

Definition at line 579 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructNode::GetWCurr(), StructNode::GetWPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

580 {
581  ASSERT(args.size() == 1 + 1 + 1);
582  ASSERT(args[0]->Type() == MathParser::AT_REAL);
583  ASSERT(args[1]->Type() == MathParser::AT_INT);
584  ASSERT(args[2]->Type() == MathParser::AT_PRIVATE);
585 
586  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
587  ASSERT(out != 0);
588 
589  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
590  ASSERT(arg1 != 0);
591  ASSERT((*arg1)() >= 0);
592 
593  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[2]);
594  ASSERT(dm != 0);
595 
596  unsigned uLabel = unsigned((*arg1)());
597 
598  const StructNode *pNode = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel);
599  if (pNode == 0) {
600  silent_cerr("model::angvel" << when2str(when) << IDX2str(IDX)
601  << "(" << uLabel << "): "
602  "unable to find StructNode(" << uLabel << ")"
603  << std::endl);
605  }
606 
607  Vec3 w;
608  switch (when) {
609  case CURR:
610  w = pNode->GetWCurr();
611  break;
612 
613  case PREV:
614  w = pNode->GetWPrev();
615  break;
616  }
617 
618  switch (IDX) {
619  case NORM:
620  *out = w.Norm();
621  break;
622 
623  case SQUARE:
624  *out = w.Dot();
625  break;
626 
627  default:
628  *out = w(IDX);
629  break;
630  }
631 
632  return 0;
633 }
virtual const Vec3 & GetWPrev(void) const
Definition: strnode.h:1018
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int angvrel ( const MathParser::MathArgs args)
static

Definition at line 640 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructNode::GetWCurr(), StructNode::GetWPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

641 {
642  ASSERT(args.size() == 1 + 2 + 1);
643  ASSERT(args[0]->Type() == MathParser::AT_REAL);
644  ASSERT(args[1]->Type() == MathParser::AT_INT);
645  ASSERT(args[2]->Type() == MathParser::AT_INT);
646  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
647 
648  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
649  ASSERT(out != 0);
650 
651  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
652  ASSERT(arg1 != 0);
653  ASSERT((*arg1)() >= 0);
654 
655  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
656  ASSERT(arg2 != 0);
657  ASSERT((*arg2)() >= 0);
658 
659  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[3]);
660  ASSERT(dm != 0);
661 
662  unsigned uLabel1 = unsigned((*arg1)());
663  unsigned uLabel2 = unsigned((*arg2)());
664 
665  const StructNode *pNode1 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel1);
666  if (pNode1 == 0) {
667  silent_cerr("model::angvrel" << when2str(when) << IDX2str(IDX)
668  << "(" << uLabel1 << "," << uLabel2 << "): "
669  "unable to find StructNode(" << uLabel1 << ")"
670  << std::endl);
672  }
673 
674  const StructNode *pNode2 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel2);
675  if (pNode2 == 0) {
676  silent_cerr("model::angvrel" << when2str(when) << IDX2str(IDX)
677  << "(" << uLabel1 << "," << uLabel2 << "): "
678  "unable to find StructNode(" << uLabel2 << ")"
679  << std::endl);
681  }
682 
683  Vec3 w;
684  switch (when) {
685  case CURR:
686  w = pNode2->GetWCurr() - pNode1->GetWCurr();
687  break;
688 
689  case PREV:
690  w = pNode2->GetWPrev() - pNode1->GetWPrev();
691  break;
692  }
693 
694  switch (IDX) {
695  case NORM:
696  *out = w.Norm();
697  break;
698 
699  case SQUARE:
700  *out = w.Dot();
701  break;
702 
703  default:
704  *out = w(IDX);
705  break;
706  }
707 
708  return 0;
709 }
virtual const Vec3 & GetWPrev(void) const
Definition: strnode.h:1018
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Vec3 & GetWCurr(void) const
Definition: strnode.h:1030
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int distance ( const MathParser::MathArgs args)
static

Definition at line 160 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructDispNode::GetXCurr(), StructDispNode::GetXPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

161 {
162  ASSERT(args.size() == 1 + 2 + 1);
163  ASSERT(args[0]->Type() == MathParser::AT_REAL);
164  ASSERT(args[1]->Type() == MathParser::AT_INT);
165  ASSERT(args[2]->Type() == MathParser::AT_INT);
166  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
167 
168  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
169  ASSERT(out != 0);
170 
171  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
172  ASSERT(arg1 != 0);
173  ASSERT((*arg1)() >= 0);
174 
175  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
176  ASSERT(arg2 != 0);
177  ASSERT((*arg2)() >= 0);
178 
179  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[3]);
180  ASSERT(dm != 0);
181 
182  unsigned uLabel1 = unsigned((*arg1)());
183  unsigned uLabel2 = unsigned((*arg2)());
184 
185  const StructNode *pNode1 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel1);
186  if (pNode1 == 0) {
187  silent_cerr("model::distance" << when2str(when) << IDX2str(IDX)
188  << "(" << uLabel1 << "," << uLabel2 << "): "
189  "unable to find StructNode(" << uLabel1 << ")"
190  << std::endl);
192  }
193 
194  const StructNode *pNode2 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel2);
195  if (pNode2 == 0) {
196  silent_cerr("model::distance" << when2str(when) << IDX2str(IDX)
197  << "(" << uLabel1 << "," << uLabel2 << "): "
198  "unable to find StructNode(" << uLabel2 << ")"
199  << std::endl);
201  }
202 
203  Vec3 d;
204  switch (when) {
205  case CURR:
206  d = pNode2->GetXCurr() - pNode1->GetXCurr();
207  break;
208 
209  case PREV:
210  d = pNode2->GetXPrev() - pNode1->GetXPrev();
211  break;
212  }
213 
214  switch (IDX) {
215  case NORM:
216  *out = d.Norm();
217  break;
218 
219  case SQUARE:
220  *out = d.Dot();
221  break;
222 
223  default:
224  *out = d(IDX);
225  break;
226  }
227 
228  return 0;
229 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
virtual const Vec3 & GetXPrev(void) const
Definition: strnode.h:304
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310

Here is the call graph for this function:

template<bool p>
static int drive ( const MathParser::MathArgs args)
static

Definition at line 716 of file modelns.cc.

References MathParser::AF_CONST, ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, DriveCaller::bIsDifferentiable(), DriveCaller::dGet(), DriveCaller::dGetP(), MathParser::MathArg_t::IsFlag(), and MBDYN_EXCEPT_ARGS.

717 {
718  ASSERT(args.size() == 1 + 2 + 2);
719  ASSERT(args[0]->Type() == MathParser::AT_REAL);
720  ASSERT(args[1]->Type() == MathParser::AT_INT);
721  ASSERT(args[2]->Type() == MathParser::AT_REAL);
722  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
723  ASSERT(args[4]->Type() == MathParser::AT_PRIVATE);
724 
725  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
726  ASSERT(out != 0);
727 
728  MathParser::MathArgReal_t *arg_val = dynamic_cast<MathParser::MathArgReal_t *>(args[2]);
729  ASSERT(arg_val != 0);
730 
731  ModelNameSpace::MathArgDCPtr *arg_ptr = dynamic_cast<ModelNameSpace::MathArgDCPtr *>(args[3]);
732  ASSERT(arg_ptr != 0);
733  const DriveCaller *pDC = (*arg_ptr)();
734  if (pDC == 0) {
735  MathParser::MathArgInt_t *arg_label = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
736  ASSERT(arg_label != 0);
737  ASSERT((*arg_label)() >= 0);
738 
739  unsigned uLabel = unsigned((*arg_label)());
740 
741  ModelNameSpace::MathArgDM *arg_dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[4]);
742  ASSERT(arg_dm != 0);
743 
744  pDC = (*arg_dm)()->GetMBDynParser().GetDrive(uLabel);
745  if (pDC == 0) {
746  silent_cerr("model::drive(" << uLabel << ") not available"
747  << std::endl);
749  }
750 
751  if (p) {
752  if (!pDC->bIsDifferentiable()) {
753  silent_cerr("model::drivep(" << uLabel << ") not differentiable"
754  << std::endl);
756  }
757  }
758 
759  if (arg_label->IsFlag(MathParser::AF_CONST)) {
760  (*arg_ptr)() = pDC;
761  }
762  }
763 
764  doublereal val = (*arg_val)();
765  if (p) {
766  ASSERT(pDC->bIsDifferentiable());
767 
768  *out = pDC->dGetP(val);
769 
770  } else {
771  *out = pDC->dGet(val);
772  }
773 
774  return 0;
775 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual doublereal dGetP(const doublereal &dVar) const
Definition: drive.cc:499
virtual bool bIsDifferentiable(void) const
Definition: drive.h:495
#define ASSERT(expression)
Definition: colamd.c:977
virtual doublereal dGet(const doublereal &dVar) const =0
bool IsFlag(const MathParser::ArgFlag f) const
Definition: mathp.h:98
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

static const char* IDX2str ( IDX_t  IDX)
static

Definition at line 52 of file modelns.cc.

References IDX1, IDX2, IDX3, MBDYN_EXCEPT_ARGS, NORM, and SQUARE.

Referenced by angle(), anglerel(), angvel(), angvrel(), distance(), position(), unitvec(), velocity(), and vrel().

53 {
54  switch (IDX) {
55  case NORM:
56  return "";
57 
58  case SQUARE:
59  return "2";
60 
61  case IDX1:
62  return "<1>";
63 
64  case IDX2:
65  return "<2>";
66 
67  case IDX3:
68  return "<3>";
69  }
70 
72 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: modelns.cc:47
Definition: modelns.cc:45
Definition: modelns.cc:46
Definition: modelns.cc:44
static int model_curr ( const MathParser::MathArgs args)
static

Definition at line 1061 of file modelns.cc.

References ASSERT, MathParser::AT_PRIVATE, MathParser::AT_REAL, MathParser::AT_STRING, ModelNameSpace::GetCurrData(), and MBDYN_EXCEPT_ARGS.

Referenced by ModelNameSpace::ModelNameSpace().

1062 {
1063  ASSERT(args.size() == 1 + 1 + 2);
1064 
1065  ASSERT(args[0]->Type() == MathParser::AT_REAL);
1066  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
1067  ASSERT(out != 0);
1068 
1069  ASSERT(args[1]->Type() == MathParser::AT_STRING);
1070  MathParser::MathArgString_t *arg_name = dynamic_cast<MathParser::MathArgString_t *>(args[1]);
1071  ASSERT(arg_name != 0);
1072  const std::string& name = (*arg_name)();
1073 
1074  ASSERT(args[2]->Type() == MathParser::AT_PRIVATE);
1075  ModelNameSpace::MathArgMNS *arg_mns = dynamic_cast<ModelNameSpace::MathArgMNS *>(args[2]);
1076  ASSERT(arg_mns != 0);
1077  const ModelNameSpace *pMNS = (*arg_mns)();
1078 
1079  TypedValue value;
1080  if (!pMNS->GetCurrData(name, value)) {
1081  silent_cerr("model::current(" << name << ") not defined" << std::endl);
1083  }
1084 
1085  *out = value.GetReal();
1086 
1087  return 0;
1088 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
bool GetCurrData(const std::string &name, TypedValue &value) const
Definition: modelns.cc:2957
#define ASSERT(expression)
Definition: colamd.c:977

Here is the call graph for this function:

template<bool unique>
static int model_elem ( const MathParser::MathArgs args)
static

Definition at line 934 of file modelns.cc.

References MathParser::AF_CONST, ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, MathParser::AT_STRING, SimulationEntity::dGetPrivData(), SimulationEntity::iGetPrivDataIdx(), MathParser::MathArg_t::IsFlag(), MBDYN_EXCEPT_ARGS, MBDynParser::pDM, DataManager::pFindElem(), and psElemNames.

935 {
936  ASSERT(args.size() == 1 + 2 - unique + 4);
937 
938  static const unsigned int out_idx = 0;
939  static const unsigned int val_idx = 2 - (unique ? 1 : 0);
940  static const unsigned int type_idx = 3 - (unique ? 1 : 0);
941  static const unsigned int ptr_idx = 4 - (unique ? 1 : 0);
942  static const unsigned int idx_idx = 5 - (unique ? 1 : 0);
943  static const unsigned int dm_idx = 6 - (unique ? 1 : 0);
944 
945  ASSERT(args[out_idx]->Type() == MathParser::AT_REAL);
946  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[out_idx]);
947  ASSERT(out != 0);
948 
949  unsigned int idx = 0;
950  ModelNameSpace::MathArgSEIdx *arg_idx = dynamic_cast<ModelNameSpace::MathArgSEIdx *>(args[idx_idx]);
951  ASSERT(arg_idx != 0);
952 
953  ModelNameSpace::MathArgSEPtr *arg_ptr = dynamic_cast<ModelNameSpace::MathArgSEPtr *>(args[ptr_idx]);
954  ASSERT(arg_ptr != 0);
955  const SimulationEntity *pElem = (*arg_ptr)();
956 
957  if (pElem == 0) {
958  unsigned uLabel(-1);
959  bool bLabelConst(true);
960  if (!unique) {
961  static const unsigned int label_idx = 1; // undefined if unique == true
962 
963  ASSERT(args[label_idx]->Type() == MathParser::AT_INT);
964  MathParser::MathArgInt_t *arg_label = dynamic_cast<MathParser::MathArgInt_t *>(args[label_idx]);
965  ASSERT(arg_label != 0);
966  int iLabel = (*arg_label)();
967  if (iLabel < 0) {
968  silent_cerr("model::element: invalid element label " << iLabel << std::endl);
970  }
971  uLabel = unsigned(iLabel);
972  bLabelConst = arg_label->IsFlag(MathParser::AF_CONST);
973  }
974 
975  ASSERT(args[val_idx]->Type() == MathParser::AT_STRING);
976  MathParser::MathArgString_t *arg_val = dynamic_cast<MathParser::MathArgString_t *>(args[val_idx]);
977  ASSERT(arg_val != 0);
978  std::string v = (*arg_val)();
979 
980  ASSERT(args[type_idx]->Type() == MathParser::AT_PRIVATE);
981  ModelNameSpace::MathArgElem *arg_elem = dynamic_cast<ModelNameSpace::MathArgElem *>(args[type_idx]);
982  ASSERT(arg_elem != 0);
983  Elem::Type type = (*arg_elem)();
984 
985  ASSERT(args[dm_idx]->Type() == MathParser::AT_PRIVATE);
986  ModelNameSpace::MathArgDM *arg_dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[dm_idx]);
987  ASSERT(arg_dm != 0);
988  const DataManager *pDM = (*arg_dm)();
989 
990  pElem = pDM->pFindElem(type, uLabel);
991  if (pElem == 0) {
992  if (unique) {
993  silent_cerr("model::element: unable to find " << psElemNames[type] << std::endl);
994 
995  } else {
996  silent_cerr("model::element: unable to find " << psElemNames[type] << "(" << uLabel << ")" << std::endl);
997  }
999  }
1000 
1001  idx = pElem->iGetPrivDataIdx(v.c_str());
1002  if (idx == 0) {
1003  if (unique) {
1004  silent_cerr("model::element: " << psElemNames[type] << ": invalid private data \"" << v << "\"" << std::endl);
1005 
1006  } else {
1007  silent_cerr("model::element: " << psElemNames[type] << "(" << dynamic_cast<const Elem *>(pElem)->GetLabel() << "): invalid private data \"" << v << "\"" << std::endl);
1008  }
1010  }
1011 
1012  if (unique || bLabelConst) {
1013  (*arg_ptr)() = pElem;
1014 
1015  /* NOTE: only set idx if element label is const,
1016  * otherwise a different element could have a different idx
1017  * for the same string */
1018  if (arg_val->IsFlag(MathParser::AF_CONST)) {
1019  (*arg_idx)() = idx;
1020  }
1021  }
1022 
1023  } else {
1024  idx = (*arg_idx)();
1025 
1026  /* NOTE: pElem is saved, so we presume it was constant;
1027  * apparently, idx was not constant, and we need to recompute it */
1028  if (idx == 0) {
1029  ASSERT(!arg_idx->IsFlag(MathParser::AF_CONST));
1030 
1031  MathParser::MathArgString_t *arg_val = dynamic_cast<MathParser::MathArgString_t *>(args[val_idx]);
1032  ASSERT(arg_val != 0);
1033  std::string v = (*arg_val)();
1034 
1035  idx = pElem->iGetPrivDataIdx(v.c_str());
1036  if (idx == 0) {
1037  ModelNameSpace::MathArgElem *arg_type = dynamic_cast<ModelNameSpace::MathArgElem *>(args[type_idx]);
1038  ASSERT(arg_type != 0);
1039  Elem::Type type = (*arg_type)();
1040 
1041  if (unique) {
1042  silent_cerr("model::element: " << psElemNames[type] << ": invalid private data \"" << v << "\"" << std::endl);
1043 
1044  } else {
1045  silent_cerr("model::element: " << psElemNames[type] << "(" << dynamic_cast<const Elem *>(pElem)->GetLabel() << "): invalid private data \"" << v << "\"" << std::endl);
1046  }
1048  }
1049  }
1050  }
1051 
1052  *out = pElem->dGetPrivData(idx);
1053 
1054  return 0;
1055 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Elem * pFindElem(Elem::Type Typ, unsigned int uElem, unsigned int iDeriv) const
Definition: elman.cc:650
#define ASSERT(expression)
Definition: colamd.c:977
Type
Definition: elem.h:91
const char * psElemNames[]
Definition: enums.cc:39
bool IsFlag(const MathParser::ArgFlag f) const
Definition: mathp.h:98

Here is the call graph for this function:

static int model_node ( const MathParser::MathArgs args)
static

Definition at line 832 of file modelns.cc.

References MathParser::AF_CONST, ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, MathParser::AT_STRING, SimulationEntity::dGetPrivData(), SimulationEntity::iGetPrivDataIdx(), MathParser::MathArg_t::IsFlag(), MBDYN_EXCEPT_ARGS, MBDynParser::pDM, DataManager::pFindNode(), and psNodeNames.

Referenced by ModelNameSpace::ModelNameSpace().

833 {
834  ASSERT(args.size() == 1 + 2 + 4);
835  ASSERT(args[0]->Type() == MathParser::AT_REAL);
836  ASSERT(args[1]->Type() == MathParser::AT_INT);
837  ASSERT(args[2]->Type() == MathParser::AT_STRING);
838  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
839  ASSERT(args[4]->Type() == MathParser::AT_PRIVATE);
840  ASSERT(args[5]->Type() == MathParser::AT_PRIVATE);
841  ASSERT(args[6]->Type() == MathParser::AT_PRIVATE);
842 
843  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
844  ASSERT(out != 0);
845 
846  unsigned int idx = 0;
847  ModelNameSpace::MathArgSEIdx *arg_idx = dynamic_cast<ModelNameSpace::MathArgSEIdx *>(args[5]);
848  ASSERT(arg_idx != 0);
849 
850  ModelNameSpace::MathArgSEPtr *arg_ptr = dynamic_cast<ModelNameSpace::MathArgSEPtr *>(args[4]);
851  ASSERT(arg_ptr != 0);
852  const SimulationEntity *pNode = (*arg_ptr)();
853 
854  if (pNode == 0) {
855  MathParser::MathArgInt_t *arg_label = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
856  ASSERT(arg_label != 0);
857  int iLabel = (*arg_label)();
858 
859  MathParser::MathArgString_t *arg_val = dynamic_cast<MathParser::MathArgString_t *>(args[2]);
860  ASSERT(arg_val != 0);
861  std::string v = (*arg_val)();
862 
863  ModelNameSpace::MathArgNode *arg_type = dynamic_cast<ModelNameSpace::MathArgNode *>(args[3]);
864  ASSERT(arg_type != 0);
865  Node::Type type = (*arg_type)();
866 
867  ModelNameSpace::MathArgDM *arg_dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[6]);
868  ASSERT(arg_dm != 0);
869  const DataManager *pDM = (*arg_dm)();
870 
871  if (iLabel < 0) {
872  silent_cerr("model::node: invalid node label " << iLabel << std::endl);
874  }
875  unsigned uLabel = unsigned(iLabel);
876 
877  pNode = pDM->pFindNode(type, uLabel);
878  if (pNode == 0) {
879  silent_cerr("model::node: unable to find " << psNodeNames[type] << "(" << uLabel << ")" << std::endl);
881  }
882 
883  idx = pNode->iGetPrivDataIdx(v.c_str());
884  if (idx == 0) {
885  silent_cerr("model::node: " << psNodeNames[type] << "(" << dynamic_cast<const Node *>(pNode)->GetLabel() << "): invalid private data \"" << v << "\"" << std::endl);
887  }
888 
889  if (arg_label->IsFlag(MathParser::AF_CONST)) {
890  (*arg_ptr)() = pNode;
891 
892  /* NOTE: only set idx if node label is const,
893  * otherwise a different node could have a different idx
894  * for the same string */
895  if (arg_val->IsFlag(MathParser::AF_CONST)) {
896  (*arg_idx)() = idx;
897  }
898  }
899 
900  } else {
901  idx = (*arg_idx)();
902 
903  /* NOTE: pNode is saved, so we presume it was constant;
904  * apparently, idx was not constant, and we need to recompute it */
905  if (idx == 0) {
906  ASSERT(!arg_idx->IsFlag(MathParser::AF_CONST));
907 
908  MathParser::MathArgString_t *arg_val = dynamic_cast<MathParser::MathArgString_t *>(args[2]);
909  ASSERT(arg_val != 0);
910  std::string v = (*arg_val)();
911 
912  idx = pNode->iGetPrivDataIdx(v.c_str());
913  if (idx == 0) {
914  ModelNameSpace::MathArgNode *arg_type = dynamic_cast<ModelNameSpace::MathArgNode *>(args[3]);
915  ASSERT(arg_type != 0);
916  Node::Type type = (*arg_type)();
917 
918  silent_cerr("model::node: " << psNodeNames[type] << "(" << dynamic_cast<const Node *>(pNode)->GetLabel() << "): invalid private data \"" << v << "\"" << std::endl);
920  }
921  }
922  }
923 
924  *out = pNode->dGetPrivData(idx);
925 
926  return 0;
927 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual unsigned int iGetPrivDataIdx(const char *s) const
Definition: simentity.cc:142
Type
Definition: node.h:71
#define ASSERT(expression)
Definition: colamd.c:977
virtual doublereal dGetPrivData(unsigned int i) const
Definition: simentity.cc:149
const char * psNodeNames[]
Definition: enums.cc:372
bool IsFlag(const MathParser::ArgFlag f) const
Definition: mathp.h:98
Node * pFindNode(Node::Type Typ, unsigned int uNode) const
Definition: nodeman.cc:179

Here is the call graph for this function:

static int model_sf ( const MathParser::MathArgs args)
static

Definition at line 781 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, DifferentiableScalarFunction::ComputeDiff(), MBDYN_EXCEPT_ARGS, and order.

Referenced by ModelNameSpace::ModelNameSpace().

782 {
783  ASSERT(args.size() == 1 + 2 + 1);
784  ASSERT(args[0]->Type() == MathParser::AT_REAL);
785  ASSERT(args[1]->Type() == MathParser::AT_REAL);
786  ASSERT(args[2]->Type() == MathParser::AT_INT);
787  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
788 
789  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
790  ASSERT(out != 0);
791 
792  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
793  ASSERT(arg1 != 0);
794  doublereal v = (*arg1)();
795 
796  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
797  ASSERT(arg2 != 0);
798  int order = (*arg2)();
799  ASSERT(order >= 0);
800 
801  ModelNameSpace::MathArgSF *sf = dynamic_cast<ModelNameSpace::MathArgSF *>(args[3]);
802  ASSERT(sf != 0);
803 
804  if (order < 0 || order > 1) {
805  silent_cerr("model::sf invalid derivative order " << order << std::endl);
807  }
808 
809  if (order == 0) {
810  *out = (*(*sf)())(v);
811 
812  } else {
813  const DifferentiableScalarFunction *dsf = dynamic_cast<const DifferentiableScalarFunction *>((*sf)());
814  if (dsf == 0) {
815  silent_cerr("model::sf "
816  "order=" << order << " only allowed "
817  "with differentiable scalar functions"
818  << std::endl);
820  }
821 
822  *out = dsf->ComputeDiff(v, order);
823  }
824 
825  return 0;
826 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
enum @55 order
#define ASSERT(expression)
Definition: colamd.c:977
virtual doublereal ComputeDiff(const doublereal x, const integer order=1) const =0
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int position ( const MathParser::MathArgs args)
static

Definition at line 99 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructDispNode::GetXCurr(), StructDispNode::GetXPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

100 {
101  ASSERT(args.size() == 1 + 1 + 1);
102  ASSERT(args[0]->Type() == MathParser::AT_REAL);
103  ASSERT(args[1]->Type() == MathParser::AT_INT);
104  ASSERT(args[2]->Type() == MathParser::AT_PRIVATE);
105 
106  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
107  ASSERT(out != 0);
108 
109  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
110  ASSERT(arg1 != 0);
111  ASSERT((*arg1)() >= 0);
112 
113  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[2]);
114  ASSERT(dm != 0);
115 
116  unsigned uLabel = unsigned((*arg1)());
117 
118  const StructNode *pNode = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel);
119  if (pNode == 0) {
120  silent_cerr("model::position" << when2str(when) << IDX2str(IDX)
121  << "(" << uLabel << "): "
122  "unable to find StructNode(" << uLabel << ")"
123  << std::endl);
125  }
126 
127  Vec3 x;
128  switch (when) {
129  case CURR:
130  x = pNode->GetXCurr();
131  break;
132 
133  case PREV:
134  x = pNode->GetXPrev();
135  break;
136  }
137 
138  switch (IDX) {
139  case NORM:
140  *out = x.Norm();
141  break;
142 
143  case SQUARE:
144  *out = x.Dot();
145  break;
146 
147  default:
148  *out = x(IDX);
149  break;
150  }
151 
152  return 0;
153 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
virtual const Vec3 & GetXPrev(void) const
Definition: strnode.h:304
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int unitvec ( const MathParser::MathArgs args)
static

Definition at line 236 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, StructDispNode::GetXCurr(), StructDispNode::GetXPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, Vec3::Norm(), PREV, and when2str().

237 {
238  ASSERT(args.size() == 1 + 2 + 1);
239  ASSERT(args[0]->Type() == MathParser::AT_REAL);
240  ASSERT(args[1]->Type() == MathParser::AT_INT);
241  ASSERT(args[2]->Type() == MathParser::AT_INT);
242  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
243 
244  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
245  ASSERT(out != 0);
246 
247  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
248  ASSERT(arg1 != 0);
249  ASSERT((*arg1)() >= 0);
250 
251  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
252  ASSERT(arg2 != 0);
253  ASSERT((*arg2)() >= 0);
254 
255  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[3]);
256  ASSERT(dm != 0);
257 
258  unsigned uLabel1 = unsigned((*arg1)());
259  unsigned uLabel2 = unsigned((*arg2)());
260 
261  const StructNode *pNode1 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel1);
262  if (pNode1 == 0) {
263  silent_cerr("model::unitvec" << when2str(when) << IDX2str(IDX)
264  << "(" << uLabel1 << "," << uLabel2 << "): "
265  "unable to find StructNode(" << uLabel1 << ")"
266  << std::endl);
268  }
269 
270  const StructNode *pNode2 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel2);
271  if (pNode2 == 0) {
272  silent_cerr("model::unitvec" << when2str(when) << IDX2str(IDX)
273  << "(" << uLabel1 << "," << uLabel2 << "): "
274  "unable to find StructNode(" << uLabel2 << ")"
275  << std::endl);
277  }
278 
279  Vec3 d;
280  switch (when) {
281  case CURR:
282  d = pNode2->GetXCurr() - pNode1->GetXCurr();
283  break;
284 
285  case PREV:
286  d = pNode2->GetXPrev() - pNode1->GetXPrev();
287  break;
288  }
289 
290  doublereal dd = d.Norm();
291  if (dd <= std::numeric_limits<doublereal>::epsilon()) {
292  silent_cerr("model::unitvec" << when2str(when) << IDX2str(IDX)
293  << "(" << uLabel1 << "," << uLabel2 << "): "
294  "null distance"
295  << std::endl);
297  }
298 
299  switch (IDX) {
300  default:
301  *out = d(IDX)/dd;
302  break;
303  }
304 
305  return 0;
306 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
virtual const Vec3 & GetXPrev(void) const
Definition: strnode.h:304
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
virtual const Vec3 & GetXCurr(void) const
Definition: strnode.h:310
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int velocity ( const MathParser::MathArgs args)
static

Definition at line 442 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructDispNode::GetVCurr(), StructDispNode::GetVPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

443 {
444  ASSERT(args.size() == 1 + 1 + 1);
445  ASSERT(args[0]->Type() == MathParser::AT_REAL);
446  ASSERT(args[1]->Type() == MathParser::AT_INT);
447  ASSERT(args[2]->Type() == MathParser::AT_PRIVATE);
448 
449  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
450  ASSERT(out != 0);
451 
452  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
453  ASSERT(arg1 != 0);
454  ASSERT((*arg1)() >= 0);
455 
456  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[2]);
457  ASSERT(dm != 0);
458 
459  unsigned uLabel = unsigned((*arg1)());
460 
461  const StructNode *pNode = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel);
462  if (pNode == 0) {
463  silent_cerr("model::velocity" << when2str(when) << IDX2str(IDX)
464  << "(" << uLabel << "): "
465  "unable to find StructNode(" << uLabel << ")"
466  << std::endl);
468  }
469 
470  Vec3 v;
471  switch (when) {
472  case CURR:
473  v = pNode->GetVCurr();
474  break;
475 
476  case PREV:
477  v = pNode->GetVPrev();
478  break;
479  }
480 
481  switch (IDX) {
482  case NORM:
483  *out = v.Norm();
484  break;
485 
486  case SQUARE:
487  *out = v.Dot();
488  break;
489 
490  default:
491  *out = v(IDX);
492  break;
493  }
494 
495  return 0;
496 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Vec3 & GetVPrev(void) const
Definition: strnode.h:316
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322

Here is the call graph for this function:

template<IDX_t IDX, when_t when>
static int vrel ( const MathParser::MathArgs args)
static

Definition at line 503 of file modelns.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_PRIVATE, MathParser::AT_REAL, CURR, Vec3::Dot(), StructDispNode::GetVCurr(), StructDispNode::GetVPrev(), IDX2str(), MBDYN_EXCEPT_ARGS, NORM, Vec3::Norm(), PREV, SQUARE, and when2str().

504 {
505  ASSERT(args.size() == 1 + 2 + 1);
506  ASSERT(args[0]->Type() == MathParser::AT_REAL);
507  ASSERT(args[1]->Type() == MathParser::AT_INT);
508  ASSERT(args[2]->Type() == MathParser::AT_INT);
509  ASSERT(args[3]->Type() == MathParser::AT_PRIVATE);
510 
511  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
512  ASSERT(out != 0);
513 
514  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
515  ASSERT(arg1 != 0);
516  ASSERT((*arg1)() >= 0);
517 
518  MathParser::MathArgInt_t *arg2 = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
519  ASSERT(arg2 != 0);
520  ASSERT((*arg2)() >= 0);
521 
522  ModelNameSpace::MathArgDM *dm = dynamic_cast<ModelNameSpace::MathArgDM *>(args[3]);
523  ASSERT(dm != 0);
524 
525  unsigned uLabel1 = unsigned((*arg1)());
526  unsigned uLabel2 = unsigned((*arg2)());
527 
528  const StructNode *pNode1 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel1);
529  if (pNode1 == 0) {
530  silent_cerr("model::vrel" << when2str(when) << IDX2str(IDX)
531  << "(" << uLabel1 << "," << uLabel2 << "): "
532  "unable to find StructNode(" << uLabel1 << ")"
533  << std::endl);
535  }
536 
537  const StructNode *pNode2 = (*dm)()->pFindNode<const StructNode, Node::STRUCTURAL>(uLabel2);
538  if (pNode2 == 0) {
539  silent_cerr("model::vrel" << when2str(when) << IDX2str(IDX)
540  << "(" << uLabel1 << "," << uLabel2 << "): "
541  "unable to find StructNode(" << uLabel2 << ")"
542  << std::endl);
544  }
545 
546  Vec3 v;
547  switch (when) {
548  case CURR:
549  v = pNode2->GetVCurr() - pNode1->GetVCurr();
550  break;
551 
552  case PREV:
553  v = pNode2->GetVCurr() - pNode1->GetVPrev();
554  break;
555  }
556 
557  switch (IDX) {
558  case NORM:
559  *out = v.Norm();
560  break;
561 
562  case SQUARE:
563  *out = v.Dot();
564  break;
565 
566  default:
567  *out = v(IDX);
568  break;
569  }
570 
571  return 0;
572 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: matvec3.h:98
doublereal Norm(void) const
Definition: matvec3.h:263
doublereal Dot(const Vec3 &v) const
Definition: matvec3.h:243
Definition: modelns.cc:75
static const char * when2str(when_t when)
Definition: modelns.cc:80
Definition: modelns.cc:47
virtual const Vec3 & GetVPrev(void) const
Definition: strnode.h:316
Definition: modelns.cc:76
#define ASSERT(expression)
Definition: colamd.c:977
static const char * IDX2str(IDX_t IDX)
Definition: modelns.cc:52
virtual const Vec3 & GetVCurr(void) const
Definition: strnode.h:322

Here is the call graph for this function:

static const char* when2str ( when_t  when)
static

Definition at line 80 of file modelns.cc.

References CURR, MBDYN_EXCEPT_ARGS, and PREV.

Referenced by angle(), anglerel(), angvel(), angvrel(), distance(), position(), unitvec(), velocity(), and vrel().

81 {
82  switch (when) {
83  case CURR:
84  return "";
85 
86  case PREV:
87  return "_prev";
88 
89  }
90 
92 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: modelns.cc:75
Definition: modelns.cc:76