📄 weights.c
字号:
#include <stdio.h>
#include <math.h>
/* w_mpt function */
void w_mpt (FILE *fp, double *rho,double *vel,double *Sw,double *Wfw,double *Nzult,double *Wdg,double *AR,double *L,double
*D,double *Wen,double *Nen,double *Bw,double *Np,double *Wstruct,double *Wlg,double *Wprop,double *Wequip,double *Wempty) {
/* Local Function Variable Declarations and Initializations */
/* baseline GA aircraft weights - Raymer(modified)
simplified estimates for level0 sizing */
double wsweep=0.;
double lambda=1.;
double toc=0.15;
double Sht=.2*(*Sw);
double htsweep=0.;
double httoc=0.15;
double htlambda=1.;
double htAR=.8*(*AR);
double Svt=.1*(*Sw);
double vtsweep=0.;
double vttoc=0.15;
double vtlambda=1.;
double vtAR=.8*(*AR);
double vtplace=0.;
double Sf=3.14159*(*D)*(*L);
double Lt=.8*(*L);
double Nl=*Nzult;
double Wl=*Wdg;
double Lm=(*D/2.)*12.;
double Ln=(*D/2.)*12.;
double Vt=*Wfw/6.5;
double Vi=Vt;
double Nt=1.;
double Wuav=.02*(*Wdg);
double M=*vel/1100.;
/* Local Function Variable Declarations */
double Q;
double Wwing;
double Wht;
double Wvt;
double Wfus;
double Wmaingr;
double Wnosegr;
double Wengine;
double Wfuelsys;
double Wflightcon;
double Whydraulics;
double Wavionics;
double Welec;
double Wacai;
/* Calculations */
Q=.5*(*rho)*pow(*vel,2);
wsweep=wsweep/57.29;
htsweep=htsweep/57.29;
vtsweep=vtsweep/57.29;
/* wing weight */
Wwing=.036*\
pow(*Sw,.758)*\
pow(*Wfw,.0035)*\
pow((*AR/pow(cos(wsweep),2)),.6)*\
pow(Q,.006)*\
pow(lambda,.04)*\
pow((100.*toc/cos(wsweep)),(-.3))*\
pow((*Nzult*(*Wdg)),.49);
/* horizontal tail */
Wht=.016*\
pow(Sht,.896)*\
pow((htAR/pow(cos(htsweep),2)),0.043)*\
pow(Q,.168)*\
pow(htlambda,(-.02))*\
pow((100.*httoc/cos(htsweep)),(-.12))*\
pow((*Nzult*(*Wdg)),.414);
/* vertical tail */
Wvt=.073*\
(1.+.2*vtplace)*\
pow(Svt,0.873)*\
pow(vtAR/pow(cos(vtsweep),2),0.357)*\
pow(Q,.122)*\
pow(vtlambda,.039)*\
pow(100.*vttoc/cos(vtsweep),-.49)*\
pow((*Nzult*(*Wdg)),.376);
/* fuselage (nonpressurized) */
Wfus =0.052*\
pow(Sf,1.086)*\
pow((*Nzult*(*Wdg)),.177)*\
pow(Lt,(-.051))*\
pow((*L/(*D)),(-.072))*\
pow(Q,.241);
Wmaingr = .095*\
pow((Nl*Wl),.768)*\
pow((Lm/12.),0.409);
Wnosegr = .125*\
pow((Nl*Wl),.556)*\
pow((Ln/12.),0.845);
Wengine = 2.575*\
pow(*Wen,.922)* \
*Nen;
Wfuelsys= 2.49*\
pow(Vt,.726)*\
pow((1./(1.+Vi/Vt)),.363)* \
pow(Nt,.242)* \
pow(*Nen,.157);
Wflightcon = 0.053* \
pow(*L,1.536)*\
pow(*Bw,0.371)*\
pow((*Nzult*(*Wdg)*.0001),.8);
Whydraulics = 0.001*\
*Wdg;
Wavionics= 2.117*\
pow(Wuav,.933);
Welec= 12.57*\
pow((Wfuelsys+Wavionics),.51);
Wacai = .265*\
pow(*Wdg,.52)*\
pow(*Np,.68)* \
pow(Wavionics,.17)* \
pow(M,0.08);
*Wstruct= Wwing + Wht + Wvt + Wfus;
*Wlg = Wmaingr + Wnosegr;
*Wprop = Wengine + Wfuelsys;
*Wequip = Wflightcon +Whydraulics +Wavionics + Welec + Wacai;
*Wempty=*Wstruct+*Wlg+*Wprop+*Wequip;
fprintf(fp,"%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G%13.8G\n",\
Wwing, Wht, Wvt, Wfus, Wmaingr, Wnosegr, Wengine, Wfuelsys, Wflightcon, Whydraulics, Wavionics,\
Welec, Wacai, *Wempty);
};
void main() {
/* Input Declarations */
double rho;
double vel;
double Swing;
double Wfuel;
double Nzult;
double AR;
double Length;
double L;
double Diameter;
double D;
double Wen;
double Nen;
double Npass;
double Wpay;
/* Output Declarations */
double Wfuelcruise;
double R;
double Range;
double Vstall;
double rhosea;
double PassWt;
double con_tol;
double Wtot;
double Wpass;
double diff;
double wtot0;
double Wempty;
double Bw;
double Wstruct;
double Wlg;
double Wprop;
double Wequip;
FILE *fpinput;
FILE *fpoutput;
FILE *fptable;
FILE *fptemp;
int i=1;
/* Get Inputs */
if ((fpinput = fopen("WeightsIn.txt","r"))==NULL) {
printf("\n");
printf("*** ERROR ***\n");
printf("Cannot open input file WeightsIn.txt. \n");
printf("\n");
exit (1);
}
fscanf(fpinput,"\n");
fscanf(fpinput," ==== Weights Analysis Input File ====\n");
fscanf(fpinput,"\n");
fscanf(fpinput,"rho = %lf\n", &rho);
fscanf(fpinput,"vel = %lf\n", &vel);
fscanf(fpinput,"Swing = %lf\n", &Swing);
fscanf(fpinput,"Nzult = %lf\n", &Nzult);
fscanf(fpinput,"AR = %lf\n", &AR);
fscanf(fpinput,"Length = %lf\n", &Length);
fscanf(fpinput,"Diameter = %lf\n", &Diameter);
fscanf(fpinput,"Wfuel = %lf\n", &Wfuel);
fscanf(fpinput,"Wen = %lf\n", &Wen);
fscanf(fpinput,"Nen = %lf\n", &Nen);
fscanf(fpinput,"Npass = %lf\n", &Npass);
fscanf(fpinput,"Wpay = %lf\n", &Wpay);
fclose(fpinput);
/* Calculations */
L=Length;
D=Diameter;
PassWt=175.0;
con_tol = 0.001;
Wtot = 0.0;
Wpass = PassWt*Npass;
diff = 500.0;
/* Write Weight Convergence Information */
if ((fptable = fopen("WeightsTable.txt","w"))==NULL) {
printf("\n");
printf("*** ERROR ***\n");
printf("Cannot open convergence file WeightsTable.txt. \n");
printf("\n");
exit (1);
}
fprintf(fptable," Iteration and Convergence of Individual Aircraft Component Weights\n");
fprintf(fptable,"%13s%13s%13s%13s%13s%13s%13s%13s%13s%13s%13s%13s%13s%13s\n",\
"Wing","H. Tail","V. Tail","Fuselage","Main Gear","Nose Gear","Engines","FuelSys",\
"Controls","Hydraulics","Avionics","Electrical","A/C&Anti-Ice","Total Empty");
/* Write Output File */
if ((fpoutput = fopen("WeightsOut.txt","w"))==NULL) {
printf("\n");
printf("*** ERROR ***\n");
printf("Cannot open output file WeightsOut.txt. \n");
printf("\n");
exit(1);
}
fprintf(fpoutput,"\n");
fprintf(fpoutput," ==== Weights Analysis Output File ====\n");
fprintf(fpoutput,"\n");
fprintf(fpoutput," =========== Convergence Data ============ \n");
fprintf(fpoutput,"\n");
while (diff > con_tol) {
wtot0 = Wtot;
/* weights calculations */
Wtot=Wpay+Wfuel+Wpass+Wempty;
/* empty weight estimation */
Bw=sqrt(AR*Swing);
w_mpt(fptable,&rho,&vel,&Swing,&Wfuel,&Nzult,&Wtot,&AR,&L,&D,&Wen,&Nen,&Bw,&Npass,&Wstruct,&Wlg,&Wprop,&Wequip,&Wempty);
diff = sqrt(pow(wtot0 - Wtot,2));
fprintf(fpoutput,"Convergence Difference: %13.8G \n", diff);
};
/* Close Convergence Information Table */
fclose(fptable);
/* Finish Generating Output File */
fprintf(fpoutput,"\n");
fprintf(fpoutput," === Weight Analysis === \n");
fprintf(fpoutput,"\n");
fprintf(fpoutput," Weight of Payload (lbs.) = %15.6G \n", Wpay);
fprintf(fpoutput," Weight of Fuel (lbs.) = %15.6G \n", Wfuel);
fprintf(fpoutput," Number of Passengers = %15.6G \n", Npass);
fprintf(fpoutput," Weight of Passengers @ %5.1f (lbs.) each = %15.6G \n", PassWt, Wpass);
fprintf(fpoutput,"\n");
fprintf(fpoutput," === Weight of Aircraft Components === \n");
fprintf(fpoutput,"\n");
fprintf(fpoutput,"Weight of Aircraft Structure (lbs.) = %15.6G \n", Wstruct);
fprintf(fpoutput,"Weight of Aircraft Landing Gear (lbs.) = %15.6G \n", Wlg);
fprintf(fpoutput,"Weight of Aircraft Propulsion System (lbs.) = %15.6G \n", Wprop);
fprintf(fpoutput,"Weight of Aircraft Internal Equipment(lbs.) = %15.6G \n", Wequip);
fprintf(fpoutput,"Total Weight of Empty Aircraft (lbs.) = %15.6G \n", Wempty);
fprintf(fpoutput,"Total Weight of Loaded Aircraft (lbs.) = %15.6G \n", Wtot);
fclose(fpoutput);
/* Lines to Slow Down the Code to Demo Parallel Feature in iSIGHT */
/*while (i < 3000) {
if ((fptemp = fopen("WeightsLoop.txt","w"))==NULL) {
printf("\n");
printf("*** ERROR ***\n");
printf("Cannot open temporary file WeightsLoop.txt. \n");
printf("\n");
exit (1);
}
fprintf(fptemp,"%d",i);
fclose(fptemp);
i++;
};*/
exit (0);
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -