You are on page 1of 21

#include<iostream>

#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<fstream>
#include<vector>
#include<string>
#include<stdio.h>
#include<time.h>
#define PI 3.14159265358979
using namespace std;
double weather(double a, double b, double c);
double wind(double a, double b, double c);
double integer_extractor(double a);
double air_density(double a, double b, double c);
double natural_convection(double a, double b, double c, double e);
double dynamic_viscosity(double a);
double thermal_cond(double a);
double wind_direction(double a);
double forced_convc(double a, double b, double c, double d, double e, double f,
double g, double h);
double select_lfc(double a, double b);
double rad_heat(double a, double b, double c, double d);
double sol_heat_gain(double a, double b, double c, double d, double e, double f);
double cond_resist(double a, double b, double c, double d, double e);
double steady_current(double a, double b, double c, double d);
double sagging_impact(double theta, double CLF, double htF, double EasF, double
careaF, double alpha_asF, double iutF, double span_lF, double wpulF);
vector<double>strength_impact(double theta, double htF, string cond_nameF,
vector<double>&condt);

const string currentDateTime()


{
time_t now = time(0);
struct tm tstruct;
char buf[80];
// tstruct = *localtime(&now);
localtime_s(&tstruct, &now);
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return buf;
}

void main()
{
double
mu_a,mu_w,sigma_a,sigma_w,theta,v_w,theta_l,theta_h,v_w_h,v_w_l,pa,pw,alpha,gamma_x
,beta,x,theta_L,theta_H,Pz;
double theta_li,theta_hi,v_w_li,v_w_hi,v_w_L,v_w_H;
double v_speed,He,em,ab,T_amb,T_max,lat,dia,pf,uf,kf,kangle,qr,qcn,phi;
double qc,sol_hr,N_day,T_flim,qc_f,I_op,T_guess;
double qs,T_high,T_low,R_max,I_max,R_low,R_high;
double
condtemp,ctwo,cthree,cfour,/*contemp,max,min*/pz,x_temp,range_amb,range_wv,r;
double x_pz; // from edit.cpp
double
span_l,wpul,ht,iut,carea,/*carg,*/sag,CL,Eal,Est,Aal,Ast,alpha_al,alpha_st,min_clr,
sm,Eas,alpha_as,iutc,thetamdt,design_sag; //sag variables
double Ifault, sag_file; // sag variables
double risk; // Global variables
double z,s;
int count,flag,check,/*p,*/p_zero;
string ambfile,windfile,temppdf,finalpdf;
string cond_name; // from strength impact file
vector<double> condt;
vector<double> col;
vector<double> ambt;
vector<double> windv;
vector<double>temp;
vector<double>PDF;
vector<double>strength1;
vector<double>sagimpact;
// char ch;
cout<<"Enter the mean of air temperature distribution"<<endl;
cin>>mu_a;
cout<<"Enter the standard deviation of air temperature distribution"<<endl;
cin>>sigma_a;
// cout<<"Enter the lower bound for air temperature"<<endl;
// cin>>theta_l;
// cout<<"Enter the upper bound for air temperature"<<endl;
// cin>>theta_h;
cout<<"Enter the mean of wind velocity distribution"<<endl;
cin>>mu_w;
cout<<"Enter the standard deviation of wind velocity distribution"<<endl;
cin>>sigma_w;
cout<<"Enter the lower bound for wind velocity"<<endl;
cin>>v_w_L;
if (v_w_L < 0)
{
cout<<"You can enter only positive values including 0"<<endl;
cout<<"Please enter lower bound for wind velocity again"<<endl;
cin>>v_w_L;
if(v_w_L < 0)
{
cout<<"Error restart the program"<<endl;
_getch();
exit (1);
}
}
cout<<"Enter the upper bound for wind velocity"<<endl;
cin>>v_w_H;
if (v_w_H < v_w_L)
{
cout<<"You upper bound is lower than the lower bound for wind
velocity"<<endl;
cout<<"Please enter upper bound for wind velocity again"<<endl;
cin>>v_w_H;
if(v_w_H < v_w_L)
{
cout<<"Error restart the program"<<endl;
_getch();
exit (1);
}
}

// Opening files

cout<<"Enter the filename for storing ambient temperature pdf"<<endl;


cin>>ambfile;
cout<<"Enter the filename for storing wind velocity pdf"<<endl;
cin>>windfile;
cout<<"Enter the filename for storing raw data for conductor temp pdf"<<endl;
cin>>temppdf;

ofstream out;
out.open((ambfile+".dat").c_str());
if(!out)
{
cout<<"Cannot open file"<<endl;
exit(1);
}

ofstream file((windfile+".dat").c_str());
if(!file)
{
cout<<"Cannot open file"<<endl;
exit(1);
}

ofstream fout((temppdf+".dat").c_str());
if(!fout)
{
cout<<"Cannot open file"<<endl;
exit(1);
}

// Air temperture distribution calculation and Wind distribution calculation


// calculating shape parameters

theta_L = mu_a-(4*sigma_a);
theta_H = mu_a+(4*sigma_a);
theta_li = integer_extractor(theta_L);
theta_hi = integer_extractor(theta_H);
if((theta_L-theta_li)<=0.5)
theta_l = theta_li;
else
theta_l = theta_li+1;
if((theta_H-theta_hi)<=0.5)
theta_h = theta_hi;
else
theta_h = theta_hi+1;
v_w_li = integer_extractor(v_w_L);
v_w_hi = integer_extractor(v_w_H);
if((v_w_L-v_w_li)<=0.5)
v_w_l = v_w_li;
else
v_w_l = v_w_li+1;
if((v_w_H-v_w_hi)<=0.5)
v_w_h = v_w_hi;
else
v_w_h = v_w_hi+1;
// theta = theta_l;
alpha = pow((0.9874/(sigma_w/mu_w)),1.0983);
x = 1+(1/alpha);
gamma_x = 0.1693*pow(x,4)-1.1495*pow(x,3)+3.3005*pow(x,2)-4.393*x+3.0726;
beta = mu_w/gamma_x;
// v_w = v_w_l;
flag = 0;
// p = 0;

// cout<<"Enter wind speed (m/s)"<<endl;


// cin>>v_speed;
cout<<"Enter Elevation (m)"<<endl;
cin>>He;
cout<<"Enter emissivity"<<endl;
cin>>em;
cout<<"Enter absorptivity"<<endl;
cin>>ab;
// cout<<"Enter ambient temperature (Celsius)"<<endl;
// cin>>T_amb;
cout<<"Enter operating current (A)"<<endl;
cin>>I_op;
T_max = 100;
// T_guess = T_max;
cout<<"Enter latitude"<<endl;
cin>>lat;
cout<<"Enter conductor diameter (mm)"<<endl;
cin>>dia;
cout<<"Enter the angle between the wind direction and the conductor
axis"<<endl;
cin>>phi;
cout<<"Enter the day number"<<endl;
cin>>N_day;
cout<<"Enter the solar hour (24hr format)"<<endl;
cin>>sol_hr;
cout<<"Enter the low temperature"<<endl;
cin>>T_low;
cout<<"Enter the high temperature"<<endl;
cin>>T_high;
cout<<"Enter the resistance at low temp (ohm/mile)"<<endl;
cin>>R_low;
cout<<"Enter the resistance at high temp (ohm/mile)"<<endl;
cin>>R_high;

cout<<"Creating your files...."<<endl;

out<<"PDF Ambient Temperature"<<endl;


file<<"PDF Wind Velocity"<<endl;
fout<<"Conductor Temp P(z) Ambient Temp Wind Velocity"<<endl;

cout << "currentDateTime()=" << currentDateTime() << endl;


getchar();

// Executing loops

for(theta=theta_l; theta<=theta_h; )
{
pa = weather(mu_a,sigma_a,theta);
out<<pa<<" "<<theta<<endl;
check = 0;
if(flag > 0)
T_max = T_guess;
for(v_w=v_w_l; v_w<=v_w_h; )
{
pw = wind(alpha,beta,v_w);
if (flag == 0)
file<<pw<<" "<<v_w<<endl;
// cout<<flag<<" "<<v_w<<endl;
T_amb = theta;
count = 0;
do
{
v_speed = v_w*0.3048;
T_flim = (T_max+T_amb)/2;
pf = air_density(T_amb,T_max,He);
qcn = natural_convection(T_amb,T_max,pf,dia);
uf = dynamic_viscosity(T_flim);
kf = thermal_cond(T_flim);
kangle = wind_direction(phi);
qc_f =
forced_convc(dia,pf,v_speed,uf,kf,kangle,T_max,T_amb);
qc = select_lfc(qc_f,qcn);
qr = rad_heat(dia,em,T_max,T_amb);
qs = sol_heat_gain(dia,N_day,sol_hr,lat,He,ab);
R_max = cond_resist(R_high,R_low,T_high,T_low,T_max);
I_max = steady_current(qc,qr,qs,R_max);
if((I_max-I_op)<=0)
T_max+=0.1;
else if((I_max-I_op)>=0)
T_max+=-0.1;
count += 1;
if(count>20000)
break;
}while(abs(I_max-I_op)>=0.5);
Pz = pa*pw;
fout<<T_max<<" "<<Pz<<" "<<theta<<" "<<v_w<<endl;
if(check == 0)
T_guess = T_max;
check = check+1;
v_w = v_w+0.1;
}
s = v_w;
if(s == v_w_h)
{
count = 0;
pw = wind(alpha,beta,v_w);
file<<pw<<" "<<v_w<<endl;
do
{
v_speed = v_w_h*0.3048;
T_flim = (T_max+T_amb)/2;
pf = air_density(T_amb,T_max,He);
qcn = natural_convection(T_amb,T_max,pf,dia);
uf = dynamic_viscosity(T_flim);
kf = thermal_cond(T_flim);
kangle = wind_direction(phi);
qc_f =
forced_convc(dia,pf,v_speed,uf,kf,kangle,T_max,T_amb);
qc = select_lfc(qc_f,qcn);
qr = rad_heat(dia,em,T_max,T_amb);
qs = sol_heat_gain(dia,N_day,sol_hr,lat,He,ab);
R_max = cond_resist(R_high,R_low,T_high,T_low,T_max);
I_max = steady_current(qc,qr,qs,R_max);
if((I_max-I_op)<=0)
T_max+=0.1;
else if((I_max-I_op)>=0)
T_max+=-0.1;
count += 1;
if(count>20000)
break;
}while(abs(I_max-I_op)>=0.5);
Pz = pa*pw;
fout<<T_max<<" "<<Pz<<" "<<theta<<" "<<v_w_h<<endl;
// cout<<theta<<" "<<s<<endl;
}
theta = theta+0.1;
// v_w = v_w_l;
flag = flag+1;
}
z = theta;
// cout<<"z = "<<z<<endl;
if(z == theta_h)
{
pa = weather(mu_a,sigma_a,theta);
out<<pa<<" "<<theta<<endl;
T_max = T_guess;
for(v_w=v_w_l; v_w<=v_w_h; )
{
pw = wind(alpha,beta,v_w);
// file<<pw<<" "<<v_w<<endl;
T_amb = theta_h;
count = 0;
do
{
v_speed = v_w*0.3048;
T_flim = (T_max+T_amb)/2;
pf = air_density(T_amb,T_max,He);
qcn = natural_convection(T_amb,T_max,pf,dia);
uf = dynamic_viscosity(T_flim);
kf = thermal_cond(T_flim);
kangle = wind_direction(phi);
qc_f =
forced_convc(dia,pf,v_speed,uf,kf,kangle,T_max,T_amb);
qc = select_lfc(qc_f,qcn);
qr = rad_heat(dia,em,T_max,T_amb);
qs = sol_heat_gain(dia,N_day,sol_hr,lat,He,ab);
R_max = cond_resist(R_high,R_low,T_high,T_low,T_max);
I_max = steady_current(qc,qr,qs,R_max);
if((I_max-I_op)<=0)
T_max+=0.1;
else if((I_max-I_op)>=0)
T_max+=-0.1;
count += 1;
if(count>20000)
break;
}while(abs(I_max-I_op)>=0.5);
Pz = pa*pw;
fout<<T_max<<" "<<Pz<<" "<<theta_h<<" "<<v_w<<endl;
v_w = v_w+0.1;
// p = p+1;
// cout<<z<<" "<<v_w<<endl;
// v_w = v_w+0.1;
// cout<<"v_w = "<<v_w<<endl;
}
if(s == v_w_h)
{
count = 0;
pw = wind(alpha,beta,v_w);
file<<pw<<" "<<v_w<<endl;
do
{
v_speed = v_w_h*0.3048;
T_flim = (T_max+T_amb)/2;
pf = air_density(T_amb,T_max,He);
qcn = natural_convection(T_amb,T_max,pf,dia);
uf = dynamic_viscosity(T_flim);
kf = thermal_cond(T_flim);
kangle = wind_direction(phi);
qc_f =
forced_convc(dia,pf,v_speed,uf,kf,kangle,T_max,T_amb);
qc = select_lfc(qc_f,qcn);
qr = rad_heat(dia,em,T_max,T_amb);
qs = sol_heat_gain(dia,N_day,sol_hr,lat,He,ab);
R_max = cond_resist(R_high,R_low,T_high,T_low,T_max);
I_max = steady_current(qc,qr,qs,R_max);
if((I_max-I_op)<=0)
T_max+=0.1;
else if((I_max-I_op)>=0)
T_max+=-0.1;
count += 1;
if(count>20000)
break;
}while(abs(I_max-I_op)>=0.5);
Pz = pa*pw;
fout<<T_max<<" "<<Pz<<" "<<theta_h<<" "<<v_w_h<<endl;
// cout<<theta<<" "<<s<<endl;
}
}

out.close();
out.clear();
fout.close();
fout.clear();
file.close();
file.clear();
cout<<"Files created successfully"<<endl;

cout << "currentDateTime()=" << currentDateTime() << endl;


// getchar();

// Adding probability distribution functions

range_amb = theta_h - theta_l;


range_wv = v_w_h - v_w_l;
r = (((10*range_amb)+1)*((10*range_wv)+1));
// r = 11;
ifstream ind;
ind.open((temppdf+".dat").c_str());
if(!ind)
{
cout<<"File could not be opened"<<endl;
exit(1);
}
for(int i=1; i<=(r+1); i++)
{
if(i<2)
{
ind.ignore(256,'\n');
}
else
{
ind>>condtemp;
condt.push_back(condtemp);
ind>>ctwo;
col.push_back(ctwo);
ind>>cthree;
// ambt.push_back(cthree);
ind>>cfour;
// windv.push_back(cfour);
}
}
ind.close();
ind.clear();

// for(size_t i=0; i<condt.size(); i++)


// {
// cout<<"Element in condt and col"<<endl;
// cout<<condt[i]<<" "<<col[i]<<endl;
// }

cout<<"Press Enter";
_getch();

p_zero = 0;
for(size_t i=0; i<(condt.size()-1); i++)
{
pz = col[i];
if(condt[i] != 0)
{
flag = 0;
for(size_t j=i+1; j<condt.size(); j++)
{
if(condt[i] == condt[j])
{
pz = pz+col[j];
x_temp = condt[j];
p_zero = p_zero+1;
condt[j] = 0;
flag = flag+1;
}
else if (flag == 0)
{
x_temp = condt[i];
pz = col[i];
}
}
temp.push_back(x_temp);
PDF.push_back(pz);
}
}
cout<<"Adding probabilities done"<<endl;
// Sorting - Insertion Sort

// cout<<"Element in condt and col after adding probabilities"<<endl;


// for(size_t i=0; i<condt.size(); i++)
// {
// cout<<condt[i]<<" "<<col[i]<<endl;
// }

// cout<<"Element in temp and PDF after adding probability"<<endl;


// for(int i=0; i<(r-p_zero); i++)
// {
// cout<<temp[i]<<" "<<PDF[i]<<endl;
// }

condt.clear();
col.clear();
_getch();

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


{
if(temp[i+1]<temp[i])
{
x_temp = temp[i];
x_pz = PDF[i];
temp[i] = temp[i+1];
PDF[i] = PDF[i+1];
temp[i+1] = x_temp;
PDF[i+1] = x_pz;
for(int j=i; j>0; j--)
{
if(temp[j]<temp[j-1])
{
x_temp = temp[j-1];
x_pz = PDF[j-1];
temp[j-1] = temp[j];
PDF[j-1] = PDF[j];
temp[j] = x_temp;
PDF[j] = x_pz;
}
}
}
}

cout<<"Sorting done"<<endl;

// cout<<"Element in temp and PDF after sorting"<<endl;


// for(int i=0; i<(r-p_zero); i++)
// {
// cout<<condt[i]<<" "<<col[i]<<endl;
// }

_getch();

cout<<"Enter the name of the conductor temperature pdf file"<<endl;


cin>>finalpdf;
cout<<"Opening "<<finalpdf<<".dat file"<<endl;
out.open((finalpdf+".dat").c_str());
if(!out)
{
cout<<"cannot open file"<<endl;
_getch();
exit(1);
}
out<<"Conductor Temperature PDF"<<endl;
for(int i=0; i<(r-p_zero); i++)
out<<temp[i]<<" "<<PDF[i]<<endl;
cout<<"Written successfully"<<endl;
cout<<"program done"<<endl;
out.close();
out.clear();

// ---------------------------Sagging and strength impact


models----------------------------------

cout<<"Enter span length, ft"<<endl;


cin>>span_l;
cout<<"Enter weight per unit lenght, lb/ft"<<endl;
cin>>wpul;
cout<<"Enter final unloaded horizontal tension, lbs"<<endl;
cin>>ht;
cout<<"Enter final unloaded temperature, F"<<endl;
cin>>iut;
cout<<"enter area of the conductor, square inch"<<endl;
cin>>carea;
cout<<"Enter elastic modulus of aluminium, psi"<<endl;
cin>>Eal;
cout<<"Enter elastic modulus of core, psi"<<endl;
cin>>Est;
cout<<"Enter area of aluminium strands, sqaure inch"<<endl;
cin>>Aal;
cout<<"Enter area of core part, square inch"<<endl;
cin>>Ast;
cout<<"Enter coefficient of thermal expansion of aluminium /F"<<endl;
cin>>alpha_al;
cout<<"Enter coefficient of thermal expansion of core /F"<<endl;
cin>>alpha_st;
cout<<"Enter design temperature"<<endl;
cin>>thetamdt;
cout<<"Enter minimum clearance to ground and safety margin (ft)"<<endl;
cin>>min_clr>>sm;

// cout<<"Enter the temp range"<<endl;


// cin>>theta_l>>theta_h;
// cout<<"Enter the wind range"<<endl;
// cin>>v_w_l>>v_w_h;

r = 12;
// range_amb = theta_h - theta_l;
// range_wv = v_w_h - v_w_l;
// r = (((10*range_amb)+1)*((10*range_wv)+1));

// Sag and Lenght calculations at final unloaded temperature

// carg = (wpul*span_l)/(2*ht);
// sag = (ht/wpul)*(cosh(carg)-1);
sag = (wpul*pow(span_l,2))/(8*ht);
CL = span_l+((8*pow(sag,2))/(3*span_l));
iutc = 5*((iut-32)/9);

// Calculations of Elastic modulus and coefficient of thermal expansion of


conductor

Eas = Eal*(Aal/carea)+Est*(Ast/carea);
alpha_as = alpha_al*(Eal/Eas)*(Aal/carea)+alpha_st*(Est/Eas)*(Ast/carea);
cout<<"alpha_as "<<alpha_as<<endl;

// Opening the file to work with

cout<<"Opening file "<<finalpdf<<".dat ...."<<endl;


ind.open((finalpdf+".dat").c_str());
if(!ind)
{
cout<<"File could not be opened"<<endl;
_getch();
exit(1);
}
for(int i=1; i<=(r+1); i++)
{
if(i<2)
{
ind.ignore(256,'\n');
}
else
{
ind>>condtemp;
condt.push_back(condtemp);
ind>>ctwo;
col.push_back(ctwo);
// ind>>cthree;
// ambt.push_back(cthree);
// ind>>cfour;
// windv.push_back(cfour);
}
}
ind.close();
ind.clear();
cout<<"operation on "<<temppdf<<".dat successful"<<endl;

// Finding out sag for theta mdt

design_sag =
sagging_impact(thetamdt,CL,ht,Eas,carea,alpha_as,iut,span_l,wpul);

// Finding sag for other temps

/* cout<<"Enter the filename for storing ambient temperature pdf with sagging
impact info"<<endl;
cin>>ambfile;
ofstream out((ambfile+".dat").c_str());
if(!out)
{
cout<<"Cannot open file"<<endl;
exit(1);
}
out<<"Cond temp Pz I(fault)"<<endl; */
for(size_t i=0; i<condt.size(); i++)
{
if(condt[i]>iutc)
{
sag_file =
sagging_impact(condt[i],CL,ht,Eas,carea,alpha_as,iut,span_l,wpul);
if(sag_file>=(design_sag+sm))
{
Ifault = 100;
sagimpact.push_back(Ifault);
}
else
{
Ifault = 0;
sagimpact.push_back(Ifault);
}
}
else
{
Ifault = 0;
sagimpact.push_back(Ifault);
}
}
// out.close();
cout<<"Sagging impact done"<<endl;
_getch();

// Strength impact calculations

cout<<"Enter ACSR or ACCR or ACCC"<<endl;


cin>>cond_name;
/* cout<<"Enter design temperature"<<endl;
cin>>thetamdt;
cout<<"Enter the final unloaded horizontal tension"<<endl;
cin>>ht; */

strength1 = strength_impact(thetamdt,ht,cond_name,condt);
cout<<"Strength impact done"<<endl;

// Adding the impacts to find risk

cout<<"Size of strength vector: "<<strength1.size()<<endl;


cout<<"Size of condt vector: "<<condt.size()<<endl;
cout<<"Size of col vector: "<<col.size()<<endl;
cout<<"Size of ambt vector: "<<sagimpact.size()<<endl;
_getch();

cout<<"Enter the file to store the risk information"<<endl; //opening file


to store results
cin>>ambfile;
out.open((ambfile+".dat").c_str());
if(!out)
{
cout<<"Cannot open file"<<endl;
exit(1);
_getch();
}
out<<"Conductor Temp Pz Ifault Ianneal"<<endl;
risk = 0;
for(size_t i = 0; i<condt.size(); i++)
{
if(condt[i]>thetamdt)
risk = risk + (col[i]*(sagimpact[i]+strength1[i]));
out<<condt[i]<<" "<<col[i]<<" "<<sagimpact[i]<<" "<<strength1[i]<<endl;
}
out<<I_op<<" "<<risk;
out.close();
out.clear();
cout<<"Risk at this current level is: "<<risk;

_getch();
}

