$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

spline.h

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #ifndef SPLINE_H
00026 #define SPLINE_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 namespace plb {
00032 
00033 template<typename T>
00034 class Spline {
00035 public:
00036     Spline() { }
00037     Spline(std::string fname);
00038     Spline(std::vector<T> const& x_, std::vector<T> const& y_);
00039     virtual ~Spline() { }
00040     virtual Spline<T>* clone() const =0;
00041     std::vector<T> const& getAbscissae() const { return x; }
00042     std::vector<T>& getAbscissae() { return x; }
00043     std::vector<T> const& getOrdinates() const { return y; }
00044     std::vector<T>& getOrdinates() { return y; }
00045     virtual T getFunctionValue(T t) const =0;
00046     virtual T getDerivativeValue(T t) const =0;
00047     virtual T getIntegralValue() const =0;
00048     virtual T getIntegralValue(T tmin, T tmax) const =0;
00049 private:
00050     std::vector<T> x, y;
00051 };
00052 
00053 template<typename T>
00054 class NaturalCubicSpline : public Spline<T> {
00055 public:
00056     NaturalCubicSpline() : icache(0) { }
00057     NaturalCubicSpline(std::string fname);
00058     NaturalCubicSpline(std::vector<T> const& x_, std::vector<T> const& y_);
00059     virtual ~NaturalCubicSpline() { }
00060     virtual NaturalCubicSpline<T>* clone() const;
00061     virtual T getFunctionValue(T t) const;
00062     virtual T getDerivativeValue(T t) const;
00063     virtual T getSecondDerivativeValue(T t) const;
00064     virtual T getThirdDerivativeValue(T t) const;
00065     virtual T getIntegralValue() const;
00066     virtual T getIntegralValue(T tmin, T tmax) const;
00067 private:
00068     void constructSpline();
00069     plint bsrch(T t, plint il, plint ih) const;
00070 private:
00071     mutable plint icache;
00072     std::vector<T> y1, y2, y3;
00073 };
00074 
00075 }  // namespace plb
00076 
00077 #endif  // SPLINE_H