-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.6.3. Update stepspy to include both parallel and serial library. I…
…t is found that the serial version without openmp is 2 times faster than the parallel version if parallel_thread_number is set as 1. Therefore, both parallel and serial library files should be created.
- Loading branch information
Showing
12 changed files
with
3,013 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Changgang Li | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# stepspy | ||
|
||
> stepspy | ||
stepspy is a Python module of Simulation Toolkit for Electrical Power Systems (STEPS). | ||
|
||
## Table of Contents | ||
|
||
- [Background](#background) | ||
- [Release Note](#release-note) | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Examples](#examples) | ||
- [Maintainers](#maintainers) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Background | ||
|
||
stepspy is a Python module of Simulation Toolkit for Electrical Power Systems (STEPS). It provides wrapper of APIs of STEPS in a dynamic library. | ||
|
||
STEPS is a simulation toolkit for powerflow and dynamic simulation of large-scale power systems. It provides detailed models of bus, line, transformer, HVDC, generator, wind turbine generator, load, and fixed shunt. For more information about STEPS, see (https://github.com/changgang/steps). | ||
|
||
## Realse Note | ||
|
||
- 0.8.1. Sep. 18, 2019. Update and README. | ||
- 0.8.0. Sep. 18, 2019. Update to enable both parallel and serial library. Since STEPS 0.6.3. | ||
- 0.7.1. Sep. 18, 2019. Fix API to set and get parallel thread number. | ||
- 0.7.0. Sep. 18, 2019. Add new API to set parallel thread number. Update README. | ||
- 0.6.1. Aug. 27, 2019 | ||
- 0.6.0. Aug. 25, 2019 | ||
|
||
|
||
## Install | ||
|
||
### Install stepspy | ||
|
||
To install stepspy, you can run the following codes on your computer or server: | ||
|
||
```python | ||
python -m pip install stepspy | ||
``` | ||
|
||
If you want to manually install stepspy, follow the instructions: | ||
|
||
1. Go to https://github.com/changgang/steps to download or fork the latest version of STEPS. | ||
2. Go to python/ folder of STEPS, and copy the latest version of stepspy/ to PYTHONPATH/Lib/site-packages/. | ||
|
||
### Install dynamic library | ||
|
||
After install the stepspy, you still need to compile and install the dynamic library of STEPS. | ||
|
||
1. Go to [steps](https://github.com/changgang/steps) to download or fork the latest version of STEPS. The latest version is usually the [work] branch. | ||
2. Compile STEPS into dynamic library following instructions of STEPS. | ||
3, Move the dynamic library of STEPS to stepspy/libsteps/ in the PYTHONPATH/Lib/site-packages/. | ||
4, If the VC runtime is missing, download and install Microsoft Visual C++ 2017 Redistributable of 32 or 64 bit version. | ||
5, If VC runtime or Mingw Runtime is missing, install vcredit or copy libwinpthread-1.dll from mingw compiler/bin/ to c:/windows/system32 and c:/windows/SysWOW64 | ||
|
||
Follow README of STEPS if you want to use both serial and parallel library. | ||
|
||
## Usage | ||
|
||
## Examples | ||
|
||
|
||
## Maintainers | ||
|
||
[@changgang](https://github.com/changgang) <[email protected]> from the School of Electrical Engineering, Shandong University, China | ||
|
||
## Contributing | ||
|
||
Feel free to dive in! [Open an issue](https://github.com/changgang/steps/issues/new). | ||
|
||
## License | ||
|
||
[MIT](LICENSE) @ Changgang Li |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
#coding = utf-8 | ||
''' | ||
Here is a demo of showing how to slove powerflow with stepspy. | ||
Changgang Li, 2019/08/25 | ||
''' | ||
|
||
from stepspy import STEPS # import the class 'STEPS' | ||
|
||
simulator = STEPS(is_default=True) # create a STEPS simulator instance | ||
|
||
|
||
powerflow_data_file = 'IEEE9.raw' # file name of powerflow data. Use absolute path if necessary | ||
powerflow_data_type = 'PSS/E' # powerflow data type. Currently, use 'PSS/E' only | ||
|
||
simulator.load_powerflow_data(powerflow_data_file, powerflow_data_type) # load powerflow data into the simulator | ||
|
||
data_type = 'D' # if you want to set or get doubule data, set data_type as 'F' or 'D'. | ||
data_name = 'MAX ACTIVE POWER IMBALANCE IN MW' # the data name in the powerflow solver of the simulator | ||
# the data_type and data_name should be consistent. make sure the data_type is correct. | ||
# If the data is double, use 'F' or 'D'. If the data is integer, use 'I'. If the data is boolean, use 'B'. If the data is string, use 'S' | ||
''' | ||
(1) when data_type is 'D' or 'F' you can set/get the following data | ||
'MAX ACTIVE POWER IMBALANCE IN MW': maximum allowed active power mismatch at each bus, in MW. This is the powerflow convergence threshold of P equations. | ||
'MAX REACTIVE POWER IMBALANCE IN MVAR': maximum allowed reactive power mismatch at each bus, in MVar. This is the powerflow convergence threshold of Q equations. | ||
'ITERATION ACCELERATOR': acceleration factor for iteration. by default it is 1.0. if >1.0, then the powerflow solver is accelerated. if <1.0, the powerflow solver is decellerated. | ||
(2) when data_type is 'I', you can set/get the following data | ||
'MAX ITERATION': maximum iteration count allowed for solving powerflow. If set as 1, you can get the solution step by step. | ||
(3)when data_type is 'B', you can set/get the following data | ||
'FLAT START LOGIC': if true, powerflow will be solved with unity voltage profile (1.0pu, 0.0deg), if false, poewrflow will be solved from the current voltage profile. | ||
''' | ||
|
||
# here goes get and set maximum active power imbalance in MW | ||
data_type = 'D' | ||
data_name = 'MAX ACTIVE POWER IMBALANCE IN MW' | ||
P_error_MW = simulator.get_powerflow_solver_parameter(data_type, data_name) | ||
|
||
value = 0.001 | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
# here goes get and set maximum reactive power imbalance in MVAR | ||
data_type = 'D' | ||
data_name = 'MAX REACTIVE POWER IMBALANCE IN MVAR' | ||
Q_error_MVar = simulator.get_powerflow_solver_parameter(data_type, data_name) | ||
|
||
value = 0.001 | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
# here goes get and set maximum iteration | ||
data_type = 'I' | ||
data_name = 'MAX ITERATION' | ||
Iter_max = simulator.get_powerflow_solver_parameter(data_type, data_name) | ||
|
||
value = 50 | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
# here goes get and set flat start logic | ||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
flat_flag = simulator.get_powerflow_solver_parameter(data_type, data_name) | ||
|
||
value = False | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
# now assuming that maximum active and reactive power imbalance are already set. | ||
# show how to solve powerflow | ||
|
||
# solve powerflow with flat start logic disabled | ||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
value = False | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
simulator.solve_powerflow('NR') # use 'NR' for Newton-Raphson solution, use 'PQ' for PQ decoupled solution | ||
|
||
# solve powerflow with flat start logic enabled | ||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
value = True | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
simulator.solve_powerflow('PQ') | ||
|
||
# if you want to solve powerflow step by step to get the solution process, | ||
# you can set MAX ITERATION as 1, and Flat start logic as false | ||
data_type = 'I' | ||
data_name = 'MAX ITERATION' | ||
value = 1 | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
value = True | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
simulator.solve_powerflow('NR') # first slove it with flat start enable | ||
|
||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
value = False | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) # from now on, disable flat start | ||
|
||
while not simulator.is_powerflow_converged(): # use is_powerflow_converged() to check if powerflow is converged | ||
simulator.solve_powerflow('NR') | ||
simulator.save_jacobian_matrix('jacobian.txt') # if you are solving with NR method, you can get jacobian matrix of each iteration in the file | ||
|
||
# once powerflow is converged, you can export powerflow result to file | ||
powerflow_result_file = 'pf_result.txt' | ||
simulator.save_powerflow_result(powerflow_result_file) # you can check the file's contents | ||
|
||
# you can get power loss of a solved powerflow case | ||
ploss_MW = simulator.get_powerflow_loss() # in MW | ||
print('Loss is:', ploss_MW) | ||
|
||
# if you want to get the voltage of each bus, you can try the following codes | ||
buses = simulator.get_all_buses() | ||
for bus in buses: | ||
bus_name = simulator.get_bus_data(bus, 'S', 'Name') | ||
voltage = simulator.get_bus_data(bus, 'D', 'Voltage in PU') | ||
angle = simulator.get_bus_data(bus, 'D', 'Angle in deg') | ||
print(bus, bus_name, voltage, angle) | ||
|
||
# if you want to get the generation of each generator, you can try the following codes | ||
generators = simulator.get_generators_at_bus(0) # 0 indicate all generators will be returned | ||
for generator in generators: | ||
P = simulator.get_generator_data(generator, 'D', 'PGEN_MW') | ||
Q = simulator.get_generator_data(generator, 'D', 'QGEN_MVAR') | ||
print(generator, P, Q) | ||
|
||
# if you want to get the load of each load, you can try the following codes | ||
loads = simulator.get_loads_at_bus(0) # 0 indicate all loads will be returned | ||
for load in loads: | ||
P = simulator.get_load_data(load, 'D', 'P_MW') | ||
Q = simulator.get_load_data(load, 'D', 'Q_MVAR') | ||
print(load, P, Q) | ||
|
||
# if you want to get the power of each line, you can try the following codes | ||
lines = simulator.get_lines_at_bus(0) # 0 indicate all lines will be returned | ||
for line in lines: | ||
bus_send = simulator.get_line_data(line, 'I', 'BUS_SEND') # get the bus number of sending side | ||
bus_recv = simulator.get_line_data(line, 'I', 'BUS_RECV') # get the bus number of receiving side | ||
Psend = simulator.get_line_data(line, 'D', 'PSEND_MW') # active power at sending side | ||
Qsend = simulator.get_line_data(line, 'D', 'QSEND_MVAR') # reactive power at sending side | ||
Precv = simulator.get_line_data(line, 'D', 'PRECV_MW') # active power at receiving side | ||
Qrecv = simulator.get_line_data(line, 'D', 'QRECV_MVAR') # reactive power at receiving side | ||
print(line, bus_send, (Psend, Qsend), bus_recv, (Precv, Qrecv)) | ||
|
||
# if you want to get the power of each transformer, you can try the following codes | ||
transformers = simulator.get_transformers_at_bus(0) # 0 indicate all transformers will be returned | ||
for transformer in transformers: | ||
bus_pri = simulator.get_transformer_data(transformer, 'I', 'Primary', 'BUS') # get the bus number of primary side | ||
bus_sec = simulator.get_transformer_data(transformer, 'I', 'Secondary', 'BUS') # get the bus number of secondary side | ||
|
||
P_pri = simulator.get_transformer_data(transformer, 'D', 'Primary', 'P_MW') # active power at primary side | ||
Q_pri = simulator.get_transformer_data(transformer, 'D', 'Primary', 'Q_MVAR') # reactive power at primary side | ||
P_sec = simulator.get_transformer_data(transformer, 'D', 'Secondary', 'P_MW') # active power at secondary side | ||
Q_sec = simulator.get_transformer_data(transformer, 'D', 'Secondary', 'Q_MVAR') # reactive power at secondary side | ||
print(transformer, bus_pri, (P_pri, Q_pri), bus_sec, (P_sec, Q_sec)) | ||
|
||
|
||
|
||
# if you want to change generation of each generaor, trye the following codes | ||
generator = (2,'1') # generator bus, and generator ID, check generator line of raw file | ||
simulator.set_generator_data(generator, 'D', 'PGEN_MW', 50.0) # remember, only P of generator at bus of type 2 can be changed | ||
|
||
data_type = 'I' | ||
data_name = 'MAX ITERATION' | ||
value = 10 | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
data_type = 'B' | ||
data_name = 'FLAT START LOGIC' | ||
value = True | ||
simulator.set_powerflow_solver_parameter(data_type, data_name, value) | ||
|
||
simulator.solve_powerflow('NR') | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
1. install wheel and twine, use: | ||
|
||
python -m pip install wheel twine | ||
|
||
2. change version of stepsy in setup.py | ||
|
||
3. to build stepspy module, use: | ||
|
||
python setup.py sdist bdist_wheel | ||
|
||
4. to upload stepspy module to pypi, use: | ||
|
||
python -m twine upload dist/* | ||
|
||
5. to check whether the built module is OK or not, use: | ||
|
||
python -m twine check dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import setuptools | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setuptools.setup( | ||
name="stepspy", | ||
version="0.8.1", | ||
author="Changgang Li", | ||
author_email="[email protected]", | ||
description="Python module of Simulation Toolkit for Electrical Power Systems", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/changgang/steps", | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: C++", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .stepspy import STEPS | ||
name = 'stepspy' | ||
__all__ = ['STEPS'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = ['pylibsteps'] |
1 change: 1 addition & 0 deletions
1
python/stepspy0.8.1/stepspy/libsteps/dll_or_so_file_should_be_put_here
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.