srenevey / ode-solvers

Numerical methods to solve ordinary differential equations in Rust.
BSD 3-Clause "New" or "Revised" License
64 stars 26 forks source link

Simulation done --> Now move instead of copy xout and yout #23

Closed DarthB closed 7 months ago

DarthB commented 9 months ago

Status Quo: At the moment users need to copy the value of x_out and y_out if they want to use them independently from the type implementing System.

My situation I have a reactor bed cascade and use solout to stop if a reaction rate reaches zero (by this concluding the length of the reactor bed). In a for loop the next reactor bed get initialized with the previous results and the results are stored in a concluding data structure. I cannot move as I can only access references to x_out and y_out.

Solution: Implement From<Dop853/ Dopri5 / RK4> for (Vec<f64>, Vec<V>)

See: from trait See: into trait

We may instead introduce a solver result type as wrapper:

pub struct SolverResult {
   x: Vec<f64>,
   y: Vec<V>,
}

and implement from for that data structure. By this we make more use of the Rust type system.

Benefit: Users can spare a copy of a heap object that may be expensive when using into or from.

Proposal If we agree on the solution, I could implement that in my free time after xmas.

srenevey commented 9 months ago

The SolverResult struct seems a good approach. Feel free to implement it and send a PR. Thanks for the suggestion.