Skip to main content

Flux

Struct Flux 

Source
pub struct Flux { /* private fields */ }
Expand description

A quantity spread over an interface’s faces, in SI units.

An amount per face rather than a density, so that summing is meaningful and the total is a total. A density would need the areas to be carried alongside every arithmetic operation, and the one thing this type must make easy is adding up.

Implementations§

Source§

impl Flux

Source

pub fn zeros(faces: usize) -> Flux

Nothing, spread over the given number of faces. At least one face, so an empty flux is not a special case every consumer has to handle.

Source

pub fn from_faces(per_face: Vec<f64>) -> Flux

Amounts per face, in SI base units and in the interface’s own order.

Source

pub fn spread_over(total: f64, interface: &Interface) -> Flux

One number spread over an interface in proportion to face area.

The honest way to turn a lumped quantity into a distributed one: it says “evenly, because I do not know better” rather than silently putting everything on the first face. Which is what the lumped coupling was doing.

Source

pub fn profiled<F>(total: f64, interface: &Interface, profile: F) -> Flux
where F: FnMut(f64) -> f64,

Distribute a total over an interface following a shape.

profile is called with each face’s centre as a fraction of the way along the boundary, from 0 to 1 in cumulative area, and returns an unnormalised weight. So a beam of waist w centred on a boundary of length l is |u| (-2.0 * (((u - 0.5) * l / w).powi(2))).exp(), written the way the physics is written rather than as a table of numbers.

The weights are scaled so the faces sum to total exactly. Which splits the two claims deliberately: the total is exact, because a coupling that loses energy is a bug the audit must be able to trust, and the shape is midpoint-accurate, because a face gets its centre’s weight rather than the profile’s integral over it. The shape error falls as the boundary is refined; the total’s does not exist.

A profile summing to zero — all weights zero, or positives and negatives cancelling — has no scale to normalise against, so it falls back to spreading by area. That is a defined answer rather than infinities, and it is the same answer Flux::spread_over gives.

Source

pub fn faces(&self) -> usize

How many faces this flux covers. Must match the interface it is published on.

Source

pub fn at(&self, face: usize) -> f64

The amount on one face. Zero past the end.

Source

pub fn per_face(&self) -> &[f64]

Amounts per face, in the order the interface defines.

Source

pub fn total(&self) -> f64

Summed in index order, so the total is a function of the data and not of how it was visited.

Source

pub fn largest(&self) -> f64

Largest single face’s amount, which is the scale a rounding tolerance should be judged against for the same reason Ledger records one.

Source

pub fn add(&mut self, other: &Flux) -> Result<(), Violation>

Add another flux face by face. Refuses a mismatched face count rather than truncating or padding.

Source

pub fn scaled(&self, by: f64) -> Flux

Scale every face.

Source

pub fn resample( &self, from: &Interface, to: &Interface, ) -> Result<Flux, Violation>

Redistribute onto a different interface, conserving the total.

Faces are treated as consecutive intervals in cumulative area, and each source face’s amount is divided among the target faces it overlaps in proportion to how much of it each covers. The overlap fractions of any source face sum to one, so the total survives by construction rather than by a corrective scaling afterwards — which is the difference between a resampling that conserves and one that is checked and then adjusted.

It conserves to summation rounding, not to the last bit: the pieces are added in a different order than they were split. That is a part in 10¹⁵, and it is why the audit’s tolerance is relative.

Note what this cannot do. Redistributing by area assumes the two interfaces cover the same boundary in the same order, which is a statement about the geometry that this type has no way to check. It is a remap, not a projection between arbitrary meshes.

Trait Implementations§

Source§

impl Clone for Flux

Source§

fn clone(&self) -> Flux

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Flux

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Flux

Source§

fn eq(&self, other: &Flux) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Flux

Auto Trait Implementations§

§

impl Freeze for Flux

§

impl RefUnwindSafe for Flux

§

impl Send for Flux

§

impl Sync for Flux

§

impl Unpin for Flux

§

impl UnsafeUnpin for Flux

§

impl UnwindSafe for Flux

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.