Skip to content

Commit

Permalink
v0.12.7.6. Add DYNAMIC_SIMULATOR::max_network_solution_divergent_thre…
Browse files Browse the repository at this point in the history
…shold to exit solve_network() when network solution is hard to converge. Typical value is 3. If network is hard to converge, the dynamic simulation will be very solve since useless network solution will be conducted. With the new added threshold, program can exit the network solution to speed up simulation. APIs also updated. stepspy is updated to v0.11.5 to include api of set/get dynamic model database capacity.
  • Loading branch information
changgang committed Jan 20, 2020
1 parent 49e558c commit baa7504
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 11 deletions.
10 changes: 5 additions & 5 deletions code/STEPS.depend
Original file line number Diff line number Diff line change
Expand Up @@ -11898,7 +11898,7 @@
"header/basic/sparse_matrix_define.h"
<ctime>

1579492826 d:\steps\code\header\toolkit\dynamic_simulator\dynamic_simulator.h
1579496972 d:\steps\code\header\toolkit\dynamic_simulator\dynamic_simulator.h
"header/basic/base.h"
"header/basic/power_mismatch_struct.h"
"header/meter/meter.h"
Expand Down Expand Up @@ -12658,7 +12658,7 @@
"header/power_system_database.h"
"header/STEPS.h"

1576762156 d:\steps\code\header\toolkit\dynamic_simulator\dynamic_simulator_test.h
1579497412 d:\steps\code\header\toolkit\dynamic_simulator\dynamic_simulator_test.h
<istream>
<cstdlib>
<cstring>
Expand Down Expand Up @@ -13780,7 +13780,7 @@
"header/data_imexporter/bpa_imexporter.h"
"header/data_imexporter/steps_imexporter.h"

1579254637 source:d:\steps\code\source\apis\steps_api_dynamic_simulation.cpp
1579497296 source:d:\steps\code\source\apis\steps_api_dynamic_simulation.cpp
"header/apis/steps_api.h"
"header/basic/utility.h"
"header/toolkit/cct_searcher/cct_searcher.h"
Expand Down Expand Up @@ -17067,7 +17067,7 @@
"header/steps_namespace.h"
"header/basic/utility.h"

1579494279 source:d:\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator_test.cpp
1579497465 source:d:\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator_test.cpp
"header/basic/test_macro.h"
"header/toolkit/dynamic_simulator/dynamic_simulator_test.h"
"header/basic/utility.h"
Expand Down Expand Up @@ -17118,7 +17118,7 @@
"header/steps_namespace.h"
<cstdio>

