headmyshoulder / odeint-v2

odeint - solving ordinary differential equations in c++ v2
http://headmyshoulder.github.com/odeint-v2/
Other
341 stars 101 forks source link

support for different layout/structures of data in symplectic integratetors #221

Closed ghost closed 5 years ago

ghost commented 6 years ago

Hi,

I'm working on a nbody simulation code want to integrate/do_step with my system. My problem is that my data is not arranged in a suited structure for odeint, as I take it from solar system example. For example, lets say I have something like:

typedef point< double , 3 > point_type;

struct Particle
{
    double mass;
    point_type q;
    point_type p;

    point_type pos() const { return q; }
    point_type momentum() const { return p; }
    point_type& pos() { return q; }
    point_type& momentum() { return p; }
};

struct World
{
    std::vector<std::shared_ptr<Particle>> list;
};

The problem is the Symplectic integratetors accept the coordinates and momenta to be separated in different containers then the step would be:

do_step(  make_pair( system_coor( masses ) ,  system_momentum( masses ) ) , make_pair( boost::ref( q ) , boost::ref( p ) ) , t , dt );

Is it possible in odeint to integrate from other structures/layout? How can I do integration considering how my data is organized?

mariomulansky commented 6 years ago

I'd highly recommend changing your data layout. You typically want to avoid Vector-of-struct patterns and rather have Struct-of-vector in performance critical situations, as this is usually a more cache-friendly memory layout. On a side note, also vector will create an enormous performance overhead in my experience.