Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide feature to update DataCollections with simulation results #224

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3574c76
Add modifications to update values in data collection.
Aug 7, 2024
781ce19
Fixed up some errors so that code compiles.
Aug 7, 2024
116ebb3
Added a updateData operation to the factory class.
Aug 8, 2024
c860321
Add modifications to update values in data collection.
Aug 7, 2024
8740054
Fixed up some errors so that code compiles.
Aug 7, 2024
a43c072
Added a updateData operation to the factory class.
Aug 8, 2024
8d96b22
Add updateData() to DS application
wperkins Aug 19, 2024
a6775bf
Add updateData() to HADREC application
wperkins Aug 19, 2024
7439b51
Add Python interface to DSF and HADREC updateData()
wperkins Aug 19, 2024
6843571
Check some "CURRENT" network values too
wperkins Aug 26, 2024
bfae104
Modified behavior of updateData function in DSFUllBus class so that i…
Aug 28, 2024
db1594d
Merge branch 'feature/update-data' of github.com:GridOPTICS/GridPACK …
Aug 28, 2024
853914a
Modify to spit out simulation state
wperkins Aug 29, 2024
ba104c8
Store current value of voltage magnitude in data collection
Aug 29, 2024
4e2fe65
Merge branch 'feature/update-data' of github.com:GridOPTICS/GridPACK …
Aug 29, 2024
f82d3d6
Change variables dumped during simulation
wperkins Aug 29, 2024
f0c09d4
add an initial version of function to monitor branch power
yliu250 Sep 3, 2024
54881e6
Merge branch 'feature/update-data' of github.com:GridOPTICS/GridPACK …
yliu250 Sep 3, 2024
c5b6890
Added code to copy current values of branch powerflows to branch data…
Sep 3, 2024
bc9db09
Restructured code a bit so branch calculation follow same template as…
Sep 4, 2024
a7ab84d
added branch PQ calculation for transformer and modified the code a bit
yliu250 Sep 4, 2024
de8fd16
Added some new definitions to describe branch flows.
Sep 6, 2024
fb4eeda
Merge branch 'feature/update-data' of github.com:GridOPTICS/GridPACK …
Sep 6, 2024
4fce4e2
Added some branch flow variables to data base.
Sep 6, 2024
5cd5d87
Added implementation for updateData for GENSAL model
Sep 11, 2024
f9e4e98
Print some branch info
wperkins Sep 11, 2024
b820de8
Print correct branch info
wperkins Sep 11, 2024
754026c
Update dynamic_simulation::Event definition
wperkins Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions python/src/dsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ def network_analytics_dump(ds_app):
ds_app.getBusInfoInt(bus, "GENERATOR_NUMBER", g),
ds_app.getBusInfoString(bus, "GENERATOR_ID", g),
ds_app.getBusInfoReal(bus, "GENERATOR_PG", g),
ds_app.getBusInfoReal(bus, "GENERATOR_QG", g))
ds_app.getBusInfoReal(bus, "GENERATOR_QG", g),
ds_app.getBusInfoReal(bus, "GENERATOR_PG_CURRENT", g),
ds_app.getBusInfoReal(bus, "GENERATOR_QG_CURRENT", g),
)
for l in range(ds_app.numLoads(bus)):
print("load: ", l,
ds_app.getBusInfoInt(bus, "LOAD_NUMBER", l),
ds_app.getBusInfoString(bus, "LOAD_ID", l),
ds_app.getBusInfoReal(bus, "LOAD_PL", l),
ds_app.getBusInfoReal(bus, "LOAD_QL", l))
ds_app.getBusInfoReal(bus, "LOAD_QL", l),
ds_app.getBusInfoReal(bus, "LOAD_PL_CURRENT", l),
ds_app.getBusInfoReal(bus, "LOAD_QL_CURRENT", l)
)
nbranch = ds_app.totalBranches()
for branch in range(0, nbranch):
(f, t) = ds_app.getBranchEndpoints(branch)
print(branch, f, t,
ds_app.getBranchInfoInt(branch, "BRANCH_ELEMENTS"),
ds_app.getBranchInfoInt(branch, "BRANCH_INDEX"),
ds_app.getBranchInfoString(branch, "BRANCH_NAME"),
ds_app.getBranchInfoReal(branch, "BRANCH_LENGTH"))


nelem = ds_app.getBranchInfoInt(branch, "BRANCH_NUM_ELEMENTS")
for e in range(0, nelem):
print(branch, ds_app.getBranchInfoInt(branch, "BRANCH_INDEX"),
f, t, e,
ds_app.getBranchInfoReal(branch, 'BRANCH_FROM_P_CURRENT', e),
ds_app.getBranchInfoReal(branch, 'BRANCH_TO_P_CURRENT', e),
ds_app.getBranchInfoReal(branch, 'BRANCH_FROM_Q_CURRENT', e),
ds_app.getBranchInfoReal(branch, 'BRANCH_TO_Q_CURRENT', e))

