Skip to content

Commit 0740668

Browse files
committed
Avoid Jacobian reset for initial and final checkpoints
1 parent df915d6 commit 0740668

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

diffsol/src/ode_solver/bdf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ where
140140
let op = if let Some(op) = self.op.as_ref() {
141141
let op = op.clone_state(&self.ode_problem.eqn);
142142
nonlinear_solver.set_problem(&op);
143-
nonlinear_solver.reset_jacobian(&op, &self.state.y, self.state.t);
144143
Some(op)
145144
} else {
146145
None
@@ -1138,6 +1137,10 @@ where
11381137
self.state.clone()
11391138
}
11401139

1140+
fn state_clone(&self) -> Self::State {
1141+
self.state.clone()
1142+
}
1143+
11411144
fn step(&mut self) -> Result<OdeSolverStopReason<Eqn::T>, DiffsolError> {
11421145
debug!(
11431146
"Taking BDF step at time {} with step size {} and order {}",

diffsol/src/ode_solver/explicit_rk.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ where
159159
self.rk.checkpoint()
160160
}
161161

162+
fn state_clone(&self) -> Self::State {
163+
self.rk.state().clone()
164+
}
165+
162166
fn step(&mut self) -> Result<OdeSolverStopReason<Eqn::T>, DiffsolError> {
163167
let mut h = self.rk.start_step()?;
164168
debug!(

diffsol/src/ode_solver/method.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ where
5656
/// Note that this will force a reinitialisation of the internal Jacobian for the solver, if it has one.
5757
fn checkpoint(&mut self) -> Self::State;
5858

59+
/// Clone the current state of the solver without triggering any internal Jacobian reset.
60+
fn state_clone(&self) -> Self::State;
61+
5962
/// Replace the current state of the solver with a new state.
6063
fn set_state(&mut self, state: Self::State);
6164

@@ -329,7 +332,7 @@ where
329332
// allocate checkpoint info
330333
let mut nsteps = 0;
331334
let t0 = self.state().t;
332-
let mut checkpoints = vec![self.checkpoint()];
335+
let mut checkpoints = vec![self.state_clone()];
333336
let mut ts = vec![t0];
334337
let mut ys = vec![self.state().y.clone()];
335338
let mut ydots = vec![self.state().dy.clone()];
@@ -361,7 +364,7 @@ where
361364
ts.push(self.state().t);
362365
ys.push(self.state().y.clone());
363366
ydots.push(self.state().dy.clone());
364-
checkpoints.push(self.checkpoint());
367+
checkpoints.push(self.state_clone());
365368

366369
// construct checkpointing
367370
let last_segment = HermiteInterpolator::new(ys, ydots, ts);
@@ -420,7 +423,7 @@ where
420423
// allocate checkpoint info
421424
let mut nsteps = 0;
422425
let t0 = self.state().t;
423-
let mut checkpoints = vec![self.checkpoint()];
426+
let mut checkpoints = vec![self.state_clone()];
424427
let mut ts = vec![t0];
425428
let mut ys = vec![self.state().y.clone()];
426429
let mut ydots = vec![self.state().dy.clone()];
@@ -450,7 +453,7 @@ where
450453
assert_eq!(step_reason, OdeSolverStopReason::TstopReached);
451454

452455
// add final checkpoint
453-
checkpoints.push(self.checkpoint());
456+
checkpoints.push(self.state_clone());
454457

455458
// construct the adjoint equations
456459
let last_segment = HermiteInterpolator::new(ys, ydots, ts);

diffsol/src/ode_solver/sdirk.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ where
337337
self.rk.state().clone()
338338
}
339339

340+
fn state_clone(&self) -> Self::State {
341+
self.rk.state().clone()
342+
}
343+
340344
fn step(&mut self) -> Result<OdeSolverStopReason<Eqn::T>, DiffsolError> {
341345
debug!(
342346
"Taking SDIRK step at time {}, step size {}",

0 commit comments

Comments
 (0)