tode.h - numeric - C++ library with numerical algorithms
 (HTM) git clone git://src.adamsgaard.dk/numeric
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tode.h (2393B)
       ---
            1 // Make sure header is only included once
            2 #ifndef ODE_H_
            3 #define ODE_H_
            4 
            5 #include <vector>
            6 #include <complex>
            7 #include "typedefs.h"
            8 
            9 // ODE class
           10 class ODE {
           11 
           12   // Values and functions only accessible from the class internally
           13   private:
           14 
           15     // System of ordinary differential equations to solve
           16     std::vector<std::complex<Floattype> > 
           17               (*f)(const std::complex<Floattype> x,
           18              const std::vector<std::complex<Floattype> > &y);
           19 
           20     // Points to be evaluated
           21     std::vector<std::complex<Floattype> > x_list;
           22     
           23     // Limits of range to evaluate
           24     const std::complex<Floattype> a; // Lower
           25     const std::complex<Floattype> b; // Upper
           26 
           27     // Step size
           28     std::complex<Floattype> h;
           29 
           30     // Results stored in 2D: vector of vectors
           31     std::vector<std::vector<std::complex<Floattype> > > y_list;
           32      
           33     // Maximum number of steps to evaluate, defined by y size
           34     const Inttype n_max;
           35 
           36     // Accuracy requirement values
           37     const Floattype delta;   // Absolute
           38     const Floattype epsilon; // Relative
           39 
           40     // Tolerance estimator
           41     Floattype tau(const std::vector<std::complex<Floattype> > &y,
           42                   const std::complex<Floattype> h);
           43 
           44     // Runge-Kutta mid-point stepper prototype
           45     void rkstep12(const std::complex<Floattype> x0,
           46                   const std::vector<std::complex<Floattype> > &y0,
           47                           std::vector<std::complex<Floattype> > &y1,
           48                         std::vector<std::complex<Floattype> > &dy);
           49 
           50     // Runge-Kutta driver function parameters
           51     const Floattype power;
           52     const Floattype safety;
           53 
           54     // Runge-Kutta driver prototype
           55     void rkdriver();
           56 
           57 
           58   // Values and functions accessible from the outside
           59   public:
           60 
           61     // Constructor, some parameters with default values
           62     ODE(std::vector<std::complex<Floattype> > 
           63                 (*f_in)(const std::complex<Floattype> x,
           64                         const std::vector<std::complex<Floattype> > &y),
           65         const std::vector<std::complex<Floattype> > y_start,
           66         const std::complex<Floattype> a_in,
           67         const std::complex<Floattype> b_in,
           68         const Floattype h_start = 0.01f,
           69         const Inttype max_steps = 1e4,
           70         const Floattype delta_in = 1e-3f,
           71         const Floattype epsilon_in = 1e-3f,
           72         const Floattype power_in = 0.25f,
           73         const Floattype safety_in = 0.95f
           74         );
           75 
           76     // Return the number of steps taken
           77     Inttype steps();
           78 
           79     // Print the x- and y-values to stdout
           80     void print();
           81 
           82     // Write the x- and y-values to file
           83     void write(const char* filename);
           84 
           85 };
           86 
           87 #endif