# -------------------------------------------------------------
# variable initialization
Expand Down Expand Up @@ -95,6 +102,7 @@ def network_analytics_dump(ds_app):
while (not ds_app.isDynSimuDone()):
ds_app.executeOneSimuStep()

ds_app.updateData()
network_analytics_dump(ds_app)

timer.stop(t_total)
Expand Down
30 changes: 30 additions & 0 deletions python/src/example/39bus_test_example_dsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@
import numpy as np
from gridpack.dynamic_simulation import DSFullApp, Event, EventVector

# -------------------------------------------------------------
# network_dump_state
# this matches (some) generator power observations output
# -------------------------------------------------------------
def network_dump_state(ds_app):
nbus = ds_app.totalBuses()
for bus in range(nbus):
print(bus,
ds_app.getBusInfoInt(bus, "BUS_NUMBER"),
ds_app.getBusInfoString(bus, "BUS_NAME"),
ds_app.getBusInfoReal(bus, "BUS_VMAG_CURRENT"))
for g in range(ds_app.numGenerators(bus)):
print(" gen: ", g,
ds_app.getBusInfoString(bus, "GENERATOR_MODEL", g),
ds_app.getBusInfoReal(bus, "GENERATOR_PG_CURRENT", g),
ds_app.getBusInfoReal(bus, "GENERATOR_QG_CURRENT", g),
)
for l in range(ds_app.numLoads(bus)):
print("load: ", l,
ds_app.getBusInfoInt(bus, "LOAD_NUMBER", l),
ds_app.getBusInfoReal(bus, "LOAD_PL_CURRENT", l),
ds_app.getBusInfoReal(bus, "LOAD_QL_CURRENT", l)
)

# -------------------------------------------------------------
# variable initialization
# -------------------------------------------------------------
Expand Down Expand Up @@ -85,6 +109,8 @@
outputob_time_step = 0.005
outputob_nsimustep = int(outputob_time_step/dt);

ds_app.updateData()
network_dump_state(ds_app)

isteps = 0
while (not ds_app.isDynSimuDone()):
Expand All @@ -108,13 +134,17 @@
ob_vals.extend(vAng)
ob_vals.extend(fOnline)
ob_vals.extend(busfreq)
ds_app.updateData()
network_dump_state(ds_app)
print('After getObservations')

print('Before insert')
observation_list.append(ob_vals)
print('After insert')
isteps = isteps + 1

network_dump_state(ds_app)

np_data = np.array(observation_list)

import pandas as pd
Expand Down
20 changes: 15 additions & 5 deletions python/src/gridpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace py = pybind11;
#include <gridpack/configuration/no_print.hpp>
#include <gridpack/parallel/communicator.hpp>
#include <gridpack/parallel/task_manager.hpp>
#include <gridpack/applications/modules/dynamic_simulation_full_y/dsf_app_module.hpp>
#include <gridpack/applications/modules/hadrec/hadrec_app_module.hpp>
#include <gridpack/timer/coarse_timer.hpp>

