#[non_exhaustive]pub struct DcOpfPreparation {Show 24 fields
pub name: String,
pub n_buses: usize,
pub n_source_generators: usize,
pub n_source_branches: usize,
pub base_mva: f64,
pub units: Units,
pub formula: BranchSusceptanceFormula,
pub objective: PreparedObjective,
pub skip_zero_impedance: bool,
pub synthesize_unrated_limits: bool,
pub synthesized_limit_window: SynthesizedLimitWindow,
pub correct_angle_difference_bounds: bool,
pub angle_difference_bounds: Option<AngleDifferenceBounds>,
pub bus_ids: Vec<BusId>,
pub bus_analysis_rows: Vec<usize>,
pub bus_source_rows: Vec<Option<usize>>,
pub reference_buses: ReferenceBuses,
pub p_d: Vec<f64>,
pub g_s: Vec<f64>,
pub p_shift: Vec<f64>,
pub hvdc_treatment: HvdcTreatment,
pub p_hvdc: Vec<f64>,
pub generators: DcGeneratorParameters,
pub branches: DcBranchParameters,
}Expand description
Matrix free DC OPF input data.
A problem instance is complete numerical input for one problem family. It is separate from the source network, a matrix projection, a solver formulation, and a solution.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: String§n_buses: usize§n_source_generators: usize§n_source_branches: usize§base_mva: f64§units: Units§formula: BranchSusceptanceFormulaFormula used to calculate each branch susceptance.
objective: PreparedObjectiveThe objective represented by the generator cost columns.
skip_zero_impedance: bool§synthesize_unrated_limits: boolWhether zero and negative source thermal ratings were replaced with synthesized limits while assembling this instance.
#[serde(default)] keeps documents written before this field readable;
their limits retain the old unsynthesized meaning.
synthesized_limit_window: SynthesizedLimitWindowThe angle difference interval those limits span. Omitted from a document when it is the stated one, so earlier documents read the window they were built with.
correct_angle_difference_bounds: boolWhether PowerModels’ angle difference correction was applied.
angle_difference_bounds: Option<AngleDifferenceBounds>Which angle difference bounds angle_min and angle_max carry.
None only in a document written before the field existed, whose
correct_angle_difference_bounds says whether the pad was applied.
bus_ids: Vec<BusId>Dense bus index to external bus ID.
bus_analysis_rows: Vec<usize>Dense bus index to row in the star-lowered analysis network.
bus_source_rows: Vec<Option<usize>>Dense bus index to source bus row. A synthetic star bus has no source row; an explicitly isolated source bus has no dense row here.
reference_buses: ReferenceBuses§p_d: Vec<f64>Nodal active demand in dense bus order.
g_s: Vec<f64>Nodal shunt conductance in dense bus order.
The DC power flow model holds voltage magnitude at one per unit, so a
shunt draws the constant real power g_s and does not depend on the
angle. It belongs in the injection: the bus susceptance matrix keeps
zero row sums and carries no shunt. A nodal balance subtracts it
beside Self::p_d, as MATPOWER runpf does.
p_shift: Vec<f64>Nodal phase shift injection in dense bus order. The complete fixed
withdrawal in L theta = Cg pg - fixed is
p_d + g_s + p_shift - p_hvdc.
hvdc_treatment: HvdcTreatmentHow in service HVDC lines entered Self::p_hvdc.
#[serde(default)] keeps documents written before this field
readable.
p_hvdc: Vec<f64>Nodal fixed HVDC injection in dense bus order: -pf at each in
service line’s from bus and +pt at its to bus
(IndexedNetwork::p_hvdc). All zero under
[HvdcTreatment::Ignore]. An injection, so the fixed withdrawal
subtracts it.
#[serde(default)]: a document written before this field reads as
empty, which Self::calc_fixed_nodal_withdrawal takes as zero.
generators: DcGeneratorParameters§branches: DcBranchParametersImplementations§
Source§impl DcOpfPreparation
impl DcOpfPreparation
pub fn n_generators(&self) -> usize
pub fn n_branches(&self) -> usize
Sourcepub fn calc_fixed_nodal_withdrawal(&self) -> Vec<f64>
pub fn calc_fixed_nodal_withdrawal(&self) -> Vec<f64>
Fixed nodal withdrawal in dense bus order.
With A oriented from bus to bus and
L = A diag(b) A^T, the DC balance is
L theta = Cg pg - (p_d + g_s + p_shift - p_hvdc).
It is calc_device_withdrawal plus
the phase shift withdrawal p_shift.
Sourcepub fn calc_device_withdrawal(&self) -> Vec<f64>
pub fn calc_device_withdrawal(&self) -> Vec<f64>
The withdrawal of the bus devices in dense bus order,
p_d + g_s - p_hvdc: the fixed nodal withdrawal without the phase
shift term, which the branch flows carry rather than the bus. Net
generation less this is the bus injection a solution reports.
Sourcepub fn calc_branch_flow_offset(&self) -> Vec<f64>
pub fn calc_branch_flow_offset(&self) -> Vec<f64>
Fixed branch flow offset in active branch column order.
The complete branch flow over this preparation’s internal positive
weights is f = diag(b) A^T theta + branch_flow_offset, where the
offset is -b * shift elementwise. In the public PowerModels sign
spelling the same flow is p_branch = -Bf va + b .* shift with the
negated susceptances (crate::DcOperators emits that
form); the two agree term for term because this b is the negation
of the public one.
Sourcepub fn calc_phase_shift_withdrawal(&self) -> Vec<f64>
pub fn calc_phase_shift_withdrawal(&self) -> Vec<f64>
The nodal phase shift withdrawal A branch_flow_offset of this
preparation’s branch columns, in dense bus order and the
preparation’s power unit: each branch’s
calc_branch_flow_offset leaves at
its from bus and arrives at its to bus. This is the calculation behind
Self::p_shift; a caller that edits the branch weights or shifts
recomputes p_shift with it.
Sourcepub fn calc_nodal_generator_data(&self) -> Result<NodalGeneratorParameters>
pub fn calc_nodal_generator_data(&self) -> Result<NodalGeneratorParameters>
Project generator cost and bounds to bus space.
The bounds at a bus are the sum of the generator bounds, which is the
range the bus total can reach. The cost curves at a bus combine by the
parallel rule q = 1 / Σ(1/qᵢ), the curve that the least cost split of
the bus total follows. That combination is an approximation: it agrees
with generator space only while the split stays inside the bound of
each generator. A bus with one generator keeps that generator’s own
coefficients.
Source§impl DcOpfPreparation
impl DcOpfPreparation
Sourcepub fn calc_bus_branch_incidence(&self) -> SparseMatrix
pub fn calc_bus_branch_incidence(&self) -> SparseMatrix
The signed bus by branch incidence matrix A of this preparation,
n_buses × n_branches CSR: column e has +1 at the branch’s from
bus and -1 at its to bus, in active branch column order. Self-loops
never reach the preparation, so every column has exactly two entries.
This is the matrix DcOpfMatrices::bus_branch_incidence carries,
from the one incidence assembly every builder in the crate uses, read
from the arrays the preparation already holds: one pass over the
branch columns, with no network indexing and no
DcOperators build. Row i of the CSR lists
the (branch, sign) pairs at bus i in ascending branch order.
§Panics
Panics if a branch column names a bus >= n_buses, which no
preparation builder produces.
Sourcepub fn calc_generator_bus_incidence(&self) -> SparseMatrix
pub fn calc_generator_bus_incidence(&self) -> SparseMatrix
The generator to bus map Cg of this preparation, n_buses × n_generators CSR with a 1 at row bus_of_gen[g] of column g. Row
i lists the generators at bus i in ascending column order. This is
DcOpfMatrices::generator_bus.
§Panics
Panics if a generator names a bus >= n_buses, which no preparation
builder produces.
Sourcepub fn calc_matrices(&self) -> DcOpfMatrices
pub fn calc_matrices(&self) -> DcOpfMatrices
Every sparse DC OPF matrix of this preparation, as
calc_dc_opf_matrices returns them for the instance the
preparation came from, without preparing it again.
Sourcepub fn calc_branch_flow(&self, theta: &[f64]) -> Vec<f64>
pub fn calc_branch_flow(&self, theta: &[f64]) -> Vec<f64>
The branch flows at the bus angles theta (radians, dense bus order),
in active branch column order and the preparation’s power unit:
f = diag(b) Aᵀ theta + branch_flow_offset, with b the positive
DcBranchParameters::susceptance_magnitude and the offset from
Self::calc_branch_flow_offset. Positive flow runs from the from
bus to the to bus.
§Panics
Panics if theta.len() is not n_buses.
Sourcepub fn calc_angle_difference(&self, theta: &[f64], branch: usize) -> f64
pub fn calc_angle_difference(&self, theta: &[f64], branch: usize) -> f64
The angle difference theta_from - theta_to across active branch
column branch, its entry of Aᵀ theta, for any bus vector theta
(angles, or a bus dual).
§Panics
Panics if branch is not an active branch column or theta is shorter
than n_buses.
Sourcepub fn calc_branch_flow_weight_derivative(
&self,
theta: &[f64],
branch: usize,
) -> f64
pub fn calc_branch_flow_weight_derivative( &self, theta: &[f64], branch: usize, ) -> f64
The derivative of branch column branch’s flow
(calc_branch_flow) at the bus angles
theta with respect to its positive weight
DcBranchParameters::susceptance_magnitude:
theta_from - theta_to - shift, in radians.