Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
141 changes: 129 additions & 12 deletions src/applications/components/vs_matrix/vs_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
// -------------------------------------------------------------
/**
* @file vs_components.cpp
* @author Bruce Palmer
* @date 2024-06-07 07:45:40 d3g293
* @author Kelvin Tan
* @date 2024-07-23 01:00:00 d3g293
*
* @updated Shri Abhyankar
* Conversion of constant current, constant admittance values from raw file
* to constant power
* @date 2022-12-23

* @brief Methods used in power flow application
* @brief Methods used in power flow and voltage stability application
*
*
*/
Expand Down Expand Up @@ -1750,6 +1745,68 @@ void gridpack::voltage_stability::VSBus::scaleLoadPower(std::string tag, double
}
}

/**
* Increment load power based off specified value.
* Increment loads in specified area.
* @param transfer value to increment load real power
* @param area index of area for incrementing load
* @param zone index of zone for incrementing load
* @param total active power demand of the area
*/
void gridpack::voltage_stability::VSBus::IncrementLoadPower(std::string tag, double value, double ltotal)
{
int i;
double p_lratio;
for (i=0; i<p_nload; i++) {
if (p_lid[i] == tag && p_lstatus[i] == 1) {
p_lratio = p_pl[i]/ltotal;
p_pl[i] = value*p_lratio + p_pl[i];
break;
}
}
}

/**
* Increment generators real power based off specified value.
* Increment generators in specified area.
* @param transfer value to increment generators real power
* @param area index of area for incrementing generation
* @param zone index of zone for incrementing generation
* @param total power generation of an area
*/
void gridpack::voltage_stability::VSBus::IncrementGeneratorPower(std::string tag, double value, double gtotal)
{
int i;
double p_gratio;
for (i=0; i<p_ngen; i++) {
if (p_gid[i] == tag && p_gstatus[i] == 1) {
p_gratio = p_pg[i]/gtotal;
p_pg[i] = value*p_gratio + p_pg[i];
break;
}
}
}

/**
* Get current generator power
* @param tag character ID for generator
* @param pg initial value of generator real power
* @param status current status of generator
*/
void gridpack::voltage_stability::VSBus::getGeneratorPower(
std::vector<std::string> &tag, std::vector<double> &pg, std::vector<int> &status)
{
tag.clear();
pg.clear();
status.clear();
int i;
for (i=0; i<p_ngen; i++) {
tag.push_back(p_gid[i]);
pg.push_back(p_savePg[i]);
status.push_back(p_gstatus[i]);
}
}

/**
* Reset power for generators and loads back to original values
*/
Expand Down Expand Up @@ -2230,6 +2287,64 @@ void gridpack::voltage_stability::VSBranch::getPQ(gridpack::voltage_stability::V
*p = v1*v2*(ybusr*cs+ybusi*sn);
*q = v1*v2*(ybusr*sn-ybusi*cs);
}
/**
* Return contribution to constraints
* @param vs: Voltage magnitude of sending bus
* @param vr: Voltage magnitude of receiving bus
*/
void gridpack::voltage_stability::VSBranch::getBranchVoltages(double *vs, double *vr, double *p_theta)
{
gridpack::voltage_stability::VSBus *bus1 =
dynamic_cast<gridpack::voltage_stability::VSBus*>(getBus1().get());
*vs = bus1->getVoltage();
gridpack::voltage_stability::VSBus *bus2 =
dynamic_cast<gridpack::voltage_stability::VSBus*>(getBus2().get());
*vr = bus2->getVoltage();
*p_theta = bus1->getPhase() - bus2->getPhase();
}

