From a7ab84d4a42b58ebde5a0b9f168a3094c70596ce Mon Sep 17 00:00:00 2001 From: yliu250 Date: Wed, 4 Sep 2024 12:00:59 -0700 Subject: [PATCH] added branch PQ calculation for transformer and modified the code a bit --- .../dsf_components.cpp | 143 +++++++++++------- 1 file changed, 88 insertions(+), 55 deletions(-) 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 e2ca87416..e0a41820b 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp @@ -3593,9 +3593,7 @@ void gridpack::dynamic_simulation::DSFullBranch::load( void gridpack::dynamic_simulation::DSFullBranch::evaluateBranchFlow() { int i; - double dbranchR, dbranchX; - double dbranchB; - double dbranchPhaseShift, dbranchTapRatio; + double pi = 4.0*atan(1.0); gridpack::dynamic_simulation::DSFullBus *bus1 = dynamic_cast(getBus1().get()); @@ -3603,15 +3601,15 @@ void gridpack::dynamic_simulation::DSFullBranch::evaluateBranchFlow() dynamic_cast(getBus2().get()); //get bus voltages - gridpack::ComplexType c_Z, c_branchcurr; - gridpack::ComplexType c_Ysh, c_frombusshuntcurr, c_tobusshuntcurr; - gridpack::ComplexType c_branchfrombuspq, c_branchtobuspq; 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(); } @@ -3621,37 +3619,72 @@ void gridpack::dynamic_simulation::DSFullBranch::evaluateBranchFlow() } 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); - } + // Here, it does not need to differentiate transformers or lines for storing the variables. + // Treating both transformers and lines as branches + double pf = real(p_branchfrombuspq[i]); + double qf = imag(p_branchfrombuspq[i]); + double pt = real(p_branchtobuspq[i]); + double qt = imag(p_branchtobuspq[i]); + if (!data->setValue(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); + } + } }