Boost logo

Boost :

Subject: [boost] Interest in a library for building simulations of dynamical systems?
From: Jay Graham (jaycgraham_at_[hidden])
Date: 2009-01-29 20:05:31


Is there interest in a library for building simulations of dynamical
systems represented by time-based differential equations?

The proposed library would implement ideas found in the C++ Model Developer
(CMD) library developed by Ray Sells, but in a more generic way. For
example,
the proposed library would support the use of user defined data types when
defining states and their derivatives. Other CMD features to be
included in the proposed library are:

1. The ability to mix both continuous and discrete events.
2. Support for a simulation structure that makes it easy to go from a
   mathematical description of a system to code.
3. Support for time-varying system topologies (e.g., multi-stage missiles).
4. User extendable set of numerical integration algorithms.

For more information on CMD see:

http://www.dtic.mil/srch/doc?collection=t2&id=ADA433836

and

http://rocket.itsc.uah.edu/u/education/files/R/IPT_Producer/AIAA/Sells/Sells.ppt

Code snippet:

// Define states and their derivatives
struct x_pos : state<
  double, // state type
  double // derivative type
> {};

struct y_pos : state< double, double > {};

// Define a simulation object
struct Ball: obj<
  rk4, // fourth-order Runge-Kutta numerical integration algorithm
  mpl::vector< x_pos, y_pos > // State vector
>
{
  Ball(double x, double y, double vx, double vy)
  {
    // Initial state
    s_<x_pos>().value = x;
    s_<y_pos>().value = y;

    this->vx = vx;
    this->vy = vy;

    // Integrators
    add_integrator<x_pos>(this->vx);
    add_integrator<y_pos>(this->vy);
  }

  template< typename S, typename C >
  inline void update(S &sim, C &clock)
  {
    // Update the derivatives
    vx = 0.8*vx;
    vy = 0.8*vy;

    // Use a discrete event to stop the simulation
    // after 10 seconds
    if (clock.event(10.0))
    {
      sim.halt();
    }
  }

  template< typename C >
  void report(C &clock)
  {
    // Report current state at 1 second intervals
    if (clock.sample(1.0))
    {
      std::cout << "Ball"
        << clock.t << " "
        << s_<x_pos>().value << " "
        << s_<y_pos>().value << "\n";
    }
  }

  double vx;
  double vy;
};

// Define the integration time-step
struct dts
{
  typedef double time_type;
  static time_type value() { return 0.01; }
};

// Define a simulation stage
struct stage_1 : stage< dts, mpl::vector<Ball> > {};

main()
{
  // Create a simulation object
  Ball ball(0.0, 0.0, 10.0, 5.0);

  // Create the simulation execution object
  sim< mpl::vector< stage_1 > > sim();

  // Initialize the simulation stage
  sim.stage_<stage_1>().obj_<Ball>() = &ball;

  // Run the simulation
  run(sim);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk