powers_pf/
pfopt.rs

1use clap::ValueEnum;
2
3#[derive(Debug, PartialEq, Copy, Clone, ValueEnum)]
4pub enum Alg {
5    /// Newton's method.
6    NR = 0,
7    /// Fast-Decoupled method (BX version).
8    FDBX = 1,
9    /// Fast-Decoupled method (XB version).
10    FDXB = 2,
11    /// Gauss-Seidel method.
12    GS = 3,
13    /// Power/current/admittance summation method (radial networks only).
14    SUM = 4,
15}
16
17#[derive(Copy, Clone)]
18pub enum Sum {
19    POWER,
20    CURRENT,
21    ADMITTANCE,
22}
23
24/// Type of nodal balance equation.
25#[derive(Copy, Clone)]
26pub enum NodalBalance {
27    POWER,
28    CURRENT,
29}
30
31#[derive(Copy, Clone)]
32pub enum BusVoltage {
33    /// bus voltage variables represented in polar coordinates
34    POLAR,
35    /// bus voltage variables represented in cartesian coordinates
36    CARTESIAN,
37    /// Polar updates computed via modified cartesian Jacobian
38    HYBRID,
39}
40
41#[derive(PartialEq, Copy, Clone)]
42pub enum GenQLimits {
43    IgnoreLimits = 0,
44    // Simultaneous bus type conversion.
45    Simultaneous = 1,
46    // One-at-a-time bus type conversion.
47    OneAtATime = 2,
48}
49
50#[derive(Default)]
51pub struct MPOpt {
52    // Linearized DC power flow that assumes lossless branches,
53    // 1pu voltages and small voltage angle differences.
54    pub dc: bool,
55
56    pub pf: PFOpt,
57    pub exp: ExpOpt,
58}
59
60#[derive(Clone)]
61pub struct PFOpt {
62    // AC power flow algorithm.
63    pub algorithm: Alg,
64
65    // Termination tolerance on per unit P & Q mismatch. Default value is 1e-8.
66    pub tolerance: f64,
67
68    // Maximum number of iterations for Newton's method. Default value is 10.
69    pub max_it_nr: usize,
70    // Maximum number of iterations for fast decoupled method. Default value is 30.
71    pub max_it_fd: usize,
72    // Maximum number of iterations for Gauss-Seidel method. Default value is 1000.
73    pub max_it_gs: usize,
74
75    // Enforce gen reactive power limits at expense of |V|.
76    pub enforce_q_limits: GenQLimits,
77
78    pub current_balance: NodalBalance,
79    pub v_cartesian: BusVoltage,
80    pub summation_method: Sum,
81}
82
83impl Default for PFOpt {
84    fn default() -> Self {
85        Self {
86            algorithm: Alg::NR,
87            tolerance: 1e-8,
88            max_it_nr: 10,
89            max_it_fd: 30,
90            max_it_gs: 1000,
91            enforce_q_limits: GenQLimits::IgnoreLimits,
92            current_balance: NodalBalance::POWER,
93            v_cartesian: BusVoltage::POLAR,
94            summation_method: Sum::POWER,
95        }
96    }
97}
98
99#[derive(Clone, Default)]
100pub struct ExpOpt {
101    pub sys_wide_zip_loads: SysWideZipLoads,
102}
103
104#[derive(Clone, Default)]
105pub struct SysWideZipLoads {
106    pub pw: Option<[f64; 3]>,
107    pub qw: Option<[f64; 3]>,
108}