Jpp
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t > Class Template Referenceabstract

Template base class for spline interpolations. More...

#include <JSpline.hh>

Inheritance diagram for JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >:
JTOOLS::JFunctional<> JTOOLS::JSplineFunction< JElement_t, JCollection_t, JResultDerivative< typename JResultType< typename JElement_t::ordinate_type >::result_type >, JDistance_t > JTOOLS::JSplineFunction< JElement_t, JCollection_t, JResultPDF< typename JResultType< typename JElement_t::ordinate_type >::result_type >, JDistance_t > JTOOLS::JSplineFunction< JElement_t, JCollection_t, typename JResultType< typename JElement_t::ordinate_type >::result_type, JDistance_t >

Public Types

typedef JCollection_t< JElement_t, JDistance_t > collection_type
 
typedef collection_type::abscissa_type abscissa_type
 
typedef collection_type::ordinate_type ordinate_type
 
typedef collection_type::value_type value_type
 
typedef collection_type::const_iterator const_iterator
 
typedef collection_type::const_reverse_iterator const_reverse_iterator
 
typedef collection_type::iterator iterator
 
typedef collection_type::reverse_iterator reverse_iterator
 
typedef JArgument_t argument_type
 
typedef JResult_t result_type
 
typedef JFunctional< argument_type, result_typefunctional_type
 
typedef JSupervisor supervisor_type
 

Public Member Functions

void compile (const JSplineBounds< ordinate_type > &bounds)
 Determination of second derivatives with specified bounds. More...
 
virtual result_type evaluate (const argument_type *pX) const=0
 Recursive function value evaluation. More...
 
JSupervisor getSupervisor () const
 Get supervisor. More...
 
const JExceptionHandler & getExceptionHandler () const
 Get exception handler. More...
 
void setExceptionHandler (const JSupervisor &supervisor)
 Set the supervisor for handling of exceptions. More...
 

Static Public Member Functions

static result_type getValue (const JFunctional &function, const argument_type *pX)
 Recursive function value evaluation. More...
 
static JClass< result_type >::argument_type getValue (typename JClass< result_type >::argument_type value, const argument_type *pX)
 Termination of recursive function value evaluation. More...
 

Protected Member Functions

 JSplineCollection ()
 Default constructor. More...
 
virtual void do_compile ()
 Determination of second derivatives with no bounds. More...
 

Protected Attributes

JSupervisor supervisor
 

Detailed Description

template<class JElement_t, template< class, class > class JCollection_t, class JDistance_t>
class JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >

Template base class for spline interpolations.

This class partially implements the JFunctional interface.

Note that the data structure of the elements in the collection should have the additional methods:

    ordinate_type getU() const;
    void setU(ordinate_type u);

to get and set the second derivatives, respectively.

Spline interpolation code is taken from reference: Numerical Recipes in C++, W.H. Press, S.A. Teukolsky, W.T. Vetterling and B.P. Flannery, Cambridge University Press.

Definition at line 174 of file JSpline.hh.

Member Typedef Documentation

◆ collection_type

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef JCollection_t<JElement_t, JDistance_t> JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::collection_type

Definition at line 180 of file JSpline.hh.

◆ abscissa_type

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::abscissa_type JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::abscissa_type

Definition at line 182 of file JSpline.hh.

◆ ordinate_type

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::ordinate_type JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::ordinate_type

Definition at line 183 of file JSpline.hh.

◆ value_type

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::value_type JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::value_type

Definition at line 184 of file JSpline.hh.

◆ const_iterator

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::const_iterator JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::const_iterator

Definition at line 186 of file JSpline.hh.

◆ const_reverse_iterator

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::const_reverse_iterator JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::const_reverse_iterator

Definition at line 187 of file JSpline.hh.

◆ iterator

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::iterator JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::iterator

Definition at line 188 of file JSpline.hh.

◆ reverse_iterator

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
typedef collection_type::reverse_iterator JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::reverse_iterator

Definition at line 189 of file JSpline.hh.

◆ argument_type

typedef JArgument_t JTOOLS::JFunctional< JArgument_t, JResult_t >::argument_type
inherited

Definition at line 84 of file JFunctional.hh.

◆ result_type