/**
* Return impedance magnitude of the line element
* @param tag describing line element on branch
* @return impedance magnitude
*/
double gridpack::voltage_stability::VSBranch::getImpedanceMagnitude(
std::string tag) // KT
{
gridpack::voltage_stability::VSBus *bus1 =
dynamic_cast<gridpack::voltage_stability::VSBus*>(getBus1().get());
double zmag, ybusr, ybusi;
ybusr = p_ybusr_frwd;
ybusi = p_ybusi_frwd;
zmag = 1/(ybusr * ybusr + ybusi * ybusi);
return zmag;
}
/**
* Return fast voltage stability index (FVSI) for the line element
* @param tag describing line element on branch
* @return voltage stability index
*/
double gridpack::voltage_stability::VSBranch::getVoltageStabilityIndex(
std::string tag)
{
double vr, vs, x, r, ybusr, ybusi, FVSI;
gridpack::ComplexType z, i, s;
s = getComplexPower(tag);
double p = real(s);
double q = imag(s);
i = ComplexType(0.0,1.0);
z = ComplexType(0.0,0.0);
ybusr = p_ybusr_frwd;
ybusi = p_ybusi_frwd;
z = 1.0/(ybusr + ybusi*i);
r = real(z);
x = imag(z);
getBranchVoltages(&vs, &vr, &p_theta);
auto zmag = getImpedanceMagnitude(tag);
FVSI = 4 * (zmag * q/p_sbase * x) / (vs * vs * (r*sin(p_theta) + x*cos(p_theta)) * (r*sin(p_theta) + x*cos(p_theta)));
if (FVSI < 0.0) FVSI = -1.0 * FVSI;
return FVSI;
}

/**
* Return complex power for line element
Expand Down Expand Up @@ -2279,8 +2394,10 @@ bool gridpack::voltage_stability::VSBranch::serialWrite(char *string, const int
std::vector<std::string> tags = getLineTags();
int i;
int ilen = 0;
double FVSI = 0.0;
for (i=0; i<p_elems; i++) {
s = getComplexPower(tags[i]);
FVSI = getVoltageStabilityIndex(tags[i]);
double p = real(s);
double q = imag(s);
if (!p_branch_status[i]) p = 0.0;
Expand All @@ -2295,13 +2412,13 @@ bool gridpack::voltage_stability::VSBranch::serialWrite(char *string, const int
perf = perf*perf;
}
if (rating) {
sprintf(buf, "%6d %6d %s %20.12e %20.12e %20.12e %20.12e %1d\n",
sprintf(buf, "%6d %6d %s %20.12e %20.12e %20.12e %20.12e %1d %3f\n",
getBus1OriginalIndex(),getBus2OriginalIndex(),tags[i].c_str(),
p,q,perf,p_rateA[i],viol);
p,q,perf,p_rateA[i],viol,FVSI);
} else {
sprintf(buf, " %6d %6d %s %12.6f %12.6f\n",
sprintf(buf, " %6d %6d %s %12.6f %12.6f %12.6f\n",
getBus1OriginalIndex(),getBus2OriginalIndex(),tags[i].c_str(),
p,q);
p,q,FVSI);
}
ilen += strlen(buf);
if (ilen<bufsize) sprintf(string,"%s",buf);
Expand Down
54 changes: 51 additions & 3 deletions src/applications/components/vs_matrix/vs_components.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// -------------------------------------------------------------
/**
* @file vs_components.hpp
* @author Bruce Palmer
* @date 2024-06-07 13:27:00 d3g293
* @author Kelvin Tan
* @date 2024-07-23 01:06:00 d3g293
*
* @brief
*
Expand Down Expand Up @@ -396,7 +396,36 @@ class VSBus
* Reset power for generators and loads back to original values
*/
void resetPower();


/**
* Get current generator power
* @param tag character ID for generator
* @param pg initial value of generator real power
* @param status current status of generator
*/
void getGeneratorPower(std::vector<std::string> &tag,
std::vector<double> &pg, std::vector<int> &status);

/**
* Increment generators real power based off specified value.
* Increment generators in specified area.
* @param transfer value to increment generators real power
* @param area index of area for incrementing generation
* @param zone index of zone for incrementing generation
* @param total power generation of an area
*/
void IncrementGeneratorPower(std::string tag, double value, double gtotal);

/**
* Increment load power based off specified value.
* Increment loads in specified area.
* @param transfer value to increment load real power
* @param area index of area for incrementing load
* @param zone index of zone for incrementing load
* @param total active power demand of the area
*/
void IncrementLoadPower(std::string tag, double value, double ltotal);

