Documentation


odeSolver_test.cpp

This is an example of how to design an use an OdeSolver
#include <iostream>
#include <animal/vector.h>
#include <animal/io.h>
#include <animal/odeSolver.h>
#include <animal/odeSolver.inl>

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::ostream;
using std::istream;


// ===============================================
// Instanciate the types used in the rest of the program

typedef float Real;
typedef Real Position;
typedef Real Velocity;
typedef animal::vector<Position> Positions;
typedef animal::vector<Velocity> Vector;



class MyPhysicalSolver:
    public animal::OdeSolver<Positions,Vector,Real>
{
public:

    MyPhysicalSolver( Real k, Real d )
        : stiffness(k)
        , dampingRatio(d)
    {}
    
protected:
    Real stiffness;
    Real dampingRatio;
    
    void computeAccelerations( Vector& a, const Positions& p, const Vector& v )
    {
        v_eq( a,p );
        v_peq( a, dampingRatio, v);
        v_teq( a, -stiffness );
    }

};



// ===============================================
// Main program.

int main()
{
  cout<<"\n============================================================\n";
  cout<<"Test program for class physicalEngine"<<endl;
  cout<<"============================================================\n"<<endl;
  
  // enter data
  cout<<"\n==== enter stiffness and damping ratio (example: 1 0.1)"
      <<endl;
  Real k,d;
  cin>>k>>d;
  MyPhysicalSolver psolver(k,d);
  cout<<endl;
  cout<<"==== enter initial position, velocity, time step, number of steps, method (example: 1 0 0.1 100 0)"<<endl;
  Positions p(1);
  Vector v(1);
  Real dt;
  int n;
  int m;
  cin>> v_input(p) >> v_input(v) >> dt >> n >> m; cout << endl;
  psolver.setMethod(m);
  
  cout<<"trajectory: "<<endl<< v_output(p) << v_output(v) << endl;
  for( int i=0; i<n; ++i )
  {
    psolver.solveODE( p, v, dt );
    cout<< v_output(p) << v_output(v) << endl;
  }
  
 
  return 0;
}

Generated on Thu Dec 23 13:52:23 2004 by doxygen 1.3.6