1579494254 source:d:\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator.cpp
1579497367 source:d:\steps\code\source\toolkit\dynamic_simulator\dynamic_simulator.cpp
"header/toolkit/dynamic_simulator/dynamic_simulator.h"
"header/basic/constants.h"
"header/basic/utility.h"
Expand Down
4 changes: 3 additions & 1 deletion code/header/toolkit/dynamic_simulator/dynamic_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DYNAMICS_SIMULATOR: public BASE
void set_min_DAE_iteration(unsigned int iteration);
void set_max_network_iteration(unsigned int iteration);
void set_max_update_iteration(unsigned int iteration);
void set_max_network_solution_divergent_threshold(unsigned int div_th);
void set_allowed_max_power_imbalance_in_MVA(double tol);
void set_iteration_accelerator(double alpha);
void set_non_divergent_solution_logic(bool logic);
Expand All @@ -48,6 +49,7 @@ class DYNAMICS_SIMULATOR: public BASE
unsigned int get_min_DAE_iteration() const;
unsigned int get_max_network_iteration() const;
unsigned int get_max_update_iteration() const;
unsigned int get_max_network_solution_divergent_threshold() const;
double get_allowed_max_power_imbalance_in_MVA() const;
double get_iteration_accelerator() const;
bool get_non_divergent_solution_logic() const;
Expand Down Expand Up @@ -237,7 +239,7 @@ class DYNAMICS_SIMULATOR: public BASE
double time_elapse_in_a_step;
double P_threshold_in_MW, Q_threshold_in_MVar;
unsigned int network_iteration_count, DAE_iteration_count;
unsigned int max_network_iteration, max_DAE_iteration, max_update_iteration, min_DAE_iteration;
unsigned int max_network_iteration, max_DAE_iteration, max_update_iteration, min_DAE_iteration, max_network_solution_divergent_threshold;
unsigned int current_max_network_iteration;
double alpha;
bool non_divergent_solution_enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DYNAMICS_SIMULATOR_TEST : public Test::Suite
void test_set_get_min_DAE_iteration();
void test_set_get_max_network_iteration();
void test_set_get_max_update_iteration();
void test_set_get_max_network_solution_divergent_threshold();
void test_set_get_allowed_max_power_imbalance_in_MVA();
void test_set_get_iteration_accelerator();
void test_set_get_rotor_angle_stability_surveillance_flag();
Expand Down
7 changes: 7 additions & 0 deletions code/source/apis/steps_api_dynamic_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ unsigned int api_get_dynamic_simulator_integer_parameter(char* parameter_name, u
return ds.get_max_network_iteration();
if(PARAMETER_NAME=="MAX_UPDATE_ITER" or PARAMETER_NAME=="MAX UPDATE ITERATION")
return ds.get_max_update_iteration();
if(PARAMETER_NAME=="MAX_NET_DIVERGENT_THRESHOLD" or PARAMETER_NAME=="MAX NETWORK DIVERGENT THRESHOLD")
return ds.get_max_network_solution_divergent_threshold();

char buffer[STEPS_MAX_TEMP_CHAR_BUFFER_SIZE];
snprintf(buffer, STEPS_MAX_TEMP_CHAR_BUFFER_SIZE, "Parameter '%s' is not supported for dynamic simulator with api %s.\n"
Expand Down Expand Up @@ -54,6 +56,11 @@ void api_set_dynamic_simulator_integer_parameter(char* parameter_name, int value
ds.set_max_update_iteration(value);
return;
}
if(PARAMETER_NAME=="MAX_NET_DIVERGENT_THRESHOLD" or PARAMETER_NAME=="MAX NETWORK DIVERGENT THRESHOLD")
{
ds.set_max_network_solution_divergent_threshold(value);
return;
}

char buffer[STEPS_MAX_TEMP_CHAR_BUFFER_SIZE];
snprintf(buffer, STEPS_MAX_TEMP_CHAR_BUFFER_SIZE, "Parameter '%s' is not supported for dynamic simulator with api %s.\n",
Expand Down
27 changes: 26 additions & 1 deletion code/source/toolkit/dynamic_simulator/dynamic_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void DYNAMICS_SIMULATOR::clear()
set_min_DAE_iteration(3);
set_max_network_iteration(50);
set_max_update_iteration(10);
set_max_network_solution_divergent_threshold(3);
set_allowed_max_power_imbalance_in_MVA(0.001);
set_iteration_accelerator(1.0);
set_non_divergent_solution_logic(false);
Expand Down Expand Up @@ -136,6 +137,12 @@ void DYNAMICS_SIMULATOR::set_max_update_iteration(unsigned int iteration)
this->max_update_iteration = iteration;
}

void DYNAMICS_SIMULATOR::set_max_network_solution_divergent_threshold(unsigned int div_th)
{
if(div_th>0)
this->max_network_solution_divergent_threshold = div_th;
}

void DYNAMICS_SIMULATOR::set_allowed_max_power_imbalance_in_MVA(double tol)
{
if(tol>0.0)
Expand Down Expand Up @@ -197,6 +204,11 @@ unsigned int DYNAMICS_SIMULATOR::get_max_update_iteration() const
return max_update_iteration;
}

unsigned int DYNAMICS_SIMULATOR::get_max_network_solution_divergent_threshold() const
{
return max_network_solution_divergent_threshold;
}

double DYNAMICS_SIMULATOR::get_allowed_max_power_imbalance_in_MVA() const
{
return P_threshold_in_MW;
Expand Down Expand Up @@ -232,6 +244,7 @@ void DYNAMICS_SIMULATOR::show_dynamic_simulator_configuration() const
<<"Minimum iteration for DAE solution: "<<get_min_DAE_iteration()<<"\n"
<<"Maximum iteration for network: "<<get_max_network_iteration()<<"\n"
<<"Maximum iteration for updating: "<<get_max_update_iteration()<<"\n"
<<"Maximum network solution divergent threshold: "<<get_max_network_solution_divergent_threshold()<<"\n"
<<"Network solution accelerator: "<<get_iteration_accelerator()<<"\n"
<<"Rotor angle stability surveillance: "<<(get_rotor_angle_stability_surveillance_flag()?"Enabled":"Disabled")<<"\n"
<<"Rotor angle stability threshold: "<<get_rotor_angle_stability_threshold_in_deg()<<" deg\n"
Expand Down Expand Up @@ -2406,6 +2419,8 @@ bool DYNAMICS_SIMULATOR::solve_network()
unsigned int network_iter_max = current_max_network_iteration;
unsigned int network_iter_count = 0;

unsigned int network_solution_divergent_count = 0;

solve_hvdcs_without_integration();
get_bus_current_mismatch();
calculate_bus_power_mismatch_in_MVA();
Expand Down Expand Up @@ -2455,7 +2470,17 @@ bool DYNAMICS_SIMULATOR::solve_network()
get_bus_current_mismatch();
calculate_bus_power_mismatch_in_MVA();
double new_smax = get_max_power_mismatch_struct().greatest_mismatch_in_MVA;
if(new_smax>get_allowed_max_power_imbalance_in_MVA())
if(new_smax>smax)
{
++network_solution_divergent_count;
if(network_solution_divergent_count>get_max_network_solution_divergent_threshold())
{
converged = false;
break;
}
}
smax = new_smax;
if(smax>get_allowed_max_power_imbalance_in_MVA())
continue;
else
{
Expand Down
15 changes: 15 additions & 0 deletions code/source/toolkit/dynamic_simulator/dynamic_simulator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DYNAMICS_SIMULATOR_TEST::DYNAMICS_SIMULATOR_TEST()
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_min_DAE_iteration);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_max_network_iteration);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_max_update_iteration);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_max_network_solution_divergent_threshold);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_allowed_max_power_imbalance_in_MVA);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_iteration_accelerator);
TEST_ADD(DYNAMICS_SIMULATOR_TEST::test_set_get_rotor_angle_stability_surveillance_flag);
Expand Down Expand Up @@ -104,6 +105,7 @@ void DYNAMICS_SIMULATOR_TEST::test_constructor()
TEST_ASSERT(simulator.get_min_DAE_iteration()==3);
TEST_ASSERT(simulator.get_max_network_iteration()==50);
TEST_ASSERT(simulator.get_max_update_iteration()==10);
TEST_ASSERT(simulator.get_max_network_solution_divergent_threshold()==3);
TEST_ASSERT(fabs(simulator.get_allowed_max_power_imbalance_in_MVA()-0.001)<FLOAT_EPSILON);
TEST_ASSERT(fabs(simulator.get_iteration_accelerator()-1.0)<FLOAT_EPSILON);
TEST_ASSERT(simulator.is_bin_file_export_enabled()==false);
Expand Down Expand Up @@ -219,6 +221,19 @@ void DYNAMICS_SIMULATOR_TEST::test_set_get_max_update_iteration()
TEST_ASSERT(simulator.get_max_update_iteration()==100);
}