/**
* Get available margin for generator
* @param tag character ID for generator
Expand Down Expand Up @@ -605,6 +634,25 @@ class VSBranch
*/
void getPQ(VSBus *bus, double *p, double *q);

/**
* Return the sending and receiving voltage of a branch
* @param vs: Sending bus voltage
* @param vr: Receiving bus voltage
* @param p_theta: Phase angle difference
*/
void getBranchVoltages(double *vs, double *vr, double *p_theta);
/**
* Return impedance magnitude for line element
* @param bus describing sending bus of the branch
* @return impedance magnitude
*/
double getImpedanceMagnitude(std::string tag);
/**
* Return fast voltage stability index (FVSI) for the line element
* @param tag describing line element on branch
* @return voltage stability index
*/
double getVoltageStabilityIndex(std::string tag);
/**
* Set the mode to control what matrices and vectors are built when using
* the mapper
Expand Down
2 changes: 2 additions & 0 deletions src/applications/contingency_analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# -------------------------------------------------------------

set(target_libraries
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_ymatrix_components
Expand Down
2 changes: 2 additions & 0 deletions src/applications/development/wind_dsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(target_libraries
gridpack_dynamic_simulation_full_y_module
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_dsmatrix_components
gridpack_ymatrix_components
gridpack_components
Expand Down
2 changes: 2 additions & 0 deletions src/applications/dynamic_simulation_dae/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ set(target_libraries
gridpack_dynamic_simulation_dae_module
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_ymatrix_components
gridpack_components
gridpack_partition
Expand Down
2 changes: 2 additions & 0 deletions src/applications/dynamic_simulation_full_y/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ set(target_libraries
gridpack_dynamic_simulation_full_y_module
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_voltage_stability_module
gridpack_vsmatrix_components
gridpack_dsmatrix_components
gridpack_ymatrix_components
gridpack_components
Expand Down
2 changes: 2 additions & 0 deletions src/applications/examples/contingency_analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
set(target_libraries
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_ymatrix_components
gridpack_components
gridpack_stream
Expand Down
2 changes: 2 additions & 0 deletions src/applications/examples/powerflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

set(target_libraries
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_ymatrix_components
gridpack_components
gridpack_stream
Expand Down
4 changes: 3 additions & 1 deletion src/applications/hadrec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# -------------------------------------------------------------

set(target_libraries
gridpack_hadrec_module
gridpack_dynamic_simulation_full_y_module
gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_voltage_stability_module
gridpack_vsmatrix_components
gridpack_hadrec_module
gridpack_ymatrix_components
gridpack_components
gridpack_stream
Expand Down
2 changes: 2 additions & 0 deletions src/applications/kalman_ds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(target_libraries
gridpack_powerflow_module
gridpack_kdsmatrix_components
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_dsmatrix_components
gridpack_ymatrix_components
gridpack_components
Expand Down
2 changes: 2 additions & 0 deletions src/applications/modules/hadrec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ set(target_libraries
gridpack_configuration
gridpack_timer
gridpack_pfmatrix_components
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_ymatrix_components
gridpack_dynamic_simulation_full_y_module
gridpack_powerflow_module
Expand Down
4 changes: 3 additions & 1 deletion src/applications/modules/powerflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(target_libraries
gridpack_math
gridpack_configuration
gridpack_timer
gridpack_vsmatrix_components
gridpack_voltage_stability_module
gridpack_pfmatrix_components
gridpack_ymatrix_components
${PARMETIS_LIBRARY} ${METIS_LIBRARY}
Expand All @@ -39,13 +41,13 @@ add_library(gridpack_powerflow_module
pf_app_module.cpp
pf_factory_module.cpp
)

gridpack_set_library_version(gridpack_powerflow_module)

target_link_libraries(gridpack_powerflow_module
gridpack_pfmatrix_components
gridpack_partition
gridpack_stream
${target_libraries}
)


Expand Down
Loading