powers/
zip.rs

1use caseformat::Bus;
2use num_complex::Complex64;
3
4/// Builds vectors of nominal complex bus power demands for ZIP loads.
5///
6/// Returns a struct with three fields, each an nb x 1 vectors. The fields
7/// 'z', 'i' and 'p' correspond to the nominal p.u. complex power
8/// (at 1 p.u. voltage magnitude) of the constant impedance, constant current,
9/// and constant power portions, respectively of the ZIP load model.
10pub fn make_sdzip(
11    base_mva: f64,
12    bus: &[Bus],
13    pw: Option<[f64; 3]>,
14    qw: Option<[f64; 3]>,
15) -> (Vec<Complex64>, Vec<Complex64>, Vec<Complex64>) {
16    let pw = pw.unwrap_or([1.0, 0.0, 0.0]);
17    let qw = qw.unwrap_or(pw);
18
19    let base_mva = Complex64::new(base_mva, 0.0);
20
21    let mut sd_z = Vec::with_capacity(bus.len());
22    let mut sd_i = Vec::with_capacity(bus.len());
23    let mut sd_p = Vec::with_capacity(bus.len());
24    for b in bus {
25        sd_z.push(Complex64::new(b.pd * pw[2], b.qd * qw[2]) / base_mva);
26        sd_i.push(Complex64::new(b.pd * pw[1], b.qd * qw[1]) / base_mva);
27        sd_p.push(Complex64::new(b.pd * pw[0], b.qd * qw[0]) / base_mva);
28    }
29    (sd_z, sd_i, sd_p)
30}