Expand Down Expand Up @@ -327,16 +328,23 @@ PYBIND11_MODULE(gridpack, gpm) {
// -------------------------------------------------------------
py::class_<gpds::Event>(dsm, "Event")
.def(py::init<>())
.def_readwrite("start", &gpds::Event::start)
.def_readwrite("end", &gpds::Event::end)
.def_readwrite("step", &gpds::Event::step)
.def_readwrite("tag", &gpds::Event::tag)
.def_readwrite("isGenerator", &gpds::Event::isGenerator)
.def_readwrite("isBus", &gpds::Event::isBus)
.def_readwrite("bus_idx", &gpds::Event::bus_idx)
.def_readwrite("isLine", &gpds::Event::isLine)
.def_readwrite("isBusFault", &gpds::Event::isBusFault)
.def_readwrite("isLineStatus", &gpds::Event::isLineStatus)
.def_readwrite("isGenStatus", &gpds::Event::isGenStatus)
.def_readwrite("start", &gpds::Event::start)
.def_readwrite("end", &gpds::Event::end)
.def_readwrite("bus_idx", &gpds::Event::bus_idx)
.def_readwrite("Gfault", &gpds::Event::Gfault)
.def_readwrite("Bfault", &gpds::Event::Bfault)
.def_readwrite("time", &gpds::Event::time)
.def_readwrite("tag", &gpds::Event::tag)
.def_readwrite("from_idx", &gpds::Event::from_idx)
.def_readwrite("to_idx", &gpds::Event::to_idx)
.def_readwrite("status", &gpds::Event::status)
.def_readwrite("step", &gpds::Event::step)
;

// -------------------------------------------------------------
Expand Down Expand Up @@ -479,6 +487,7 @@ PYBIND11_MODULE(gridpack, gpm) {
return py::make_tuple(total, pmin, pmax);
})
.def("resetPower", &gpds::DSFullApp::resetPower)
.def("updateData", &gpds::DSFullApp::updateData)
.def("writeRTPRDiagnostics",
[](gpds::DSFullApp& self,
int src_area, int src_zone, int load_area,
Expand Down Expand Up @@ -767,6 +776,7 @@ PYBIND11_MODULE(gridpack, gpm) {
.def(py::init<>())
.def("transferPFtoDS", &gph::HADRECAppModule::transferPFtoDS)
.def("executeDynSimuOneStep", &gph::HADRECAppModule::executeDynSimuOneStep)
.def("updateData", &gph::HADRECAppModule::updateData)
.def("isDynSimuDone", &gph::HADRECAppModule::isDynSimuDone)
.def("applyAction", &gph::HADRECAppModule::applyAction)
.def("getObservations", &gph::HADRECAppModule::getObservations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ void gridpack::dynamic_simulation::BaseExciterModel::load(
{
}

/**
* Update parameters in DataCollection object with current values from
* exciter
* @param data collection object for bus that hosts exciter
* @param index of generator on bus
*/
void gridpack::dynamic_simulation::BaseExciterModel::updateData(
boost::shared_ptr<gridpack::component::DataCollection>
data, int idx)
{
}

/**
* Initialize exciter model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class BaseExciterModel
virtual void load(boost::shared_ptr<gridpack::component::DataCollection>
data, int idx);

/**
* Update parameters in DataCollection object with current values from
* exciter
* @param data collection object for bus that hosts exciter
* @param index of generator on bus
*/
virtual void updateData(boost::shared_ptr<gridpack::component::DataCollection>
data, int idx);

/**
* Initialize exciter model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ gridpack::dynamic_simulation::BaseGeneratorModel::~BaseGeneratorModel(void) {}
void gridpack::dynamic_simulation::BaseGeneratorModel::load(
boost::shared_ptr<gridpack::component::DataCollection> data, int idx) {}

/**
* Update parameters in DataCollection object with current values from
* generator
* @param data collection object for bus that hosts generator
* @param index of generator on bus
*/
void gridpack::dynamic_simulation::BaseGeneratorModel::updateData(
boost::shared_ptr<gridpack::component::DataCollection> data, int idx) {}


/**
* Initialize generator model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ class BaseGeneratorModel {
* Load parameters from DataCollection object into generator model
* @param data collection of generator parameters from input files
* @param index of generator on bus
* TODO: might want to move this functionality to BaseGeneratorModel
*/
virtual void load(boost::shared_ptr<gridpack::component::DataCollection> data,
int idx);

/**
* Update parameters in DataCollection object with current values from
* generator
* @param data collection object for bus that hosts generator
* @param index of generator on bus
*/
virtual void updateData(boost::shared_ptr<gridpack::component::DataCollection> data,
int idx);

/**
* Initialize generator model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ void gridpack::dynamic_simulation::BaseGovernorModel::load(
{
}

/**
* Update parameters in DataCollection object with current values from
* governor
* @param data collection object for bus that hosts governor
* @param index of generator on bus
*/
void gridpack::dynamic_simulation::BaseGovernorModel::updateData(
boost::shared_ptr<gridpack::component::DataCollection>
data, int idx)
{
}

/**
* Initialize governor model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class BaseGovernorModel
virtual void load(boost::shared_ptr<gridpack::component::DataCollection>
data, int idx);

/**
* Update parameters in DataCollection object with current values from
* governor
* @param data collection object for bus that hosts governor
* @param index of generator on bus
*/
virtual void updateData(boost::shared_ptr<gridpack::component::DataCollection>
data, int idx);

/**
* Initialize governor model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ void gridpack::dynamic_simulation::BaseLoadModel::load(
{
}

/**
* Update parameters in DataCollection object with current values from
* load
* @param data collection object for bus that hosts load
* @param index of generator on bus
*/
void gridpack::dynamic_simulation::BaseLoadModel::updateData(
boost::shared_ptr<gridpack::component::DataCollection> data, int idx)
{
}

/**
* Initialize load model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class BaseLoadModel
virtual void load(boost::shared_ptr<gridpack::component::DataCollection>
data, int idx, double loadP, double loadQ, int ibCMPL);

/**
* Update parameters in DataCollection object with current values from
* load
* @param data collection object for bus that hosts load
* @param index of generator on bus
*/
virtual void updateData(boost::shared_ptr<gridpack::component::DataCollection> data,
int idx);

/**
* Initialize load model before calculation
* @param mag voltage magnitude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,15 @@ void gridpack::dynamic_simulation::DSFullApp::resetPower()
return p_factory->resetPower();
}

/**
* Update data collection objects for all buses and branches with
* current values from simulations
*/
void gridpack::dynamic_simulation::DSFullApp::updateData()
{
return p_factory->updateData();
}

/**
* Read in loads that should be monitored during simulation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ class DSFullApp
*/
void resetPower();

/**
* Update data collection objects for all buses and branches with
* current values from simulations
*/
void updateData();

/**
* Write real time path rating diagnostics
* @param src_area generation area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ void gridpack::dynamic_simulation::DSFullApp::runonestep()

/* Update frequency */
p_factory->updateBusFreq(p_time_step);

/* yuan add: update branch power*/
p_factory->updateData();

std::vector <double> vwideareafreqs;
vwideareafreqs = p_factory->grabWideAreaFreq();
Expand Down
Loading