1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
void fPrintOutput(FILE ** file,realtype t,N_Vector y,unsigned short Z,
Engine * e,Mechanism * mec,double R,double * coeffvol)
{
/* Write on the hard disk the outputs
t : time in s
y : index i(ns+1) to i(ns+1)+ns-1 : mass of each species of the ith zone
index i(ns+1)+ns : temperature of the ith zone
where ns is the numbers of species of the mechanism and i=0..Z-1
Z : numbers of zones
e : data about the engine
mec : the mechanism
R : perfect gaz constant
coeffvol : proportionality coefficient of each zone to compute the volume of
each zone
For each file (1 file for 1 zone) from the first to the (Z-1)th :
1st column : crank angle in dV
2nd column : pressure in Pa
3rd column : temperature in K
4st column to the last : mass of each species. The order of the species is
given in the table mec->species
for the file MeanOutputs.txt (number Z)
1st column : mean pressure in Pa
2nd column : mean temperature in K
for the file Volumes.txt (number Z+2)
1st column : total volume (in m3)
columns 2 to Z+1 : volume of each zone (in m3);
*/
unsigned short i,s,insp1;
const double theta=e->rpm6*t-180.0; /* crank angle in dV */
const unsigned short ns=mec->ns, nsp1=ns+1;
double V,Vdot,P,aux;
V_Vp(t,e,&V,&Vdot);
double m=0.; /* total mass of the mixture */
double * mz=malloc(Z*sizeof(*mz)); assert(mz!=NULL); /* mass of each zone */
/* total mass of each species */
double * ms=malloc(ns*sizeof(*ms)); assert(ms!=NULL);
for(s=0;s<ns;++s) ms[s]=0.;
/* compute :
m : total mass of the mixture
mz : mass of each zone
ms : mass of each species
*/
for(i=0;i<Z;++i)
{
mz[i]=0.;
insp1=i*nsp1;
for(s=0;s<ns;++s)
{
aux=NV_Ith_S(y,insp1+s);
m+=aux;
mz[i]+=aux;
ms[s]+=aux;
}
}
double Tmean=MeanTemperature(y,mec,Z,R,m); /* mean temperature (in K) */
/* mean pressure (in Pa) so the factor 0.1 to convert mean pressure from
dyne/cm2 to Pa
*/
double Pmean=MeanPressure(Tmean,ms,mec,V,R)*0.1;
for(i=0;i<Z;++i)
{
insp1=i*nsp1;
P=Pressure(y,coeffvol[i]*V,i,mec,mz[i],R);
fprintf(file[i],"%14.6le\t%14.6le\t%14.6le",theta,P,NV_Ith_S(y,(i+1)*ns+i));
for(s=0;s<ns;++s) fprintf(file[i],"\t%14.6le",NV_Ith_S(y,insp1+s));
fprintf(file[i],"\n");
} /* end of for(i=0;i<Z;++i) */
/* writing of mean pressure and mean temperature */
fprintf(file[Z],"%14.6le\t%14.6le\n",Pmean,Tmean);
/* writing of the total volume and the volume of each zone */
V*=1e-6; /* to convert volumes from cm3 to m3 */
fprintf(file[Z+2],"%14.6le",V);
for(i=0;i<Z;++i) fprintf(file[Z+2],"\t%14.6le",coeffvol[i]*V);
fprintf(file[Z+2],"\n");
free(mz); mz=NULL;
free(ms); ms=NULL;
} |
Partager