Skip to main content

ODEBVP

Struct ODEBVP 

Source
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>

Source

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}
Source

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

pub fn tolerance(&mut self, tolerance: f64)

Edit the convergence tolerance

Source

pub fn delta(&mut self, delta: f64)

Edit the finite difference derivative step

Source§

impl ODEBVP<f64>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V