//functions for air temperature distributions and wind velocity distributions

double weather (double a, double b, double c)


{
double p,sigma2,exp2;
sigma2 = pow(b,2);
exp2 = pow((c-a),2);
p = (1/pow((2*PI*sigma2),0.5))*exp(-(exp2/(2*sigma2)));
return p;
}

double wind (double a, double b, double c)


{
double p1;
p1 = ((a/pow(b,a))*pow(c,a-1)*exp(-(pow((c/b),a))));
return p1;
}

double integer_extractor(double a)
{
double fpart, ipart;
fpart = modf(a, &ipart);
return ipart;
}

// Natural convection heat loss


double air_density(double a, double b, double c)
{
double A,D,d,e;
double B,C;
d = (a+b)/2;
A = 1.293;
B = 1.525*pow(10,-4);
C = 6.379*pow(10,-9);
D = 0.00367;
e = (A-(B*c)+(C*pow(c,2)))/(1+(D*d));
return e;
}

double natural_convection(double a, double b, double c, double e)


{
double E,d;
E = 0.0205;
d = E*pow(c,0.5)*pow(e,0.75)*pow((b-a),1.25);
return d;
}

// Forced convection heat loss


double dynamic_viscosity(double a)
{
double b;
double F;
F = 1.458*pow(10,-6);
b = (F*pow((a+273),1.5))/(a+383.4);
return b;
}

