MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mathp.cc File Reference
#include "mbconfig.h"
#include <cerrno>
#include <cfloat>
#include <cstdlib>
#include <climits>
#include <limits>
#include <sstream>
#include "mathp.h"
#include "parser.h"
Include dependency graph for mathp.cc:

Go to the source code of this file.

Classes

struct  TypeName_t
 
struct  typemodifiernames
 
struct  declarationmodifiernames
 

Typedefs

typedef double(* mp_f1_f )(double)
 
typedef double(* mp_f2_f )(double, double)
 

Enumerations

enum  mp_in_e { IN_LL, IN_LE, IN_EL, IN_EE }
 

Functions

template<class Tin , class Tout , mp_f1_f F>
static int mp_func_1 (const MathParser::MathArgs &args)
 
template<class Tin , class Tout , mp_f2_f F>
static int mp_func_2 (const MathParser::MathArgs &args)
 
static int mp_asin_t (const MathParser::MathArgs &args)
 
static int mp_acos_t (const MathParser::MathArgs &args)
 
static int mp_tan_t (const MathParser::MathArgs &args)
 
static int mp_acosh_t (const MathParser::MathArgs &args)
 
static int mp_atanh_t (const MathParser::MathArgs &args)
 
static int mp_greater_than_0_t (const MathParser::MathArgs &args)
 
static int mp_greater_than_or_equal_to_0_t (const MathParser::MathArgs &args)
 
static int mp_rand (const MathParser::MathArgs &args)
 
static int mp_rndm (const MathParser::MathArgs &args)
 
static int mp_srnd (const MathParser::MathArgs &args)
 
static int mp_sprintf (const MathParser::MathArgs &args)
 
std::ostream & operator<< (std::ostream &out, const MathParser::MathArgVoid_t &)
 
std::ostream & operator<< (std::ostream &out, const MathParser::MathArgBool_t &v)
 
std::ostream & operator<< (std::ostream &out, const MathParser::MathArgInt_t &v)
 
std::ostream & operator<< (std::ostream &out, const MathParser::MathArgReal_t &v)
 
std::ostream & operator<< (std::ostream &out, const MathParser::MathArgString_t &v)
 
static int mp_print (const MathParser::MathArgs &args)
 
static int mp_stop (const MathParser::MathArgs &args)
 
static int mp_ctg (const MathParser::MathArgs &args)
 
static int mp_ctg_t (const MathParser::MathArgs &args)
 
static int mp_actg (const MathParser::MathArgs &args)
 
static int mp_actg2 (const MathParser::MathArgs &args)
 
static int mp_ctgh (const MathParser::MathArgs &args)
 
static int mp_ctgh_t (const MathParser::MathArgs &args)
 
static int mp_sign (const MathParser::MathArgs &args)
 
static int mp_max (const MathParser::MathArgs &args)
 
static int mp_min (const MathParser::MathArgs &args)
 
static int mp_step (const MathParser::MathArgs &args)
 
static int mp_ramp (const MathParser::MathArgs &args)
 
static int mp_sramp (const MathParser::MathArgs &args)
 
static int mp_par (const MathParser::MathArgs &args)
 
template<mp_in_e IN>
static int mp_in (const MathParser::MathArgs &args)
 
static int mp_cast (const MathParser::MathArgs &args)
 
bool operator! (const TypedValue &v)
 
TypedValue operator- (const TypedValue &v)
 
TypedValue operator+ (const TypedValue &v)
 
std::ostream & operator<< (std::ostream &out, const TypedValue &v)
 

Variables

static const TypeName_t TypeNames []
 
static const typemodifiernames TypeModifierNames []
 
static const
declarationmodifiernames 
DeclarationModifierNames []
 
static bool sns = 0
 

Typedef Documentation

typedef double(* mp_f1_f)(double)

Definition at line 55 of file mathp.cc.

typedef double(* mp_f2_f)(double, double)

Definition at line 56 of file mathp.cc.

Enumeration Type Documentation

enum mp_in_e
Enumerator
IN_LL 
IN_LE 
IN_EL 
IN_EE 

Definition at line 712 of file mathp.cc.

712  {
713  IN_LL,
714  IN_LE,
715  IN_EL,
716  IN_EE
717 };
Definition: mathp.cc:713
Definition: mathp.cc:716
Definition: mathp.cc:715
Definition: mathp.cc:714

