Skip to content

Commit

Permalink
[ode] Fix bug: at least two output stations are required for dense ou…
Browse files Browse the repository at this point in the history
…tput
  • Loading branch information
cpmech committed Jun 3, 2024
1 parent 3f79eca commit 0154f3d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion russell_ode/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl<'a, A> Output<'a, A> {
if self.with_dense_output() {
if let Some(h_out) = self.dense_h_out {
// uniform spacing
let n = ((x1 - x0) / h_out) as usize + 1;
let n = usize::max(2, ((x1 - x0) / h_out) as usize + 1); // at least 2 (first and last) are required
if self.dense_x.len() != n {
self.dense_x.resize(n, 0.0);
}
Expand Down Expand Up @@ -808,6 +808,14 @@ mod tests {
assert_eq!(y0_out.len(), 4);
}

#[test]
fn initialize_with_dense_output_works_at_least_two_stations() {
let mut out = Output::<'_, NoArgs>::new();
out.set_dense_h_out(0.5).unwrap().set_dense_recording(&[0]);
out.initialize(0.99, 1.0, false).unwrap();
assert_eq!(out.dense_x.len(), 2);
}

#[test]
fn initialize_with_step_output_works() {
let mut out = Output::<'_, NoArgs>::new();
Expand Down

0 comments on commit 0154f3d

Please sign in to comment.