double thermal_cond(double a)
{
double G,b;
double H,I;
G = 0.02424;
H = 7.477*pow(10,-5);
I = 4.407*pow(10,-9);
b = G+(H*a)-(I*pow(a,2));
return b;
}

double wind_direction(double a)
{
double phir,b;
phir = a*(PI/180);
b = 1.194-cos(phir)+0.194*cos(2*phir)+0.368*sin(2*phir);
return b;
}

double forced_convc(double a, double b, double c, double d, double e, double


f, double g, double h)
{
double qc12,qc1,qc2;
qc1 = (1.01+(0.0372*pow((a*b*c)/d,0.52)))*e*f*(g-h);
qc2 = (0.0119*pow(((a*b*c)/d),0.6)*e*f*(g-h));
if(qc1>=qc2)
{
qc12=qc1;
return qc12;
}
else
{
qc12=qc2;
return qc12;
}
}

// Selection of larger of the convection heat loss


double select_lfc(double a, double b)
{
double c;
if (a>=b)
{
c = a;
return c;
}
else
{
c = b;
return c;
}
}

// Radiated heat loss


double rad_heat(double a, double b, double c, double d)
{
double e;
e = 0.0178*a*b*(pow((c+273)/100,4)-pow((d+273)/100,4));
return e;
}

