Circuit Graph and Views¶
krang.graph¶
Krang has a graph attribute that returns a networkx Graph. The nodes of this graph are constituted by the buses; the
edges are the elements that connect these buses, such as Line, Transformer, Reactor…
The nodes have:
- a property
'bus', which is thePackedOpendssElementcorresponding to that bus; - a property
'el', which is a list of thePackedOpendssElementthat are bound to that bus;
The edges have:
- a property
'el', which is a list of thePackedOpendssElementthat are bound to that couple of buses.
Since it contains a plethora of PackedOpendssElement, the graph has the potentiality for retrieving all sorts of useful
information and is amenable to data query and reorganization with networkx.
GraphView¶
To aid in working with the graph, krangpower exposes the template class GraphView. The GraphView is initialized with a
Krang instance and two arguments, busfun and edgefun, that are functions meant to be applied to every 'el'[0] of the
edges and to every 'bus' in the nodes (these function can also be None).
Initialized in this way, the GraphView is then bracket-indicizable with bus names
(for nodes) or couples of bus names (for edges) and retrieves the result of the application of the function on that bus
or edge.
-
class
krangpower.GraphView(busfun, edgefun, ckgr: krangpower._krangsuit.Krang, raw_mode=False)¶ -
__getitem__(item)¶ Gets the value of busfun at a bus, or the value of edgefun at an edge. If GraphView.raw_mode == True, it behaves like a nx.Graph.
-
__init__(busfun, edgefun, ckgr: krangpower._krangsuit.Krang, raw_mode=False)¶ Applies a busfun and and edgefun to the graph of a Krang. It then is indicizable with bus names and tuples of two bus names to retrieve the relative results.
-
raw_mode= None¶ If True, __getitem__ has the same behavior as nx.Graph. If False, __getitem__ returns the values of busfun or edgefun directly.
-
Another method of usage is to inherit GraphView and override its __init__ method in order to pack busfun and
edgefun inside it. This is done, for example, with the built-in VoltageView, that can be found in the submodule gv and initialized with just
a Krang instance and returns the property Voltages() of both 'bus' at buses and 'el'[0] at edges.
More specialized built-in GraphView s can and will be added in the future to krangpower.gv.
Example:
>>> import krangpower as kp
>>> from numpy import round
>>>
>>> um = kp.UM
>>> src = kp.Vsource(basekv = 10.0 * um.kV)
>>> twc = kp.Krang('twc', src)
>>> twc['sourcebus', 'a'] << kp.Line(units= 'm', length=20.0 * um.m).aka('l1')
>>> trf = kp.Transformer(windings=3,
>>> conns=['delta', 'wye', 'wye'],
>>> kvs=[10.0, 2.0, 3.0] * um.kV,
>>> kvas=[100.0, 20.0, 85.0] * um.kW,
>>> taps=[1.0, 1.0, 1.0],
>>> pctrs=[1.0, 1.0, 1.0]).aka('trf')
>>> twc['a', 'b', 'c'] << trf
>>> twc['b', 'bb'] << kp.Line(units= 'm', length=10.0 * um.m).aka('lbb')
>>> twc['c', 'cc'] << kp.Line(units= 'm', length=15.0 * um.m).aka('lcc')
>>> twc['bb',] << kp.Load(kv=2.0 * um.kV, kw = 5.0 * um.kW).aka('loadlow')
>>> twc['cc',] << kp.Load(kv=3.0 * um.kV, kw = 35.0 * um.kW).aka('loadhi')
>>> twc.solve()
>>> bvo = kp.gv.VoltageView(twc)
>>> print(round(bvo['bb'], 2))
[ 974.96 -581.68j -991.23 -553.5j 16.27+1135.18j] volt
>>> print(round(bvo['b','bb'], 2))
[[ 977.18 -581.47j -992.16 -555.52j 14.98+1137.j ] [ 974.96 -581.68j -991.23 -553.5j 16.27+1135.18j]] volt