void DYNAMICS_SIMULATOR_TEST::test_set_get_max_network_solution_divergent_threshold()
{
show_test_information_for_function_of_class(__FUNCTION__,"DYNAMICS_SIMULATOR_TEST");

DYNAMICS_SIMULATOR& simulator = default_toolkit.get_dynamic_simulator();
simulator.set_max_network_solution_divergent_threshold(2);
TEST_ASSERT(simulator.get_max_network_solution_divergent_threshold()==2);
simulator.set_max_network_solution_divergent_threshold(100);
TEST_ASSERT(simulator.get_max_network_solution_divergent_threshold()==100);
simulator.set_max_network_solution_divergent_threshold(1);
TEST_ASSERT(simulator.get_max_network_solution_divergent_threshold()==1);
}

void DYNAMICS_SIMULATOR_TEST::test_set_get_allowed_max_power_imbalance_in_MVA()
{
show_test_information_for_function_of_class(__FUNCTION__,"DYNAMICS_SIMULATOR_TEST");
Expand Down
7 changes: 7 additions & 0 deletions python/stepspy-current/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ STEPS is a simulation toolkit for powerflow and dynamic simulation of large-scal

## Realse Note

- 0.11.5. Jan. 20, 2020. Add new APIs: set/get_dynamic_model_database_capacity().
- 0.11.4. Jan. 2, 2020. Fix bug of c_unit in pylibsteps.py.
- 0.11.3. Dec. 27, 2019. Add API to set toolkit log file: set_toolkit_log_file(log_file, log_file_append_mode). This version has fatal bug. DONOT use it. Use new version instead.
- 0.11.2. Dec. 19, 2019. Update 'is' to '==' when comparing string in stepspy.py.
Expand Down Expand Up @@ -57,6 +58,12 @@ To install stepspy, you can run the following codes on your computer or server:
python -m pip install stepspy
```

To update stepspy, you can run the following codes on your computer or server:

```python
python -m pip install --upgrade 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.
Expand Down
7 changes: 5 additions & 2 deletions python/stepspy-current/demo/demo_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

print("here goes running dynamic simulation")

simulator.set_dynamic_model_database_capacity(1000000)
simulator.load_dynamic_data('IEEE39.dyr','psse')
simulator.check_missing_models()
simulator.check_dynamic_data()
Expand All @@ -91,8 +92,10 @@
data = simulator.get_generator_related_model_parameter_pair(gen, "gen")
print(gen_model, data)

simulator.set_dynamic_simulator_parameter('i', 'max_DAE_iter', 200)
simulator.set_dynamic_simulator_parameter('i', 'max_NET_iter', 1)
simulator.set_dynamic_simulator_parameter('i', 'max_DAE_iter', 3)
simulator.set_dynamic_simulator_parameter('i', 'max_NET_iter', 25)
simulator.set_dynamic_simulator_parameter('i', 'max_UPDATE_iter', 1)
simulator.set_dynamic_simulator_parameter('i', 'max_network_divergent_threshold', 2)
simulator.set_dynamic_simulator_parameter('b', 'bin export logic', False)
simulator.set_dynamic_simulator_parameter('b', 'csv export logic', True)
simulator.set_dynamic_simulation_time_step(0.01)
Expand Down
3 changes: 1 addition & 2 deletions python/stepspy-current/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="stepspy",
version="0.11.4",
version="0.11.5",
author="Changgang Li",
author_email="[email protected]",
description="Python module of Simulation Toolkit for Electrical Power Systems",
Expand All @@ -14,7 +14,6 @@
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",
Expand Down

0 comments on commit baa7504

Please sign in to comment.