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

#include <ScalarFunctionsImpl.h>

Inheritance diagram for ChebychevScalarFunction:
Collaboration diagram for ChebychevScalarFunction:

Public Member Functions

 ChebychevScalarFunction (const std::vector< doublereal > &v, const doublereal &a, const doublereal &b, bool doNotExtrapolate=false)
 
virtual ~ChebychevScalarFunction (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< doublerealvCoef
 
const doublereal da
 
const doublereal dfa
 
const doublereal dfap
 
const doublereal db
 
const doublereal dfb
 
const doublereal dfbp
 
bool doNotExtrapolate
 

Detailed Description

Definition at line 151 of file ScalarFunctionsImpl.h.

Constructor & Destructor Documentation

ChebychevScalarFunction::ChebychevScalarFunction ( const std::vector< doublereal > &  v,
const doublereal a,
const doublereal b,
bool  doNotExtrapolate = false 
)

Definition at line 649 of file ScalarFunctionsImpl.cc.

References a, ComputeDiff(), dfa, dfap, dfb, dfbp, and doNotExtrapolate.

652 : vCoef(v), da(a), dfa(0.), dfap(0.), db(b), dfb(0.), dfbp(0.),
653 doNotExtrapolate(dne)
654 {
655  if (!doNotExtrapolate) {
656  const_cast<doublereal&>(dfa) = this->operator()(a);
657  const_cast<doublereal&>(dfap) = this->ComputeDiff(a);
658  const_cast<doublereal&>(dfb) = this->operator()(b);
659  const_cast<doublereal&>(dfbp) = this->ComputeDiff(b);
660  }
661 }
virtual doublereal ComputeDiff(const doublereal t, const integer order=1) const
std::vector< doublereal > vCoef
static const doublereal a
Definition: hfluid_.h:289
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

ChebychevScalarFunction::~ChebychevScalarFunction ( void  )
virtual

Definition at line 663 of file ScalarFunctionsImpl.cc.

References NO_OP.

664 {
665  NO_OP;
666 }
#define NO_OP
Definition: myassert.h:74

Member Function Documentation

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

Implements DifferentiableScalarFunction.

Definition at line 706 of file ScalarFunctionsImpl.cc.

References ASSERTMSGBREAK, da, db, dfap, dfbp, doNotExtrapolate, MBDYN_EXCEPT_ARGS, operator()(), and vCoef.

Referenced by ChebychevScalarFunction().

707 {
708  ASSERTMSGBREAK(order >=0, "Error in ChebychevScalarFunction::ComputeDiff, order<0");
709 
710  switch (order) {
711  case 0:
712  return operator()(x);
713 
714  case 1:
715  break;
716 
717  default:
718  silent_cerr("differentiation of order " << order << " not supported yet" << std::endl);
720  }
721 
722  if (x < da) {
723  if (doNotExtrapolate) {
724  silent_cerr("Chebychev interpolation: "
725  "x=" << x << " is out of range "
726  "[" << da << "," << db << "]" << std::endl);
728  }
729 
730  return dfap;
731 
732  } else if (x > db) {
733  if (doNotExtrapolate) {
734  silent_cerr("Chebychev interpolation: "
735  "x=" << x << " is out of range "
736  "[" << da << "," << db << "]" << std::endl);
738  }
739 
740  return dfbp;
741  }
742 
743  doublereal xi = (2.*x - (da + db))/(db - da);
744  doublereal xip = 2./(db - da);
745  doublereal d[2] = { 1., xi };
746  doublereal dp[2] = { 0., 1. };
747  doublereal val = vCoef[1];
748 
749  for (unsigned i = 2; i < vCoef.size(); i++) {
750  doublereal Tx = 2.*xi*d[1 - i%2] - d[i%2];
751  doublereal Txp = 2.*d[1 - i%2] + 2.*xi*dp[1 - i%2] - dp[i%2];
752  val += vCoef[i]*Txp;
753  d[i%2] = Tx;
754  dp[i%2] = Txp;
755  }
756 
757  return xip*val;
758 }
#define ASSERTMSGBREAK(expr, msg)
Definition: myassert.h:222
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual doublereal operator()(const doublereal x) const
enum @55 order
std::vector< doublereal > vCoef
double doublereal
Definition: colamd.c:52

Here is the call graph for this function:

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

Implements DifferentiableScalarFunction.

Definition at line 669 of file ScalarFunctionsImpl.cc.

References da, db, dfa, dfap, dfb, dfbp, doNotExtrapolate, MBDYN_EXCEPT_ARGS, and vCoef.

Referenced by ComputeDiff().

670 {
671  if (x < da) {
672  if (doNotExtrapolate) {
673  silent_cerr("Chebychev interpolation: "
674  "x=" << x << " is out of range "
675  "[" << da << "," << db << "]" << std::endl);
677  }
678 
679  return dfa + dfap*(x - da);
680 
681  } else if (x > db) {
682  if (doNotExtrapolate) {
683  silent_cerr("Chebychev interpolation: "
684  "x=" << x << " is out of range "
685  "[" << da << "," << db << "]" << std::endl);
687  }
688 
689  return dfb + dfbp*(x - db);
690  }
691 
692  doublereal xi = (2.*x - (da + db))/(db - da);
693  doublereal d[2] = { 1., xi };
694  doublereal val = vCoef[0] + vCoef[1]*xi;
695 
696  for (unsigned i = 2; i < vCoef.size(); i++) {
697  doublereal Tx = 2.*xi*d[1 - i%2] - d[i%2];
698  val += vCoef[i]*Tx;
699  d[i%2] = Tx;
700  }
701 
702  return val;
703 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
std::vector< doublereal > vCoef
double doublereal
Definition: colamd.c:52

Member Data Documentation

const doublereal ChebychevScalarFunction::da
private

Definition at line 154 of file ScalarFunctionsImpl.h.

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

const doublereal ChebychevScalarFunction::db
private

Definition at line 154 of file ScalarFunctionsImpl.h.

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

const doublereal ChebychevScalarFunction::dfa
private

Definition at line 154 of file ScalarFunctionsImpl.h.

Referenced by ChebychevScalarFunction(), and operator()().

const doublereal ChebychevScalarFunction::dfap
private

Definition at line 154 of file ScalarFunctionsImpl.h.

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

const doublereal ChebychevScalarFunction::dfb
private

Definition at line 154 of file ScalarFunctionsImpl.h.

Referenced by ChebychevScalarFunction(), and operator()().

const doublereal ChebychevScalarFunction::dfbp
private

Definition at line 154 of file ScalarFunctionsImpl.h.

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

bool ChebychevScalarFunction::doNotExtrapolate
private

Definition at line 155 of file ScalarFunctionsImpl.h.

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

std::vector<doublereal> ChebychevScalarFunction::vCoef
private

Definition at line 153 of file ScalarFunctionsImpl.h.

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


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