scirs2_integrate/ode/utils/stiffness/
integration.rs1use crate::IntegrateFloat;
4
5#[derive(Debug, Clone)]
7pub struct AdaptiveMethodState<F: IntegrateFloat> {
8 pub method_type: AdaptiveMethodType,
10 pub steps_since_switch: usize,
12 pub order: usize,
14 pub config: crate::ode::utils::stiffness::StiffnessDetectionConfig<F>,
16 pub detector: crate::ode::utils::stiffness::StiffnessDetector<F>,
18}
19
20impl<F: IntegrateFloat> AdaptiveMethodState<F> {
21 pub fn with_config(config: crate::ode::utils::stiffness::StiffnessDetectionConfig<F>) -> Self {
23 let detector = crate::ode::utils::stiffness::StiffnessDetector::with_config(config.clone());
24 Self {
25 method_type: AdaptiveMethodType::Adams,
26 steps_since_switch: 0,
27 order: 1, config,
29 detector,
30 }
31 }
32
33 pub fn record_step(&mut self, _errorestimate: F) {
35 self.steps_since_switch += 1;
36 }
37
38 pub fn check_method_switch(&self) -> Option<AdaptiveMethodType> {
40 if self.steps_since_switch > 10 {
41 None
43 } else {
44 None
45 }
46 }
47
48 pub fn switch_method(
50 &mut self,
51 new_method: AdaptiveMethodType,
52 _steps: usize,
53 ) -> crate::error::IntegrateResult<()> {
54 self.method_type = new_method;
55 self.steps_since_switch = 0;
56 Ok(())
57 }
58
59 pub fn generate_diagnostic_message(&self) -> String {
61 format!(
62 "AdaptiveMethodState: method={:?}, steps_since_switch={}",
63 self.method_type, self.steps_since_switch
64 )
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq)]
70pub enum AdaptiveMethodType {
71 Adams,
73 BDF,
75 RungeKutta,
77 Implicit,
79 Explicit,
81}