pub struct Mesh1D<T, X> { /* private fields */ }
Implementations§
source§impl<T: Clone + Number, X: Clone + Number + Copy> Mesh1D<T, X>
impl<T: Clone + Number, X: Clone + Number + Copy> Mesh1D<T, X>
sourcepub fn new(nodes: Vector<X>, nvars: usize) -> Self
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 ---" );
}
sourcepub fn nnodes(&self) -> usize
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 ---" );
}
sourcepub fn nvars(&self) -> usize
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 ---" );
}
sourcepub fn set_nodes_vars(&mut self, node: usize, vec: Vector<T>)
pub fn set_nodes_vars(&mut self, node: usize, vec: Vector<T>)
Set the variables stored at a specified node
sourcepub fn get_nodes_vars(&self, node: usize) -> Vector<T>
pub fn get_nodes_vars(&self, node: usize) -> Vector<T>
Get the vector of variables stored at a specified node
source§impl Mesh1D<f64, f64>
impl Mesh1D<f64, f64>
sourcepub fn get_interpolated_vars(&self, x_pos: f64) -> Vector<f64>
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 ---" );
}
sourcepub fn trapezium(&self, var: usize) -> f64
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 ---" );
}
Trait Implementations§
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> 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