Skip to content

Commit

Permalink
v0.6.2. Fix bug in API to set bus angle in deg. Update class STEPS to…
Browse files Browse the repository at this point in the history
… add parallel_thread_number and its set/get function. APIs are added to set and get toolkit's parallel_thread_number. Remove environment variable dependency in dynamic simulator. Upgrade stepspy to 0.7.1 to include the APIs to set/get parallel thread number.
  • Loading branch information
changgang committed Sep 18, 2019
1 parent d19e911 commit 7d9be77
Show file tree
Hide file tree
Showing 17 changed files with 3,030 additions and 22 deletions.
13 changes: 7 additions & 6 deletions code/STEPS.depend
Original file line number Diff line number Diff line change
Expand Up @@ -5424,7 +5424,7 @@
"header/basic/constants.h"
<mutex>

1567397368 c:\users\dr.li\steps\code\header\steps.h
1568800454 c:\users\dr.li\steps\code\header\steps.h
"header/power_system_database.h"
"header/toolkit/powerflow_solver/powerflow_solver.h"
"header/toolkit/dynamic_simulator/dynamic_simulator.h"
Expand Down Expand Up @@ -6032,7 +6032,7 @@
"header/data_imexporter/psse_imexporter.h"
"header/data_imexporter/bpa_imexporter.h"

1567397368 c:\users\dr.li\steps\code\header\apis\steps_api.h
1568800698 c:\users\dr.li\steps\code\header\apis\steps_api.h
<cstdlib>
"header/basic/constants.h"

Expand Down Expand Up @@ -6129,7 +6129,7 @@
"header/data_imexporter/psse_imexporter.h"
"header/data_imexporter/bpa_imexporter.h"

1567397369 source:c:\users\dr.li\steps\code\source\apis\steps_api_set_get_bus_parameters.cpp
1568802159 source:c:\users\dr.li\steps\code\source\apis\steps_api_set_get_bus_parameters.cpp
"header/apis/steps_api.h"
"header/apis/steps_api_common.h"
"header/basic/utility.h"
Expand Down Expand Up @@ -6252,7 +6252,7 @@
"header/data_imexporter/psse_imexporter.h"
"header/data_imexporter/bpa_imexporter.h"

1567397369 source:c:\users\dr.li\steps\code\source\apis\steps_api_utilities.cpp
1568800788 source:c:\users\dr.li\steps\code\source\apis\steps_api_utilities.cpp
"header/apis/steps_api.h"
"header/apis/steps_api_common.h"
"header/basic/utility.h"
Expand Down Expand Up @@ -9552,9 +9552,10 @@
"header/steps_namespace.h"
"header/basic/utility.h"

1567397369 source:c:\users\dr.li\steps\code\source\steps.cpp
1568802858 source:c:\users\dr.li\steps\code\source\steps.cpp
"header/STEPS.h"
"header/basic/utility.h"
"header/steps_namespace.h"
<iostream>
<chrono>
<thread>
Expand Down Expand Up @@ -10094,7 +10095,7 @@
<cstdio>
<iostream>

1568701400 source:c:\users\dr.li\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator.cpp
1568802295 source:c:\users\dr.li\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator.cpp
"header/toolkit/dynamic_simulator/dynamic_simulator.h"
"header/basic/utility.h"
"header/steps_namespace.h"
Expand Down
5 changes: 5 additions & 0 deletions code/header/STEPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class STEPS
void set_toolkit_name(string name);
string get_toolkit_name() const;

void set_thread_number(size_t n);
size_t get_thread_number() const;

char get_next_alphabeta();
void open_log_file(string file);
void close_log_file();
Expand Down Expand Up @@ -66,5 +69,7 @@ class STEPS
ofstream log_file;
bool detailed_log_enabled;
char current_alphabeta;

size_t thread_number;
};
#endif // STEPS_H
4 changes: 4 additions & 0 deletions code/header/apis/steps_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ EXPORT_STEPS_DLL void api_delete_toolkit(size_t toolkit_index=INDEX_NOT_EXIST);
EXPORT_STEPS_DLL void api_initialize_toolkit(size_t toolkit_index=INDEX_NOT_EXIST);
EXPORT_STEPS_DLL void api_clear_toolkit(size_t toolkit_index=INDEX_NOT_EXIST);

EXPORT_STEPS_DLL void api_set_toolkit_parallel_thread_number(size_t n, size_t toolkit_index=INDEX_NOT_EXIST);
EXPORT_STEPS_DLL size_t api_get_toolkit_parallel_thread_number(size_t toolkit_index=INDEX_NOT_EXIST);


EXPORT_STEPS_DLL double api_get_toolkit_float_data(char* parameter_name, size_t toolkit_index=INDEX_NOT_EXIST);
EXPORT_STEPS_DLL void api_set_toolkit_float_data(char* parameter_name, double value, size_t toolkit_index=INDEX_NOT_EXIST);
EXPORT_STEPS_DLL const char* api_get_toolkit_string_data(char* parameter_name, size_t toolkit_index=INDEX_NOT_EXIST);
Expand Down
22 changes: 17 additions & 5 deletions code/source/STEPS.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "header/STEPS.h"
#include "header/basic/utility.h"
#include "header/steps_namespace.h"
#include <iostream>
#include <chrono>
#include <thread>
Expand Down Expand Up @@ -28,8 +29,9 @@ STEPS::STEPS(string name, string log_file)

