0% found this document useful (0 votes)
35 views10 pages

Steady State Stability

The document discusses calculating steady state stability limits for a power system. It includes code to generate a circle defined by a center coordinate and radius, then calculate and output the real and reactive power values for points around the circle within given x limits with a set step size.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
35 views10 pages

Steady State Stability

The document discusses calculating steady state stability limits for a power system. It includes code to generate a circle defined by a center coordinate and radius, then calculate and output the real and reactive power values for points around the circle within given x limits with a set step size.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 10

#include<iostream>

#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<fstream>
#include<vector>
#include<string>
#include<stdio.h>
#include<time.h>
#include<direct.h>
#include<iomanip>
using namespace std;

void folder_creation(string file);


int lor_rx_points(char a, int f, string path, ofstream& lt);

void main()
{
double /*h,*/ k = 0, r = 0, y1, y2, x1, x2, x_first, x_last, step_x, x, rem,
delta, remf, remi, condition = 0;
double xd, xt, gen_base = 0, xmin_s1, kV_high, kV_low, kV_gen, xtg, kV_sys,
xmin_st1, xmin_sg, xe, xfmr_base;
vector<double>ay1;
vector<double>ay2;
vector<double>ax;
char ch;
int status, flag = 0, rec = 0, rec1 = 0, rec2 = 0, conditionint;
string folder, filepath, sys_stab_file, freqtime, folder1, sys_cir_file,
gname;

ofstream out;
// ifstream ind;

while (rec1 == 0)
{
cout << "Do you want to skip system stability limit calc and also free
circle plotting? (y/n)" << endl;
cin >> ch;
if (ch == 'n' || ch == 'N')
{
while (rec == 0)
{
cout << "Do you want free circle plotting instead of system
stability limit calc (y/n)" << endl;
cin >> ch;
cout << "Enter the folder name" << endl;
cin >> folder;
folder1 = "C:/Users/kbanerjee/Documents/Visual Studio
2019/Steady_State_Stability"; //Change when executing in different machine
filepath = folder1 + "/" + folder; //Change when executing
in different machine
folder_creation(filepath);

flag = 1;

if (ch == 'N' || ch == 'n')


{
cout << "Enter the name of the system stability calc
file to store" << endl;
cin >> sys_stab_file;
cout << "Opening " << sys_stab_file << ".dat file" <<
endl;
out.open((filepath + '/' + sys_stab_file +
".dat").c_str());
if (!out)
{
cout << "cannot open file" << endl;
_getch();
exit(1);
}

cout << "Enter the name of generator for which the


steady state calculations are being performed" << endl;
cin >> gname;
cout << "Enter the transformer base" << endl;
cin >> xfmr_base;
cout << "Enter step-up transformer reactance on
transformer base" << endl;
cin >> xt;
cout << "Enter generator synchronous reactance and
gen base" << endl;
cin >> xd >> gen_base;
cout << "Enter genrator voltage" << endl;
cin >> kV_gen;
cout << "Enter system voltage" << endl;
cin >> kV_sys;
cout << "Enter system impedance with strongest source
OOS from ASPEN/CAPE (100 MVA base)" << endl;
cin >> xmin_s1;
cout << "Enter transformer high side and low side
taps" << endl;
cin >> kV_high >> kV_low;
xtg = (gen_base / xfmr_base) * (pow(kV_low, 2) /
pow(kV_gen, 2)) * xt;
cout << "xtg " << xtg << endl;
xmin_st1 = (gen_base / 100) * (pow(kV_sys, 2) /
pow(kV_high, 2)) * xmin_s1;
cout << "xmin_st1 " << xmin_st1 << endl;
xmin_sg = (pow(kV_low, 2) / pow(kV_gen, 2)) *
xmin_st1;
cout << "xmin_sg " << xmin_sg << endl;
xe = xtg + xmin_sg;
cout << "xe " << xe << endl;
k = ((xd - xe) / (2 * xe * xd)) * gen_base; //1
p.u. gen voltage - Center
r = ((xd + xe) / (2 * xe * xd)) * gen_base; //1
p.u. gen voltage - Radius
cout << "k " << k << " r " << r << endl;
cout << "gen_base " << gen_base << endl;
rec += 1;
}

else if (ch == 'Y' || ch == 'y')


{
cout << "Enter the name of the free form cirlce calc
file to store" << endl;
cin >> sys_cir_file;
cout << "Opening " << sys_cir_file << ".dat file" <<
endl;
out.open((filepath + '/' + sys_cir_file +
".dat").c_str());
if (!out)
{
cout << "cannot open file" << endl;
_getch();
exit(1);
}

cout << "Enter center coordinates (0,y)" << endl;


cin >> k;
cout << "Enter radius" << endl;
cin >> r;
rec += 1;
}

else
{
cout << "You entered the wrong choice...Please choose
yes (y) or no (n)" << endl;
rec = 0;
}
}

if (fabs(k) > r)
{
cout << "Radius is less than center coordinate. Error in
calculating steady state stability" << endl;
_getch();
exit(0);
}
cout << "For x = 0" << endl;
y1 = k + r;
y2 = k - r;
cout << "y1 and y2 " << y1 << " " << y2 << endl;
cout << " For y = 0" << endl;
x1 = pow(((r + k) * (r - k)), 0.5);
x2 = -(pow(((r + k) * (r - k)), 0.5));
cout << "x1 and x2 " << x1 << " " << x2 << endl;
cout << "Enter x_first and x_last within x1 and x2" << endl;
cin >> x_first >> x_last;
cout << "Enter step change" << endl;
cin >> step_x;
x = x_first;
cout << "processing..." << endl;
cout << "------------------------------STEADY STATE STABILITY
LIMIT----------------------------------------------" << endl;
out << "------------------------------STEADY STATE STABILITY
LIMIT----------------------------------------------" << endl;
cout << "Calculations for - " << gname << " " << gen_base << "
MVA"<< endl;
out << "Calculations for - " << gname << " " << gen_base << "
MVA"<< endl;
cout << "SSS Center: " << k << " MVAr" << endl;
out << "SSS Center: " << k << " MVAr" << endl;
cout << "SSS Radius: " << r << " MVA" << endl;
out << "SSS Radius: " << r << " MVA" << endl;
out << "Plotting points for steady state stability with step
change of " << step_x << " MVA" << endl;
out << right << setw(20) << "P (MVA)" << right << setw(20) << "+Q
(MVAr)" << right << setw(20) << "-Q (MVAr)" << endl;
cout << "Plotting points for steady state stability with step
change of " << step_x << " MVA" << endl;
cout << right << setw(20) << "P (MVA)" << right << setw(20) <<
"+Q (MVAr)" << right << setw(20) << "-Q (MVAr)" << endl;
while (x <= x_last)
{
y1 = k + pow(((r + x) * (r - x)), 0.5);
y2 = k - pow(((r + x) * (r - x)), 0.5);
ay1.push_back(y1);
ay2.push_back(y2);
ax.push_back(x);
out << right << setw(20) << x << right << setw(20) << y1 <<
right << setw(20) << y2 << endl;
cout << right << setw(20) << x << right << setw(20) << y1
<< right << setw(20) << y2 << endl;
x += step_x;
}

delta = x_last - x_first;


rem = delta / step_x;
remf = modf(rem, &remi);

if (remf > 0)
{
y1 = k + pow(((r + x_last) * (r - x_last)), 0.5);
y2 = k - pow(((r + x_last) * (r - x_last)), 0.5);
ay1.push_back(y1);
ay2.push_back(y2);
ax.push_back(x_last);
out << right << setw(20) << x_last << right << setw(20) <<
y1 << right << setw(20) << y2 << endl;
cout << right << setw(20) << x_last << right << setw(20) <<
y1 << right << setw(20) << y2 << endl;
cout << "This loop was also executed" << endl;
}

//cin.get();

_getch();

cout << "Y1" << endl;


out << endl << "Y1" << endl;

if (remf > 0)
{
condition = rem + 1;
}
else if (remf == 0)
{
condition = rem;
}

for (int i = 0; i <= condition; i++)


{
out << ay1[i] << endl;
cout << ay1[i] << endl;
}

cout << "-Y1" << endl;


out << endl << "-Y1" << endl;

conditionint = (int)condition;

for (int i = 0; i <= condition; i++)


{
out << ay1[conditionint - i] << endl;
cout << ay1[conditionint - i] << endl;
}

//cin.get();
_getch();
cout << endl;
cout << "Y2" << endl;
out << endl << "Y2" << endl;
for (int i = 0; i <= condition; i++)
{
out << ay2[i] << endl;
cout << ay2[i] << endl;
}

_getch();

cout << endl;


cout << "X" << endl;
out << endl << "X" << endl;
for (int i = 0; i <= condition; i++)
{
cout << ax[i] << endl;
out << ax[i] << endl;
}

cout << "-X" << endl;


out << endl << "-X" << endl;

for (int i = 0; i <= condition; i++)


{
out << ax[conditionint - i] << endl;
cout << ax[conditionint - i] << endl;
}

out.close();
out.clear();
if (ch == 'n' || ch == 'N')
{
cout << "Plot points written in " << sys_stab_file << ".dat
file" << endl;
}

else if (ch == 'y' || ch == 'Y')


{
cout << "Plot points written in " << sys_cir_file << ".dat
file" << endl;
}
_getch();
rec1 += 1;
}
else if (ch == 'y' || ch == 'Y')
{
cout << "Exiting the loop (Press any key)" << endl;
_getch();
break;
}
else
{
cout << "You entered the wrong choice...Please choose yes (y) or
no (n)" << endl;
rec1 = 0;
}
}

while (rec2 == 0)
{
cout << "Do you wish to plot LOR impedances (y/n)" << endl;
cin >> ch;

ofstream lout;
if (flag == 0)
{
filepath = "undefined";
}
status = lor_rx_points(ch, flag, filepath, lout);

if (status == 0)
{
cout << "LOR impedance plotting skipped..." << endl;
rec2 += 1;
}
else if (status == 1)
{
cout << "LOR impedance plotting performed" << endl;
rec2 += 1;
}
else if (status == 2)
{
cout << "Please choose between yes or no (y/n)" << endl;
rec = 0;
}
else
{
cout << "Error in LOR impedance plotting procedure" << endl;
rec2 += 1;
}
}

_getch();

void folder_creation(string file)


{

int status;
status = _mkdir((file).c_str());
if (status == 0)
cout << "Directory created successfully" << endl;
else
{
cout << "Directory already present....putting all files in that
directory" << endl;
}
}

int lor_rx_points(char a, int f, string path, ofstream& lt)


{
if (a == 'n' || a == 'N')
return 0;

else if (a == 'y' || a == 'Y')


{
double zc, zr, x1, x2, step_x, x, y1, y2, delta, rem, remf, remi,
condition = 0, itn = 0;
string lor_file;
vector<double>ay1;
vector<double>ay2;
vector<double>ax;

if (f != 1)
{
string folder, folder1, filepath;
cout << "Enter the folder name" << endl;
cin >> folder;
folder1 = "C:/Users/kbanerjee/Documents/Visual Studio
2019/Steady_State_Stability"; //Change when executing in different machine
filepath = folder1 + "/" + folder; //Change when executing in
different machine
path = filepath;
folder_creation(filepath);
}

else if (f == 1)
{
cout << "Putting lor files in the folder which was created for
system stability calc" << endl;
// cout << filepath;
}

cout << "Enter the name of the LOR points file to store" << endl;
cin >> lor_file;
cout << "Opening " << lor_file << ".dat file" << endl;
lt.open((path + '/' + lor_file + ".dat").c_str());
if (!lt)
{
cout << "cannot open file" << endl;
_getch();
exit(1);
}

cout << "Enter the Zone center and radius in ohms" << endl;
cin >> zc >> zr;
x1 = -zr;
x2 = zr;
cout << "Enter the step" << endl;
cin >> step_x;
x = x1;
cout << "Processing...." << endl;
lt << "Plotting LOR points in ohms with a step of " << step_x << "
ohms" << endl;
lt << right << setw(20) << "X" << right << setw(20) << "Y1" << right <<
setw(20) << "Y2" << endl;
cout << "Plotting LOR points in ohms with a step of " << step_x << "
ohms" << endl;
cout << right << setw(20) << "X" << right << setw(20) << "Y1" << right
<< setw(20) << "Y2" << endl;
while (x <= x2)
{
y1 = zc + pow(((zr + x) * (zr - x)), 0.5);
y2 = zc - pow(((zr + x) * (zr - x)), 0.5);
ay1.push_back(y1);
ay2.push_back(y2);
ax.push_back(x);
lt << right << setw(20) << x << right << setw(20) << y1 << right
<< setw(20) << y2 << endl;
cout << right << setw(20) << x << right << setw(20) << y1 <<
right << setw(20) << y2 << endl;
x += step_x;
itn = itn + 1;
// cout << "X = " << x << endl;
}
cout << "x = " << x << endl;
delta = x2 - x1;
rem = delta / step_x;
cout << "rem = " << rem << endl;
remf = modf(rem, &remi);

if (remf > 0)
{
y1 = zc + pow(((zr + x2) * (zr - x2)), 0.5);
y2 = zc - pow(((zr + x2) * (zr - x2)), 0.5);
ay1.push_back(y1);
ay2.push_back(y2);
ax.push_back(x2);
lt << right << setw(20) << x2 << right << setw(20) << y1 << right
<< setw(20) << y2 << endl;
cout << right << setw(20) << x2 << right << setw(20) << y1 <<
right << setw(20) << y2 << endl;
itn = itn + 1;
cout << "This loop was also executed" << endl;
}
cout << "remf =" << remf << endl;
cout << "Iterations = " << itn << endl;

_getch();

lt << endl << "Y1" << endl;


cout << "Y1" << endl;
// if (remf > 0)
// {
// condition = rem + 1;
// }
// else if (remf == 0)
// {
// condition = rem;
// }

for (int i = 0; i <= itn-1; i++)


{
lt << ay1[i] << endl;
cout << ay1[i] << endl;
}

//cin.get();
_getch();
lt << endl << "Y2" << endl;
cout << endl;
cout << "Y2" << endl;
for (int i = 0; i <= itn-1; i++)
{
lt << ay2[i] << endl;
cout << ay2[i] << endl;
}

_getch();

lt << endl << "-Y2" << endl;


cout << endl;
cout << "-Y2" << endl;
for (int i = 0; i <= itn - 1; i++)
{
lt << ay2[itn - 1 - i] << endl;
cout << ay2[itn - 1 - i] << endl;
}

_getch();

lt << endl << "X" << endl;


cout << endl;
cout << "X" << endl;
for (int i = 0; i <= itn-1; i++)
{
lt << ax[i] << endl;
cout << ax[i] << endl;
}

lt << endl << "-X" << endl;


cout << endl;
cout << "-X" << endl;
for (int i = 0; i <= itn-1; i++)
{
lt << ax[itn-1-i] << endl;
cout << ax[itn-1-i] << endl;
}

lt.close();
lt.clear();
cout << "Plot points written in " << lor_file << ".dat file" << endl;
_getch();
return 1;
}
else
{
// cout << "You entered the wrong choice...Please choose yes (y) or no
(n)" << endl;
return 2;
}
}

You might also like