Professional Documents
Culture Documents
#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);
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
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);
}
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;
// 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<<"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
condt.clear();
col.clear();
_getch();
cout<<"Sorting done"<<endl;
_getch();
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));
// 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);
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;
design_sag =
sagging_impact(thetamdt,CL,ht,Eas,carea,alpha_as,iut,span_l,wpul);
/* 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();
strength1 = strength_impact(thetamdt,ht,cond_name,condt);
cout<<"Strength impact done"<<endl;
_getch();
}
double integer_extractor(double a)
{
double fpart, ipart;
fpart = modf(a, &ipart);
return ipart;
}
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;
}
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;
}
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];
}
}
// 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);
}