pub struct ODEBVP<T> {
pub max_iter: usize,
pub tol: f64,
pub delta: f64,
pub solution: Mesh1D<T, f64>,
}Fields§
§max_iter: usize§tol: f64§delta: f64§solution: Mesh1D<T, f64>Implementations§
Source§impl<T: Clone + Number> ODEBVP<T>
impl<T: Clone + Number> ODEBVP<T>
Sourcepub fn new(nodes: Vector<f64>, order: usize) -> Self
pub fn new(nodes: Vector<f64>, order: usize) -> Self
Create a new ODEBVP solver
Examples found in repository?
examples/blasius.rs (line 48)
36fn main() {
37 println!("----- Blasius equation -----");
38
39 const ETA_INF: f64 = 20.0;
40 const N: usize = 512;
41
42 println!( " * Solving the Blasius equation f''' + f * f'' = 0 in the domain" );
43 println!( " * \u{03B7}=[0,{}] subject to the boundary conditions", ETA_INF );
44 println!( " * f(0) = 0, f'(0) = 0, f' -> 1 as \u{03B7} -> \u{03B7}_\u{221E} = {}.", ETA_INF );
45 println!( " * The number of nodes in the discretisation is N = {}.", N );
46
47 let nodes = Vec64::powspace( 0.0, ETA_INF, N, 1.2 ); // More nodes near eta=0
48 let mut ode_bvp = ODEBVP::<f64>::new( nodes.clone(), 3 );
49 ode_bvp.iterations( 20 );
50
51 // Set the initial guess for the solution
52 for i in 0..N {
53 let eta = ode_bvp.solution.coord( i );
54 let exp_minus_eta = (-eta).exp();
55 ode_bvp.solution[i][0] = eta * ( 1.0 - exp_minus_eta );
56 ode_bvp.solution[i][1] = 1.0 - exp_minus_eta + eta * exp_minus_eta;
57 ode_bvp.solution[i][2] = 2.0 * exp_minus_eta - eta * exp_minus_eta;
58 }
59
60 println!( " * Solving the Blasius equation using the finite difference method..." );
61 let result = ode_bvp.solve( &blasius_eqn, &plate_bc, &free_bc, None );
62 assert!( result.is_ok() && !result.is_err() );
63
64 let fdd_0 = ode_bvp.solution.get_interpolated_vars( 0.0 )[2];
65 println!( " * The computed value of f''(0) is {:.8}.", fdd_0 );
66
67 let c= 1.65519036023f64;
68 let reference = 1. / c.powf( 1.5 );
69 println!( " * The reference value of f''(0) is {:.8}.", reference );
70 println!( " * The relative error is {:.8}%.", ( fdd_0 - reference ).abs() / reference * 100.0 );
71
72 println!( " * Finished solving the Blasius equation." );
73 fs::create_dir_all( "DATA" ).expect( "Could not create DATA output directory" );
74 let mut string = String::from( "DATA/Blasius_equation" );
75 string.push_str( format!( "_N_{}.dat", N ).as_str() );
76 ode_bvp.solution.output( &string, 6 );
77
78 print!( " * For a plot of the solution run: " );
79 println!( "python3 Plotting/Blasius_plot.py {}", N );
80 println!( " * and view the resulting file DATA/Blasius_equation_N_{}.png", N );
81
82 println!( "--- FINISHED ---" );
83}Sourcepub fn iterations(&mut self, iterations: usize)
pub fn iterations(&mut self, iterations: usize)
Edit the maximum number of iterations
Examples found in repository?
examples/blasius.rs (line 49)
36fn main() {
37 println!("----- Blasius equation -----");
38
39 const ETA_INF: f64 = 20.0;
40 const N: usize = 512;
41
42 println!( " * Solving the Blasius equation f''' + f * f'' = 0 in the domain" );
43 println!( " * \u{03B7}=[0,{}] subject to the boundary conditions", ETA_INF );
44 println!( " * f(0) = 0, f'(0) = 0, f' -> 1 as \u{03B7} -> \u{03B7}_\u{221E} = {}.", ETA_INF );
45 println!( " * The number of nodes in the discretisation is N = {}.", N );
46
47 let nodes = Vec64::powspace( 0.0, ETA_INF, N, 1.2 ); // More nodes near eta=0
48 let mut ode_bvp = ODEBVP::<f64>::new( nodes.clone(), 3 );
49 ode_bvp.iterations( 20 );
50
51 // Set the initial guess for the solution
52 for i in 0..N {
53 let eta = ode_bvp.solution.coord( i );
54 let exp_minus_eta = (-eta).exp();
55 ode_bvp.solution[i][0] = eta * ( 1.0 - exp_minus_eta );
56 ode_bvp.solution[i][1] = 1.0 - exp_minus_eta + eta * exp_minus_eta;
57 ode_bvp.solution[i][2] = 2.0 * exp_minus_eta - eta * exp_minus_eta;
58 }
59
60 println!( " * Solving the Blasius equation using the finite difference method..." );
61 let result = ode_bvp.solve( &blasius_eqn, &plate_bc, &free_bc, None );
62 assert!( result.is_ok() && !result.is_err() );
63
64 let fdd_0 = ode_bvp.solution.get_interpolated_vars( 0.0 )[2];
65 println!( " * The computed value of f''(0) is {:.8}.", fdd_0 );
66
67 let c= 1.65519036023f64;
68 let reference = 1. / c.powf( 1.5 );
69 println!( " * The reference value of f''(0) is {:.8}.", reference );
70 println!( " * The relative error is {:.8}%.", ( fdd_0 - reference ).abs() / reference * 100.0 );
71
72 println!( " * Finished solving the Blasius equation." );
73 fs::create_dir_all( "DATA" ).expect( "Could not create DATA output directory" );
74 let mut string = String::from( "DATA/Blasius_equation" );
75 string.push_str( format!( "_N_{}.dat", N ).as_str() );
76 ode_bvp.solution.output( &string, 6 );
77
78 print!( " * For a plot of the solution run: " );
79 println!( "python3 Plotting/Blasius_plot.py {}", N );
80 println!( " * and view the resulting file DATA/Blasius_equation_N_{}.png", N );
81
82 println!( "--- FINISHED ---" );
83}Source§impl ODEBVP<f64>
impl ODEBVP<f64>
Sourcepub fn solve(
&mut self,
eqn: &dyn Fn(&Vec64, &f64) -> Vec64,
bc_left: &dyn Fn(&Vec64) -> Vector<Option<f64>>,
bc_right: &dyn Fn(&Vec64) -> Vector<Option<f64>>,
jacobian: Option<&dyn Fn(&Vec64, &f64) -> Mat64>,
) -> Result<(), f64>
pub fn solve( &mut self, eqn: &dyn Fn(&Vec64, &f64) -> Vec64, bc_left: &dyn Fn(&Vec64) -> Vector<Option<f64>>, bc_right: &dyn Fn(&Vec64) -> Vector<Option<f64>>, jacobian: Option<&dyn Fn(&Vec64, &f64) -> Mat64>, ) -> Result<(), f64>
Examples found in repository?
examples/blasius.rs (line 61)
36fn main() {
37 println!("----- Blasius equation -----");
38
39 const ETA_INF: f64 = 20.0;
40 const N: usize = 512;
41
42 println!( " * Solving the Blasius equation f''' + f * f'' = 0 in the domain" );
43 println!( " * \u{03B7}=[0,{}] subject to the boundary conditions", ETA_INF );
44 println!( " * f(0) = 0, f'(0) = 0, f' -> 1 as \u{03B7} -> \u{03B7}_\u{221E} = {}.", ETA_INF );
45 println!( " * The number of nodes in the discretisation is N = {}.", N );
46
47 let nodes = Vec64::powspace( 0.0, ETA_INF, N, 1.2 ); // More nodes near eta=0
48 let mut ode_bvp = ODEBVP::<f64>::new( nodes.clone(), 3 );
49 ode_bvp.iterations( 20 );
50
51 // Set the initial guess for the solution
52 for i in 0..N {
53 let eta = ode_bvp.solution.coord( i );
54 let exp_minus_eta = (-eta).exp();
55 ode_bvp.solution[i][0] = eta * ( 1.0 - exp_minus_eta );
56 ode_bvp.solution[i][1] = 1.0 - exp_minus_eta + eta * exp_minus_eta;
57 ode_bvp.solution[i][2] = 2.0 * exp_minus_eta - eta * exp_minus_eta;
58 }
59
60 println!( " * Solving the Blasius equation using the finite difference method..." );
61 let result = ode_bvp.solve( &blasius_eqn, &plate_bc, &free_bc, None );
62 assert!( result.is_ok() && !result.is_err() );
63
64 let fdd_0 = ode_bvp.solution.get_interpolated_vars( 0.0 )[2];
65 println!( " * The computed value of f''(0) is {:.8}.", fdd_0 );
66
67 let c= 1.65519036023f64;
68 let reference = 1. / c.powf( 1.5 );
69 println!( " * The reference value of f''(0) is {:.8}.", reference );
70 println!( " * The relative error is {:.8}%.", ( fdd_0 - reference ).abs() / reference * 100.0 );
71
72 println!( " * Finished solving the Blasius equation." );
73 fs::create_dir_all( "DATA" ).expect( "Could not create DATA output directory" );
74 let mut string = String::from( "DATA/Blasius_equation" );
75 string.push_str( format!( "_N_{}.dat", N ).as_str() );
76 ode_bvp.solution.output( &string, 6 );
77
78 print!( " * For a plot of the solution run: " );
79 println!( "python3 Plotting/Blasius_plot.py {}", N );
80 println!( " * and view the resulting file DATA/Blasius_equation_N_{}.png", N );
81
82 println!( "--- FINISHED ---" );
83}Auto Trait Implementations§
impl<T> Freeze for ODEBVP<T>
impl<T> RefUnwindSafe for ODEBVP<T>where
T: RefUnwindSafe,
impl<T> Send for ODEBVP<T>where
T: Send,
impl<T> Sync for ODEBVP<T>where
T: Sync,
impl<T> Unpin for ODEBVP<T>where
T: Unpin,
impl<T> UnwindSafe for ODEBVP<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more