@@ -246,11 +246,15 @@ where
246246 & mut self ,
247247 continuous_output : & mut ContinuousOutputModel < T , OVector < T , D > > ,
248248 ) -> Result < Stats , IntegrationError > {
249+ self . out_type = OutputType :: Continuous ;
249250 self . integrate_core ( Some ( continuous_output) )
250251 }
251252
252253 /// Integrates the system.
253254 pub fn integrate ( & mut self ) -> Result < Stats , IntegrationError > {
255+ if self . out_type == OutputType :: Continuous {
256+ panic ! ( "Please use `integrate_with_continuous_output_model` to compute a continuous output model." ) ;
257+ }
254258 self . integrate_core ( None )
255259 }
256260
@@ -334,8 +338,8 @@ where
334338 k[ 1 ] = k[ 6 ] . clone ( ) ;
335339 self . stats . num_eval += 6 ;
336340
337- // Prepare dense output
338- if self . out_type == OutputType :: Dense {
341+ // Prepare dense/continuous output
342+ if self . out_type == OutputType :: Dense || self . out_type == OutputType :: Continuous {
339343 self . rcont [ 4 ] = ( & k[ 0 ] * dopri54:: d :: < T > ( 1 )
340344 + & k[ 2 ] * dopri54:: d :: < T > ( 3 )
341345 + & k[ 3 ] * dopri54:: d :: < T > ( 4 )
@@ -396,8 +400,8 @@ where
396400 }
397401 }
398402
399- // Prepare dense output
400- if self . out_type == OutputType :: Dense {
403+ // Prepare dense/continuous output
404+ if self . out_type == OutputType :: Dense || self . out_type == OutputType :: Continuous {
401405 let h = self . h ;
402406
403407 let ydiff = & y_next - & self . y ;
@@ -414,7 +418,7 @@ where
414418 self . x += self . h ;
415419 self . h_old = self . h ;
416420
417- self . solution_output ( y_next, & mut continuous_output_model) ;
421+ self . solution_output ( y_next, & mut continuous_output_model, & k [ 0 ] ) ;
418422
419423 if self
420424 . f
@@ -443,6 +447,7 @@ where
443447 & mut self ,
444448 y_next : OVector < T , D > ,
445449 continuous_output_model : & mut Option < & mut ContinuousOutputModel < T , OVector < T , D > > > ,
450+ dy : & OVector < T , D > ,
446451 ) {
447452 if self . out_type == OutputType :: Dense {
448453 while self . xd . abs ( ) <= self . x . abs ( ) {
@@ -453,6 +458,13 @@ where
453458 self . results . push ( self . xd , y_out) ;
454459 self . xd += self . dx ;
455460 }
461+
462+ if self
463+ . f
464+ . solout ( self . xd , self . results . get ( ) . 1 . last ( ) . unwrap ( ) , dy)
465+ {
466+ break ;
467+ }
456468 }
457469
458470 // Ensure the last point is added if it's within floating point error of x_end.
@@ -514,7 +526,7 @@ mod tests {
514526 use crate :: { OVector , System , Vector1 } ;
515527 use nalgebra:: { allocator:: Allocator , DefaultAllocator , Dim } ;
516528
517- // Same as Test3 from rk4.rs, but aborts after x is greater/ equal than 0.5
529+ // Same as Test3 from rk4.rs, but aborts after x is equal to or greater than 0.5
518530 struct Test1 { }
519531 impl < D : Dim > System < f64 , OVector < f64 , D > > for Test1
520532 where
@@ -536,9 +548,34 @@ mod tests {
536548 let _ = stepper. integrate ( ) ;
537549
538550 let x = stepper. x_out ( ) ;
539- assert ! ( ( * x. last( ) . unwrap( ) - 0.5 ) . abs( ) < 1.0E-9 ) ; //
551+ assert ! ( ( * x. last( ) . unwrap( ) - 0.5 ) . abs( ) < 1.0E-9 ) ;
540552
541553 let out = stepper. y_out ( ) ;
542- assert ! ( ( & out[ 5 ] [ 0 ] - 0.913059243 ) . abs( ) < 1.0E-9 ) ;
554+ assert ! ( ( & out[ 5 ] [ 0 ] - 0.9130611474392001 ) . abs( ) < 1.0E-9 ) ;
555+ }
556+
557+ #[ test]
558+ #[ should_panic]
559+ fn test_integrate_when_continuous_output_type_panic ( ) {
560+ let system = Test1 { } ;
561+ let mut stepper = Dopri5 :: from_param (
562+ system,
563+ 0. ,
564+ 1. ,
565+ 0.1 ,
566+ Vector1 :: new ( 1. ) ,
567+ 1e-12 ,
568+ 1e-6 ,
569+ 0.1 ,
570+ 0.2 ,
571+ 0.3 ,
572+ 2.0 ,
573+ 5.0 ,
574+ 0.1 ,
575+ 10000 ,
576+ 1000 ,
577+ OutputType :: Continuous ,
578+ ) ;
579+ let _ = stepper. integrate ( ) ;
543580 }
544581}
0 commit comments