75 T1* out =
dynamic_cast<T1*
>(arg);
78 std::cerr <<
"ptr_cast error" << std::endl;
80 throw std::bad_cast();
87 static T1*
const cast(T2&arg) {
88 T1*
const out =
dynamic_cast<T1*const
>(arg);
91 std::cerr <<
"ptr_cast error" << std::endl;
93 throw std::bad_cast();
100 static const T1*
cast(T2&arg) {
101 const T1* out =
dynamic_cast<const T1*
>(arg);
104 std::cerr <<
"ptr_cast error" << std::endl;
106 throw std::bad_cast();
113 static const T1*
const cast(T2&arg) {
114 const T1*
const out =
dynamic_cast<const T1*const
>(arg);
117 std::cerr <<
"ptr_cast error" << std::endl;
119 throw std::bad_cast();
125 template<
class T1,
class T2>
163 ASSERTMSGBREAK(order >=0,
"Error in ConstScalarFunction::ComputeDiff, order<0");
190 ASSERTMSGBREAK(t_i != t_f,
"LinearScalarFunction error, t_i == t_f");
191 m = (y_f - y_i)/(t_f - t_i);
209 ASSERTMSGBREAK(order >=0,
"Error in LinearScalarFunction::ComputeDiff, order<0");
256 ASSERTMSGBREAK(order >=0,
"Error in PowScalarFunction::ComputeDiff, order<0");
266 return mul*
pow(x,
pw - order);
285 : mul_input(ml), mul_const(ml), base(b), coef(c)
302 silent_cerr(
"LogScalarFunction: argument must be positive" << std::endl);
312 ASSERTMSGBREAK(order >= 0,
"Error in LogScalarFunction::ComputeDiff, order<0");
318 silent_cerr(
"LogScalarFunction: argument must be positive" << std::endl);
333 for (
int i = 1; i <
order; i++) {
348 silent_cerr(
"LogSFR: "
362 silent_cerr(
"LogSFR: "
363 "invalid coefficient " << c
381 : mul(ml), base(b), coef_input(c), coef_const(c)
402 ASSERTMSGBREAK(order >= 0,
"Error in ExpScalarFunction::ComputeDiff, order<0");
415 for (
int i = 0; i <
order; i++) {
430 silent_cerr(
"ExpSFR: "
443 silent_cerr(
"ExpSFR: "
444 "invalid coefficient " << c
459 const std::vector<doublereal>& y_i,
460 const std::vector<doublereal>& x_i,
461 bool doNotExtrapolate)
462 : Y_i(y_i), X_i(x_i),
463 doNotExtrapolate(doNotExtrapolate)
466 "CubicSplineScalarFunction error, Y_i.size() != X_i.size()");
467 std::vector<doublereal>::iterator xi, xe;
470 for (
unsigned i = 0; xi != xe; ++xi, ++i) {
471 if (*xi >= *(xi + 1)) {
472 silent_cerr(
"CubicSplineScalarFunction error, "
474 "X[" << i <<
"]=" << *xi
475 <<
" is not less than "
476 "X[" << i + 1 <<
"]=" << *(xi + 1)
497 int s =
X_i.size() - 1;
509 ASSERTMSGBREAK(order >=0,
"Error in CubicSplineScalarFunction::ComputeDiff, order<0");
532 bool doNotExtrapolate(
false);
533 if (HP.
IsKeyWord(
"do" "not" "extrapolate")) {
534 doNotExtrapolate =
true;
536 std::vector<doublereal> y_i;
537 std::vector<doublereal> x_i;
540 for (
int i=0; i<3; i++) {
545 int size = x_i.size();
558 const std::vector<doublereal>& y_i,
559 const std::vector<doublereal>& x_i,
560 bool doNotExtrapolate)
561 : Y_i(y_i), X_i(x_i),
562 doNotExtrapolate(doNotExtrapolate)
565 "MultiLinearScalarFunction error, Y_i.size() != X_i.size()");
566 std::vector<doublereal>::iterator xi, xe;
569 for (
unsigned i = 0; xi != xe; ++xi, ++i) {
570 if (*xi >= *(xi + 1)) {
571 silent_cerr(
"MultiLinearScalarFunction error, "
573 "X[" << i <<
"]=" << *xi
574 <<
" is not less than "
575 "X[" << i + 1 <<
"]=" << *(xi + 1)
595 int s =
X_i.size() - 1;
607 ASSERTMSGBREAK(order >=0,
"Error in MultiLinearScalarFunction::ComputeDiff, order<0");
624 bool doNotExtrapolate(
false);
625 if (HP.
IsKeyWord(
"do" "not" "extrapolate")) {
626 doNotExtrapolate =
true;
628 std::vector<doublereal> y_i;
629 std::vector<doublereal> x_i;
632 for (
int i=0; i<2; i++) {
637 int size = x_i.size();
650 const std::vector<doublereal>& v,
652 : vCoef(v), da(a), dfa(0.), dfap(0.), db(b), dfb(0.), dfbp(0.),
653 doNotExtrapolate(dne)
673 silent_cerr(
"Chebychev interpolation: "
674 "x=" << x <<
" is out of range "
675 "[" <<
da <<
"," <<
db <<
"]" << std::endl);
683 silent_cerr(
"Chebychev interpolation: "
684 "x=" << x <<
" is out of range "
685 "[" <<
da <<
"," <<
db <<
"]" << std::endl);
696 for (
unsigned i = 2; i <
vCoef.size(); i++) {
708 ASSERTMSGBREAK(order >=0,
"Error in ChebychevScalarFunction::ComputeDiff, order<0");
718 silent_cerr(
"differentiation of order " << order <<
" not supported yet" << std::endl);
724 silent_cerr(
"Chebychev interpolation: "
725 "x=" << x <<
" is out of range "
726 "[" <<
da <<
"," <<
db <<
"]" << std::endl);
734 silent_cerr(
"Chebychev interpolation: "
735 "x=" << x <<
" is out of range "
736 "[" <<
da <<
"," <<
db <<
"]" << std::endl);
749 for (
unsigned i = 2; i <
vCoef.size(); i++) {
751 doublereal Txp = 2.*d[1 - i%2] + 2.*xi*dp[1 - i%2] - dp[i%2];
766 bool doNotExtrapolate(
false);
767 if (HP.
IsKeyWord(
"do" "not" "extrapolate")) {
768 doNotExtrapolate =
true;
771 silent_cerr(
"Upper interval bound "
772 "of Chebychev series b=" << b
773 <<
" must be larger than lower bound a=" << a
778 std::vector<doublereal> v;
784 unsigned order = v.size();
786 silent_cerr(
"Need at least one Chebychev series coefficient "
812 return a1->operator()(x) +
a2->operator()(x);
818 ASSERTMSGBREAK(order >=0,
"Error in SumScalarFunction::ComputeDiff, order<0");
859 return a1->operator()(x) -
a2->operator()(x);
865 ASSERTMSGBREAK(order >= 0,
"Error in SubScalarFunction::ComputeDiff, order<0");
906 return a1->operator()(x)*
a2->operator()(x);
912 ASSERTMSGBREAK(order >= 0,
"Error in MulScalarFunction::ComputeDiff, order<0");
954 d =
a2->operator()(x);
957 silent_cerr(
"DivScalarFunction: division by zero" << std::endl);
960 n =
a1->operator()(x);
968 ASSERTMSGBREAK(order >= 0,
"Error in DivScalarFunction::ComputeDiff, order<0");
974 d =
a2->operator()(x);
977 silent_cerr(
"DivScalarFunction: division by zero" << std::endl);
1000 typedef std::map<std::string, const ScalarFunctionRead *, ltstrcase>
SFReadType;
1017 const char *s = HP.
IsWord(SFWordSet);
1022 SFReadType::iterator
func =
SFRead.find(std::string(s));
1023 if (func ==
SFRead.end()) {
1024 silent_cerr(
"unknown scalar function type \"" << s <<
"\" "
1025 "for function \"" << func_name <<
"\" "
1031 sf = func->second->Read(pDM, HP);
1033 silent_cerr(
"Unable to parse "
1034 "ScalarFunction(\"" << func_name <<
"\") "
1039 silent_cerr(
"scalar function \"" << func_name <<
"\" "
1040 "already defined at line " << HP.
GetLineData() << std::endl);
1044 }
else if (HP.
IsWord(SFWordSet)) {
1045 silent_cerr(
"Error: redefinition of "
1046 "\"" << func_name <<
"\" scalar function "
1080 virtual std::ostream&
Restart(std::ostream& out)
const {
1081 silent_cerr(
"ScalarFunctionDriveCaller: Restart not implemented"
1091 return (ptr_cast<const DifferentiableScalarFunction*const>(
sc) != 0);
1107 NeedDM(pDM, HP, bDeferred,
"scalar function");
1111 silent_cerr(
"sorry, since the driver is not owned by a DataManager" << std::endl
1112 <<
"no driver dependent drivers are allowed;" << std::endl
1113 <<
"aborting..." << std::endl);
1135 template <
class T,
class Tder>
1145 if (
typeid(T) ==
typeid(
Vec3)) {
1148 }
else if (
typeid(T) ==
typeid(
Vec6)) {
1152 silent_cerr(
"ScalarFunctionIsotropicCL<" <<
typeid(T).name() <<
", " <<
typeid(Tder).name() <<
"> not implemented" << std::endl);
1173 virtual std::ostream&
Restart(std::ostream& out)
const {
1174 return out <<
"# not implemented!";
1177 virtual void Update(
const T& Eps,
const T& = 0.) {
1179 for (
int i = 1; i <=
n; i++) {
1180 #if defined(MBDYN_X_WORKAROUND_GCC_3_2) || defined(MBDYN_X_WORKAROUND_GCC_3_3)
1183 #else // !MBDYN_X_WORKAROUND_GCC_3_2 && ! MBDYN_X_WORKAROUND_GCC_3_3
1186 #endif // !MBDYN_X_WORKAROUND_GCC_3_3 && ! MBDYN_X_WORKAROUND_GCC_3_3
1219 virtual std::ostream&
Restart(std::ostream& out)
const {
1220 return out <<
"# not implemented!";
1231 template <
class T,
class Tder>
1237 template <
class T,
class Tder>
1251 }
else if (
typeid(T) ==
typeid(
Vec3)) {
1254 }
else if (
typeid(T) ==
typeid(
Vec6)) {
1258 silent_cerr(
"ScalarFunctionIsotropicCL"
1259 "<" <<
typeid(T).name() <<
", " <<
typeid(Tder).name() <<
"> "
1260 "not implemented" << std::endl);
1267 silent_cerr(
"ScalarFunction must be differentiable "
1280 template <
class T,
class Tder>
1284 std::vector<const DifferentiableScalarFunction *>
SF;
1290 if (
typeid(T) ==
typeid(
Vec3)) {
1293 }
else if (
typeid(T) ==
typeid(
Vec6)) {
1297 silent_cerr(
"ScalarFunctionOrthotropicCL<" <<
typeid(T).name() <<
", " <<
typeid(Tder).name() <<
"> not implemented" << std::endl);
1303 for (
unsigned i = 0; i <
n; i++) {
1324 virtual std::ostream&
Restart(std::ostream& out)
const {
1325 return out <<
"# not implemented!";
1328 virtual void Update(
const T& Eps,
const T& = 0.) {
1330 for (
unsigned i = 1; i <=
n; i++) {
1332 if (
SF[i - 1] == 0) {
1336 #if defined(MBDYN_X_WORKAROUND_GCC_3_2) || defined(MBDYN_X_WORKAROUND_GCC_3_3)
1339 #else // !MBDYN_X_WORKAROUND_GCC_3_2 && ! MBDYN_X_WORKAROUND_GCC_3_3
1342 #endif // !MBDYN_X_WORKAROUND_GCC_3_2 && ! MBDYN_X_WORKAROUND_GCC_3_3
1348 template <
class T,
class Tder>
1354 template <
class T,
class Tder>
1365 if (
typeid(T) ==
typeid(
Vec3)) {
1368 }
else if (
typeid(T) ==
typeid(
Vec6)) {
1371 }
else if (
typeid(T) !=
typeid(
doublereal)) {
1372 silent_cerr(
"ScalarFunctionOrthotropicCL<" <<
typeid(T).name() <<
", " <<
typeid(Tder).name() <<
"> not implemented" << std::endl);
1376 std::vector<const DifferentiableScalarFunction *> SF(n);
1377 for (
int i = 0; i < n; i++) {
1385 silent_cerr(
"ScalarFunction #" << i + 1 <<
" must be differentiable "
1401 pedantic_cout(
"registering scalar function \"" << s <<
"\""
1403 return SFRead.insert(SFReadType::value_type(s, rf)).second;
1447 silent_cerr(
"unable to register scalar function drive caller"
1456 if (!
SetCL1D(
"scalar" "function" "elastic" "isotropic", rf1D)) {
1459 silent_cerr(
"unable to register scalar function isotropic 1D constitutive law"
1466 if (!
SetCL1D(
"scalar" "function" "elastic" "orthotropic", rf1D)) {
1469 silent_cerr(
"unable to register scalar function orthotropic 1D constitutive law"
1476 if (!
SetCL1D(
"scalar" "function" "elastic", rf1D)) {
1479 silent_cerr(
"unable to register scalar function 1D constitutive law"
1486 if (!
SetCL3D(
"scalar" "function" "elastic" "isotropic", rf3D)) {
1489 silent_cerr(
"unable to register scalar function isotropic 3D constitutive law"
1496 if (!
SetCL3D(
"scalar" "function" "elastic" "orthotropic", rf3D)) {
1499 silent_cerr(
"unable to register scalar function orthotropic 3D constitutive law"
1506 if (!
SetCL6D(
"scalar" "function" "elastic" "isotropic", rf6D)) {
1509 silent_cerr(
"unable to register scalar function isotropic 6D constitutive law"
1516 if (!
SetCL6D(
"scalar" "function" "elastic" "orthotropic", rf6D)) {
1519 silent_cerr(
"unable to register scalar function orthotropic 6D constitutive law"
1530 silent_cerr(
"DestroySF() called once too many" << std::endl);
1538 for (SFReadType::iterator i =
SFRead.begin(); i !=
SFRead.end(); ++i) {
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
GradientExpression< UnaryExpr< FuncExp, Expr > > exp(const GradientExpression< Expr > &u)
virtual ~ChebychevScalarFunction(void)
bool SetSF(const std::string &s, const ScalarFunctionRead *rf)
virtual ~DifferentiableScalarFunction()
ScalarFunctionOrthotropicCL(const std::vector< const DifferentiableScalarFunction * > &sf)
bool SetDriveCallerData(const char *name, DriveCallerRead *rf)
#define ASSERTMSGBREAK(expr, msg)
virtual DriveCaller * pCopy(void) const
const BasicScalarFunction * GetScalarFunction(void)
GradientExpression< BinaryExpr< FuncPow, LhsExpr, RhsExpr > > pow(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
virtual ~LinearScalarFunction(void)
#define MBDYN_EXCEPT_ARGS
virtual doublereal operator()(const doublereal x) const
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
ConstLawType::Type GetConstLawType(void) const
virtual const char * IsWord(const HighParser::WordSet &ws)
virtual doublereal dGetP(const doublereal &dVar) const
virtual ~ScalarFunctionIsotropicCL(void)
virtual ~ScalarFunctionOrthotropicCL(void)
virtual doublereal operator()(const doublereal x) const
void spline(const std::vector< doublereal > &x, const std::vector< doublereal > &y, std::vector< doublereal > &b, std::vector< doublereal > &c, std::vector< doublereal > &d)
ConstScalarFunction(const doublereal v)
const DifferentiableScalarFunction * pSF
ScalarFunctionIsotropicCL(const DifferentiableScalarFunction *psf)
const DifferentiableScalarFunction * pSF
virtual ~SumScalarFunction(void)
const DriveHandler * pGetDrvHdl(void) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual doublereal operator()(const doublereal x) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
DivScalarFunction(const BasicScalarFunction *const b1, const BasicScalarFunction *const b2)
virtual doublereal operator()(const doublereal x) const
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
virtual doublereal operator()(const doublereal x) const
const DifferentiableScalarFunction *const a1
static T1 * cast(T2 &arg)
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
virtual ~PowScalarFunction(void)
static T1 *const cast(T2 &arg)
const DifferentiableScalarFunction *const a1
virtual ~ScalarFunctionDriveCaller(void)
bool SetScalarFunction(const std::string &s, const BasicScalarFunction *sf)
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
PowScalarFunction(const doublereal p)
std::vector< doublereal > c
virtual ~ExpScalarFunction(void)
const DifferentiableScalarFunction *const a2
const BasicScalarFunction *const sc
virtual doublereal dGet(const doublereal &dVar) const
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
ExpScalarFunction(const doublereal &ml, const doublereal &b, const doublereal &c)
GradientExpression< UnaryExpr< FuncLog, Expr > > log(const GradientExpression< Expr > &u)
virtual ConstitutiveLaw< T, Tder > * pCopy(void) const
const DifferentiableScalarFunction *const a1
doublereal leval(const doublereal &u, const std::vector< doublereal > &x, const std::vector< doublereal > &y, const int diff)
virtual bool bIsDifferentiable(void) const
virtual bool IsKeyWord(const char *sKeyWord)
ScalarFunctionDriveCaller(const DriveHandler *pDH, const BasicScalarFunction *const f)
std::vector< doublereal > Y_i
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
ScalarFunctionIsotropicCL(const DifferentiableScalarFunction *psf)
static SFWordSetType SFWordSet
virtual doublereal operator()(const doublereal x) const
virtual ~ConstScalarFunction(void)
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
virtual void Update(const doublereal &Eps, const doublereal &=0.)
MulScalarFunction(const BasicScalarFunction *const b1, const BasicScalarFunction *const b2)
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
bool IsWord(const std::string &s) const
virtual ~ScalarFunctionIsotropicCL(void)
bool SetCL3D(const char *name, ConstitutiveLawRead< Vec3, Mat3x3 > *rf)
LinearScalarFunction(const doublereal t_i, const doublereal y_i, const doublereal t_f, const doublereal y_f)
SubScalarFunction(const BasicScalarFunction *const b1, const BasicScalarFunction *const b2)
virtual doublereal operator()(const doublereal x) const
virtual ConstitutiveLaw< T, Tder > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
virtual ~DivScalarFunction(void)
virtual std::ostream & Restart(std::ostream &out) const
virtual ~MulScalarFunction(void)
virtual ~MultiLinearScalarFunction(void)
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
#define ASSERT(expression)
virtual doublereal operator()(const doublereal x) const
static const T1 *const cast(T2 &arg)
virtual doublereal operator()(const doublereal x) const
virtual doublereal operator()(const doublereal x) const
virtual doublereal ComputeDiff(const doublereal x, const integer order=1) const =0
virtual void Update(const T &Eps, const T &=0.)
virtual doublereal operator()(const doublereal x) const
bool SetCL1D(const char *name, ConstitutiveLawRead< doublereal, doublereal > *rf)
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
std::vector< doublereal > X_i
virtual ConstitutiveLaw< T, Tder > * Read(const DataManager *pDM, MBDynParser &HP, ConstLawType::Type &CLType)
std::vector< doublereal > vCoef
virtual std::ostream & Restart(std::ostream &out) const
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
CubicSplineScalarFunction(const std::vector< doublereal > &y_i, const std::vector< doublereal > &x_i, bool doNotExtrapolate=false)
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
bool SetCL6D(const char *name, ConstitutiveLawRead< Vec6, Mat6x6 > *rf)
static std::stack< cleanup * > c
virtual std::ostream & Restart(std::ostream &out) const
const DifferentiableScalarFunction *const a2
virtual doublereal operator()(const doublereal x) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual ~CubicSplineScalarFunction(void)
DriveCaller * Read(const DataManager *pDM, MBDynParser &HP, bool bDeferred)
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
std::vector< doublereal > X_i
virtual ~LogScalarFunction(void)
virtual std::ostream & Restart(std::ostream &out) const
std::vector< doublereal > b
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
std::vector< const DifferentiableScalarFunction * > SF
const DifferentiableScalarFunction *const a1
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
const BasicScalarFunction *const ParseScalarFunction(MBDynParser &HP, DataManager *const pDM)
virtual void Update(const T &Eps, const T &=0.)
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
virtual ConstitutiveLaw< doublereal, doublereal > * pCopy(void) const
ConstLawType::Type GetConstLawType(void) const
static const doublereal a
virtual ~BasicScalarFunction()
void NeedDM(const DataManager *pDM, MBDynParser &HP, bool bDeferred, const char *const name)
static const T1 * cast(T2 &arg)
const doublereal coef_input
SumScalarFunction(const BasicScalarFunction *const b1, const BasicScalarFunction *const b2)
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
ChebychevScalarFunction(const std::vector< doublereal > &v, const doublereal &a, const doublereal &b, bool doNotExtrapolate=false)
virtual ~SubScalarFunction(void)
virtual HighParser::ErrOut GetLineData(void) const
const DifferentiableScalarFunction *const a2
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
virtual const BasicScalarFunction * Read(DataManager *const pDM, MBDynParser &HP) const
ConstLawType::Type GetConstLawType(void) const
doublereal seval(const doublereal &u, const std::vector< doublereal > &x, const std::vector< doublereal > &y, const std::vector< doublereal > &b, const std::vector< doublereal > &c, const std::vector< doublereal > &d, const int diff)
std::vector< doublereal > Y_i
LogScalarFunction(const doublereal &ml, const doublereal &b, const doublereal &c)
MultiLinearScalarFunction(const std::vector< doublereal > &y_i, const std::vector< doublereal > &x_i, bool doNotExtrapolate=false)
std::map< std::string, const ScalarFunctionRead *, ltstrcase > SFReadType
const DifferentiableScalarFunction *const a2
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
std::vector< doublereal > d
virtual doublereal GetReal(const doublereal &dDefval=0.0)