PolynomialTimeDependence.h 1.05 KB
Newer Older
1 2 3 4 5
#ifndef _CLASSIC_SRC_ALGORITHMS_POLYNOMIALTIMEDEPENDENCE_H_
#define _CLASSIC_SRC_ALGORITHMS_POLYNOMIALTIMEDEPENDENCE_H_

#include <vector>
#include <iostream>
6
#include "Ippl.h"
7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "Algorithms/AbstractTimeDependence.h"

class PolynomialTimeDependence : public AbstractTimeDependence {
  public:
    PolynomialTimeDependence(std::vector<double> ptd) : coeffs(ptd) {}
    PolynomialTimeDependence() {}
    ~PolynomialTimeDependence() {}
    inline double getValue(double time);
    PolynomialTimeDependence* clone() {
      std::vector<double> temp(coeffs);
      PolynomialTimeDependence* d = new PolynomialTimeDependence(temp);
      return d;
    }

21 22
    Inform &print(Inform &os);

23 24 25 26 27 28 29 30 31 32 33 34 35 36
  private:
    std::vector<double> coeffs;
};

double PolynomialTimeDependence::getValue(double time) {
    double x = 0.;
    double t_power = 1.;
    for (std::size_t i = 0; i < coeffs.size() ; ++i) {
        x += coeffs[i]*t_power;
        t_power *= time;
    }
    return x;
}

37 38 39 40 41 42

inline
Inform &operator<<(Inform &os, PolynomialTimeDependence &p) {
  return p.print(os);
}

43 44
#endif