Function Documentation

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

Definition at line 120 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

121 {
122  ASSERT(args.size() == 1 + 1);
123  ASSERT(args[1]->Type() == MathParser::AT_REAL);
124 
125  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
126  ASSERT(arg1 != 0);
127 
128  const Real a1 = (*arg1)();
129  if (a1 > 1. || a1 < -1.) {
130  return 1;
131  }
132 
133  return 0;
134 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_acosh_t ( const MathParser::MathArgs args)
static

Definition at line 156 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

157 {
158  ASSERT(args.size() == 1 + 1);
159  ASSERT(args[1]->Type() == MathParser::AT_REAL);
160 
161  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
162  ASSERT(arg1 != 0);
163 
164  if ((*arg1)() <= 1.) {
165  return 1;
166  }
167 
168  return 0;
169 }
#define ASSERT(expression)
Definition: colamd.c:977
static int mp_actg ( const MathParser::MathArgs args)
static

Definition at line 438 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and grad::atan2().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

439 {
440  ASSERT(args.size() == 1 + 1);
441  ASSERT(args[0]->Type() == MathParser::AT_REAL);
442  ASSERT(args[1]->Type() == MathParser::AT_REAL);
443 
444  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
445  ASSERT(out != 0);
446 
447  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
448  ASSERT(arg1 != 0);
449 
450  *out = atan2(1., (*arg1)());
451 
452  return 0;
453 }
#define ASSERT(expression)
Definition: colamd.c:977
GradientExpression< BinaryExpr< FuncAtan2, LhsExpr, RhsExpr > > atan2(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2962

Here is the call graph for this function:

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

Definition at line 456 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and grad::atan2().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

457 {
458  ASSERT(args.size() == 1 + 2);
459  ASSERT(args[0]->Type() == MathParser::AT_REAL);
460  ASSERT(args[1]->Type() == MathParser::AT_REAL);
461  ASSERT(args[2]->Type() == MathParser::AT_REAL);
462 
463  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
464  ASSERT(out != 0);
465 
466  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
467  ASSERT(arg1 != 0);
468 
469  MathParser::MathArgReal_t *arg2 = dynamic_cast<MathParser::MathArgReal_t*>(args[2]);
470  ASSERT(arg2 != 0);
471 
472  Real a1 = (*arg1)();
473  Real a2 = (*arg2)();
474 
475  *out = atan2(a2, a1);
476 
477  return 0;
478 }
#define ASSERT(expression)
Definition: colamd.c:977
GradientExpression< BinaryExpr< FuncAtan2, LhsExpr, RhsExpr > > atan2(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
Definition: gradient.h:2962
double Real
Definition: mathtyp.h:39

Here is the call graph for this function:

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

Definition at line 103 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

104 {
105  ASSERT(args.size() == 1 + 1);
106  ASSERT(args[1]->Type() == MathParser::AT_REAL);
107 
108  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
109  ASSERT(arg1 != 0);
110 
111  const Real a1 = (*arg1)();
112  if (a1 > 1. || a1 < -1.) {
113  return 1;
114  }
115 
116  return 0;
117 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_atanh_t ( const MathParser::MathArgs args)
static

Definition at line 172 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

173 {
174  ASSERT(args.size() == 1 + 1);
175  ASSERT(args[1]->Type() == MathParser::AT_REAL);
176 
177  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
178  ASSERT(arg1 != 0);
179 
180  Real a1 = (*arg1)();
181  if (a1 >= 1. || a1 <= -1.) {
182  return 1;
183  }
184 
185  return 0;
186 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_cast ( const MathParser::MathArgs args)
static

Definition at line 787 of file mathp.cc.

References ASSERT, MathParser::AT_ANY, MathParser::AT_BOOL, MathParser::AT_INT, MathParser::AT_REAL, MathParser::AT_STRING, TypedValue::Cast(), TypedValue::GetString(), and TypedValue::VAR_STRING.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

788 {
789  ASSERT(args.size() == 1 + 1);
790  ASSERT(args[0]->Type() == MathParser::AT_ANY);
791 
792  MathParser::MathArgAny_t *arg1 = dynamic_cast<MathParser::MathArgAny_t*>(args[1]);
793  ASSERT(arg1 != 0);
794 
795  switch (args[0]->Type()) {
796  case MathParser::AT_BOOL: {
797  MathParser::MathArgBool_t *out = dynamic_cast<MathParser::MathArgBool_t*>(args[0]);
798  ASSERT(out != 0);
799  (*out)() = (*arg1)().GetBool();
800  } break;
801 
802  case MathParser::AT_INT: {
803  MathParser::MathArgInt_t *out = dynamic_cast<MathParser::MathArgInt_t*>(args[0]);
804  ASSERT(out != 0);
805  (*out)() = (*arg1)().GetInt();
806  } break;
807 
808  case MathParser::AT_REAL: {
809  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
810  ASSERT(out != 0);
811  (*out)() = (*arg1)().GetReal();
812  } break;
813 
814  case MathParser::AT_STRING: {
815  MathParser::MathArgString_t *out = dynamic_cast<MathParser::MathArgString_t*>(args[0]);
816  ASSERT(out != 0);
818  val.Cast((*arg1)());
819  (*out)() = val.GetString();
820  } break;
821 
822  default:
823  // add support for future types
824  return 1;
825  }
826 
827  return 0;
828 }
#define ASSERT(expression)
Definition: colamd.c:977

Here is the call graph for this function:

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

Definition at line 401 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and grad::tan().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

402 {
403  ASSERT(args.size() == 1 + 1);
404  ASSERT(args[0]->Type() == MathParser::AT_REAL);
405  ASSERT(args[1]->Type() == MathParser::AT_REAL);
406 
407  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t *>(args[0]);
408  ASSERT(out != 0);
409 
410  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
411  ASSERT(arg1 != 0);
412 
413  *out = 1./tan((*arg1)());
414 
415  return 0;
416 }
#define ASSERT(expression)
Definition: colamd.c:977
GradientExpression< UnaryExpr< FuncTan, Expr > > tan(const GradientExpression< Expr > &u)
Definition: gradient.h:2979

Here is the call graph for this function:

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

Definition at line 419 of file mathp.cc.

References a, ASSERT, MathParser::AT_REAL, grad::fabs(), and M_PI.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

420 {
421  ASSERT(args.size() == 1 + 1);
422  ASSERT(args[1]->Type() == MathParser::AT_REAL);
423 
424  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
425  ASSERT(arg1 != 0);
426 
427  Real a1 = (*arg1)();
428  Real a = a1;
429  a -= int(a1/M_PI)*M_PI;
430  if (fabs(a) < std::numeric_limits<double>::epsilon()) {
431  return 1;
432  }
433 
434  return 0;
435 }
#define M_PI
Definition: gradienttest.cc:67
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
#define ASSERT(expression)
Definition: colamd.c:977
static const doublereal a
Definition: hfluid_.h:289
double Real
Definition: mathtyp.h:39

Here is the call graph for this function:

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

Definition at line 481 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and grad::tanh().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

482 {
483  ASSERT(args.size() == 1 + 1);
484  ASSERT(args[0]->Type() == MathParser::AT_REAL);
485  ASSERT(args[1]->Type() == MathParser::AT_REAL);
486 
487  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
488  ASSERT(out != 0);
489 
490  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
491  ASSERT(arg1 != 0);
492 
493  *out = 1./tanh((*arg1)());
494 
495  return 0;
496 }
GradientExpression< UnaryExpr< FuncTanh, Expr > > tanh(const GradientExpression< Expr > &u)
Definition: gradient.h:2982
#define ASSERT(expression)
Definition: colamd.c:977

Here is the call graph for this function:

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

Definition at line 499 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and grad::fabs().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

500 {
501  ASSERT(args.size() == 1 + 1);
502  ASSERT(args[1]->Type() == MathParser::AT_REAL);
503 
504  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
505  ASSERT(arg1 != 0);
506 
507  if (fabs((*arg1)()) < std::numeric_limits<double>::epsilon()) {
508  return 1;
509  }
510 
511  return 0;
512 }
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
#define ASSERT(expression)
Definition: colamd.c:977

Here is the call graph for this function:

template<class Tin , class Tout , mp_f1_f F>
static int mp_func_1 ( const MathParser::MathArgs args)
static

Definition at line 60 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

61 {
62  ASSERT(args.size() == 1 + 1);
63  ASSERT(args[0]->Type() == MathParser::AT_REAL);
64  ASSERT(args[1]->Type() == MathParser::AT_REAL);
65 
66  Tout *out = dynamic_cast<Tout *>(args[0]);
67  ASSERT(out != 0);
68 
69  Tin *arg1 = dynamic_cast<Tin *>(args[1]);
70  ASSERT(arg1 != 0);
71 
72  *out = F((*arg1)());
73 
74  return 0;
75 }
#define ASSERT(expression)
Definition: colamd.c:977
template<class Tin , class Tout , mp_f2_f F>
static int mp_func_2 ( const MathParser::MathArgs args)
static

Definition at line 79 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

80 {
81  ASSERT(args.size() == 1 + 1);
82  ASSERT(args[0]->Type() == MathParser::AT_REAL);
83  ASSERT(args[1]->Type() == MathParser::AT_REAL);
84  ASSERT(args[2]->Type() == MathParser::AT_REAL);
85 
86  Tout *out = dynamic_cast<Tout *>(args[0]);
87  ASSERT(out != 0);
88 
89  Tin *arg1 = dynamic_cast<Tin *>(args[1]);
90  ASSERT(arg1 != 0);
91 
92  Tin *arg2 = dynamic_cast<Tin *>(args[2]);
93  ASSERT(arg2 != 0);
94 
95  Real a1 = (*arg1)();
96  Real a2 = (*arg2)();
97  *out = F(a1, a2);
98 
99  return 0;
100 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_greater_than_0_t ( const MathParser::MathArgs args)
static

Definition at line 189 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

190 {
191  ASSERT(args.size() == 1 + 1);
192  ASSERT(args[1]->Type() == MathParser::AT_REAL);
193 
194  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
195  ASSERT(arg1 != 0);
196 
197  if ((*arg1)() <= 0.) {
198  return 1;
199  }
200 
201  return 0;
202 }
#define ASSERT(expression)
Definition: colamd.c:977
static int mp_greater_than_or_equal_to_0_t ( const MathParser::MathArgs args)
static

Definition at line 205 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

206 {
207  ASSERT(args.size() == 1 + 1);
208  ASSERT(args[1]->Type() == MathParser::AT_REAL);
209 
210  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
211  ASSERT(arg1 != 0);
212 
213  if ((*arg1)() < 0.) {
214  return 1;
215  }
216 
217  return 0;
218 }
#define ASSERT(expression)
Definition: colamd.c:977
template<mp_in_e IN>
static int mp_in ( const MathParser::MathArgs args)
static

Definition at line 721 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, IN_EE, IN_EL, IN_LE, and IN_LL.

722 {
723  ASSERT(args.size() == 1 + 3);
724  ASSERT(args[0]->Type() == MathParser::AT_REAL);
725  ASSERT(args[1]->Type() == MathParser::AT_REAL);
726  ASSERT(args[2]->Type() == MathParser::AT_REAL);
727  ASSERT(args[3]->Type() == MathParser::AT_REAL);
728 
729  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
730  ASSERT(out != 0);
731 
732  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
733  ASSERT(arg1 != 0);
734 
735  MathParser::MathArgReal_t *arg2 = dynamic_cast<MathParser::MathArgReal_t*>(args[2]);
736  ASSERT(arg2 != 0);
737 
738  MathParser::MathArgReal_t *arg3 = dynamic_cast<MathParser::MathArgReal_t*>(args[3]);
739  ASSERT(arg3 != 0);
740 
741  Real l = (*arg1)();
742  Real x = (*arg2)();
743  Real u = (*arg3)();
744 
745  switch (IN) {
746  case IN_LL:
747  case IN_LE:
748  if (x <= l) {
749  *out = 0;
750  return 0;
751  }
752  break;
753 
754  case IN_EL:
755  case IN_EE:
756  if (x < l) {
757  *out = 0;
758  return 0;
759  }
760  break;
761  }
762 
763  switch (IN) {
764  case IN_LL:
765  case IN_EL:
766  if (x >= u) {
767  *out = 0;
768  return 0;
769  }
770  break;
771 
772  case IN_LE:
773  case IN_EE:
774  if (x > u) {
775  *out = 0;
776  return 0;
777  }
778  break;
779  }
780 
781  *out = 1;
782 
783  return 0;
784 }
Definition: mathp.cc:713
Definition: mathp.cc:716
Definition: mathp.cc:715
Definition: mathp.cc:714
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_max ( const MathParser::MathArgs args)
static

Definition at line 538 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

539 {
540  ASSERT(args.size() == 1 + 2);
541  ASSERT(args[0]->Type() == MathParser::AT_REAL);
542  ASSERT(args[1]->Type() == MathParser::AT_REAL);
543  ASSERT(args[2]->Type() == MathParser::AT_REAL);
544 
545  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
546  ASSERT(out != 0);
547 
548  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
549  ASSERT(arg1 != 0);
550 
551  MathParser::MathArgReal_t *arg2 = dynamic_cast<MathParser::MathArgReal_t*>(args[2]);
552  ASSERT(arg2 != 0);
553 
554  Real a1 = (*arg1)();
555  Real a2 = (*arg2)();
556  *out = std::max(a1, a2);
557 
558  return 0;
559 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_min ( const MathParser::MathArgs args)
static

Definition at line 562 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

563 {
564  ASSERT(args.size() == 1 + 2);
565  ASSERT(args[0]->Type() == MathParser::AT_REAL);
566  ASSERT(args[1]->Type() == MathParser::AT_REAL);
567  ASSERT(args[2]->Type() == MathParser::AT_REAL);
568 
569  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
570  ASSERT(out != 0);
571 
572  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
573  ASSERT(arg1 != 0);
574 
575  MathParser::MathArgReal_t *arg2 = dynamic_cast<MathParser::MathArgReal_t*>(args[2]);
576  ASSERT(arg2 != 0);
577 
578  Real a1 = (*arg1)();
579  Real a2 = (*arg2)();
580  *out = std::min(a1, a2);
581 
582  return 0;
583 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_par ( const MathParser::MathArgs args)
static

Definition at line 689 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

690 {
691  ASSERT(args.size() == 1 + 1);
692  ASSERT(args[0]->Type() == MathParser::AT_REAL);
693  ASSERT(args[1]->Type() == MathParser::AT_REAL);
694 
695  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
696  ASSERT(out != 0);
697 
698  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
699  ASSERT(arg1 != 0);
700 
701  Real a1 = (*arg1)();
702  if (a1 > 0.) {
703  *out = a1*a1;
704 
705  } else {
706  *out = 0.;
707  }
708 
709  return 0;
710 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_print ( const MathParser::MathArgs args)
static

Definition at line 344 of file mathp.cc.

References ASSERT, MathParser::AT_BOOL, MathParser::AT_INT, MathParser::AT_REAL, MathParser::AT_STRING, and MBDYN_EXCEPT_ARGS.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

345 {
346  ASSERT(args.size() == 1 + 1);
347 
348  switch (args[1]->Type()) {
349  case MathParser::AT_BOOL:
350  silent_cout((*dynamic_cast<MathParser::MathArgBool_t*>(args[1])) << std::endl);
351  break;
352 
353  case MathParser::AT_INT:
354  silent_cout((*dynamic_cast<MathParser::MathArgInt_t*>(args[1])) << std::endl);
355  break;
356 
357  case MathParser::AT_REAL:
358  silent_cout((*dynamic_cast<MathParser::MathArgReal_t*>(args[1])) << std::endl);
359  break;
360 
362  silent_cout((*dynamic_cast<MathParser::MathArgString_t*>(args[1])) << std::endl);
363  break;
364 
365  default:
367  }
368 
369  return 0;
370 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define ASSERT(expression)
Definition: colamd.c:977
static int mp_ramp ( const MathParser::MathArgs args)
static

Definition at line 633 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

634 {
635  ASSERT(args.size() == 1 + 1);
636  ASSERT(args[0]->Type() == MathParser::AT_REAL);
637  ASSERT(args[1]->Type() == MathParser::AT_REAL);
638 
639  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
640  ASSERT(out != 0);
641 
642  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
643  ASSERT(arg1 != 0);
644 
645  Real a1 = (*arg1)();
646  if (a1 > 0.) {
647  *out = a1;
648 
649  } else {
650  *out = 0.;
651  }
652 
653  return 0;
654 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_rand ( const MathParser::MathArgs args)
static

Definition at line 221 of file mathp.cc.

References ASSERT, and MathParser::AT_INT.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

222 {
223  ASSERT(args.size() == 1 + 0);
224  ASSERT(args[0]->Type() == MathParser::AT_INT);
225 
226  MathParser::MathArgInt_t* out = dynamic_cast<MathParser::MathArgInt_t*>(args[0]);
227  ASSERT(out != 0);
228 
229  *out = rand();
230 
231  return 0;
232 }
#define ASSERT(expression)
Definition: colamd.c:977
static int mp_rndm ( const MathParser::MathArgs args)
static

Definition at line 235 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

236 {
237  ASSERT(args.size() == 1 + 0);
238  ASSERT(args[0]->Type() == MathParser::AT_REAL);
239 
240  MathParser::MathArgReal_t* out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
241  ASSERT(out != 0);
242 
243  *out = -1. + 2.*(Real(rand())/Real(RAND_MAX));
244 
245  return 0;
246 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_sign ( const MathParser::MathArgs args)
static

Definition at line 515 of file mathp.cc.

References ASSERT, MathParser::AT_REAL, and copysign().

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

516 {
517  ASSERT(args.size() == 1 + 1);
518  ASSERT(args[0]->Type() == MathParser::AT_REAL);
519  ASSERT(args[1]->Type() == MathParser::AT_REAL);
520 
521  MathParser::MathArgInt_t *out = dynamic_cast<MathParser::MathArgInt_t*>(args[0]);
522  ASSERT(out != 0);
523 
524  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
525  ASSERT(arg1 != 0);
526 
527  Real a1 = (*arg1)();
528  if (a1 == 0.) {
529  *out = 0;
530  } else {
531  *out = Int(copysign(1., a1));
532  }
533 
534  return 0;
535 }
int Int
Definition: mathtyp.h:40
doublereal copysign(doublereal x, doublereal y)
Definition: gradient.h:97
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39

Here is the call graph for this function:

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

Definition at line 264 of file mathp.cc.

References ASSERT, MathParser::AT_ANY, MathParser::AT_STRING, buf, MBDYN_EXCEPT_ARGS, TypedValue::VAR_BOOL, TypedValue::VAR_INT, TypedValue::VAR_REAL, and TypedValue::VAR_STRING.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

265 {
266  ASSERT(args.size() == 1 + 2);
267  ASSERT(args[0]->Type() == MathParser::AT_STRING);
268  ASSERT(args[1]->Type() == MathParser::AT_STRING);
269  ASSERT(args[2]->Type() == MathParser::AT_ANY);
270 
271  MathParser::MathArgString_t *arg1 = dynamic_cast<MathParser::MathArgString_t *>(args[1]);
272  MathParser::MathArgAny_t *arg2 = dynamic_cast<MathParser::MathArgAny_t *>(args[2]);
273  ASSERT(arg1 != 0);
274 
275  char buf[BUFSIZ];
276  const char *fmt = ((std::string&)(*arg1)()).c_str();
277  int rc;
278 
279  switch ((*arg2)().GetType()) {
280  case TypedValue::VAR_BOOL: {
281  rc = snprintf(buf, sizeof(buf), fmt, (*arg2)().GetBool());
282  } break;
283 
284  case TypedValue::VAR_INT: {
285  rc = snprintf(buf, sizeof(buf), fmt, (*arg2)().GetInt());
286  } break;
287 
288  case TypedValue::VAR_REAL: {
289  rc = snprintf(buf, sizeof(buf), fmt, (*arg2)().GetReal());
290  } break;
291 
292  case TypedValue::VAR_STRING: {
293  rc = snprintf(buf, sizeof(buf), fmt, (*arg2)().GetString().c_str());
294  } break;
295 
296  default:
297  // impossible?
299  }
300 
301  if (rc < 0 || (unsigned long)rc >= sizeof(buf)) {
303  }
304 
305  MathParser::MathArgString_t* out = dynamic_cast<MathParser::MathArgString_t*>(args[0]);
306  ASSERT(out != 0);
307 
308  *out = std::string(buf);
309 
310  return 0;
311 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define ASSERT(expression)
Definition: colamd.c:977
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
static int mp_sramp ( const MathParser::MathArgs args)
static

Definition at line 657 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

658 {
659  ASSERT(args.size() == 1 + 2);
660  ASSERT(args[0]->Type() == MathParser::AT_REAL);
661  ASSERT(args[1]->Type() == MathParser::AT_REAL);
662  ASSERT(args[2]->Type() == MathParser::AT_REAL);
663 
664  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
665  ASSERT(out != 0);
666 
667  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
668  ASSERT(arg1 != 0);
669 
670  MathParser::MathArgReal_t *arg2 = dynamic_cast<MathParser::MathArgReal_t*>(args[2]);
671  ASSERT(arg2 != 0);
672 
673  Real a1 = (*arg1)();
674  Real a2 = (*arg2)();
675  if (a1 < 0.) {
676  *out = 0.;
677 
678  } else if (a1 > a2) {
679  *out = a2;
680 
681  } else {
682  *out = a1;
683  }
684 
685  return 0;
686 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_srnd ( const MathParser::MathArgs args)
static

Definition at line 249 of file mathp.cc.

References ASSERT, MathParser::AT_INT, and MathParser::AT_VOID.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

250 {
251  ASSERT(args.size() == 1 + 1);
252  ASSERT(args[0]->Type() == MathParser::AT_VOID);
253  ASSERT(args[1]->Type() == MathParser::AT_INT);
254 
255  MathParser::MathArgInt_t *arg1 = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
256  ASSERT(arg1 != 0);
257 
258  srand((unsigned int)(*arg1)());
259 
260  return 0;
261 }
#define ASSERT(expression)
Definition: colamd.c:977
static int mp_step ( const MathParser::MathArgs args)
static

Definition at line 606 of file mathp.cc.

References ASSERT, and MathParser::AT_REAL.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

607 {
608  ASSERT(args.size() == 1 + 1);
609  ASSERT(args[0]->Type() == MathParser::AT_REAL);
610  ASSERT(args[1]->Type() == MathParser::AT_REAL);
611 
612  MathParser::MathArgReal_t *out = dynamic_cast<MathParser::MathArgReal_t*>(args[0]);
613  ASSERT(out != 0);
614 
615  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t*>(args[1]);
616  ASSERT(arg1 != 0);
617 
618  Real a1 = (*arg1)();
619  if (a1 > 0.) {
620  *out = 1.;
621 
622  } else if (a1 < 0.) {
623  *out = 0.;
624 
625  } else {
626  *out = .5;
627  }
628 
629  return 0;
630 }
#define ASSERT(expression)
Definition: colamd.c:977
double Real
Definition: mathtyp.h:39
static int mp_stop ( const MathParser::MathArgs args)
static

Definition at line 373 of file mathp.cc.

References ASSERT, MathParser::AT_INT, MathParser::AT_VOID, and MBDYN_EXCEPT_ARGS.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

374 {
375  ASSERT(args.size() == 1 + 2);
376  ASSERT(args[0]->Type() == MathParser::AT_VOID);
377  ASSERT(args[1]->Type() == MathParser::AT_INT);
378  ASSERT(args[2]->Type() == MathParser::AT_INT);
379 
380  MathParser::MathArgInt_t *s = dynamic_cast<MathParser::MathArgInt_t *>(args[1]);
381  ASSERT(s != 0);
382 
383  MathParser::MathArgInt_t *v = dynamic_cast<MathParser::MathArgInt_t *>(args[2]);
384  ASSERT(v != 0);
385 
386  if ((*s)() != 0) {
387  if ((*v)() == 0) {
388  silent_cout("mp_stop(SUCCESS)" << std::endl);
389  throw NoErr(MBDYN_EXCEPT_ARGS);
390 
391  } else {
392  silent_cout("mp_stop(FAILURE)" << std::endl);
394  }
395  }
396 
397  return 0;
398 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define ASSERT(expression)
Definition: colamd.c:977
Definition: except.h:79
static int mp_tan_t ( const MathParser::MathArgs args)
static

Definition at line 137 of file mathp.cc.

References a, ASSERT, MathParser::AT_REAL, grad::fabs(), and M_PI.

Referenced by MathParser::StaticNameSpace::StaticNameSpace().

138 {
139  ASSERT(args.size() == 1 + 1);
140  ASSERT(args[1]->Type() == MathParser::AT_REAL);
141 
142  MathParser::MathArgReal_t *arg1 = dynamic_cast<MathParser::MathArgReal_t *>(args[1]);
143  ASSERT(arg1 != 0);
144 
145  Real a1 = (*arg1)();
146  Real a = a1;
147  a -= int(a1/M_PI)*M_PI;
148  if (fabs(fabs(a) - M_PI_2) < std::numeric_limits<double>::epsilon()) {
149  return 1;
150  }
151 
152  return 0;
153 }
#define M_PI
Definition: gradienttest.cc:67
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Definition: gradient.h:2973
#define ASSERT(expression)
Definition: colamd.c:977
static const doublereal a
Definition: hfluid_.h:289
double Real
Definition: mathtyp.h:39

Here is the call graph for this function:

bool operator! ( const TypedValue v)

Definition at line 1657 of file mathp.cc.

References TypedValue::GetReal(), TypedValue::GetString(), TypedValue::GetType(), and TypedValue::VAR_STRING.

1658 {
1659  if (v.GetType() == TypedValue::VAR_STRING) {
1660  return v.GetString().empty();
1661  }
1662 
1663  return (!v.GetReal());
1664 }
Real GetReal(void) const
Definition: mathp.cc:1228
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const std::string & GetString(void) const
Definition: mathp.cc:1247

Here is the call graph for this function:

TypedValue operator+ ( const TypedValue v)

Definition at line 1689 of file mathp.cc.

1690 {
1691  return v;
1692 }
TypedValue operator- ( const TypedValue v)

Definition at line 1667 of file mathp.cc.

References TypedValue::GetInt(), TypedValue::GetReal(), TypedValue::GetType(), MBDYN_EXCEPT_ARGS, TypedValue::VAR_BOOL, TypedValue::VAR_INT, TypedValue::VAR_REAL, and TypedValue::VAR_STRING.

1668 {
1669  switch (v.GetType()) {
1670  case TypedValue::VAR_BOOL:
1671  // bool is implicitly cast to Int
1672  case TypedValue::VAR_INT:
1673  return TypedValue(-v.GetInt());
1674 
1675  case TypedValue::VAR_REAL:
1676  return TypedValue(-v.GetReal());
1677 
1680 
1681  default:
1683  }
1684 
1685  return 0;
1686 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

std::ostream& operator<< ( std::ostream &  out,
const MathParser::MathArgVoid_t  
)

Definition at line 314 of file mathp.cc.

315 {
316  return out;
317 }
std::ostream& operator<< ( std::ostream &  out,
const MathParser::MathArgBool_t v 
)

Definition at line 320 of file mathp.cc.

321 {
322  return out << v();
323 }
std::ostream& operator<< ( std::ostream &  out,
const MathParser::MathArgInt_t v 
)

Definition at line 326 of file mathp.cc.

327 {
328  return out << v();
329 }
std::ostream& operator<< ( std::ostream &  out,
const MathParser::MathArgReal_t v 
)

Definition at line 332 of file mathp.cc.

333 {
334  return out << v();
335 }
std::ostream& operator<< ( std::ostream &  out,
const MathParser::MathArgString_t v 
)

Definition at line 338 of file mathp.cc.

339 {
340  return out << v();
341 }
std::ostream& operator<< ( std::ostream &  out,
const TypedValue v 
)

Definition at line 1695 of file mathp.cc.

References TypedValue::GetInt(), TypedValue::GetReal(), TypedValue::GetString(), TypedValue::GetType(), MBDYN_EXCEPT_ARGS, TypedValue::VAR_BOOL, TypedValue::VAR_INT, TypedValue::VAR_REAL, and TypedValue::VAR_STRING.

1696 {
1697  switch (v.GetType()) {
1698  case TypedValue::VAR_BOOL:
1699  case TypedValue::VAR_INT:
1700  return out << v.GetInt();
1701 
1702  case TypedValue::VAR_REAL: {
1703  // FIXME: precision?
1704  // make sure there is a (trailing) '.'
1705  std::ostringstream os;
1706  os << v.GetReal();
1707  if (os.str().find('.') == std::string::npos) {
1708  os << '.';
1709  }
1710  return out << os.str();
1711  }
1712 
1714  return out << '"' << v.GetString() << '"';
1715 
1716  default:
1718  }
1719 
1720  return out;
1721 }
Real GetReal(void) const
Definition: mathp.cc:1228
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
TypedValue::Type GetType(void) const
Definition: mathp.cc:1155
const std::string & GetString(void) const
Definition: mathp.cc:1247
Int GetInt(void) const
Definition: mathp.cc:1209

Here is the call graph for this function:

Variable Documentation

const declarationmodifiernames DeclarationModifierNames[]
static
Initial value:

Definition at line 860 of file mathp.cc.

bool sns = 0
static

Definition at line 2006 of file mathp.cc.

const typemodifiernames TypeModifierNames[]
static
Initial value:

Definition at line 850 of file mathp.cc.

const TypeName_t TypeNames[]
static
Initial value:

Definition at line 836 of file mathp.cc.