Struct ohsl::mesh1d::Mesh1D

source ·
pub struct Mesh1D<T, X> { /* private fields */ }

Implementations§

source§

impl<T: Clone + Number, X: Clone + Number + Copy> Mesh1D<T, X>

source

pub fn new(nodes: Vector<X>, nvars: usize) -> Self

Create a new 1D mesh

Examples found in repository?
examples/basic_integration.rs (line 16)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() {
    println!("--------- Basic integration ---------");

    println!( "  * Create a 1D mesh with 2 variables and set " );
    println!( "  * one equal 2x and the other to x^2. " );

    let nodes = Vec64::linspace( 0.0, 1.0, 101 );
    let mut mesh = Mesh1D::<f64, f64>::new( nodes.clone(), 2 );
    for i in 0..nodes.size() {
        let x = nodes[i].clone();
        mesh[i][0] = 2.0 * x;
        mesh[i][1] = x * x;
    }

    println!( "  * number of nodes = {}", mesh.nnodes() );
    println!( "  * number of variables = {}", mesh.nvars() );
    println!( "  * Interpolate the value of each of the ");
    println!( "  * variables at x = 0.314 ");
    let vars = mesh.get_interpolated_vars( 0.314 );
    println!( "  * vars = {}", vars );

    println!( "  * Numerically integrate the variables over " );
    println!( "  * the domain (from 0 to 1) " );
    println!( "  * Integral 2x = {}", mesh.trapezium( 0 ) );
    println!( "  * Integral x^2 = {}", mesh.trapezium( 1 ) );

    // The mesh may be printed to a file using
    // mesh.output( "./output.txt", 5 );
    // here 5 is the precision of the output values.
    // Similarly a pre-existing file can be read into a mesh using
    //mesh.read( "./output.txt" );
    
    println!( "--- FINISHED ---" );
}
source

pub fn nnodes(&self) -> usize

Return the number of nodal points in the mesh

Examples found in repository?
examples/basic_integration.rs (line 23)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() {
    println!("--------- Basic integration ---------");

    println!( "  * Create a 1D mesh with 2 variables and set " );
    println!( "  * one equal 2x and the other to x^2. " );

    let nodes = Vec64::linspace( 0.0, 1.0, 101 );
    let mut mesh = Mesh1D::<f64, f64>::new( nodes.clone(), 2 );
    for i in 0..nodes.size() {
        let x = nodes[i].clone();
        mesh[i][0] = 2.0 * x;
        mesh[i][1] = x * x;
    }

    println!( "  * number of nodes = {}", mesh.nnodes() );
    println!( "  * number of variables = {}", mesh.nvars() );
    println!( "  * Interpolate the value of each of the ");
    println!( "  * variables at x = 0.314 ");
    let vars = mesh.get_interpolated_vars( 0.314 );
    println!( "  * vars = {}", vars );

    println!( "  * Numerically integrate the variables over " );
    println!( "  * the domain (from 0 to 1) " );
    println!( "  * Integral 2x = {}", mesh.trapezium( 0 ) );
    println!( "  * Integral x^2 = {}", mesh.trapezium( 1 ) );

    // The mesh may be printed to a file using
    // mesh.output( "./output.txt", 5 );
    // here 5 is the precision of the output values.
    // Similarly a pre-existing file can be read into a mesh using
    //mesh.read( "./output.txt" );
    
    println!( "--- FINISHED ---" );
}
source

pub fn nvars(&self) -> usize

Return the number of variables stored at each node in the mesh

Examples found in repository?
examples/basic_integration.rs (line 24)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() {
    println!("--------- Basic integration ---------");

    println!( "  * Create a 1D mesh with 2 variables and set " );
    println!( "  * one equal 2x and the other to x^2. " );

    let nodes = Vec64::linspace( 0.0, 1.0, 101 );
    let mut mesh = Mesh1D::<f64, f64>::new( nodes.clone(), 2 );
    for i in 0..nodes.size() {
        let x = nodes[i].clone();
        mesh[i][0] = 2.0 * x;
        mesh[i][1] = x * x;
    }

    println!( "  * number of nodes = {}", mesh.nnodes() );
    println!( "  * number of variables = {}", mesh.nvars() );
    println!( "  * Interpolate the value of each of the ");
    println!( "  * variables at x = 0.314 ");
    let vars = mesh.get_interpolated_vars( 0.314 );
    println!( "  * vars = {}", vars );

    println!( "  * Numerically integrate the variables over " );
    println!( "  * the domain (from 0 to 1) " );
    println!( "  * Integral 2x = {}", mesh.trapezium( 0 ) );
    println!( "  * Integral x^2 = {}", mesh.trapezium( 1 ) );

    // The mesh may be printed to a file using
    // mesh.output( "./output.txt", 5 );
    // here 5 is the precision of the output values.
    // Similarly a pre-existing file can be read into a mesh using
    //mesh.read( "./output.txt" );
    
    println!( "--- FINISHED ---" );
}
source

pub fn coord(&self, node: usize) -> X

