Skip to content

Commit

Permalink
add transformer control tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lthurner committed Sep 26, 2019
1 parent 3124a51 commit 89d461c
Show file tree
Hide file tree
Showing 2 changed files with 295 additions and 0 deletions.
155 changes: 155 additions & 0 deletions pandapower/test/control/test_continous_tap_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2016-2019 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.

import pandapower as pp
import pytest
import networks as nw
import pplog
import numpy as np

logger = pplog.getLogger(__name__)
from pandapower.control.run_control import run_control
from pandapower.control import ContinuousTapControl

def test_continuous_tap_control_lv():
# --- load system and run power flow
net = nw.simple_four_bus_system()
pp.set_user_pf_options(net, init='dc', calculate_voltage_angles=True)
# --- initial tap data
net.trafo.tap_side = 'lv'
net.trafo.tap_neutral = 0
net.trafo.tap_min = -2
net.trafo.tap_max = 2
net.trafo.tap_step_percent = 1.25
net.trafo.tap_pos = 0
# --- run loadflow
pp.runpp(net)

# todo: rewrite to not compare to hardcoded values
tid = 0
ContinuousTapControl(net, tid=tid, u_set=0.99, side='lv')
# DiscreteTapControl(net, tid=0, side='lv', u_lower=0.95, u_upper=0.99)

logger.info("case1: low voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.values, net.trafo.tap_pos.values))

assert np.isclose(net.res_trafo.vm_lv_pu.at[tid], 0.99, atol=1e-3)
assert np.isclose(net.trafo.tap_pos.values, -.528643)
# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 1.03
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

assert np.isclose(net.trafo.tap_pos.values, -2)
# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 0.98
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))
assert np.isclose(net.res_trafo.vm_lv_pu.at[tid], 0.99, atol=1e-3)
assert np.isclose(net.trafo.tap_pos.values, 1.077656)


def test_continuous_tap_control_hv():
# --- load system and run power flow
net = nw.simple_four_bus_system()
# --- initial tap data
net.trafo.tap_side = 'hv'
net.trafo.tap_neutral = 0
net.trafo.tap_min = -2
net.trafo.tap_max = 2
net.trafo.tap_step_percent = 1.25
net.trafo.tap_pos = 0
# --- run loadflow
pp.runpp(net)
tid = 0
ContinuousTapControl(net, tid=tid, u_set=0.99, side='lv')
# td = control.DiscreteTapControl(net, tid=0, side='lv', u_lower=0.95, u_upper=0.99)

logger.info("case1: low voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

assert np.isclose(net.res_trafo.vm_lv_pu.at[tid], 0.99, atol=1e-3)
assert np.isclose(net.trafo.tap_pos.values, 0.528643)

# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 1.03
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))
assert np.isclose(net.trafo.tap_pos.values, 2)

# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 0.98
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))

# run control
run_control(net)
pp.runpp(net)
logger.info(
"after ContinuousTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_trafo.vm_lv_pu.at[tid], net.trafo.tap_pos.values))
assert np.isclose(net.res_trafo.vm_lv_pu.at[tid], 0.99, atol=1e-3)
assert np.isclose(net.trafo.tap_pos.values, -1.07765621)


if __name__ == '__main__':
pytest.main(['-xs', __file__])
140 changes: 140 additions & 0 deletions pandapower/test/control/test_discrete_tap_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2016-2019 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.

import pandapower as pp
from pandapower.control import DiscreteTapControl
from pandapower.control.run_control import run_control
import pytest
import networks as nw
import pplog

logger = pplog.getLogger(__name__)


def test_discrete_tap_control_lv():
# --- load system and run power flow
net = nw.simple_four_bus_system()
pp.set_user_pf_options(net, init='dc', calculate_voltage_angles=True)
# --- initial tap data
net.trafo.tap_side = 'lv'
net.trafo.tap_neutral = 0
net.trafo.tap_min = -2
net.trafo.tap_max = 2
net.trafo.tap_step_percent = 1.25
net.trafo.tap_pos = 0
# --- run loadflow
pp.runpp(net)

DiscreteTapControl(net, tid=0, side='lv', u_lower=0.95, u_upper=0.99)

logger.info("case1: low voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == -1

# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 1.03
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == -2
# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 0.949
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == 1


def test_discrete_tap_control_hv():
# --- load system and run power flow
net = nw.simple_four_bus_system()
pp.set_user_pf_options(net, init='dc', calculate_voltage_angles=True)
# --- initial tap data
net.trafo.tap_side = 'hv'
net.trafo.tap_neutral = 0
net.trafo.tap_min = -2
net.trafo.tap_max = 2
net.trafo.tap_step_percent = 1.25
net.trafo.tap_pos = 0
# --- run loadflow
pp.runpp(net)

DiscreteTapControl(net, tid=0, side='lv', u_lower=0.95, u_upper=0.99)

logger.info("case1: low voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == 1
# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 1.03
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == 2
# increase voltage from 1.0 pu to 1.03 pu
net.ext_grid.vm_pu = 0.949
# switch back tap position
net.trafo.tap_pos.at[0] = 0
pp.runpp(net)

logger.info("case2: high voltage")
logger.info("before control: trafo voltage at low voltage bus is %f, tap position is %u"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))

# run control
run_control(net)
logger.info(
"after DiscreteTapControl: trafo voltage at low voltage bus is %f, tap position is %f"
% (net.res_bus.vm_pu[net.trafo.lv_bus].values, net.trafo.tap_pos.values))
assert net.trafo.tap_pos.values == -1


if __name__ == '__main__':
# test_discrete_tap_control_lv()
# test_discrete_tap_control_hv()
pytest.main(['-xs', __file__])

0 comments on commit 89d461c

Please sign in to comment.