Crate dimensional_analyser

Crate dimensional_analyser 

Source
Expand description

A library made for dynamic dimensional analysis capable of:

  • Generating new base units
  • Dimensional analysis by getting the exponents needed to multiply some base quantities to a target dimension

§Example usage

use dimensional_analyser::{Result, dim, dimension::{DIMENSIONLESS, Dimension, Prefix}, dimensions::le_systeme_international_d_unites::{HOUR, JOULE, LITER, MINUTE, base_units::{KILOGRAM, METER, SECOND}}, quantity::{DimensionalAnalysableQuantity, Quantity}};
 
fn main() -> Result {
    let height       = Quantity::new(5 , dim!(METER));
    println!("Height:       {}", height);
    let mass         = Quantity::new(15, dim!(KILOGRAM));
    println!("Mass:         {}", mass);
    let acceleration = Quantity::new(9.81,dim!(METER SECOND^-2));
    println!("Acceleration: {}", acceleration);
    let speed        = Quantity::new(20, dim!(METER SECOND^-1));
    println!("Speed:        {}", speed); 
    let energy = dim!(JOULE); 
    let potential_energy = [&height, &mass, &acceleration].convert_to(energy)?;
    println!("Potential energy: {}", potential_energy);
    let kinetic_energy = [&mass, &speed].convert_to(energy)? / 2;
    println!("Kinetic energy:   {}", kinetic_energy);
    let total_energy = (&potential_energy + &kinetic_energy)?;
    println!("Total energy:     {}", total_energy);
     
    let minute = &*MINUTE;
    println!("Minute: {:?}", minute.exponents());
    let letter = Dimension::new("letter");
    println!("Letter: {:?}", letter.exponents());
    let word = letter.scale(5);
    let typing_speed = Quantity::new(24, dim!(word minute^-1));
    println!("Minute: {:?}", minute.exponents());
    println!("Typing speed: {}", typing_speed); 
    let dollar = Dimension::new("dollar");
    let money_gained = Quantity::new(40, dim!(dollar));
    let match_duration = Quantity::new(7, dim!(MINUTE));
    println!("Salary: {}", [&money_gained, &match_duration].convert_to(dim!(dollar HOUR^-1))?);
    Ok(())
}

Re-exports§

pub use dimension::Dimension;
pub use quantity::Quantity;
pub use dimension::DimensionalAnalysable;
pub use quantity::DimensionalAnalysableQuantity;
pub use dimensions::le_systeme_international_d_unites;

Modules§

dimension
Provides some arithmetic and conversion between Dimension’s expressed in arbitrary units.
dimensions
The module containing the different unit systems.
quantity
Provides dimensional arithmetic and conversion between physical Quantity’s expressed in arbitrary units. Built on top of Dimension.

Macros§

debug_println
A helper macro that only prints with the debug-print fature enabled.
dim
Reorganizes product_of_powers to be more easily used inside code
dimension
Creates a static LazyLock
product_of_powers
Returns the product of each Dimension optionally prefixed prefixed and then optionally raised to a power

Enums§

Error
An error enum that encompasses every error in this library

Type Aliases§

Result
The type returned the the main function