diff --git a/src/lib.rs b/src/lib.rs index 43f7b981..4eed38f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,7 +115,7 @@ mod tests { let y = solver.solve(&problem, t).unwrap(); let mut state = OdeSolverState::new(&problem); - solver.set_problem(&mut state, problem); + solver.set_problem(&mut state, &problem); while state.t <= t { solver.step(&mut state).unwrap(); } diff --git a/src/ode_solver/bdf.rs b/src/ode_solver/bdf.rs index b22d2101..4ff820b8 100644 --- a/src/ode_solver/bdf.rs +++ b/src/ode_solver/bdf.rs @@ -259,9 +259,10 @@ where fn problem(&self) -> Option<&OdeSolverProblem> { self.ode_problem.as_ref() } - - fn set_problem(&mut self, state: &mut OdeSolverState, problem: OdeSolverProblem) { - self.ode_problem = Some(problem); + + fn set_problem(&mut self, state: &mut OdeSolverState, problem: &OdeSolverProblem) { + let problem_clone = problem.clone(); + self.ode_problem = Some(problem_clone); let problem = self.ode_problem.as_ref().unwrap(); let nstates = problem.eqn.nstates(); self.order = 1usize; diff --git a/src/ode_solver/mod.rs b/src/ode_solver/mod.rs index 9b9cec83..e0f892f6 100644 --- a/src/ode_solver/mod.rs +++ b/src/ode_solver/mod.rs @@ -26,13 +26,13 @@ pub mod diffsl; pub trait OdeSolverMethod { fn problem(&self) -> Option<&OdeSolverProblem>; - fn set_problem(&mut self, state: &mut OdeSolverState, problem: OdeSolverProblem); + fn set_problem(&mut self, state: &mut OdeSolverState, problem: &OdeSolverProblem); fn step(&mut self, state: &mut OdeSolverState) -> Result<()>; fn interpolate(&self, state: &OdeSolverState, t: Eqn::T) -> Eqn::V; fn solve(&mut self, problem: &OdeSolverProblem, t: Eqn::T) -> Result { let problem = problem.clone(); let mut state = OdeSolverState::new(&problem); - self.set_problem(&mut state, problem); + self.set_problem(&mut state, &problem); while state.t <= t { self.step(&mut state)?; } @@ -46,7 +46,7 @@ pub trait OdeSolverMethod { ) -> Result { let problem = problem.clone(); let mut state = OdeSolverState::new_consistent(&problem, root_solver)?; - self.set_problem(&mut state, problem); + self.set_problem(&mut state, &problem); while state.t <= t { self.step(&mut state)?; } @@ -254,7 +254,7 @@ mod tests { Eqn: OdeEquations, { let mut state = OdeSolverState::new_consistent(&problem, &mut root_solver).unwrap(); - method.set_problem(&mut state, problem); + method.set_problem(&mut state, &problem); for point in solution.solution_points.iter() { while state.t < point.t { method.step(&mut state).unwrap();