headmyshoulder / odeint-v2

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

Changes to system object were lost in chain of calls #187

Closed Bob-F closed 8 years ago

Bob-F commented 8 years ago

Sometime ago in order to solve a problem in my application with odeint, I had to change all "System system" to "System& system" to pass system object by reference in about 57 files [e.g., ... integrate( System system , State &start_state , Time start_time , Time end_time , Time dt ) in odeint/integrate/integrate.hpp]. The issue was that a lot of copies of system were made in the chain of calls, and changes to the system at the end of the chain were not retained when backing up call stack to return to the original system object. In my view, after the integration from the start time to the end time, the system was changed, and there should be a way to keep the changes in the system object.

mariomulansky commented 8 years ago

We decided to use pass-by-value as default for performance reasons. You can easily enforce pass-by-reference by using a reference wrapper such as std::ref (C++11) or boost::ref. See also http://headmyshoulder.github.io/odeint-v2/doc/boost_numeric_odeint/odeint_in_detail/using_boost__ref.html