Composition

Struct Composition 

Source
#[repr(C)]
pub struct Composition {
Show 21 fields pub methane: f64, pub nitrogen: f64, pub carbon_dioxide: f64, pub ethane: f64, pub propane: f64, pub isobutane: f64, pub n_butane: f64, pub isopentane: f64, pub n_pentane: f64, pub hexane: f64, pub heptane: f64, pub octane: f64, pub nonane: f64, pub decane: f64, pub hydrogen: f64, pub oxygen: f64, pub carbon_monoxide: f64, pub water: f64, pub hydrogen_sulfide: f64, pub helium: f64, pub argon: f64,
}
Expand description

A complete gas composition made up of gas components.

A gas composition contains 21 gas components named by the field names in the struct. The unit for each component is mole fraction, so the sum of all components should be 1.0. If the initial sum of components is not 1.0, you can use the normalize function to scale it to 1.0.

§Example

let air = aga8::composition::Composition {
    nitrogen: 0.78,
    oxygen: 0.21,
    argon: 0.009,
    carbon_dioxide: 0.000_4,
    water: 0.000_6,
    ..Default::default()
    };

assert!((air.sum() - 1.0).abs() < 1.0e-10);

Fields§

§methane: f64

Methane CH4

§nitrogen: f64

Nitrogen N

§carbon_dioxide: f64

Carbon Dioxide CO2

§ethane: f64

Ethane C2H6

§propane: f64

Propane C3H8

§isobutane: f64

Isobutane C4H10

§n_butane: f64

Butane C4H10

§isopentane: f64

Isopentane C5H12

§n_pentane: f64

Pentane C5H12

§hexane: f64

Isopentane C6H14

§heptane: f64

Heptane C7H16

§octane: f64

Octane C8H18

§nonane: f64

Nonane C9H20

§decane: f64

Decane C10H22

§hydrogen: f64

Hydrogen H

§oxygen: f64

Oxygen O

§carbon_monoxide: f64

Carbon monoxide CO

§water: f64

Water H2O

§hydrogen_sulfide: f64

Hydrogen sulfide H2S

§helium: f64

Helium He

§argon: f64

Argon Ar

Implementations§

Source§

impl Composition

Source

pub fn sum(&self) -> f64

Compute the sum of all components.

§Example
let comp = aga8::composition::Composition {
    methane: 50.0,
    ethane: 25.0,
    carbon_dioxide: 25.0,
    ..Default::default()
};

assert!((comp.sum() - 100.0).abs() < 1.0e-10);
Source

pub fn normalize(&mut self) -> Result<(), CompositionError>

Normalizes the composition sum to 1.0.

§Example
let mut comp = aga8::composition::Composition {
    methane: 50.0,
    ethane: 50.0,
    ..Default::default()
};

comp.normalize();

assert!((comp.ethane - 0.5).abs() < 1.0e-10);
assert!((comp.methane - 0.5).abs() < 1.0e-10);
Source

pub fn check(&self) -> Result<(), CompositionError>

Checks that the composition is valid.

§Example
let mut comp = aga8::composition::Composition {
    methane: 0.5,
    ethane: 0.5,
    ..Default::default()
};

assert_eq!(comp.check(), Ok(()));

Trait Implementations§

Source§

impl Clone for Composition

Source§

fn clone(&self) -> Composition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Composition

Source§

fn default() -> Composition

Returns the “default value” for a type. Read more
Source§

impl Copy for Composition

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.