Skip to main content

powerio_dist/dss/
defaults.rs

1//! OpenDSS constructor defaults for the phase A classes.
2//!
3//! Values come from the object constructors in epri-dev/OpenDSS-C and are
4//! verified empirically against the engine (opendssdirect via
5//! `tools/verify_defaults.py`; rerun it when bumping the engine). The reader
6//! materializes these into explicit model values and records each
7//! materialization in `DistNetwork::defaulted`.
8//!
9//! The generator note: the constructor sets kW=1000, PF=0.88, kvar=60
10//! (`generator.cpp`, member init), while the property display strings claim
11//! kW=100, PF=0.80; the engine reports the constructor values, so those are
12//! the defaults here.
13
14pub mod line {
15    //! Sequence impedances in ohm per unit length, capacitance in nF per
16    //! unit length, with `units = none` (factor 1).
17    pub const R1: f64 = 0.058;
18    pub const X1: f64 = 0.1206;
19    pub const R0: f64 = 0.1784;
20    pub const X0: f64 = 0.4047;
21    pub const C1_NF: f64 = 3.4;
22    pub const C0_NF: f64 = 1.6;
23    pub const LENGTH: f64 = 1.0;
24    pub const PHASES: usize = 3;
25    pub const NORMAMPS: f64 = 400.0;
26    pub const EMERGAMPS: f64 = 600.0;
27}
28
29pub mod linecode {
30    pub const NPHASES: usize = 3;
31}
32
33pub mod load {
34    pub const PHASES: usize = 3;
35    pub const KV: f64 = 12.47;
36    pub const KW: f64 = 10.0;
37    pub const PF: f64 = 0.88;
38    /// Constant power.
39    pub const MODEL: i64 = 1;
40}
41
42pub mod transformer {
43    pub const PHASES: usize = 3;
44    pub const WINDINGS: usize = 2;
45    pub const KV: f64 = 12.47;
46    pub const KVA: f64 = 1000.0;
47    pub const TAP: f64 = 1.0;
48    pub const PCT_R: f64 = 0.2;
49    pub const XHL: f64 = 7.0;
50    pub const XHT: f64 = 35.0;
51    pub const XLT: f64 = 30.0;
52}
53
54pub mod vsource {
55    pub const BASEKV: f64 = 115.0;
56    pub const PU: f64 = 1.0;
57    pub const ANGLE_DEG: f64 = 0.0;
58    pub const PHASES: usize = 3;
59    pub const BUS1: &str = "sourcebus";
60}
61
62pub mod capacitor {
63    pub const PHASES: usize = 3;
64    pub const KVAR: f64 = 1200.0;
65    pub const KV: f64 = 12.47;
66}
67
68pub mod reactor {
69    //! `TReactorObj.Create` (Reactor.pas): 3 phases, 100 kvar, 12.47 kV,
70    //! wye. Unlike the capacitor's 1200 kvar bank, the reactor constructor
71    //! seeds a 100 kvar rating.
72    pub const PHASES: usize = 3;
73    pub const KVAR: f64 = 100.0;
74    pub const KV: f64 = 12.47;
75}
76
77pub mod generator {
78    pub const PHASES: usize = 3;
79    pub const KV: f64 = 12.47;
80    pub const KW: f64 = 1000.0;
81    pub const KVAR: f64 = 60.0;
82    /// Constructor PFNominal; kw/pf writes resync kvar from it.
83    pub const PF: f64 = 0.88;
84}
85
86/// Base frequency when no `Set DefaultBaseFrequency` appears.
87pub const BASE_FREQUENCY: f64 = 60.0;
88
89/// `GetUnitsCode` + `To_Meters` from Shared/LineUnits.cpp. The engine
90/// matches on the first two characters; `no*` and anything unrecognized
91/// are UNITS_NONE, which has no conversion factor.
92pub fn unit_to_meters(code: &str) -> Option<f64> {
93    let two: String = code
94        .chars()
95        .take(2)
96        .map(|c| c.to_ascii_lowercase())
97        .collect();
98    Some(match two.as_str() {
99        "mi" => 1609.344,
100        "kf" => 304.8,
101        "km" => 1000.0,
102        "m" | "me" => 1.0,
103        "ft" => 0.3048,
104        "in" => 0.0254,
105        "cm" => 0.01,
106        "mm" => 0.001,
107        _ => return None,
108    })
109}