Skip to content
GitLab
Menu
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
5eda69e7
Commit
5eda69e7
authored
Mar 27, 2019
by
martin.moraga
Browse files
remove class results from nv_powerflow_cim.py
parent
440596b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
acs/state_estimation/nv_powerflow_cim.py
View file @
5eda69e7
...
...
@@ -2,171 +2,8 @@ import sys
import
math
import
numpy
as
np
from
network
import
BusType
import
results
sys
.
path
.
append
(
"../../../dataprocessing"
)
from
villas.dataprocessing.readtools
import
read_timeseries_dpsim
class
PowerflowNode
():
def
__init__
(
self
,
topo_node
):
self
.
topology_node
=
topo_node
self
.
voltage
=
complex
(
0
,
0
)
self
.
current
=
complex
(
0
,
0
)
self
.
power
=
complex
(
0
,
0
)
class
PowerflowBranch
():
def
__init__
(
self
,
topo_branch
):
self
.
topology_branch
=
topo_branch
self
.
current
=
complex
(
0
,
0
)
self
.
power
=
complex
(
0
,
0
)
#complex power flow at branch, measured at initial node
self
.
power2
=
complex
(
0
,
0
)
#complex power flow at branch, measured at final node
class
PowerflowResults
():
def
__init__
(
self
,
system
):
self
.
nodes
=
[]
self
.
branches
=
[]
self
.
Ymatrix
=
system
.
Ymatrix
self
.
Adjacencies
=
system
.
Adjacencies
for
node
in
system
.
nodes
:
self
.
nodes
.
append
(
PowerflowNode
(
topo_node
=
node
))
for
branch
in
system
.
branches
:
self
.
branches
.
append
(
PowerflowBranch
(
topo_branch
=
branch
))
def
read_data_dpsim
(
self
,
file_name
):
"""
read the voltages from a dpsim input file
"""
loadflow_results
=
read_timeseries_dpsim
(
file_name
,
print_status
=
False
)
for
node
in
self
.
nodes
:
node
.
V
=
loadflow_results
[
node
.
topology_node
.
uuid
].
values
[
0
]
def
load_voltages
(
self
,
V
):
"""
load the voltages of V-array (result of powerflow_cim.solve)
"""
for
index
in
range
(
len
(
V
)):
for
elem
in
self
.
nodes
:
if
elem
.
topology_node
.
index
==
index
:
elem
.
voltage
=
V
[
index
]
def
calculateI
(
self
):
"""
To calculate the branch currents
"""
for
branch
in
self
.
branches
:
fr
=
branch
.
topology_branch
.
start_node
.
index
to
=
branch
.
topology_branch
.
end_node
.
index
branch
.
current
=
-
(
self
.
nodes
[
fr
].
voltage
-
self
.
nodes
[
to
].
voltage
)
*
self
.
Ymatrix
[
fr
][
to
]
def
calculateIinj
(
self
):
"""
calculate current injections at a node
"""
for
node
in
self
.
nodes
:
to
=
complex
(
0
,
0
)
#sum of the currents flowing to the node
fr
=
complex
(
0
,
0
)
#sum of the currents flowing from the node
for
branch
in
self
.
branches
:
if
node
.
topology_node
.
index
==
branch
.
topology_branch
.
start_node
.
index
:
fr
=
fr
+
branch
.
current
if
node
.
topology_node
.
index
==
branch
.
topology_branch
.
end_node
.
index
:
to
=
to
+
branch
.
current
node
.
current
=
to
-
fr
def
calculateSinj
(
self
):
"""
calculate power injection at a node
"""
for
node
in
self
.
nodes
:
node
.
power
=
node
.
voltage
*
np
.
conj
(
node
.
current
)
def
calculateS1
(
self
):
"""
calculate complex power flow at branch, measured at initial node
"""
for
branch
in
self
.
branches
:
branch_index
=
branch
.
topology_branch
.
start_node
.
index
for
node
in
self
.
nodes
:
if
branch_index
==
node
.
topology_node
.
index
:
branch
.
power
=
node
.
voltage
*
(
np
.
conj
(
branch
.
current
))
def
calculateS2
(
self
):
"""
calculate complex ower flow at branch, measured at final node
"""
for
branch
in
self
.
branches
:
branch_index
=
branch
.
topology_branch
.
end_node
.
index
for
node
in
self
.
nodes
:
if
branch_index
==
node
.
topology_node
.
index
:
branch
.
power2
=
-
node
.
voltage
*
(
np
.
conj
(
branch
.
current
))
def
get_node
(
self
,
index
):
"""
return the PowerflowNode with PowerflowNode.topology_node.index == index
"""
for
node
in
self
.
nodes
:
if
index
==
node
.
topology_node
.
index
:
return
node
def
get_voltages
(
self
):
"""
get complex Power Injection at nodes
for a test purpose
"""
voltages
=
np
.
zeros
(
len
(
self
.
nodes
),
dtype
=
np
.
complex_
)
for
node
in
self
.
nodes
:
voltages
[
node
.
topology_node
.
index
]
=
node
.
voltage
return
voltages
def
get_Iinj
(
self
):
"""
get node currents
for a test purpose
"""
Iinj
=
np
.
zeros
(
len
(
self
.
nodes
),
dtype
=
np
.
complex_
)
for
node
in
self
.
nodes
:
Iinj
[
node
.
topology_node
.
index
]
=
node
.
current
return
Iinj
def
get_Sinj
(
self
):
"""
get node power
for a test purpose
"""
Sinj
=
np
.
zeros
(
len
(
self
.
nodes
),
dtype
=
np
.
complex_
)
for
node
in
self
.
nodes
:
Sinj
[
node
.
topology_node
.
index
]
=
node
.
power
return
Sinj
def
getI
(
self
):
"""
get branch currents
for a test purpose
"""
I
=
np
.
array
([])
for
branch
in
self
.
branches
:
I
=
np
.
append
(
I
,
branch
.
current
)
return
I
def
get_S1
(
self
):
"""
get complex Power flow at branch, measured at initial node
for a test purpose
"""
S1
=
np
.
array
([])
for
branch
in
self
.
branches
:
S1
=
np
.
append
(
S1
,
branch
.
power
)
return
S1
def
get_S2
(
self
):
"""
get complex Power flow at branch, measured at final node
for a test purpose
"""
S2
=
np
.
array
([])
for
branch
in
self
.
branches
:
S2
=
np
.
append
(
S2
,
branch
.
power2
)
return
S2
def
solve
(
system
):
"""It performs Power Flow by using rectangular node voltage state variables."""
...
...
@@ -223,12 +60,12 @@ def solve(system):
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
inner
(
H
[
m
+
1
],
State
)
elif
type
is
BusType
.
PQ
:
z
[
m
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
real
+
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
imag
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
z
[
m
+
1
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
imag
-
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
real
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
z
[
m
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
np
.
real
(
V
[
i
])
+
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
np
.
imag
(
V
[
i
])
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
z
[
m
+
1
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
np
.
imag
(
V
[
i
])
-
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
np
.
real
(
V
[
i
])
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
inner
(
H
[
m
+
1
],
State
)
elif
type
is
BusType
.
PV
:
z
[
m
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
real
+
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
V
[
i
]
.
imag
)
/
(
np
.
abs
(
V
[
i
])
**
2
)
z
[
m
]
=
(
np
.
real
(
system
.
nodes
[
i
].
power
)
*
np
.
real
(
V
[
i
])
+
np
.
imag
(
system
.
nodes
[
i
].
power
)
*
np
.
imag
(
V
[
i
])
)(
np
.
abs
(
V
[
i
])
**
2
)
h
[
m
]
=
np
.
inner
(
H
[
m
],
State
)
h
[
m
+
1
]
=
np
.
abs
(
V
[
i
])
H
[
m
+
1
][
i
]
=
np
.
cos
(
np
.
angle
(
V
[
i
]))
...
...
@@ -244,13 +81,13 @@ def solve(system):
num_iter
=
num_iter
+
1
results
=
Powerflow
Results
(
system
)
results
.
load_voltages
(
V
)
results
.
calculateI
()
results
.
calculateIinj
()
results
.
calculateSinj
()
results
.
calculateI
()
results
.
calculateS1
()
results
.
calculateS2
()
powerflow_
results
=
results
.
Results
(
system
)
powerflow_
results
.
load_voltages
(
V
)
powerflow_
results
.
calculateI
()
powerflow_
results
.
calculateIinj
()
powerflow_
results
.
calculateSinj
()
powerflow_
results
.
calculateI
()
powerflow_
results
.
calculateS1
()
powerflow_
results
.
calculateS2
()
return
results
,
num_iter
\ No newline at end of file
return
powerflow_results
,
num_iter
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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