typedef JResult_t JTOOLS::JFunctional< JArgument_t, JResult_t >::result_type
inherited

Definition at line 87 of file JFunctional.hh.

◆ functional_type

typedef JFunctional<argument_type, result_type> JTOOLS::JFunctional< JArgument_t, JResult_t >::functional_type
inherited

Definition at line 88 of file JFunctional.hh.

◆ supervisor_type

typedef JSupervisor JTOOLS::JFunctional< JArgument_t, JResult_t >::supervisor_type
inherited

Definition at line 89 of file JFunctional.hh.

Constructor & Destructor Documentation

◆ JSplineCollection()

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::JSplineCollection ( )
inlineprotected

Default constructor.

Definition at line 294 of file JSpline.hh.

295  {}

Member Function Documentation

◆ compile()

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
void JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::compile ( const JSplineBounds< ordinate_type > &  bounds)
inline

Determination of second derivatives with specified bounds.

Parameters
bounds1st derivatives at two extrema.

Definition at line 199 of file JSpline.hh.

200  {
201  const int numberOfElements = this->size();
202 
203  using namespace std;
204 
205  if (numberOfElements > 2) {
206 
207  std::vector<double> buffer(numberOfElements);
208 
209  if (bounds.hasFirstDerivativeAtXmin()) {
210 
211  iterator j = this->begin();
212  iterator i = j++;
213 
214  const double dx = this->getDistance(i->getX(), j->getX());
215  const ordinate_type dy = (j->getY() - i->getY());
216 
217  buffer[0] = -0.5;
218 
219  i->setU((3.0/dx) * (dy/dx - bounds.getFirstDerivativeAtXmin()));
220 
221  } else {
222 
223  buffer[0] = 0.0;
224 
225  this->begin()->setU(JMATH::zero);
226  }
227 
228  int index = 1;
229 
230  for (iterator k = this->begin(), i = k++, j = k++; k != this->end(); ++i, ++j, ++k, ++index) {
231 
232  const abscissa_type x1 = i->getX();
233  const abscissa_type x2 = j->getX();
234  const abscissa_type x3 = k->getX();
235 
236  const ordinate_type& y1 = i->getY();
237  const ordinate_type& y2 = j->getY();
238  const ordinate_type& y3 = k->getY();
239 
240  const double sig = this->getDistance(x1, x2) / this->getDistance(x1, x3);
241  const double h = sig * buffer[index-1] + 2.0;
242 
243  buffer[index] = (sig - 1.0) / h;
244 
245  j->setU((y3 - y2) / this->getDistance(x2, x3) -
246  (y2 - y1) / this->getDistance(x1, x2));
247 
248  j->setU((6.0 * j->getU() / this->getDistance(x1, x3) - sig * i->getU()) / h);
249  }
250 
251 
252  if (bounds.hasFirstDerivativeAtXmax()) {
253 
254  reverse_iterator j = this->rbegin();
255  reverse_iterator i = j++;
256 
257  index = numberOfElements - 2;
258 
259  const double dx = this->getDistance(i->getX(), j->getX());
260  const ordinate_type dy = (j->getY() - i->getY());
261 
262  i->setU((3.0/dx) * (bounds.getFirstDerivativeAtXmax() - dy/dx));
263 
264  i->setU((i->getU() - 0.5*j->getU()) / (0.5*buffer[index] + 1.0));
265 
266  } else {
267 
268  this->rbegin()->setU(JMATH::zero);
269  }
270 
271 
272  reverse_iterator j = this->rbegin();
273  reverse_iterator i = j++;
274 
275  index = numberOfElements - 2;
276 
277  for ( ; j != this->rend(); ++i, ++j, --index) {
278  j->setU(j->getU() + i->getU() * buffer[index]);
279  }
280 
281  } else {
282 
283  for (iterator i = this->begin(); i != this->end(); ++i) {
284  i->setU(JMATH::zero);
285  }
286  }
287  }

◆ do_compile()

template<class JElement_t , template< class, class > class JCollection_t, class JDistance_t >
virtual void JTOOLS::JSplineCollection< JElement_t, JCollection_t, JDistance_t >::do_compile ( )
inlineprotectedvirtual

◆ evaluate()

