LightSim2grid¶
This module provides the interface between a
Network and lightsim2grid, used when
settings.pf_solver is lightsim2grid. See Power flow solver.
convert_net¶
Convert a gridfm_datakit Network to lightsim2grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network to convert. |
required |
Returns:
| Type | Description |
|---|---|
LoadedNetwork
|
The lightsim2grid LSGrid, the network itself and the index maps between the two. |
Source code in gridfm_datakit/lightsim2grid/__init__.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
to_lightsim2grid¶
Build a lightsim2grid LSGrid from the current state of net.
Loads, generator set points, statuses and branch parameters are all read
from net.buses / net.gens / net.branches, so the result is
valid for one perturbed copy of the network only. Use
:func:update_lightsim2grid to re-synchronise it with another one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
The network to convert. |
required |
Returns:
| Type | Description |
|---|---|
ConvertedNetwork
|
The LSGrid, its index maps to |
Raises:
| Type | Description |
|---|---|
ImportError
|
If lightsim2grid is not available. |
Source code in gridfm_datakit/lightsim2grid/convert.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
update_lightsim2grid¶
Return a lightsim2grid model in sync with net.
With no converted the LSGrid is built from scratch. Otherwise the
LSGrid of converted is updated in place with what changed since it
was last synchronised (branch parameters and statuses, generator statuses
and set points, loads), which lets lightsim2grid keep its solver caches.
It is rebuilt only if something it cannot update changed (topology, taps
and shifts, shunts, which buses have a load, the slack
generators). converted is modified and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
The network the LSGrid has to match. |
required |
converted
|
Optional[ConvertedNetwork]
|
The result of a previous call, or None to build the LSGrid. |
None
|
Returns:
| Type | Description |
|---|---|
ConvertedNetwork
|
|
ConvertedNetwork
|
had to be built or rebuilt. |
Source code in gridfm_datakit/lightsim2grid/convert.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
run_ls_pf¶
Run an AC (or DC) power flow with lightsim2grid and format the results.
The power flow starts from the voltages stored in net.buses (see
:func:gridfm_datakit.lightsim2grid.convert.initial_voltage).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ls_net
|
Any
|
The lightsim2grid LSGrid, in sync with |
required |
net
|
Network
|
The network the LSGrid was built from or updated with. |
required |
mapping_l2g
|
MappingL2G
|
Index maps between |
required |
dc
|
bool
|
Run a DC power flow instead of an AC one. |
False
|
max_iter
|
int
|
Maximum number of iterations. |
50
|
tol
|
float
|
Convergence tolerance. |
1e-08
|
as_arrays
|
bool
|
Return the results as dense arrays under |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The power flow results in PowerModels' format (see :func: |
Dict[str, Any]
|
solving time in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the power flow did not converge. |
Source code in gridfm_datakit/lightsim2grid/preprocess.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
get_pf_res¶
Format lightsim2grid power flow results for the pf_post_process function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ls_net
|
Any
|
lightsim2grid LSGrid, on which a power flow was just run |
required |
v
|
ndarray
|
complex voltage returned by the power flow (empty if it diverged) |
required |
solve_time
|
float
|
power flow solving time |
required |
net
|
Network
|
gridfm Network the LSGrid was built from |
required |
mapping_l2g
|
MappingL2G
|
lightsim2grid-to-gridfm index maps |
required |
as_arrays
|
bool
|
Skip the per-element dicts (which |
False
|
with_ybus
|
bool
|
With |
False
|
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Power flow results in a nested Dict format, similar to PowerModel's power flow results |
Source code in gridfm_datakit/lightsim2grid/preprocess.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
get_ybus¶
Bus admittance matrix of the LSGrid, indexed like :func:gridfm_datakit.network.makeYbus.
lightsim2grid builds it for its AC power flow, so this is much cheaper than
rebuilding it from net. It must be called after an AC power flow, which is
what updates it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ls_net
|
Any
|
The lightsim2grid LSGrid, on which an AC power flow was just run. |
required |
net
|
Network
|
The network the LSGrid is in sync with. |
required |
Returns:
| Type | Description |
|---|---|
csr_matrix
|
The sparse Ybus (no explicit zeros, sorted indices), with row and column |
csr_matrix
|
|
csr_matrix
|
|
csr_matrix
|
summation order. |
Source code in gridfm_datakit/lightsim2grid/preprocess.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
build_l2g_maps¶
Build the index maps of the LSGrid that :func:to_lightsim2grid creates from net.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
The network the LSGrid is built from. |
required |
Returns:
| Type | Description |
|---|---|
MappingL2G
|
The maps: which |
MappingL2G
|
lightsim2grid, and the bus index of every lightsim2grid bus. |
Source code in gridfm_datakit/lightsim2grid/mapping.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
MappingL2G¶
lightsim2grid-to-gridfm index maps.
Attributes¶
line_rows : np.ndarray
line_rows[k] is the net.branches row of the k-th lightsim2grid powerline.
trafo_rows : np.ndarray
trafo_rows[k] is the net.branches row of the k-th lightsim2grid transformer.
bus_index : np.ndarray
bus_index[r] is the continuous bus index (BUS_I) of the r-th
lightsim2grid bus (= r-th row of net.buses).
Source code in gridfm_datakit/lightsim2grid/mapping.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
ConvertedNetwork¶
A lightsim2grid LSGrid together with its maps to the gridfm Network.
Source code in gridfm_datakit/lightsim2grid/convert.py
34 35 36 37 38 39 40 41 | |
LoadedNetwork¶
Bundles the lightsim2grid and gridfm_datakit representations of a network.
Source code in gridfm_datakit/lightsim2grid/__init__.py
35 36 37 38 39 40 41 | |