Coverage for src/distopf/matrix_models/lindist.py: 50%
14 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
1from typing import Optional
2import pandas as pd
3from distopf.matrix_models.base import LinDistBase
4import distopf as opf
7class LinDistModel(LinDistBase):
8 """
9 LinDistFlow Model class for linear power flow modeling.
11 This class represents a linearized distribution model used for calculating
12 power flows, voltages, and other system properties in a distribution network
13 using the linearized branch-flow formulation from [1]. The model is composed of several power system components
14 such as buses, branches, generators, capacitors, and regulators.
16 Parameters
17 ----------
18 branch_data : pd.DataFrame
19 DataFrame containing branch data including resistance and reactance values and limits.
20 bus_data : pd.DataFrame
21 DataFrame containing bus data such as loads, voltages, and limits.
22 gen_data : pd.DataFrame
23 DataFrame containing generator data.
24 cap_data : pd.DataFrame
25 DataFrame containing capacitor data.
26 reg_data : pd.DataFrame
27 DataFrame containing regulator data.
29 References
30 ----------
31 [1] R. R. Jha, A. Dubey, C.-C. Liu, and K. P. Schneider,
32 “Bi-Level Volt-VAR Optimization to Coordinate Smart Inverters
33 With Voltage Control Devices,”
34 IEEE Trans. Power Syst., vol. 34, no. 3, pp. 1801–1813,
35 May 2019, doi: 10.1109/TPWRS.2018.2890613.
37 Examples
38 --------
39 This example demonstrates how to set up and solve a linear distribution flow model
40 using a provided case, and visualize the results.
42 >>> import distopf as opf
43 >>> # Prepare the case data
44 >>> case = opf.DistOPFCase(data_path="ieee123_30der")
45 >>> # Initialize the LinDistModel
46 >>> model = LinDistModel(
47 ... branch_data=case.branch_data,
48 ... bus_data=case.bus_data,
49 ... gen_data=case.gen_data,
50 ... cap_data=case.cap_data,
51 ... reg_data=case.reg_data,
52 ... )
53 >>> # Solve the model using the specified objective function
54 >>> result = opf.lp_solve(model, opf.gradient_load_min(model))
55 >>> # Extract and plot results
56 >>> v = model.get_voltages(result.x)
57 >>> s = model.get_apparent_power_flows(result.x)
58 >>> p_gens = model.get_p_gens(result.x)
59 >>> q_gens = model.get_q_gens(result.x)
60 >>> # Visualize network and power flows
61 >>> opf.plot_network(model, v=v, s=s, p_gen=p_gens, q_gen=q_gens).show()
62 >>> opf.plot_voltages(v).show()
63 >>> opf.plot_power_flows(s).show()
64 >>> opf.plot_gens(p_gens, q_gens).show()
65 """
67 def __init__(
68 self,
69 branch_data: Optional[pd.DataFrame] = None,
70 bus_data: Optional[pd.DataFrame] = None,
71 gen_data: Optional[pd.DataFrame] = None,
72 cap_data: Optional[pd.DataFrame] = None,
73 reg_data: Optional[pd.DataFrame] = None,
74 ):
75 super().__init__(branch_data, bus_data, gen_data, cap_data, reg_data)
76 self.build()
79if __name__ == "__main__":
80 # Prepare the case data
81 case = opf.DistOPFCase(data_path="ieee123_30der")
82 # Initialize the LinDistModel
83 model = LinDistModel(
84 branch_data=case.branch_data,
85 bus_data=case.bus_data,
86 gen_data=case.gen_data,
87 cap_data=case.cap_data,
88 reg_data=case.reg_data,
89 )
90 # Solve the model using the specified objective function
91 result = opf.lp_solve(model, opf.gradient_load_min(model))
92 # Extract and plot results
93 v = model.get_voltages(result.x)
94 s = model.get_apparent_power_flows(result.x)
95 # s = model.get_apparent_power_flows(result.x)
96 # p_gens = model.get_p_gens(result.x)
97 # q_gens = model.get_q_gens(result.x)
98 # # Visualize network and power flows
99 # opf.plot_network(model, v=v, s=s, p_gen=p_gens, q_gen=q_gens).show()
100 # opf.plot_voltages(v).show()
101 # opf.plot_power_flows(s).show()
102 # opf.plot_gens(p_gens, q_gens).show()