network_matrix.set_toolkit(*this);

show_information_with_leading_time_stamp("STEPS simulation toolkit "+toolkit_name+" is created @ "+num2str(size_t(this)));
set_thread_number(1);

show_information_with_leading_time_stamp("STEPS simulation toolkit "+toolkit_name+" is created @ "+num2str(size_t(this)));

clear();
}
Expand Down Expand Up @@ -57,6 +59,16 @@ string STEPS::get_toolkit_name() const
return toolkit_name;
}

void STEPS::set_thread_number(size_t n)
{
thread_number = n;
}

size_t STEPS::get_thread_number() const
{
return thread_number;
}

void STEPS::clear()
{
current_alphabeta = 'Z';
Expand Down Expand Up @@ -175,17 +187,17 @@ void STEPS::show_information_with_leading_time_stamp(string info)
string sys_time = get_system_time_stamp_string();
if(log_file.is_open())
{
log_file<<"["<<get_toolkit_name()<<"]"<<sys_time<<" "<<splitted_info[0]<<"\n";
log_file<<"["<<get_toolkit_name()<<"]"<<sys_time<<" "<<splitted_info[0]<<endl;

for(size_t i=1; i!=info_size; ++i)
log_file<<"["<<get_toolkit_name()<<"]"<<sys_time<<" + "<<splitted_info[i]<<"\n";
log_file<<"["<<get_toolkit_name()<<"]"<<sys_time<<" + "<<splitted_info[i]<<endl;
}
else
{
cout<<"["<<get_toolkit_name()<<"]"<<sys_time<<" "<<splitted_info[0]<<"\n";
cout<<"["<<get_toolkit_name()<<"]"<<sys_time<<" "<<splitted_info[0]<<endl;

for(size_t i=1; i!=info_size; ++i)
cout<<"["<<get_toolkit_name()<<"]"<<sys_time<<" + "<<splitted_info[i]<<"\n";
cout<<"["<<get_toolkit_name()<<"]"<<sys_time<<" + "<<splitted_info[i]<<endl;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/source/apis/steps_api_set_get_bus_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void api_set_bus_float_data(size_t bus, char* parameter_name, double value, size
return busptr->set_angle_in_rad(value);

if(PARAMETER_NAME=="ANGLE_DEG" or PARAMETER_NAME=="ANGLE IN DEG")
return busptr->set_angle_in_rad(value);
return busptr->set_angle_in_deg(value);

if(PARAMETER_NAME=="VMAX_PU" or PARAMETER_NAME=="NORMAL VMAX IN PU")
return busptr->set_normal_voltage_upper_limit_in_pu(value);
Expand Down
13 changes: 13 additions & 0 deletions code/source/apis/steps_api_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ void api_clear_toolkit(size_t toolkit_index)
toolkit.get_power_system_database().clear();
toolkit.get_dynamic_simulator().clear();
}

void api_set_toolkit_parallel_thread_number(size_t n, size_t toolkit_index)
{
STEPS& toolkit = get_toolkit(toolkit_index);
toolkit.set_thread_number(n);
}

size_t api_get_toolkit_parallel_thread_number(size_t toolkit_index)
{
STEPS& toolkit = get_toolkit(toolkit_index);
return toolkit.get_thread_number();
}

double api_get_toolkit_float_data(char* parameter_name, size_t toolkit_index)
{
STEPS& toolkit = get_toolkit(toolkit_index);
Expand Down
12 changes: 2 additions & 10 deletions code/source/toolkit/dynamic_simulator/dynamic_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,18 +1661,10 @@ complex<double> DYNAMICS_SIMULATOR::get_bus_complex_voltage_in_pu_with_internal_
}
void DYNAMICS_SIMULATOR::set_openmp_number_of_threads()
{
int omp_num_thread = 1;
char* omp_num_threads_env = getenv("STEPS_NUM_THREADS");
if(omp_num_threads_env != NULL)
sscanf(omp_num_threads_env, "%d", &omp_num_thread);

if(omp_num_thread<0)
omp_num_thread = -omp_num_thread;

STEPS& toolkit = get_toolkit(__PRETTY_FUNCTION__);
size_t omp_num_thread = toolkit.get_thread_number();
if(omp_num_thread==0)
{
STEPS& toolkit = get_toolkit(__PRETTY_FUNCTION__);

size_t nbus = toolkit.get_power_system_database().get_bus_count();
if(nbus<=1000)
omp_set_num_threads(1);
Expand Down
21 changes: 21 additions & 0 deletions python/stepspy0.7.1/LICENSE
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.
72 changes: 72 additions & 0 deletions python/stepspy0.7.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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.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

## 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
Loading

0 comments on commit 7d9be77

Please sign in to comment.