Steady State Stability
Steady State Stability
#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 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;
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;
}
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();
if (remf > 0)
{
condition = rem + 1;
}
else if (remf == 0)
{
condition = rem;
}
conditionint = (int)condition;
//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();
out.close();
out.clear();
if (ch == 'n' || ch == 'N')
{
cout << "Plot points written in " << sys_stab_file << ".dat
file" << endl;
}
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();
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;
}
}
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();
//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();
_getch();
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;
}
}