Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Power System Automation and Monitoring
pyVolt
pyVolt
Commits
6055c5f6
Commit
6055c5f6
authored
Nov 07, 2018
by
Markus Mirz
Browse files
remove complex workarounds
parent
3db666e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
acs-state-estimation/bc_powerflow.py
View file @
6055c5f6
...
...
@@ -67,23 +67,22 @@ def BC_power_flow(branches, nodes):
V
=
np
.
ones
(
nodes
.
num
)
+
1j
*
np
.
zeros
(
nodes
.
num
)
num_iter
=
0
State
=
np
.
zero
s
(
2
*
branches
.
num
)
State
=
np
.
one
s
(
2
*
branches
.
num
)
State
=
np
.
concatenate
((
np
.
array
([
1
,
0
]),
State
),
axis
=
0
)
while
diff
>
epsilon
:
for
k
in
range
(
1
,
nodes
.
num
+
1
):
i
=
k
-
1
m
=
2
*
i
t
=
nodes
.
type
[
i
]
if
t
==
'slack'
:
if
nodes
.
type
[
i
]
==
'slack'
:
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
inner
(
H
[
m
+
1
],
State
)
elif
t
==
'PQ'
:
elif
nodes
.
type
[
i
]
==
'PQ'
:
z
[
m
]
=
(
nodes
.
pwr_flow_values
[
1
][
i
]
*
V
[
i
].
real
+
nodes
.
pwr_flow_values
[
2
][
i
]
*
V
[
i
].
imag
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
z
[
m
+
1
]
=
(
nodes
.
pwr_flow_values
[
1
][
i
]
*
V
[
i
].
imag
-
nodes
.
pwr_flow_values
[
2
][
i
]
*
V
[
i
].
real
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
inner
(
H
[
m
+
1
],
State
)
elif
t
==
'PV'
:
elif
nodes
.
type
[
i
]
==
'PV'
:
z
[
m
]
=
(
nodes
.
pwr_flow_values
[
1
][
i
]
*
V
[
i
].
real
+
nodes
.
pwr_flow_values
[
2
][
i
]
*
V
[
i
].
imag
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
abs
(
V
[
i
])
...
...
@@ -126,9 +125,7 @@ def BC_power_flow(branches, nodes):
Sinj_rx
=
np
.
multiply
(
V
,
np
.
conj
(
Iinj
))
Sinj
=
np
.
real
(
Sinj_rx
)
+
1j
*
np
.
imag
(
Sinj_rx
)
S1_rx
=
np
.
multiply
(
V
[
branchs
.
start
-
1
],
np
.
conj
(
I
))
S2_rx
=
np
.
multiply
(
V
[
branchs
.
end
-
1
],
np
.
conj
(
I
))
S1
=
np
.
real
(
S1_rx
)
+
1j
*
np
.
imag
(
S1_rx
)
S2
=
np
.
real
(
S2_rx
)
+
1j
*
np
.
imag
(
S2_rx
)
S1
=
np
.
multiply
(
V
[
branchs
.
start
-
1
],
np
.
conj
(
I
))
S2
=
np
.
multiply
(
V
[
branchs
.
end
-
1
],
np
.
conj
(
I
))
return
V
,
I
,
Iinj
,
S1
,
S2
,
Sinj
,
num_iter
\ No newline at end of file
acs-state-estimation/nv_powerflow.py
View file @
6055c5f6
import
numpy
import
numpy
as
np
import
math
class
Real_to_all
:
def
__init__
(
self
,
Ar
,
Ax
):
self
.
real
=
Ar
self
.
imag
=
Ax
self
.
complex
=
Ar
+
1j
*
Ax
self
.
mag
=
numpy
.
absolute
(
self
.
complex
)
self
.
phase
=
numpy
.
angle
(
self
.
complex
)
def
Ymatrix_calc
(
branch
,
node
):
Ymatrix
=
n
umpy
.
zeros
((
node
.
num
,
node
.
num
),
dtype
=
n
umpy
.
complex
)
Ymatrix
=
n
p
.
zeros
((
node
.
num
,
node
.
num
),
dtype
=
n
p
.
complex
)
Adjacencies
=
[[]
for
_
in
range
(
node
.
num
)]
for
index
in
range
(
branch
.
num
):
fr
=
branch
.
start
[
index
]
-
1
...
...
@@ -28,9 +20,9 @@ def NV_power_flow(branch, node):
Ymatrix
,
Adj
=
Ymatrix_calc
(
branch
,
node
)
z
=
n
umpy
.
zeros
(
2
*
(
node
.
num
))
h
=
n
umpy
.
zeros
(
2
*
(
node
.
num
))
H
=
n
umpy
.
zeros
((
2
*
(
node
.
num
),
2
*
(
node
.
num
)))
z
=
n
p
.
zeros
(
2
*
(
node
.
num
))
h
=
n
p
.
zeros
(
2
*
(
node
.
num
))
H
=
n
p
.
zeros
((
2
*
(
node
.
num
),
2
*
(
node
.
num
)))
for
k
in
range
(
1
,
node
.
num
+
1
):
i
=
k
-
1
...
...
@@ -45,92 +37,86 @@ def NV_power_flow(branch, node):
H
[
m
][
i
]
=
1
H
[
m
+
1
][
i2
]
=
1
elif
t
==
'PQ'
:
H
[
m
][
i
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
i
])
H
[
m
][
i2
]
=
n
umpy
.
imag
(
Ymatrix
[
i
][
i
])
H
[
m
+
1
][
i
]
=
-
n
umpy
.
imag
(
Ymatrix
[
i
][
i
])
H
[
m
+
1
][
i2
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
i
])
idx1
=
n
umpy
.
subtract
(
Adj
[
i
],
1
)
H
[
m
][
i
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
i
])
H
[
m
][
i2
]
=
n
p
.
imag
(
Ymatrix
[
i
][
i
])
H
[
m
+
1
][
i
]
=
-
n
p
.
imag
(
Ymatrix
[
i
][
i
])
H
[
m
+
1
][
i2
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
i
])
idx1
=
n
p
.
subtract
(
Adj
[
i
],
1
)
idx2
=
idx1
+
node
.
num
H
[
m
][
idx1
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx2
]
=
n
umpy
.
imag
(
Ymatrix
[
i
][
idx1
])
H
[
m
+
1
][
idx1
]
=
-
n
umpy
.
imag
(
Ymatrix
[
i
][
idx1
])
H
[
m
+
1
][
idx2
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx1
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx2
]
=
n
p
.
imag
(
Ymatrix
[
i
][
idx1
])
H
[
m
+
1
][
idx1
]
=
-
n
p
.
imag
(
Ymatrix
[
i
][
idx1
])
H
[
m
+
1
][
idx2
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
idx1
])
elif
t
==
'PV'
:
z
[
m
+
1
]
=
node
.
pwr_flow_values
[
2
][
i
]
H
[
m
][
i
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
i
])
H
[
m
][
i2
]
=
n
umpy
.
imag
(
Ymatrix
[
i
][
i
])
idx1
=
n
umpy
.
subtract
(
Adj
[
i
],
1
)
H
[
m
][
i
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
i
])
H
[
m
][
i2
]
=
n
p
.
imag
(
Ymatrix
[
i
][
i
])
idx1
=
n
p
.
subtract
(
Adj
[
i
],
1
)
idx2
=
idx1
+
node
.
num
H
[
m
][
idx1
]
=
-
n
umpy
.
real
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx2
]
=
n
umpy
.
imag
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx1
]
=
-
n
p
.
real
(
Ymatrix
[
i
][
idx1
])
H
[
m
][
idx2
]
=
n
p
.
imag
(
Ymatrix
[
i
][
idx1
])
epsilon
=
5
Vr
=
numpy
.
ones
(
node
.
num
)
Vx
=
numpy
.
zeros
(
node
.
num
)
V
=
Real_to_all
(
Vr
,
Vx
)
epsilon
=
10
**
(
-
10
)
diff
=
5
V
=
np
.
ones
(
nodes
.
num
)
+
1j
*
np
.
zeros
(
nodes
.
num
)
num_iter
=
0
StateVr
=
numpy
.
ones
(
node
.
num
)
StateVx
=
numpy
.
zeros
(
node
.
num
)
State
=
numpy
.
concatenate
((
StateVr
,
StateVx
),
axis
=
0
)
State
=
np
.
ones
(
2
*
branches
.
num
)
State
=
np
.
concatenate
((
np
.
array
([
1
,
0
]),
State
),
axis
=
0
)
while
epsilon
>
10
**
(
-
10
)
:
while
diff
>
epsilon
:
for
k
in
range
(
1
,
node
.
num
+
1
):
i
=
k
-
1
m
=
2
*
i
i2
=
i
+
node
.
num
t
=
node
.
type
[
i
]
if
t
==
'slack'
:
h
[
m
]
=
numpy
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
numpy
.
inner
(
H
[
m
+
1
],
State
)
elif
t
==
'PQ'
:
if
nodes
.
type
[
i
]
==
'slack'
:
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
inner
(
H
[
m
+
1
],
State
)
elif
nodes
.
type
[
i
]
==
'PQ'
:
z
[
m
]
=
(
node
.
pwr_flow_values
[
1
][
i
]
*
V
.
real
[
i
]
+
node
.
pwr_flow_values
[
2
][
i
]
*
V
.
imag
[
i
])
/
(
V
.
mag
[
i
]
**
2
)
z
[
m
+
1
]
=
(
node
.
pwr_flow_values
[
1
][
i
]
*
V
.
imag
[
i
]
-
node
.
pwr_flow_values
[
2
][
i
]
*
V
.
real
[
i
])
/
(
V
.
mag
[
i
]
**
2
)
h
[
m
]
=
n
umpy
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
n
umpy
.
inner
(
H
[
m
+
1
],
State
)
elif
t
==
'PV'
:
h
[
m
]
=
n
p
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
n
p
.
inner
(
H
[
m
+
1
],
State
)
elif
nodes
.
type
[
i
]
==
'PV'
:
z
[
m
]
=
(
node
.
pwr_flow_values
[
1
][
i
]
*
V
.
real
[
i
]
+
node
.
pwr_flow_values
[
2
][
i
]
*
V
.
imag
[
i
])
/
(
V
.
mag
[
i
]
**
2
)
h
[
m
]
=
n
umpy
.
inner
(
H
[
m
],
State
)
h
[
m
]
=
n
p
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
V
.
mag
[
i
]
H
[
m
+
1
][
i
]
=
n
umpy
.
cos
(
V
.
phase
[
i
])
H
[
m
+
1
][
i2
]
=
n
umpy
.
sin
(
V
.
phase
[
i
])
H
[
m
+
1
][
i
]
=
n
p
.
cos
(
V
.
phase
[
i
])
H
[
m
+
1
][
i2
]
=
n
p
.
sin
(
V
.
phase
[
i
])
r
=
n
umpy
.
subtract
(
z
,
h
)
Hinv
=
n
umpy
.
linalg
.
inv
(
H
)
Delta_State
=
n
umpy
.
inner
(
Hinv
,
r
)
r
=
n
p
.
subtract
(
z
,
h
)
Hinv
=
n
p
.
linalg
.
inv
(
H
)
Delta_State
=
n
p
.
inner
(
Hinv
,
r
)
State
=
State
+
Delta_State
epsilon
=
numpy
.
amax
(
n
umpy
.
absolute
(
Delta_State
))
diff
=
np
.
amax
(
n
p
.
absolute
(
Delta_State
))
V
.
real
=
State
[:
node
.
num
]
V
.
imag
=
State
[
node
.
num
:]
V
=
Real_to_all
(
V
.
real
,
V
.
imag
)
V
=
State
[:
node
.
num
]
+
1j
*
State
[
node
.
num
:]
num_iter
=
num_iter
+
1
Irx
=
n
umpy
.
zeros
((
branch
.
num
),
dtype
=
n
umpy
.
complex
)
Irx
=
n
p
.
zeros
((
branch
.
num
),
dtype
=
n
p
.
complex
)
for
idx
in
range
(
branch
.
num
):
fr
=
branch
.
start
[
idx
]
-
1
to
=
branch
.
end
[
idx
]
-
1
Irx
[
idx
]
=
-
(
V
.
complex
[
fr
]
-
V
.
complex
[
to
])
*
Ymatrix
[
fr
][
to
]
Ir
=
n
umpy
.
real
(
Irx
)
Ix
=
n
umpy
.
imag
(
Irx
)
Irx
[
idx
]
=
-
(
V
[
fr
]
-
V
[
to
])
*
Ymatrix
[
fr
][
to
]
Ir
=
n
p
.
real
(
Irx
)
Ix
=
n
p
.
imag
(
Irx
)
I
=
Real_to_all
(
Ir
,
Ix
)
Iinj_r
=
n
umpy
.
zeros
(
node
.
num
)
Iinj_x
=
n
umpy
.
zeros
(
node
.
num
)
I
=
Ir
+
1j
*
Ix
Iinj_r
=
n
p
.
zeros
(
node
.
num
)
Iinj_x
=
n
p
.
zeros
(
node
.
num
)
for
k
in
range
(
1
,
node
.
num
+
1
):
to
=
n
umpy
.
where
(
branch
.
end
==
k
)
fr
=
n
umpy
.
where
(
branch
.
start
==
k
)
Iinj_r
[
k
-
1
]
=
n
umpy
.
sum
(
I
.
real
[
to
[
0
]])
-
n
umpy
.
sum
(
I
.
real
[
fr
[
0
]])
Iinj_x
[
k
-
1
]
=
n
umpy
.
sum
(
I
.
imag
[
to
[
0
]])
-
n
umpy
.
sum
(
I
.
imag
[
fr
[
0
]])
to
=
n
p
.
where
(
branch
.
end
==
k
)
fr
=
n
p
.
where
(
branch
.
start
==
k
)
Iinj_r
[
k
-
1
]
=
n
p
.
sum
(
I
[
to
[
0
]]
.
real
)
-
n
p
.
sum
(
I
[
fr
[
0
]]
.
real
)
Iinj_x
[
k
-
1
]
=
n
p
.
sum
(
I
[
to
[
0
]]
.
imag
)
-
n
p
.
sum
(
I
[
fr
[
0
]]
.
imag
)
Iinj
=
Real_to_all
(
Iinj_r
,
Iinj_x
)
Sinj_rx
=
numpy
.
multiply
(
V
.
complex
,
numpy
.
conj
(
Iinj
.
complex
))
Sinj
=
Real_to_all
(
numpy
.
real
(
Sinj_rx
),
numpy
.
imag
(
Sinj_rx
))
S1_rx
=
numpy
.
multiply
(
V
.
complex
[
branch
.
start
-
1
],
numpy
.
conj
(
I
.
complex
))
S2_rx
=
-
numpy
.
multiply
(
V
.
complex
[
branch
.
end
-
1
],
numpy
.
conj
(
I
.
complex
))
S1
=
Real_to_all
(
numpy
.
real
(
S1_rx
),
numpy
.
imag
(
S1_rx
))
S2
=
Real_to_all
(
numpy
.
real
(
S2_rx
),
numpy
.
imag
(
S2_rx
))
Iinj
=
Iinj_r
+
1j
*
Iinj_x
Sinj_rx
=
np
.
multiply
(
V
,
np
.
conj
(
Iinj
))
Sinj
=
np
.
real
(
Sinj_rx
)
+
1j
*
np
.
imag
(
Sinj_rx
)
S1
=
np
.
multiply
(
V
[
branchs
.
start
-
1
],
np
.
conj
(
I
))
S2
=
-
np
.
multiply
(
V
[
branchs
.
end
-
1
],
np
.
conj
(
I
))
return
V
,
I
,
Iinj
,
S1
,
S2
,
Sinj
,
num_iter
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment