pub type CurrentSources<'a> = EdgeValueInputs<'a, CURRENT>;
Expand description
Alias of EdgeValueInputs
specifically for current sources. Please see the docstring of EdgeValueInputs
for details.
Aliased Type§
pub enum CurrentSources<'a> {
Slice(&'a [f64]),
IdxAndVals(&'a [(usize, f64)]),
Function(&'a dyn Fn(FunctionArgs<'_>)),
None,
}
Variants§
Slice(&'a [f64])
If all current / voltage excitations or resistances are constant, it can be convenient to provide their values as a slice. This slice has to fulfill the following constraints:
- Its length must be equal to the number of edges.
- If an edge has another type, its corresponding entry must be zero.
- If an edge is a resistance, its corresponding slice entry must be larger than zero.
These conditions are checked at the start of a call to
NetworkAnalysis::solve
and aSolveError
is returned if they’re not fulfilled.
IdxAndVals(&'a [(usize, f64)])
This is an alternative to EdgeValueInputs::Slice
where the values are provided directly
together with their indices as a tuple (index, value)
- useful if the network does not contain many current / voltage excitations or resistances.
For example, these two Resistances
lead in the same resultat when used in a solve
call:
use network_analysis::Resistances;
let res1 = Resistances::Slice(&[0.0, 0.0, 1.0, 2.0, 0.0]);
let res1 = Resistances::IdxAndVals(&[(2, 1.0f64), (3, 2.0f64)]);
The indices have to fulfill the following constraints:
- They must be within bounds (i.e. smaller than the number of edges)-
- They must not contain duplicates.
- They must not index edges of a different type.
Additionally, the values must always be larger than zero
These conditions are checked at the start of a call to
NetworkAnalysis::solve
and aSolveError
is returned if they’re not fulfilled.
Function(&'a dyn Fn(FunctionArgs<'_>))
This variant can be used to represent variable resistances - for example, resistances whose
value depends on the current going through them. It wraps a user-provided function pointer
which takes a single argument FunctionArgs
. This argument contains the edge currents
and voltages of the current iteration and a EdgeValueAndTypeMut
wrapper over a mutable
edge resistance slice. See EdgeValueAndTypeMut::iter_mut
for an example.
None
If no edges of the specified type exist within the network, this variant can be used.