MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
CubicSplineScalarFunction Class Reference

#include <ScalarFunctionsImpl.h>

Inheritance diagram for CubicSplineScalarFunction:
Collaboration diagram for CubicSplineScalarFunction:

Public Member Functions

 CubicSplineScalarFunction (const std::vector< doublereal > &y_i, const std::vector< doublereal > &x_i, bool doNotExtrapolate=false)
 
virtual ~CubicSplineScalarFunction (void)
 
virtual doublereal operator() (const doublereal x) const
 
virtual doublereal ComputeDiff (const doublereal t, const integer order=1) const
 
- Public Member Functions inherited from DifferentiableScalarFunction
virtual ~DifferentiableScalarFunction ()
 
- Public Member Functions inherited from BasicScalarFunction
virtual ~BasicScalarFunction ()
 

Private Attributes

std::vector< doublerealY_i
 
std::vector< doublerealX_i
 
std::vector< doublerealb
 
std::vector< doublerealc
 
std::vector< doublereald
 
bool doNotExtrapolate
 

Detailed Description

Definition at line 120 of file ScalarFunctionsImpl.h.

Constructor & Destructor Documentation

CubicSplineScalarFunction::CubicSplineScalarFunction ( const std::vector< doublereal > &  y_i,
const std::vector< doublereal > &  x_i,
bool  doNotExtrapolate = false 
)

Definition at line 458 of file ScalarFunctionsImpl.cc.

References ASSERTMSGBREAK, b, c, d, MBDYN_EXCEPT_ARGS, spline(), X_i, and Y_i.

462 : Y_i(y_i), X_i(x_i),
464 {
465  ASSERTMSGBREAK(Y_i.size() == X_i.size(),
466  "CubicSplineScalarFunction error, Y_i.size() != X_i.size()");
467  std::vector<doublereal>::iterator xi, xe;
468  xi = X_i.begin();
469  xe = X_i.end() - 1;
470  for (unsigned i = 0; xi != xe; ++xi, ++i) {
471  if (*xi >= *(xi + 1)) {
472  silent_cerr("CubicSplineScalarFunction error, "
473  "X is not ordered: "
474  "X[" << i << "]=" << *xi
475  << " is not less than "
476  "X[" << i + 1 << "]=" << *(xi + 1)
477  << std::endl);
479  }
480  }
481  spline(X_i, Y_i, b, c, d);
482 }
#define ASSERTMSGBREAK(expr, msg)
Definition: myassert.h:222
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
void spline(const std::vector< doublereal > &x, const std::vector< doublereal > &y, std::vector< doublereal > &b, std::vector< doublereal > &c, std::vector< doublereal > &d)
Definition: interp.cc:8
std::vector< doublereal > c
std::vector< doublereal > X_i
std::vector< doublereal > b
std::vector< doublereal > Y_i
std::vector< doublereal > d

Here is the call graph for this function:

CubicSplineScalarFunction::~CubicSplineScalarFunction ( void  )
virtual

Definition at line 484 of file ScalarFunctionsImpl.cc.

References NO_OP.

485 {
486  NO_OP;
487 }
#define NO_OP
Definition: myassert.h:74

Member Function Documentation

doublereal CubicSplineScalarFunction::ComputeDiff ( const doublereal  t,
const integer  order = 1 
) const
virtual

Implements DifferentiableScalarFunction.

Definition at line 507 of file ScalarFunctionsImpl.cc.

References ASSERTMSGBREAK, b, c, d, operator()(), seval(), X_i, and Y_i.

508 {
509  ASSERTMSGBREAK(order >=0, "Error in CubicSplineScalarFunction::ComputeDiff, order<0");
510  switch (order) {
511  case 0:
512  return this->operator()(x);
513 
514  case 1:
515  return seval(x, X_i, Y_i, b, c, d, 1);
516 
517  case 2:
518  return seval(x, X_i, Y_i, b, c, d, 2);
519 
520  case 3:
521  return seval(x, X_i, Y_i, b, c, d, 3);
522 
523  default:
524  return 0.;
525  }
526 }
#define ASSERTMSGBREAK(expr, msg)
Definition: myassert.h:222
enum @55 order
std::vector< doublereal > c
virtual doublereal operator()(const doublereal x) const
std::vector< doublereal > X_i
std::vector< doublereal > b
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)
Definition: interp.cc:128
std::vector< doublereal > Y_i
std::vector< doublereal > d

Here is the call graph for this function:

doublereal CubicSplineScalarFunction::operator() ( const doublereal  x) const
virtual

Implements DifferentiableScalarFunction.

Definition at line 490 of file ScalarFunctionsImpl.cc.

References b, c, d, doNotExtrapolate, seval(), X_i, and Y_i.

Referenced by ComputeDiff().

491 {
492  if (doNotExtrapolate) {
493  if (x <= X_i[0]) {
494  return Y_i[0];
495  }
496 
497  int s = X_i.size() - 1;
498  if (x >= X_i[s]) {
499  return Y_i[s];
500  }
501  }
502 
503  return seval(x, X_i, Y_i, b, c, d);
504 }
std::vector< doublereal > c
std::vector< doublereal > X_i
std::vector< doublereal > b
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)
Definition: interp.cc:128
std::vector< doublereal > Y_i
std::vector< doublereal > d

Here is the call graph for this function:

Member Data Documentation

std::vector<doublereal> CubicSplineScalarFunction::b
private

Definition at line 124 of file ScalarFunctionsImpl.h.

Referenced by ComputeDiff(), CubicSplineScalarFunction(), and operator()().

std::vector<doublereal> CubicSplineScalarFunction::c
private

Definition at line 124 of file ScalarFunctionsImpl.h.

Referenced by ComputeDiff(), CubicSplineScalarFunction(), and operator()().

std::vector<doublereal> CubicSplineScalarFunction::d
private

Definition at line 124 of file ScalarFunctionsImpl.h.

Referenced by ComputeDiff(), CubicSplineScalarFunction(), and operator()().

bool CubicSplineScalarFunction::doNotExtrapolate
private

Definition at line 125 of file ScalarFunctionsImpl.h.

Referenced by operator()().

std::vector<doublereal> CubicSplineScalarFunction::X_i
private

Definition at line 123 of file ScalarFunctionsImpl.h.

Referenced by ComputeDiff(), CubicSplineScalarFunction(), and operator()().

std::vector<doublereal> CubicSplineScalarFunction::Y_i
private

Definition at line 122 of file ScalarFunctionsImpl.h.

Referenced by ComputeDiff(), CubicSplineScalarFunction(), and operator()().


The documentation for this class was generated from the following files: