Struct StateBuilder

Source
pub struct StateBuilder<'a, E, const IG: bool> { /* private fields */ }
Expand description

A simple tool to construct States with arbitrary input parameters.

§Examples

// Create a state for given T,V,N
let eos = Arc::new(PengRobinson::new(Arc::new(PengRobinsonParameters::new_simple(&[369.8], &[41.9 * 1e5], &[0.15], &[15.0])?)));
let state = StateBuilder::new(&eos)
                .temperature(300.0 * KELVIN)
                .volume(12.5 * METER.powi::<P3>())
                .moles(&(arr1(&[2.5]) * MOL))
                .build()?;
assert_eq!(state.density, 0.2 * MOL / METER.powi::<P3>());

// For a pure component, the composition does not need to be specified.
let eos = Arc::new(PengRobinson::new(Arc::new(PengRobinsonParameters::new_simple(&[369.8], &[41.9 * 1e5], &[0.15], &[15.0])?)));
let state = StateBuilder::new(&eos)
                .temperature(300.0 * KELVIN)
                .volume(12.5 * METER.powi::<P3>())
                .total_moles(2.5 * MOL)
                .build()?;
assert_eq!(state.density, 0.2 * MOL / METER.powi::<P3>());

// The state can be constructed without providing any extensive property.
let eos = Arc::new(PengRobinson::new(
    Arc::new(PengRobinsonParameters::new_simple(
        &[369.8, 305.4],
        &[41.9 * 1e5, 48.2 * 1e5],
        &[0.15, 0.10],
        &[15.0, 30.0]
    )?)
));
let state = StateBuilder::new(&eos)
                .temperature(300.0 * KELVIN)
                .partial_density(&(arr1(&[0.2, 0.6]) * MOL / METER.powi::<P3>()))
                .build()?;
assert_relative_eq!(state.molefracs, arr1(&[0.25, 0.75]));
assert_relative_eq!(state.density, 0.8 * MOL / METER.powi::<P3>());

Implementations§

Source§

impl<E: Residual> StateBuilder<'_, E, false>

Source

pub fn new(eos: &Arc<E>) -> Self

Create a new StateBuilder for the given equation of state.

Source§

impl<'a, E: Residual, const IG: bool> StateBuilder<'a, E, IG>

Source

pub fn temperature(self, temperature: Temperature) -> Self

Provide the temperature for the new state.

Source

pub fn volume(self, volume: Volume) -> Self

Provide the volume for the new state.

Source

pub fn density(self, density: Density) -> Self

Provide the density for the new state.

Source

pub fn partial_density(self, partial_density: &'a Density<Array1<f64>>) -> Self

Provide partial densities for the new state.

Source

pub fn total_moles(self, total_moles: Moles) -> Self

Provide the total moles for the new state.

Source

pub fn moles(self, moles: &'a Moles<Array1<f64>>) -> Self

Provide the moles for the new state.

Source

pub fn molefracs(self, molefracs: &'a Array1<f64>) -> Self

Provide the molefracs for the new state.

Source

pub fn pressure(self, pressure: Pressure) -> Self

Provide the pressure for the new state.

Source

pub fn vapor(self) -> Self

Specify a vapor state.

Source

pub fn liquid(self) -> Self

Specify a liquid state.

Source

pub fn initial_density(self, initial_density: Density) -> Self

Provide an initial density used in density iterations.

Source§

impl<'a, E: Residual + IdealGas, const IG: bool> StateBuilder<'a, E, IG>

Source

pub fn molar_enthalpy( self, molar_enthalpy: MolarEnergy, ) -> StateBuilder<'a, E, true>

Provide the molar enthalpy for the new state.

Source

pub fn molar_entropy( self, molar_entropy: MolarEntropy, ) -> StateBuilder<'a, E, true>

Provide the molar entropy for the new state.

Source

pub fn molar_internal_energy( self, molar_internal_energy: MolarEnergy, ) -> StateBuilder<'a, E, true>

Provide the molar internal energy for the new state.

Source

pub fn initial_temperature( self, initial_temperature: Temperature, ) -> StateBuilder<'a, E, true>

Provide an initial temperature used in the Newton solver.

Source§

impl<E: Residual> StateBuilder<'_, E, false>

Source

pub fn build(self) -> EosResult<State<E>>

Try to build the state with the given inputs.

Source§

impl<E: Residual + IdealGas> StateBuilder<'_, E, true>

Source

pub fn build(self) -> EosResult<State<E>>

Try to build the state with the given inputs.

Trait Implementations§

Source§

impl<E, const IG: bool> Clone for StateBuilder<'_, E, IG>

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl<'a, E, const IG: bool> Freeze for StateBuilder<'a, E, IG>

§

impl<'a, E, const IG: bool> RefUnwindSafe for StateBuilder<'a, E, IG>
where E: RefUnwindSafe,

§

impl<'a, E, const IG: bool> Send for StateBuilder<'a, E, IG>
where E: Sync + Send,

§

impl<'a, E, const IG: bool> Sync for StateBuilder<'a, E, IG>
where E: Sync + Send,

§

impl<'a, E, const IG: bool> Unpin for StateBuilder<'a, E, IG>

§

impl<'a, E, const IG: bool> UnwindSafe for StateBuilder<'a, E, IG>
where E: RefUnwindSafe,

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<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
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, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
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<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
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<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.