// Solar heat gain


double sol_heat_gain(double a, double b, double c, double d, double e, double
f)
{
double
A_pro,del_arg,del_argr,del,w,latr,delr,Hc,Hc_deg,J,K,L,Qs,ksolar,Qse,g;
double M,N,O,P,Q,R;
A_pro = a/1000;
del_arg = ((284+b)/365)*360;
del_argr = del_arg*(PI/180);
del = 23.4583*sin(del_argr);
w = (c-12)*15*(PI/180);
latr = d*(PI/180);
delr = del*(PI/180);
Hc = asin((cos(latr)*cos(delr)*cos(w))+(sin(latr)*sin(delr)));
Hc_deg = Hc*(180/PI);
J = -42.2391;
K = 63.8044;
L = -1.9220;
M = 3.46921*pow(10,-2);
N = -3.61118*pow(10,-4);
O = 1.94318*pow(10,-6);
P = -4.07608*pow(10,-9);

Qs = J+(K*Hc_deg)+(L*pow(Hc_deg,2))+(M*pow(Hc_deg,3))+(N*pow(Hc_deg,4))
+(O*pow(Hc_deg,5))+(P*pow(Hc_deg,6)); //heat flux recieved at the sea level

Q = 1.148*pow(10,-4);
R = -1.108*pow(10,-8);
ksolar = 1+(Q*e)+(R*pow(e,2));
Qse = ksolar*Qs; //heat flux corrected for elevation

g = f*Qse*A_pro;
return g;
}

