diff --git a/python/src/dsf.py b/python/src/dsf.py index 6f0162368..b7e9e7a1f 100644 --- a/python/src/dsf.py +++ b/python/src/dsf.py @@ -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 @@ -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) diff --git a/python/src/example/39bus_test_example_dsf.py b/python/src/example/39bus_test_example_dsf.py index f1c30a022..ba3e8a60b 100644 --- a/python/src/example/39bus_test_example_dsf.py +++ b/python/src/example/39bus_test_example_dsf.py @@ -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 # ------------------------------------------------------------- @@ -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()): @@ -108,6 +134,8 @@ 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') @@ -115,6 +143,8 @@ print('After insert') isteps = isteps + 1 +network_dump_state(ds_app) + np_data = np.array(observation_list) import pandas as pd diff --git a/python/src/gridpack.cpp b/python/src/gridpack.cpp index fe3c5b5a3..3f3411678 100644 --- a/python/src/gridpack.cpp +++ b/python/src/gridpack.cpp @@ -22,6 +22,7 @@ namespace py = pybind11; #include #include #include +#include #include #include @@ -327,16 +328,23 @@ PYBIND11_MODULE(gridpack, gpm) { // ------------------------------------------------------------- py::class_(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) ; // ------------------------------------------------------------- @@ -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, @@ -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, diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.cpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.cpp index 3151128df..da4cd2b30 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.cpp @@ -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 + data, int idx) +{ +} + /** * Initialize exciter model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.hpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.hpp index 3c4dda23b..7c7e44fc0 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_exciter_model.hpp @@ -44,6 +44,15 @@ class BaseExciterModel virtual void load(boost::shared_ptr 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 + data, int idx); + /** * Initialize exciter model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.cpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.cpp index 540adfb0f..ec95195ac 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.cpp @@ -53,6 +53,16 @@ gridpack::dynamic_simulation::BaseGeneratorModel::~BaseGeneratorModel(void) {} void gridpack::dynamic_simulation::BaseGeneratorModel::load( boost::shared_ptr 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 data, int idx) {} + + /** * Initialize generator model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.hpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.hpp index 0940b52bf..c6e96e402 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_generator_model.hpp @@ -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 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 data, + int idx); + /** * Initialize generator model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.cpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.cpp index b82db3d79..0fa60304f 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.cpp @@ -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 + data, int idx) +{ +} + /** * Initialize governor model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.hpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.hpp index 11bebf11c..f0f059042 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_governor_model.hpp @@ -44,6 +44,15 @@ class BaseGovernorModel virtual void load(boost::shared_ptr 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 + data, int idx); + /** * Initialize governor model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.cpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.cpp index 26fe8fe21..d10a706f7 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.cpp @@ -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 data, int idx) +{ +} + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.hpp b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.hpp index 62dcbc992..62de180cb 100644 --- a/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/base_classes/base_load_model.hpp @@ -43,6 +43,15 @@ class BaseLoadModel virtual void load(boost::shared_ptr 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 data, + int idx); + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.cpp b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.cpp index cbc3be822..7a9383f71 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.cpp @@ -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 */ diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.hpp b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.hpp index d7c815905..89d37da9d 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module.hpp @@ -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 diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module2.cpp b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module2.cpp index 09bc6cd25..afcfae044 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_app_module2.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_app_module2.cpp @@ -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 vwideareafreqs; vwideareafreqs = p_factory->grabWideAreaFreq(); diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp b/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp index 133ea6c42..4792a2c54 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp @@ -1284,6 +1284,50 @@ void gridpack::dynamic_simulation::DSFullBus::load( } +/** + * Update data collection object with current values from simulation + * @param data: DataCollection object containing parameters for this bus + */ +void gridpack::dynamic_simulation::DSFullBus::updateData( + boost::shared_ptr &data) +{ + int i; + std::string name; + gridpack::ComplexType voltage = getComplexVoltage(); + double rV = real(voltage); + double iV = imag(voltage); + rV = sqrt(rV*rV+iV*iV); + if (!data->setValue(BUS_VMAG_CURRENT, rV)) { + data->addValue(BUS_VMAG_CURRENT, rV); + } + for (i=0; igetValue(GENERATOR_MODEL,&name,i)) { + p_generators[i]->updateData(data, i); + } else { + if (!data->setValue(GENERATOR_PG_CURRENT, p_pg[i], i)) { + data->addValue(GENERATOR_PG_CURRENT, p_pg[i], i); + } + if (!data->setValue(GENERATOR_QG_CURRENT, p_qg[i], i)) { + data->addValue(GENERATOR_QG_CURRENT, p_qg[i], i); + } + } + } + int lcnt = 0; + for (i=0; igetValue(LOAD_MODEL,&name,i)) { + p_loadmodels[lcnt]->updateData(data, i); + lcnt++; + } else { + if (!data->setValue(LOAD_PL_CURRENT, p_powerflowload_p[i], i)) { + data->addValue(LOAD_PL_CURRENT, p_powerflowload_p[i], i); + } + if (!data->setValue(LOAD_QL_CURRENT, p_powerflowload_q[i], i)) { + data->addValue(LOAD_QL_CURRENT, p_powerflowload_q[i], i); + } + } + } +} + /** * set voltage for the extended buses from composite load model */ @@ -3543,6 +3587,148 @@ void gridpack::dynamic_simulation::DSFullBranch::load( } } +/** + * Evaluate branch flows for the to and from bus on the branch + */ +void gridpack::dynamic_simulation::DSFullBranch::evaluateBranchFlow() +{ + int i; + double pi = 4.0*atan(1.0); + + gridpack::dynamic_simulation::DSFullBus *bus1 = + dynamic_cast(getBus1().get()); + gridpack::dynamic_simulation::DSFullBus *bus2 = + dynamic_cast(getBus2().get()); + + //get bus voltages + p_branchfrombusvolt = bus1->getComplexVoltage(); + p_branchtobusvolt = bus2->getComplexVoltage(); + + // printf ("Branch volts bus1, %8.4f+%8.4fj, bus 2, %8.4f+%8.4fj,\n", real(p_branchfrombusvolt), + // imag(p_branchfrombusvolt), real(p_branchtobusvolt),imag(p_branchtobusvolt) ); + + // define branch from and to bus p + jq + gridpack::ComplexType c_branchfrombuspq, c_branchtobuspq; + + if (!p_branchfrombuspq.empty()){ + p_branchfrombuspq.clear(); + } + + if (!p_branchtobuspq.empty()){ + p_branchtobuspq.clear(); + } + + for ( i=0 ; i &data) +{ + int i; + evaluateBranchFlow(); + updateBranchCurrent(); + for (i=0; isetValue(BRANCH_FROM_P_CURRENT, pf, i)) { + data->addValue(BRANCH_FROM_P_CURRENT, pf, i); + } + if (!data->setValue(BRANCH_FROM_Q_CURRENT, qf, i)) { + data->addValue(BRANCH_FROM_Q_CURRENT, qf, i); + } + if (!data->setValue(BRANCH_TO_P_CURRENT, pt, i)) { + data->addValue(BRANCH_TO_P_CURRENT, pt, i); + } + if (!data->setValue(BRANCH_TO_Q_CURRENT, qt, i)) { + data->addValue(BRANCH_TO_Q_CURRENT, qt, i); + } + pf = real(p_branchcurrent[i]); + qf = imag(p_branchcurrent[i]); + if (!data->setValue(BRANCH_IRFLOW_CURRENT, pf, i)) { + data->addValue(BRANCH_IRFLOW_CURRENT, pf, i); + } + if (!data->setValue(BRANCH_IIFLOW_CURRENT, qf, i)) { + data->addValue(BRANCH_IIFLOW_CURRENT, qf, i); + } + } +} + /** * update branch current */ diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_components.hpp b/src/applications/modules/dynamic_simulation_full_y/dsf_components.hpp index 9cd3eccef..0e852e355 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_components.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_components.hpp @@ -243,6 +243,12 @@ class DSFullBus * bus that were read in when network was initialized */ void load(const boost::shared_ptr &data); + + /** + * Update data collection object with current values from simulation + * @param data: DataCollection object containing parameters for this bus + */ + void updateData(boost::shared_ptr &data); /** * load parameters for the extended buses from composite load model @@ -936,6 +942,17 @@ class DSFullBranch */ void load(const boost::shared_ptr &data); + /** + * Evaluate branch flows for the to and from bus on the branch + */ + void evaluateBranchFlow(); + + /** + * Update data collection object with current values from simulation + * @param data: DataCollection object containing parameters for this branch + */ + void updateData(boost::shared_ptr &data); + /** * Return the complex admittance of the branch * @return: complex addmittance of branch @@ -1104,6 +1121,9 @@ class DSFullBranch gridpack::ComplexType p_branchfrombusvolt; //renke add gridpack::ComplexType p_branchtobusvolt; //renke add + std::vector p_branchfrombuspq; //yuan add + std::vector p_branchtobuspq; //yuan add + bool p_line_status_change; // Flag to indicate line status change gridpack::ComplexType p_yft,p_ytf; // Ybus off-diagonal contributions from this line friend class boost::serialization::access; diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_factory.cpp b/src/applications/modules/dynamic_simulation_full_y/dsf_factory.cpp index cc9bd1feb..100e0384a 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_factory.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_factory.cpp @@ -714,5 +714,24 @@ void gridpack::dynamic_simulation::DSFullFactory::setRTPRParams( } } +/** + * Update data collection objects for all buses and branches with + * current values from simulations + */ +void gridpack::dynamic_simulation::DSFullFactory::updateData() +{ + int i; + boost::shared_ptr data; + for (i=0; igetBusData(i); + p_buses[i]->updateData(data); + } + + for (i=0; igetBranchData(i); + p_branches[i]->updateData(data); + } +} + } // namespace dynamic_simulation } // namespace gridpack diff --git a/src/applications/modules/dynamic_simulation_full_y/dsf_factory.hpp b/src/applications/modules/dynamic_simulation_full_y/dsf_factory.hpp index d4e381d27..ce97ab086 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_factory.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_factory.hpp @@ -196,6 +196,12 @@ class DSFullFactory */ void resetPower(); + /** + * Update data collection objects for all buses and branches with + * current values from simulations + */ + void updateData(); + /** * Set parameters for real time path rating diagnostics * @param src_area generation area diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.cpp index d713235ca..11eba07dc 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.cpp @@ -307,6 +307,26 @@ void gridpack::dynamic_simulation::AcmotorLoad::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::AcmotorLoad::updateData( + boost::shared_ptr data, int idx) +{ + double pl = getDynLoadP(); + double ql = getDynLoadQ(); + if (!data->setValue(LOAD_PL_CURRENT, pl, idx)) { + data->addValue(LOAD_PL_CURRENT, pl, idx); + } + if (!data->setValue(LOAD_QL_CURRENT, ql, idx)) { + data->addValue(LOAD_QL_CURRENT, ql, idx); + } + +} + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.hpp index 02819bd7e..ebf871e5d 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/acmotor.hpp @@ -44,6 +44,15 @@ class AcmotorLoad : public BaseLoadModel void load(boost::shared_ptr 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 + */ + void updateData(boost::shared_ptr data, + int idx); + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.cpp index a46770d81..26723c456 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.cpp @@ -79,6 +79,23 @@ void gridpack::dynamic_simulation::ClassicalGenerator::load( //printf("---classical gen load p_h = %f, p_d0 = %f\n", p_h, p_d0); } +/** + * 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::ClassicalGenerator::updateData( + boost::shared_ptr data, int idx) +{ + if (!data->setValue(GENERATOR_PG_CURRENT, p_pg, idx)) { + data->addValue(GENERATOR_PG_CURRENT, p_pg, idx); + } + if (!data->setValue(GENERATOR_QG_CURRENT, p_qg, idx)) { + data->addValue(GENERATOR_QG_CURRENT, p_qg, idx); + } +} + /** * Initialize generator model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.hpp index 4976599dc..a798bcbb7 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/classical.hpp @@ -44,6 +44,15 @@ class ClassicalGenerator : public BaseGeneratorModel void load(boost::shared_ptr 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 updateData(boost::shared_ptr data, + int idx); + /** * Initialize generator model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.cpp index 65c08c952..7b57adae0 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.cpp @@ -119,6 +119,29 @@ void gridpack::dynamic_simulation::GenrouGenerator::load( } +/** + * 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::GenrouGenerator::updateData( + boost::shared_ptr data, int idx) +{ + if (!data->setValue(GENERATOR_PG_CURRENT, p_pg, idx)) { + data->addValue(GENERATOR_PG_CURRENT, p_pg, idx); + } + if (!data->setValue(GENERATOR_QG_CURRENT, p_qg, idx)) { + data->addValue(GENERATOR_QG_CURRENT, p_qg, idx); + } + if (p_exciter.get() != NULL) { + p_exciter->updateData(data, idx); + } + if (p_governor.get() != NULL) { + p_governor->updateData(data, idx); + } +} + /** * Saturation function * @ param x diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.hpp index 87543b876..1ded7fc26 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/genrou.hpp @@ -44,12 +44,21 @@ class GenrouGenerator : public BaseGeneratorModel void load(boost::shared_ptr 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 updateData(boost::shared_ptr data, + int idx); + /** * Saturation function * @ param x */ double Sat(double x); - + /** * Initialize generator model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.cpp index c4f25c88b..161325ee1 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.cpp @@ -89,6 +89,29 @@ void gridpack::dynamic_simulation::GensalGenerator::load( } } +/** + * 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::GensalGenerator::updateData( + boost::shared_ptr data, int idx) +{ + if (!data->setValue(GENERATOR_PG_CURRENT, p_pg, idx)) { + data->addValue(GENERATOR_PG_CURRENT, p_pg, idx); + } + if (!data->setValue(GENERATOR_QG_CURRENT, p_qg, idx)) { + data->addValue(GENERATOR_QG_CURRENT, p_qg, idx); + } + if (p_exciter.get() != NULL) { + p_exciter->updateData(data, idx); + } + if (p_governor.get() != NULL) { + p_governor->updateData(data, idx); + } +} + /** * Saturation function * @ param x diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.hpp index 59c0d43bd..548cd9602 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/gensal.hpp @@ -44,6 +44,15 @@ class GensalGenerator : public BaseGeneratorModel void load(boost::shared_ptr 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 updateData(boost::shared_ptr data, + int idx); + /** * Saturation function * @ param x diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.cpp index 411df7f2c..a4bc33f59 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.cpp @@ -131,6 +131,24 @@ void gridpack::dynamic_simulation::IeelLoad::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::IeelLoad::updateData( + boost::shared_ptr data, int idx) +{ + if (!data->setValue(LOAD_PL_CURRENT, P, idx)) { + data->addValue(LOAD_PL_CURRENT, P, idx); + } + if (!data->setValue(LOAD_QL_CURRENT, Q, idx)) { + data->addValue(LOAD_QL_CURRENT, Q, idx); + } + +} + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.hpp index a0557a78a..1064e46fd 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/ieel.hpp @@ -44,6 +44,15 @@ class IeelLoad : public BaseLoadModel void load(boost::shared_ptr data, int idx, double dloadP, double dloadQ, 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 + */ + void updateData(boost::shared_ptr data, + int idx); + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.cpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.cpp index c7d92b164..490ddc5bb 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.cpp @@ -199,6 +199,24 @@ void gridpack::dynamic_simulation::MotorwLoad::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::MotorwLoad::updateData( + boost::shared_ptr data, int idx) +{ + if (!data->setValue(LOAD_PL_CURRENT, Pmotor, idx)) { + data->addValue(LOAD_PL_CURRENT, Pmotor, idx); + } + if (!data->setValue(LOAD_QL_CURRENT, Qmotor, idx)) { + data->addValue(LOAD_QL_CURRENT, Qmotor, idx); + } + +} + /** * Initialize load model before calculation * @param mag voltage magnitude diff --git a/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.hpp b/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.hpp index 02fd0b773..8fda37710 100644 --- a/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.hpp +++ b/src/applications/modules/dynamic_simulation_full_y/model_classes/motorw.hpp @@ -44,6 +44,15 @@ class MotorwLoad : public BaseLoadModel void load(boost::shared_ptr data, int idx, double dloadP, double dloadQ, 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 + */ + void updateData(boost::shared_ptr data, + int idx); + /** * Initialize load model before calculation * @param mag voltage magnitude @@ -158,7 +167,7 @@ class MotorwLoad : public BaseLoadModel // derivatives of state variables for corrector double depq_dt, depd_dt, deppq_dt, deppd_dt, dslip_dt; - // oter varialbes + // other varialbes double w0, TL, Tm0, p, q, Pmotor, Qmotor, Qmotor_init, sysMVABase; gridpack::ComplexType nortonImpedance_sysMVA; double Fonline; diff --git a/src/applications/modules/hadrec/hadrec_app_module.cpp b/src/applications/modules/hadrec/hadrec_app_module.cpp index ab31e743d..96947eaff 100644 --- a/src/applications/modules/hadrec/hadrec_app_module.cpp +++ b/src/applications/modules/hadrec/hadrec_app_module.cpp @@ -7,7 +7,7 @@ /** * @file hadrec_app.cpp * @author Bruce Palmer - * @date 2024-05-15 12:27:32 d3g096 + * @date 2024-08-19 14:12:49 d3g096 * * @brief * @@ -380,6 +380,18 @@ void gridpack::hadrec::HADRECAppModule::executeDynSimuOneStep(){ */ } +/** + * Update data collection objects for all buses and branches with + * current values from simulations + */ +void gridpack::hadrec::HADRECAppModule::updateData() +{ + if (ds_app_sptr) { + ds_app_sptr->updateData(); + } +} + + /** * return observations after each simulation time step */ diff --git a/src/applications/modules/hadrec/hadrec_app_module.hpp b/src/applications/modules/hadrec/hadrec_app_module.hpp index d1f3747a2..58bac0d57 100644 --- a/src/applications/modules/hadrec/hadrec_app_module.hpp +++ b/src/applications/modules/hadrec/hadrec_app_module.hpp @@ -7,7 +7,7 @@ /** * @file hadrec_app_module.hpp * @author Bruce Palmer - * @date 2024-05-22 09:32:28 d3g096 + * @date 2024-08-19 14:09:06 d3g096 * * @brief * @@ -106,6 +106,13 @@ class HADRECAppModule * Execute only one simulation time step */ void executeDynSimuOneStep(); + + /** + * Update data collection objects for all buses and branches with + * current values from simulations + */ + void updateData(); + /** * Check whether the dynamic simulation is done diff --git a/src/parser/variable_defs/branch_defs.hpp b/src/parser/variable_defs/branch_defs.hpp index 20045f2cf..dda2ccce6 100644 --- a/src/parser/variable_defs/branch_defs.hpp +++ b/src/parser/variable_defs/branch_defs.hpp @@ -19,6 +19,12 @@ * index are denoted with the keyword "indexed". */ +/** + * Variables that have _CURRENT appended to them may be added to the data + * collection during runtime and updated as the simulation + * proceeds + */ + #ifndef _BRANCH_VAR_HPP_ #define _BRANCH_VAR_HPP_ @@ -315,4 +321,46 @@ */ #define BRANCH_SEQ_BI "BRANCH_SEQ_BI" +/** + * Real power from "from" bus of branch + * type: real float + * indexed + */ +#define BRANCH_FROM_P_CURRENT "BRANCH_FROM_P_CURRENT" + +/** + * Reactive power from "from" bus of branch + * type: real float + * indexed + */ +#define BRANCH_FROM_Q_CURRENT "BRANCH_FROM_Q_CURRENT" + +/** + * Real power from "to" bus of branch + * type: real float + * indexed + */ +#define BRANCH_TO_P_CURRENT "BRANCH_TO_P_CURRENT" + +/** + * Reactive power from "to" bus of branch + * type: real float + * indexed + */ +#define BRANCH_TO_Q_CURRENT "BRANCH_TO_Q_CURRENT" + +/** + * Real branch current + * type: real float + * indexed + */ +#define BRANCH_IRFLOW_CURRENT "BRANCH_IRFLOW_CURRENT" + +/** + * Imaginary branch current + * type: real float + * indexed + */ +#define BRANCH_IIFLOW_CURRENT "BRANCH_IIFLOW_CURRENT" + #endif /* _BRANCH_VAR_HPP_ */ diff --git a/src/parser/variable_defs/bus_defs.hpp b/src/parser/variable_defs/bus_defs.hpp index 9447f6f58..5527a2494 100644 --- a/src/parser/variable_defs/bus_defs.hpp +++ b/src/parser/variable_defs/bus_defs.hpp @@ -76,6 +76,7 @@ * type: real float */ #define BUS_VOLTAGE_MAG "BUS_VOLTAGE_MAG" +#define BUS_VMAG_CURRENT "BUS_VMAG_CURRENT" /** * Bus voltage phase angle, in degrees diff --git a/src/parser/variable_defs/generator_defs.hpp b/src/parser/variable_defs/generator_defs.hpp index 47b719e4f..b611f5c57 100644 --- a/src/parser/variable_defs/generator_defs.hpp +++ b/src/parser/variable_defs/generator_defs.hpp @@ -19,6 +19,13 @@ * index are denoted with the keyword "indexed". */ + +/** + * Variables that have _CURRENT appended to them may be added to the data + * collection during runtime and updated as the simulation + * proceeds + */ + #ifndef _GENERATOR_VAR_HPP_ #define _GENERATOR_VAR_HPP_ @@ -57,6 +64,7 @@ * indexed */ #define GENERATOR_PG "GENERATOR_PG" +#define GENERATOR_PG_CURRENT "GENERATOR_PG_CURRENT" /** * Generator reactive power output, entered in MVar @@ -64,6 +72,7 @@ * indexed */ #define GENERATOR_QG "GENERATOR_QG" +#define GENERATOR_QG_CURRENT "GENERATOR_QG_CURRENT" /** * Maximum generator reactive power output; entered in Mvar @@ -85,6 +94,7 @@ * indexed */ #define GENERATOR_VS "GENERATOR_VS" +#define GENERATOR_VS_CURRENT "GENERATOR_VS_CURRENT" /** * Bus number of a remote type 1 or 2 bus whose voltage is to be regulated by this plant to the @@ -1432,4 +1442,11 @@ */ #define GENERATOR_MODEL "GENERATOR_MODEL" +/** + * Nominal power of the generator + * type: float + * indexed + */ +#define GENERATOR_NOM_POWER_CURRENT "GENERATOR_NOM_POWER_CURRENT" + #endif /* _GENERATOR_VAR_HPP_ */ diff --git a/src/parser/variable_defs/load_defs.hpp b/src/parser/variable_defs/load_defs.hpp index 6e7b8c0d1..72d5614ef 100644 --- a/src/parser/variable_defs/load_defs.hpp +++ b/src/parser/variable_defs/load_defs.hpp @@ -19,6 +19,13 @@ * index are denoted with the keyword "indexed". */ +/** + * Variables that have _CURRENT appended to them may be added to the data + * collection during runtime and updated as the simulation + * proceeds + */ + + #ifndef _LOAD_VAR_HPP_ #define _LOAD_VAR_HPP_ @@ -75,6 +82,7 @@ * indexed */ #define LOAD_PL "LOAD_PL" +#define LOAD_PL_CURRENT "LOAD_PL_CURRENT" /** * Reactive power component of constant power load; entered in MVar @@ -82,6 +90,7 @@ * indexed */ #define LOAD_QL "LOAD_QL" +#define LOAD_QL_CURRENT "LOAD_QL_CURRENT" /** * Active power component of constant current load; entered in MW diff --git a/src/parser/variable_defs/transformer_defs.hpp b/src/parser/variable_defs/transformer_defs.hpp index d358aea4f..6f0752913 100644 --- a/src/parser/variable_defs/transformer_defs.hpp +++ b/src/parser/variable_defs/transformer_defs.hpp @@ -19,6 +19,12 @@ * index are denoted with the keyword "indexed". */ +/** + * Variables that have _CURRENT appended to them may be added to the data + * collection during runtime and updated as the simulation + * proceeds + */ + #ifndef _TRANSFORMER_VAR_HPP_ #define _TRANSFORMER_VAR_HPP_