Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a reference of problem for set_problem() #4

Merged
merged 6 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions src/ode_solver/bdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ where
fn problem(&self) -> Option<&OdeSolverProblem<Eqn>> {
self.ode_problem.as_ref()
}

fn set_problem(&mut self, state: &mut OdeSolverState<Eqn::M>, problem: OdeSolverProblem<Eqn>) {
self.ode_problem = Some(problem);

fn set_problem(&mut self, state: &mut OdeSolverState<Eqn::M>, problem: &OdeSolverProblem<Eqn>) {
let problem_clone = problem.clone();
mhovd marked this conversation as resolved.
Show resolved Hide resolved
self.ode_problem = Some(problem_clone);
let problem = self.ode_problem.as_ref().unwrap();
let nstates = problem.eqn.nstates();
self.order = 1usize;
Expand Down
8 changes: 4 additions & 4 deletions src/ode_solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub mod diffsl;

pub trait OdeSolverMethod<Eqn: OdeEquations> {
fn problem(&self) -> Option<&OdeSolverProblem<Eqn>>;
fn set_problem(&mut self, state: &mut OdeSolverState<Eqn::M>, problem: OdeSolverProblem<Eqn>);
fn set_problem(&mut self, state: &mut OdeSolverState<Eqn::M>, problem: &OdeSolverProblem<Eqn>);
fn step(&mut self, state: &mut OdeSolverState<Eqn::M>) -> Result<()>;
fn interpolate(&self, state: &OdeSolverState<Eqn::M>, t: Eqn::T) -> Eqn::V;
fn solve(&mut self, problem: &OdeSolverProblem<Eqn>, t: Eqn::T) -> Result<Eqn::V> {
let problem = problem.clone();
mhovd marked this conversation as resolved.
Show resolved Hide resolved
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)?;
}
Expand All @@ -46,7 +46,7 @@ pub trait OdeSolverMethod<Eqn: OdeEquations> {
) -> Result<Eqn::V> {
let problem = problem.clone();
mhovd marked this conversation as resolved.
Show resolved Hide resolved
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)?;
}
Expand Down Expand Up @@ -254,7 +254,7 @@ mod tests {
Eqn: OdeEquations<M = M, T = M::T, V = M::V>,
{
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();
Expand Down
Loading