// Conductor electrical resistance


double cond_resist(double a, double b, double c, double d, double e)
{
double f;
f = ((((a-b)/1609.34)/(c-d))*(e-d))+(b/1609.34);
return f;
}

// Steady state heat balance


double steady_current(double a, double b, double c, double d)
{
double HR,e;
HR = (a+b-c)/d;
if(HR < 0)
{
HR = 0;
return HR;
}
else
{
e = pow(HR,0.5);
return e;
}
}

// Sagging impact model for the conductors

double sagging_impact(double theta, double CLF, double htF, double EasF, double
careaF, double alpha_asF, double iutF, double span_lF, double wpulF)
{
double x_temp,ZTLi,ZTLh,L_high,D_high,H_high,ZTD,ZTH,Lh[100],D[100],H[100];
x_temp = ((theta/5)*9)+32;
ZTLi = CLF*(1+(-htF/(EasF*careaF)));
ZTLh = ZTLi*(1+(alpha_asF*(x_temp-iutF)));
if (ZTLh<span_lF)
{
L_high = CLF*(1+(alpha_asF*(x_temp-iutF)));
D_high = sqrt((3*span_lF*(L_high-span_lF))/8);
H_high = ((wpulF*pow(span_lF,2))/8*D_high);
if(D_high>(0.05*span_lF))
D_high = D_high+((pow(D_high,2)*wpulF)/(6*H_high));
return D_high;
}
else
{
ZTD = sqrt((3*span_lF*(ZTLh-span_lF))/8);
ZTH = (wpulF*pow(span_lF,2))/(8*ZTD);
int ar=0;
Lh[0] = ZTLh*(1+(ZTH/(EasF*careaF)));
D[0] = sqrt((3*span_lF*(Lh[0]-span_lF))/8);
H[0] = (wpulF*pow(span_lF,2))/(8*D[0]);
H[0] = (H[0]+ZTH)/2;
do
{
ar = ar+1;
Lh[ar] = ZTLh*(1+(H[ar-1]/(EasF*careaF)));
D[ar] = sqrt((3*span_lF*(Lh[ar-1]-span_lF))/8);
H[ar] = (wpulF*pow(span_lF,2))/(8*D[ar-1]);
H_high = H[ar];
H[ar] = (H[ar]+H[ar-1])/2;
} while((Lh[ar-1]-Lh[ar])>=0.01);
if(D[ar]>(0.05*span_lF))
D[ar] = D[ar]+((pow(D[ar],2)*wpulF)/(6*H_high));
return D[ar];
}
}

// Strength impact function for ACSR, ACCR and ACCC

vector<double>strength_impact(double theta, double htF, string cond_nameF,


vector<double>&condt)
{
double
ten_cond,Dw,W,A,B,C,D,AB,t,delt,tmdt,I_anneal,ER,k,accc_st,accc_ust,w,ht_accc; //
strength variables
double X,Y; // strength variables
string acsr,accr,accc;
char ch;
vector<double>strength;
acsr = "ACSR";
accr = "ACCR";
accc = "ACCC";

// ACSR strength impact model works only for design temperature of 100 or
above

if(cond_nameF == acsr)
{
cout<<"Enter the tensile strength of the conductor, lbs"<<endl;
cin>>ten_cond;
cout<<"Enter the diameter of the conductor wire, mm"<<endl;
cin>>Dw;
cout<<"Aluminium(A) or aluminium alloy(L)?"<<endl;
cin>>ch;
W = 100*((ten_cond-htF)/ten_cond);
cout<<W<<endl;
if(ch == 'A')
{
do
{
A = 134;
B = -0.24;
C = 0.241;
D = -0.00254;
AB = A+(B*theta);
cout<<"AB "<<AB<<endl;
if(AB > 100)
AB = 100;
cout<<"AB "<<AB<<endl;
X = log((100-W)/AB)/((C+(D*theta))/Dw);
cout<<"X "<<X<<endl;
_getch();
if(X < 0)
{
cout<<"Error! Please enter a new design
temperature"<<endl;
cin>>theta;
}
}while(X < 0);
}
else if(ch =='L')
{
do
{
A = 176;
B = -0.52;
C = 0.3;
D = -0.00305;
AB = A+(B*theta);
if(AB > 100)
AB = 100;
X = (log((100-W)/AB))/((C+(D*theta))/Dw);
if(X < 0)
{
cout<<"Error! Please enter a new design
temperature"<<endl;
cin>>theta;
}
}while(X < 0);
}

for(size_t i = 0; i<condt.size(); i++)


{
if(condt[i]>theta)
{
AB = A+(B*condt[i]);
cout<<"AB"<<i<<" "<<AB<<endl;
if(AB > 100)
AB = 100;
Y = (log((100-W)/AB))/((C+(D*condt[i]))/Dw);
cout<<"Y"<<i<<" "<<Y<<endl;
delt = Y-X;
cout<<"delt"<<i<<" "<<delt<<endl;
I_anneal = 1-exp(delt);
cout<<"I_anneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"Strength"<<i<<" "<<strength[i]<<endl;
}
else
{
I_anneal = 0;
cout<<"I_anneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"Strength"<<i<<" "<<strength[i]<<endl;
}
}
return strength;
}

// ACCR strength impact model

else if(cond_nameF == accr)


{
ER = 25729;
A = 1.977e16;
k = A*(exp(-ER/(theta+273)));
tmdt = 1/k;
cout<<"tmdt "<<tmdt<<endl;
for(size_t i = 0; i<condt.size(); i++)
{
if(condt[i]>theta)
{
k = A*(exp(-ER/(condt[i]+273)));
t = 1/k;
cout<<"t"<<i<<" "<<t<<endl;
delt = tmdt-t;
I_anneal = delt/tmdt;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
if(condt[i] > 600)
I_anneal = 100;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
else
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
return strength;
}

// ACCC strength imapct model

else if(cond_nameF == accc)


{
cout<<"Enter the tensile strength of the conductor, kN"<<endl;
cin>>ten_cond;
ht_accc = 0.0044482216*htF;
W = 100*((ten_cond-ht_accc)/ten_cond);
cout<<"W "<<W<<endl;
accc_ust = 70;
for(size_t i = 0; i<condt.size(); i++)
{
cout<<"condt"<<i<<"="<<condt[i]<<endl;
}
_getch();
for(size_t i = 0; i<condt.size(); i++)
{
if(condt[i]>theta)
{
if(condt[i]<=110)
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
else if(condt[i]>110 && condt[i]<=200)
{
accc_st = (131.12+(condt[i]*(-5.0f/9)));
cout<<"accr_st"<<i<<" "<<accc_st<<endl;
w = ((accc_ust - accc_st)/accc_ust)*100;
cout<<"w"<<i<<" "<<w<<endl;
if(w >= W)
{
I_anneal = 100;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
else
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
else if(condt[i]>200 && condt[i]<=250)
{
if(W <= (500.0f/7))
{
I_anneal = 100;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
else
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
else if(condt[i]>250 && condt[i]<=300)
{
accc_st = (((-1.0f/5)*condt[i])+70);
w = ((accc_ust - accc_st)/accc_ust)*100;
cout<<"w"<<i<<" "<<w<<endl;
if(w >= W)
{
I_anneal = 100;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
else
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
else if(condt[i]>300)
{
I_anneal = 100;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
else
{
I_anneal = 0;
cout<<"Ianneal"<<i<<" "<<I_anneal<<endl;
strength.push_back(I_anneal);
cout<<"strength"<<i<<" "<<strength[i]<<endl;
}
}
return strength;
}
else
{
cout << "This option is wrong...exiting program" << endl;
_getch();
exit(0);
}
}

You might also like