Return the nodal coordinate at a specified index

source

pub fn set_nodes_vars(&mut self, node: usize, vec: Vector<T>)

Set the variables stored at a specified node

source

pub fn get_nodes_vars(&self, node: usize) -> Vector<T>

Get the vector of variables stored at a specified node

source

pub fn nodes(&self) -> Vector<X>

Return the vector of nodal positions

source§

impl Mesh1D<f64, f64>

source

pub fn get_interpolated_vars(&self, x_pos: f64) -> Vector<f64>

Get the variables at an interpolated position ( first order scheme )

Examples found in repository?
examples/basic_integration.rs (line 27)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() {
    println!("--------- Basic integration ---------");

    println!( "  * Create a 1D mesh with 2 variables and set " );
    println!( "  * one equal 2x and the other to x^2. " );

    let nodes = Vec64::linspace( 0.0, 1.0, 101 );
    let mut mesh = Mesh1D::<f64, f64>::new( nodes.clone(), 2 );
    for i in 0..nodes.size() {
        let x = nodes[i].clone();
        mesh[i][0] = 2.0 * x;
        mesh[i][1] = x * x;
    }

    println!( "  * number of nodes = {}", mesh.nnodes() );
    println!( "  * number of variables = {}", mesh.nvars() );
    println!( "  * Interpolate the value of each of the ");
    println!( "  * variables at x = 0.314 ");
    let vars = mesh.get_interpolated_vars( 0.314 );
    println!( "  * vars = {}", vars );

    println!( "  * Numerically integrate the variables over " );
    println!( "  * the domain (from 0 to 1) " );
    println!( "  * Integral 2x = {}", mesh.trapezium( 0 ) );
    println!( "  * Integral x^2 = {}", mesh.trapezium( 1 ) );

    // The mesh may be printed to a file using
    // mesh.output( "./output.txt", 5 );
    // here 5 is the precision of the output values.
    // Similarly a pre-existing file can be read into a mesh using
    //mesh.read( "./output.txt" );
    
    println!( "--- FINISHED ---" );
}
source

pub fn trapezium(&self, var: usize) -> f64

Integrate a given variable over the domain (trapezium rule)

Examples found in repository?
examples/basic_integration.rs (line 32)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() {
    println!("--------- Basic integration ---------");

    println!( "  * Create a 1D mesh with 2 variables and set " );
    println!( "  * one equal 2x and the other to x^2. " );

    let nodes = Vec64::linspace( 0.0, 1.0, 101 );
    let mut mesh = Mesh1D::<f64, f64>::new( nodes.clone(), 2 );
    for i in 0..nodes.size() {
        let x = nodes[i].clone();
        mesh[i][0] = 2.0 * x;
        mesh[i][1] = x * x;
    }

    println!( "  * number of nodes = {}", mesh.nnodes() );
    println!( "  * number of variables = {}", mesh.nvars() );
    println!( "  * Interpolate the value of each of the ");
    println!( "  * variables at x = 0.314 ");
    let vars = mesh.get_interpolated_vars( 0.314 );
    println!( "  * vars = {}", vars );

    println!( "  * Numerically integrate the variables over " );
    println!( "  * the domain (from 0 to 1) " );
    println!( "  * Integral 2x = {}", mesh.trapezium( 0 ) );
    println!( "  * Integral x^2 = {}", mesh.trapezium( 1 ) );

    // The mesh may be printed to a file using
    // mesh.output( "./output.txt", 5 );
    // here 5 is the precision of the output values.
    // Similarly a pre-existing file can be read into a mesh using
    //mesh.read( "./output.txt" );
    
    println!( "--- FINISHED ---" );
}
source

pub fn read(&mut self, filename: &str)

Read data from a file (overwrites nodes with file nodes)

source§

impl<T: Display, X: Display> Mesh1D<T, X>

source

pub fn output(&self, filename: &str, precision: usize)

Print the mesh to a file

Trait Implementations§

source§

impl<T, X> Index<usize> for Mesh1D<T, X>

source§

fn index<'a>(&'a self, node: usize) -> &'a Vector<T>

Indexing operator [] (read only) - returns the vector of variables stored at the specified node.

§

type Output = Vector<T>

The returned type after indexing.
source§

impl<T, X> IndexMut<usize> for Mesh1D<T, X>

source§

fn index_mut(&mut self, node: usize) -> &mut Vector<T>

Indexing operator [] (read/write) - returns the vector of variables stored at the specified node.

Auto Trait Implementations§

§

impl<T, X> RefUnwindSafe for Mesh1D<T, X>where T: RefUnwindSafe, X: RefUnwindSafe,

§

impl<T, X> Send for Mesh1D<T, X>where T: Send, X: Send,

§

impl<T, X> Sync for Mesh1D<T, X>where T: Sync, X: Sync,

§

impl<T, X> Unpin for Mesh1D<T, X>where T: Unpin, X: Unpin,

§

impl<T, X> UnwindSafe for Mesh1D<T, X>where T: UnwindSafe, X: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V