virtual result_type JTOOLS::JFunctional< JArgument_t, JResult_t >::evaluate ( const argument_type pX) const
pure virtualinherited

◆ getValue() [1/2]

static result_type JTOOLS::JFunctional< JArgument_t, JResult_t >::getValue ( const JFunctional<> &  function,
const argument_type pX 
)
inlinestaticinherited

Recursive function value evaluation.

Parameters
functionfunction
pXpointer to abscissa values

Definition at line 107 of file JFunctional.hh.

109  {
110  return function.evaluate(pX);
111  }

◆ getValue() [2/2]

static JClass<result_type>::argument_type JTOOLS::JFunctional< JArgument_t, JResult_t >::getValue ( typename JClass< result_type >::argument_type  value,
const argument_type pX 
)
inlinestaticinherited

Termination of recursive function value evaluation.

Parameters
valueresult
pXpointer to abscissa values

Definition at line 121 of file JFunctional.hh.

123  {
124  return value;
125  }

◆ getSupervisor()

JSupervisor JTOOLS::JFunctional< JArgument_t, JResult_t >::getSupervisor ( ) const
inlineinherited

Get supervisor.

Returns
supervisor

Definition at line 266 of file JFunctional.hh.

267  {
268  return supervisor;
269  }

◆ getExceptionHandler()

const JExceptionHandler& JTOOLS::JFunctional< JArgument_t, JResult_t >::getExceptionHandler ( ) const
inlineinherited

Get exception handler.

Returns
exception handler

Definition at line 277 of file JFunctional.hh.

278  {
279  return *supervisor;
280  }

◆ setExceptionHandler()

void JTOOLS::JFunctional< JArgument_t, JResult_t >::setExceptionHandler ( const JSupervisor &  supervisor)
inlineinherited

Set the supervisor for handling of exceptions.

Parameters
supervisorsupervisor

Definition at line 288 of file JFunctional.hh.

289  {
290  this->supervisor = supervisor;
291  }

Member Data Documentation

◆ supervisor

JSupervisor JTOOLS::JFunctional< JArgument_t, JResult_t >::supervisor
protectedinherited

Definition at line 295 of file JFunctional.hh.


The documentation for this class was generated from the following file:
JTOOLS::JFunctional<>::supervisor
JSupervisor supervisor
Definition: JFunctional.hh:295
std::iterator
Definition: JSTDTypes.hh:18
JTOOLS::pX
pX
Definition: JPolint.hh:625
std::vector< double >
JTOOLS::j
int j
Definition: JPolint.hh:634
JTOOLS::JSplineCollection::ordinate_type
collection_type::ordinate_type ordinate_type
Definition: JSpline.hh:183
JTOOLS::JSplineCollection::abscissa_type
collection_type::abscissa_type abscissa_type
Definition: JSpline.hh:182
JTOOLS::JSplineBounds
Auxiliary class to define first derivates of the spline function at the two extrema.
Definition: JSpline.hh:34
JTOOLS::JSplineCollection::reverse_iterator
collection_type::reverse_iterator reverse_iterator
Definition: JSpline.hh:189
JTOOLS::JSplineCollection::compile
void compile(const JSplineBounds< ordinate_type > &bounds)
Determination of second derivatives with specified bounds.
Definition: JSpline.hh:199
JTOOLS::JSplineBounds::getFirstDerivativeAtXmax
ordinate_type getFirstDerivativeAtXmax() const
Get first derivative of function at maximal abscissa value.
Definition: JSpline.hh:128
JMATH::getDistance
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
Definition: JMathToolkit.hh:116
JTOOLS::JSplineBounds::hasFirstDerivativeAtXmin
const bool & hasFirstDerivativeAtXmin() const
Has first derivative of function at minimal abscissa value.
Definition: JSpline.hh:92
JTOOLS::JSplineBounds::getFirstDerivativeAtXmin
ordinate_type getFirstDerivativeAtXmin() const
Get first derivative of function at minimal abscissa value.
Definition: JSpline.hh:114
std
Definition: jaanetDictionary.h:36
JMATH::zero
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:94
JTOOLS::JSplineBounds::hasFirstDerivativeAtXmax
const bool & hasFirstDerivativeAtXmax() const
Has first derivative of function at maximal abscissa value.
Definition: JSpline.hh:103