From af19e94d07c89618f6f41304acb20311aac7f464 Mon Sep 17 00:00:00 2001 From: Tahmid Khan <60913202+ta7mid@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:53:23 +0600 Subject: [PATCH 1/2] fix(dynamic_simulation_full_y_module): update voltage angles on `updateData` --- .../dsf_components.cpp | 17 ++++++++++------- src/parser/variable_defs/bus_defs.hpp | 1 + 2 files changed, 11 insertions(+), 7 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 972116071..5434076ef 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp @@ -3,6 +3,7 @@ * Licensed under modified BSD License. A copy of this license can be found * in the LICENSE file in the top level directory of this distribution. */ +#include #include #include @@ -1300,11 +1301,13 @@ void gridpack::dynamic_simulation::DSFullBus::updateData( 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); + auto vmag = std::abs(voltage); + if (!data->setValue(BUS_VMAG_CURRENT, vmag)) { + data->addValue(BUS_VMAG_CURRENT, vmag); + } + auto vang = std::arg(voltage); + if (!data->setValue(BUS_VANG_CURRENT, vang)) { + data->addValue(BUS_VANG_CURRENT, vang); } for (i=0; igetValue(GENERATOR_MODEL,&name,i)) { @@ -1325,8 +1328,8 @@ void gridpack::dynamic_simulation::DSFullBus::updateData( lcnt++; } else { double pl_current,ql_current; - pl_current = rV*rV*p_gload[i]; - ql_current = -rV*rV*p_bload[i]; + pl_current = vmag*vmag*p_gload[i]; + ql_current = -vmag*vmag*p_bload[i]; if(p_bscatterinjload_flag_compensateY) { pl_current -= p_scatterinjload_p; ql_current -= p_scatterinjload_q; diff --git a/src/parser/variable_defs/bus_defs.hpp b/src/parser/variable_defs/bus_defs.hpp index 097986fce..6f6dcb042 100644 --- a/src/parser/variable_defs/bus_defs.hpp +++ b/src/parser/variable_defs/bus_defs.hpp @@ -83,6 +83,7 @@ * type: real float */ #define BUS_VOLTAGE_ANG "BUS_VOLTAGE_ANG" +#define BUS_VANG_CURRENT "BUS_VANG_CURRENT" /** * Bus voltage frequency at current time From 4f3ec3c44801b7b5d0b422b435972036581d3d44 Mon Sep 17 00:00:00 2001 From: Tahmid Khan <60913202+ta7mid@users.noreply.github.com> Date: Sat, 29 Nov 2025 14:18:58 +0600 Subject: [PATCH 2/2] fix: BUS_VANG_CURRENT should be in degrees --- .../dynamic_simulation_full_y/dsf_components.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 5434076ef..2463aab48 100644 --- a/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp +++ b/src/applications/modules/dynamic_simulation_full_y/dsf_components.cpp @@ -3,6 +3,7 @@ * Licensed under modified BSD License. A copy of this license can be found * in the LICENSE file in the top level directory of this distribution. */ +#include #include #include #include @@ -13,6 +14,11 @@ #include "lvshbl.hpp" #include "gridpack/utilities/string_utils.hpp" +namespace { + +const double pi = 4.0*std::atan(1.0); + +} // namespace /** * Simple constructor @@ -892,7 +898,6 @@ void gridpack::dynamic_simulation::DSFullBus::load( data->getValue(BUS_AREA, &p_area); p_zone = 1; data->getValue(BUS_ZONE, &p_zone); - double pi = 4.0*atan(1.0); p_angle = p_angle*pi/180.0; p_shunt = true; @@ -1305,7 +1310,7 @@ void gridpack::dynamic_simulation::DSFullBus::updateData( if (!data->setValue(BUS_VMAG_CURRENT, vmag)) { data->addValue(BUS_VMAG_CURRENT, vmag); } - auto vang = std::arg(voltage); + auto vang = std::arg(voltage)*180.0/pi; if (!data->setValue(BUS_VANG_CURRENT, vang)) { data->addValue(BUS_VANG_CURRENT, vang); } @@ -1481,7 +1486,6 @@ void gridpack::dynamic_simulation::DSFullBus::LoadExtendedCmplBus( } //load data for LOAD_BUS - double pi = 4.0*atan(1.0); //p_shunt = true; //p_shunt = p_shunt && data->getValue(LOAD_BSS, &p_shunt_bs); @@ -1933,7 +1937,6 @@ void gridpack::dynamic_simulation::DSFullBus::computeBusVolFrequency( double tim { const double dFREQ_SYS = 60.0; const double dTf = 0.1; - const double pi = 4.0*atan(1.0); const double dw0 = 2.0*dFREQ_SYS*pi; double dstatex, dstatex1, ddx1, ddx2, dva_old, dva; @@ -3455,7 +3458,6 @@ void gridpack::dynamic_simulation::DSFullBranch::setYBus(void) // printf ("from %d-> to %d: p_phase_shift = %f, a = %f+%fi\n", bus1->getOriginalIndex(), bus2->getOriginalIndex(), p_phase_shift, real(a), imag(a) ); // } //p_theta = bus1->getPhase() - bus2->getPhase(); - double pi = 4.0*atan(1.0); p_theta = (bus1->getPhase() - bus2->getPhase()); //printf("p_phase_shift: %12.6f\n",p_phase_shift); //printf("p_theta: %12.6f\n",p_theta); @@ -3531,7 +3533,6 @@ void gridpack::dynamic_simulation::DSFullBranch::load( double rvar; int ivar; bool lvar; - double pi = 4.0*atan(1.0); p_active = false; ok = data->getValue(CASE_SBASE, &p_sbase); int idx; @@ -3618,7 +3619,6 @@ void gridpack::dynamic_simulation::DSFullBranch::load( void gridpack::dynamic_simulation::DSFullBranch::evaluateBranchFlow() { int i; - double pi = 4.0*atan(1.0); gridpack::dynamic_simulation::DSFullBus *bus1 = dynamic_cast(getBus1().get());