void g_power(const double a[3], double y[3]) { int k; for (k = 0; k < 3; k++) { y[k] = rt_powd_snf(a[k], 2.0); } }
void power(const real_T b[4], real_T y[4]) { int32_T k; for (k = 0; k < 4; k++) { y[k] = rt_powd_snf(10.0, b[k]); } }
void f_power(const double a[22001], double y[22001]) { int k; for (k = 0; k < 22001; k++) { y[k] = rt_powd_snf(a[k], 2.0); } }
void c_power(const double a[2], double y[2]) { int k; for (k = 0; k < 2; k++) { y[k] = rt_powd_snf(a[k], 0.5); } }
void c_power(const real_T a[257], real_T y[257]) { int32_T k; for (k = 0; k < 257; k++) { y[k] = rt_powd_snf(a[k], -1.0); } }
/* * The function calculates the diffusivity of the binary gas system (HC vapor * to air) in the low pressure according to procedure 13B1.2 in API Technical * Book : Petroleum Refining . (<3.45 MPa) * Input * p : pressure in Pa * T : Temperature in K * MW : Molecular weight of fuel in kg/kmol * C : Number of carbon in the fuel chemical formula * H : Number of hydrogen in the fuel chemical formula * O : Number of oxygen in the fuel chemical formula * N : Number of nitrogen in the fuel chemical formula * Aromatic : 1 if aromatic, 0 otherwise * Output * D_v : Diffusivity in m2/sec * Ref * Technical Data Book - Petroleum Refining(1985) Americal Petroleum Institute. * Created by Kevin Koosup Yum, 18 September 2013 * Arguments : double p * double T * double MW * double C * double H * double O * double N * boolean_T Aromatic * Return Type : double */ double GetDiffusivityHCVaporToAir(double p, double T, double MW, double C, double H, double O, double N, boolean_T Aromatic) { double D_v; double a; /* % Diffusivity at low pressure */ a = rt_powd_snf((((C * 16.5 + H * 1.98) + O * 5.48) + N * 5.69) - (double) Aromatic * 20.2, 0.3333) + 2.7186621817323884; D_v = 0.01015 * (rt_powd_snf(T, 1.75) * sqrt(0.034650034650034647 + 1.0 / MW)) / (p * (a * a)); /* T_R = T*1.8; */ /* p_lb = 1.450377e-4*p; */ /* Sigma = 1.864 - 0.1662e-2*T_R + 0.1036e-5*T_R^2 - 0.2390e-9*T_R^3; */ /* D_v_1 = 0.00064516*11.339e-6*T^1.5/(p_lb*Sigma); */ /* % */ return D_v; }
double gp_max_fixed(double m, double s) { double coeff[5]; coeff[4] = rt_powd_snf(m, 4.0) / (4.0 * rt_powd_snf(s, 4.0)); coeff[3] = 3.0 * (m * m) / (2.0 * (s * s)); coeff[2] = 3.75 - m * m / (2.0 * rt_powd_snf(s, 4.0)); coeff[1] = -5.0 / (2.0 * (s * s)); coeff[0] = 1.0 / (4.0 * rt_powd_snf(s, 4.0)); double foundRoots[10]; gsl_poly_complex_workspace * workspace = gsl_poly_complex_workspace_alloc(5); gsl_poly_complex_solve(coeff, 5, workspace, foundRoots); gsl_poly_complex_workspace_free(workspace); int numRealRoots = 0; double realRoots[10]; double re; double im; for (int i = 0; i < 4; i++) { re = foundRoots[2 * i]; im = foundRoots[2 * i + 1]; if (im <= 0.000000000000001) { if (re >= 0) { realRoots[numRealRoots] = re; numRealRoots++; } } } double y[10]; onestagepdf_prime_fixed(realRoots, numRealRoots, m, s, y); double largest = 0; for (int i = 0; i < numRealRoots; i++) { if (y[i] > largest) { largest = y[i]; } } return largest; }
void k_power(const emxArray_real_T *a, emxArray_real_T *y) { unsigned int a_idx_0; int k; a_idx_0 = (unsigned int)a->size[0]; k = y->size[0]; y->size[0] = (int)a_idx_0; emxEnsureCapacity((emxArray__common *)y, k, sizeof(double)); for (k = 0; k + 1 <= a->size[0]; k++) { y->data[k] = rt_powd_snf(a->data[k], 3.0); } }
/* Function Definitions */ void quadrotorDrag(const real_T uin[6], const DragParameters parameter, real_T dt, real_T y[6]) { int32_T i; real_T absoluteVelocity; real_T absoluteAngularVelocity; /* initialize vectors */ for (i = 0; i < 6; i++) { y[i] = 0.0; } /* Input variables */ /* Constants */ /* temporarily used vector */ absoluteVelocity = sqrt((rt_powd_snf(uin[0], 2.0) + rt_powd_snf(uin[1], 2.0)) + rt_powd_snf(uin[2], 2.0)); absoluteAngularVelocity = sqrt((rt_powd_snf(uin[3], 2.0) + rt_powd_snf(uin[4], 2.0)) + rt_powd_snf(uin[5], 2.0)); /* system outputs */ /* calculate drag force */ y[0] = parameter.C_wxy * absoluteVelocity * uin[0]; y[1] = parameter.C_wxy * absoluteVelocity * uin[1]; y[2] = parameter.C_wz * absoluteVelocity * uin[2]; /* calculate draq torque */ y[3] = parameter.C_mxy * absoluteAngularVelocity * uin[3]; y[4] = parameter.C_mxy * absoluteAngularVelocity * uin[4]; y[5] = parameter.C_mz * absoluteAngularVelocity * uin[5]; }
/* * Fs - Sampling frequency * Arguments : double Fs * emxArray_real_T *data * emxArray_real_T *f * emxArray_real_T *YY * Return Type : void */ void spectral(double Fs, emxArray_real_T *data, emxArray_real_T *f, emxArray_real_T *YY) { emxArray_boolean_T *b; int nxin; int k0; int nrowx; int nxout; int k; emxArray_real_T *b_data; int eint; double fdbl; double delta1; emxArray_creal_T *Y; double NFFT; emxArray_creal_T *x; emxInit_boolean_T(&b, 1); nxin = b->size[0]; b->size[0] = data->size[0]; emxEnsureCapacity((emxArray__common *)b, nxin, (int)sizeof(boolean_T)); k0 = data->size[0]; for (nxin = 0; nxin < k0; nxin++) { b->data[nxin] = rtIsNaN(data->data[nxin]); } nxin = data->size[0]; nrowx = data->size[0]; nxout = 0; for (k = 1; k <= b->size[0]; k++) { nxout += b->data[k - 1]; } nxout = data->size[0] - nxout; k0 = -1; for (k = 1; k <= nxin; k++) { if ((k > b->size[0]) || (!b->data[k - 1])) { k0++; data->data[k0] = data->data[k - 1]; } } emxFree_boolean_T(&b); if (nrowx != 1) { if (1 > nxout) { k0 = 0; } else { k0 = nxout; } emxInit_real_T(&b_data, 1); nxin = b_data->size[0]; b_data->size[0] = k0; emxEnsureCapacity((emxArray__common *)b_data, nxin, (int)sizeof(double)); for (nxin = 0; nxin < k0; nxin++) { b_data->data[nxin] = data->data[nxin]; } nxin = data->size[0]; data->size[0] = b_data->size[0]; emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double)); k0 = b_data->size[0]; for (nxin = 0; nxin < k0; nxin++) { data->data[nxin] = b_data->data[nxin]; } emxFree_real_T(&b_data); } else { nxin = data->size[0]; if (1 > nxout) { data->size[0] = 0; } else { data->size[0] = nxout; } emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double)); } fdbl = frexp(data->size[0], &eint); delta1 = eint; if (fdbl == 0.5) { delta1 = (double)eint - 1.0; } emxInit_creal_T(&Y, 1); NFFT = rt_powd_snf(2.0, delta1); /* Next power of 2 from length of y */ fft(data, NFFT, Y); nxout = data->size[0]; nxin = Y->size[0]; emxEnsureCapacity((emxArray__common *)Y, nxin, (int)sizeof(creal_T)); k0 = Y->size[0]; for (nxin = 0; nxin < k0; nxin++) { fdbl = Y->data[nxin].re; delta1 = Y->data[nxin].im; if (delta1 == 0.0) { Y->data[nxin].re = fdbl / (double)nxout; Y->data[nxin].im = 0.0; } else if (fdbl == 0.0) { Y->data[nxin].re = 0.0; Y->data[nxin].im = delta1 / (double)nxout; } else { Y->data[nxin].re = fdbl / (double)nxout; Y->data[nxin].im = delta1 / (double)nxout; } } fdbl = Fs / 2.0; nxin = f->size[0] * f->size[1]; f->size[0] = 1; f->size[1] = (int)floor(NFFT / 2.0 + 1.0); emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double)); f->data[f->size[1] - 1] = 1.0; if (f->size[1] >= 2) { f->data[0] = 0.0; if (f->size[1] >= 3) { delta1 = 1.0 / ((double)f->size[1] - 1.0); nxin = f->size[1]; for (k = 0; k <= nxin - 3; k++) { f->data[1 + k] = (1.0 + (double)k) * delta1; } } } nxin = f->size[0] * f->size[1]; f->size[0] = 1; emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double)); nxout = f->size[0]; k0 = f->size[1]; k0 *= nxout; for (nxin = 0; nxin < k0; nxin++) { f->data[nxin] *= fdbl; } emxInit_creal_T(&x, 1); fdbl = NFFT / 2.0 + 1.0; k0 = (int)(NFFT / 2.0 + 1.0); nxin = x->size[0]; x->size[0] = k0; emxEnsureCapacity((emxArray__common *)x, nxin, (int)sizeof(creal_T)); for (nxin = 0; nxin < k0; nxin++) { x->data[nxin] = Y->data[nxin]; } emxFree_creal_T(&Y); nxin = YY->size[0]; YY->size[0] = (int)fdbl; emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double)); for (k = 0; k + 1 <= (int)fdbl; k++) { YY->data[k] = rt_hypotd_snf(x->data[k].re, x->data[k].im); } emxFree_creal_T(&x); nxin = YY->size[0]; emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double)); k0 = YY->size[0]; for (nxin = 0; nxin < k0; nxin++) { YY->data[nxin] *= 2.0; } /* figure; */ /* plot(f,2*abs(Y(1:NFFT/2+1))); */ /* L = length(data); % Length of signal */ /* NFFT = 2^nextpow2(L); */ /* f = Fs/2*linspace(0,1,NFFT/2+1); */ /* figure(1) */ /* Y = fft(data,NFFT)/L; */ /* % Plot single-sided amplitude spectrum. */ /* plot(f,2*abs(Y(1:NFFT/2+1))) % 船首向信号谱分析 */ /* set(gca,'xlim',[0.005 0.5],'ylimmode','auto'); */ /* title('艏向快速傅里叶变换'); */ /* xlabel('频率/Hz'); */ /* ylabel('功率'); */ /* box off */ }
/* Function Definitions */ void GetTotalStaticPT(double varargin_1, double varargin_2, const double varargin_3[12], double varargin_4, double, double, double varargin_7, double *p0, double *T0, double *Ts) { double err; double rhoTemp; double unusedUd; double unusedUc; double unusedUb; double unusedUa; double CpTemp; double mtmp; double cSq; double p0TempNew; double deltaT; double T0TempNew; double TsTempNew; double p0Temp; double T0Temp; double TsTemp; double T_sq; double T_cb; double T_qt; int ixstart; static const double b[12] = { 1.00794, 15.9994, 14.0067, 2.01588, 17.00734, 28.0101, 30.0061, 31.9988, 18.01528, 44.0095, 28.0134, 39.948 }; double a_CO2[7]; double a_CO[7]; double a_O2[7]; double a_H2[7]; double a_H2O[7]; double a_OH[7]; double a_O[7]; double a_N2[7]; double a_N[7]; double a_NO[7]; static const double dv79[7] = { 4.6365111, 0.0027414569, -9.9589759E-7, 1.6038666E-10, -9.1619857E-15, -49024.904, -1.9348955 }; static const double dv80[7] = { 3.0484859, 0.0013517281, -4.8579405E-7, 7.8853644E-11, -4.6980746E-15, -14266.117, 6.0170977 }; static const double dv81[7] = { 3.66096083, 0.000656365523, -1.41149485E-7, 2.05797658E-11, -1.29913248E-15, -1215.97725, 3.41536184 }; static const double dv82[7] = { 2.9328305, 0.00082659802, -1.4640057E-7, 1.5409851E-11, -6.8879615E-16, -813.05582, -1.0243164 }; static const double dv83[7] = { 2.6770389, 0.0029731816, -7.7376889E-7, 9.4433514E-11, -4.2689991E-15, -29885.894, 6.88255 }; static const double dv84[7] = { 2.83853033, 0.00110741289, -2.94000209E-7, 4.20698729E-11, -2.4228989E-15, 3697.80808, 5.84494652 }; static const double dv85[7] = { 2.54363697, -2.73162486E-5, -4.1902952E-9, 4.95481845E-12, -4.79553694E-16, 29226.012, 4.92229457 }; static const double dv86[7] = { 2.95257637, 0.0013969004, -4.92631603E-7, 7.86010195E-11, -4.60755204E-15, -923.948688, 5.87188762 }; static const double dv87[7] = { 2.4159429, 0.00017489065, -1.1902369E-7, 3.0226244E-11, -2.0360983E-15, 56133.775, 4.6496095 }; static const double dv88[7] = { 3.26071234, 0.00119101135, -4.29122646E-7, 6.94481463E-11, -4.03295681E-15, 9921.43132, 6.36900518 }; static const double dv89[7] = { 2.356813, 0.0089841299, -7.1220632E-6, 2.4573008E-9, -1.4288548E-13, -48371.971, 9.9009035 }; static const double dv90[7] = { 3.5795335, -0.00061035369, 1.0168143E-6, 9.0700586E-10, -9.0442449E-13, -14344.086, 3.5084093 }; static const double dv91[7] = { 3.78245636, -0.00299673415, 9.847302E-6, -9.68129508E-9, 3.24372836E-12, -1063.94356, 3.65767573 }; static const double dv92[7] = { 2.3443029, 0.0079804248, -1.9477917E-5, 2.0156967E-8, -7.3760289E-12, -917.92413, 0.68300218 }; static const double dv93[7] = { 4.1986352, -0.0020364017, 6.5203416E-6, -5.4879269E-9, 1.771968E-12, -30293.726, -0.84900901 }; static const double dv94[7] = { 3.99198424, -0.00240106655, 4.61664033E-6, -3.87916306E-9, 1.36319502E-12, 3368.89836, -0.103998477 }; static const double dv95[7] = { 3.1682671, -0.00327931884, 6.64306396E-6, -6.12806624E-9, 2.11265971E-12, 29122.2592, 2.05193346 }; static const double dv96[7] = { 3.53100528, -0.000123660988, -5.02999433E-7, 2.43530612E-9, -1.40881235E-12, -1046.97628, 2.96747038 }; static const double dv97[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, 56104.638, 4.1939088 }; static const double dv98[7] = { 4.21859896, -0.00463988124, 1.10443049E-5, -9.34055507E-9, 2.80554874E-12, 9845.09964, 2.28061001 }; double a_H[84]; double dv99[7]; static const double b_a_H[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, 25473.66, -0.44668285 }; static const double a_Ar[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.3796749 }; double a_gas[7]; int ix; double dv100[7]; double x[3]; double y[3]; boolean_T exitg1; /* Calculates the total pressure, total and static temperature based from the */ /* measurements. */ /* Input */ /* - p : Pressure measurement (static) [Pa] */ /* - T : Temperature measurement [K] */ /* - x : Composition of the gas in mole fraction (12x1) */ /* - RF : Recovery factor for temperature measurement [K] */ /* - mDot : mass flow at the measurement [kg/s] */ /* - Area : Sectional area at the measurement [m2] */ /* - c : velocity of the gas at the measurement [m/s], optional */ /* Output */ /* - p0 : Total pressure [Pa] */ /* - T0 : Total temperature [K]; */ /* - Ts : Static temperature [K]; */ err = 1.0; GetThermoDynProp(varargin_1, varargin_2, varargin_3, &mtmp, &CpTemp, &unusedUa, &unusedUb, &unusedUc, &unusedUd, &rhoTemp); cSq = varargin_7 * varargin_7; p0TempNew = varargin_1 + 0.5 * rhoTemp * cSq; deltaT = 0.5 * cSq / CpTemp; T0TempNew = varargin_2 + (1.0 - varargin_4) * deltaT; TsTempNew = varargin_2 - varargin_4 * deltaT; while (err > 0.001) { p0Temp = p0TempNew; T0Temp = T0TempNew; TsTemp = TsTempNew; /* Calculate the specific thermodynamic properties of the gas based on the */ /* pressure, temperature and the composition based on the 7-coefficient NASA */ /* polynomials. Valid in the temperature range 300~6000K. */ /* Input */ /* P : Pressure in Pa */ /* T : Temperature in Kelvin */ /* x : Composition of the gas */ /* x(1) = x_H; x(2) = x_O; x(3) = x_N; x(4) = x_H2; */ /* x(5) = x_OH; x(6) = x_CO; x(7) = x_NO; x(8) = x_O2; */ /* x(9) = x_H2O; x(10) = x_CO2;x(11) = x_N2; x(12) = x_Ar */ /* Output */ /* R : Gas constant */ /* Cp : Specific heat capacity at constant pressure (J/kg/K) */ /* Cv : Specific heat capacity at constant volume (J/kg/K) */ /* u : Specific internal energy (J/kg) */ /* h : Specific enthalpy (J/kg) */ /* s : Specific entropy (J/kg/T) */ /* rho : Density of the gas (kg/m3) */ /* */ /* Atomic weight calculation from NIST atomic weights */ /* Ref : http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl */ /* */ /* The NASA 7-coefficients are obtained from the reference: */ /* Burcat, A., B. Ruscic, et al. (2005). Third millenium ideal gas and */ /* condensed phase thermochemical database for combustion with updates */ /* from active thermochemical tables, Argonne National Laboratory */ /* Argonne, IL. */ /* */ /* Created by Kevin Koosup Yum on 29 June */ /* % */ T_sq = TsTempNew * TsTempNew; T_cb = rt_powd_snf(TsTempNew, 3.0); T_qt = rt_powd_snf(TsTempNew, 4.0); /* in J/kmol/K */ /* % Calculate R */ /* kg/kmol */ /* in kg/kmol */ mtmp = 0.0; for (ixstart = 0; ixstart < 12; ixstart++) { mtmp += varargin_3[ixstart] * b[ixstart]; } unusedUa = 8314.4621 / mtmp; /* in J/kg/K */ /* % */ if (TsTempNew >= 1000.0) { /* Valid upto */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ for (ixstart = 0; ixstart < 7; ixstart++) { a_CO2[ixstart] = dv79[ixstart]; a_CO[ixstart] = dv80[ixstart]; a_O2[ixstart] = dv81[ixstart]; a_H2[ixstart] = dv82[ixstart]; a_H2O[ixstart] = dv83[ixstart]; a_OH[ixstart] = dv84[ixstart]; a_O[ixstart] = dv85[ixstart]; a_N2[ixstart] = dv86[ixstart]; a_N[ixstart] = dv87[ixstart]; a_NO[ixstart] = dv88[ixstart]; } /* 1000~6000K */ } else { /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ for (ixstart = 0; ixstart < 7; ixstart++) { a_CO2[ixstart] = dv89[ixstart]; a_CO[ixstart] = dv90[ixstart]; a_O2[ixstart] = dv91[ixstart]; a_H2[ixstart] = dv92[ixstart]; a_H2O[ixstart] = dv93[ixstart]; a_OH[ixstart] = dv94[ixstart]; a_O[ixstart] = dv95[ixstart]; a_N2[ixstart] = dv96[ixstart]; a_N[ixstart] = dv97[ixstart]; a_NO[ixstart] = dv98[ixstart]; } /* 300~1000K */ } /* % Calculate Cp & Cv */ /* k = x ./ M_mw'; */ /* a_gas_Cp = k*A; */ dv99[0] = 1.0; dv99[1] = TsTempNew; dv99[2] = T_sq; dv99[3] = T_cb; dv99[4] = T_qt; dv99[5] = 0.0; dv99[6] = 0.0; for (ixstart = 0; ixstart < 7; ixstart++) { a_H[12 * ixstart] = b_a_H[ixstart]; a_H[1 + 12 * ixstart] = a_O[ixstart]; a_H[2 + 12 * ixstart] = a_N[ixstart]; a_H[3 + 12 * ixstart] = a_H2[ixstart]; a_H[4 + 12 * ixstart] = a_OH[ixstart]; a_H[5 + 12 * ixstart] = a_CO[ixstart]; a_H[6 + 12 * ixstart] = a_NO[ixstart]; a_H[7 + 12 * ixstart] = a_O2[ixstart]; a_H[8 + 12 * ixstart] = a_H2O[ixstart]; a_H[9 + 12 * ixstart] = a_CO2[ixstart]; a_H[10 + 12 * ixstart] = a_N2[ixstart]; a_H[11 + 12 * ixstart] = a_Ar[ixstart]; a_gas[ixstart] = 0.0; for (ix = 0; ix < 12; ix++) { a_gas[ixstart] += varargin_3[ix] * a_H[ix + 12 * ixstart]; } a_CO2[ixstart] = a_gas[ixstart] * dv99[ixstart]; } unusedUb = a_CO2[0]; for (ixstart = 0; ixstart < 6; ixstart++) { unusedUb += a_CO2[ixstart + 1]; } /* J/kmol/K */ /* J/kmol/K */ /* % Calculate h and u */ /* x(1) = x_H; x(2) = x_O; x(3) = x_N; x(4) = x_H2; */ /* x(5) = x_OH; x(6) = x_CO; x(7) = x_NO; x(8) = x_O2; */ /* x(9) = x_H2O; x(10) = x_CO2;x(11) = x_N2; x(12) = x_Ar */ /* (J/kmol / J/kmol/K) */ /* J/kmol */ /* % Calculate s */ dv100[0] = log(TsTempNew); dv100[1] = TsTempNew; dv100[2] = T_sq / 2.0; dv100[3] = T_cb / 3.0; dv100[4] = T_qt / 4.0; dv100[5] = 0.0; dv100[6] = 1.0; for (ixstart = 0; ixstart < 7; ixstart++) { a_CO2[ixstart] = a_gas[ixstart] * dv100[ixstart]; } mtmp = a_CO2[0]; for (ixstart = 0; ixstart < 6; ixstart++) { mtmp += a_CO2[ixstart + 1]; } /* % Calculate rho */ p0TempNew = varargin_1 + 0.5 * (unusedUa * mtmp) * cSq; deltaT = 0.5 * cSq / (unusedUa * unusedUb); T0TempNew = varargin_2 + (1.0 - varargin_4) * deltaT; TsTempNew = varargin_2 - varargin_4 * deltaT; x[0] = (p0TempNew - p0Temp) / p0Temp; x[1] = (T0TempNew - T0Temp) / T0Temp; x[2] = (TsTempNew - TsTemp) / TsTemp; for (ixstart = 0; ixstart < 3; ixstart++) { y[ixstart] = fabs(x[ixstart]); } ixstart = 1; mtmp = y[0]; if (rtIsNaN(y[0])) { ix = 2; exitg1 = false; while ((!exitg1) && (ix < 4)) { ixstart = ix; if (!rtIsNaN(y[ix - 1])) { mtmp = y[ix - 1]; exitg1 = true; } else { ix++; } } } if (ixstart < 3) { while (ixstart + 1 < 4) { if (y[ixstart] > mtmp) { mtmp = y[ixstart]; } ixstart++; } } err = mtmp; } *p0 = p0TempNew; *T0 = T0TempNew; *Ts = TsTempNew; }
/* Function Definitions */ void GetFuelPropertyN_Dodecane(double p, double T, double *p_v, double *rho_l, double *h_l, double *Cp_l, double *h_fg, double *mu_l, double *lambda_l, double *sigma_l) { double T_R[8]; int i; double p_R[4]; double dv7[4]; double d5; int i7; static const double a[4] = { 14.50170196, -14.9159925, -8.86263462, 0.414336894 }; double dv8[5]; double b_a[4]; int i8; static const double c_a[20] = { 1105.3, -1329.8, 1663.7, -1069.7, -31.164, 147.71, -246.21, 169.74, 1.4274, -5.4041, 8.6951, -7.685, -0.0052975, -0.055594, 0.099981, 0.064605, -0.00046749, 0.0035522, -0.0058678, 0.0014729 }; double T_RB; double T_RB2; double T_RB3; double dv9[4]; static const double d_a[4] = { 3331.5840000000003, -6193.63, 9064.86, -3179.248 }; double dv10[4]; double dv11[8]; static const double e_a[8] = { 2.140406765E+7, -2.394932736E+8, 1.154699081E+9, -3.051087445E+9, 4.767135466E+9, -4.406307056E+9, 2.232100727E+9, -4.784187787E+8 }; double T_F; double dv12[6]; static const double f_a[6] = { 3.21248, -0.0381521, 0.000240018, -8.33717E-7, 1.4875E-9, -1.05978E-12 }; /* The function calculates the thermodynamic and transportation property of */ /* the liquid n-dodecane fuel */ /* input */ /* p : Pressure of the liquid fuel in Pa */ /* T : Liquid fuel temperature in Kelvin */ /* Output */ /* p_v : vapor pressure of the liquid in Pa */ /* rho_l : density of the fuel in kg/m3 */ /* h_l : specific enthalpy of the fuel in J/kg (0 at 0K) */ /* Cp_l : isobaric specific heat capacity in J/kg/K */ /* h_fg : specific latent heat of vaporization in J/kg */ /* mu_l : dynamic viscosity in Ns/m2 */ /* lambda_l : Thermal conductivity in W/m/K */ /* sigma_l : Surface tension in N/m */ /* */ /* Created by Kevin Koosup Yum (NTNU) on 22 August */ /* */ /* Ref */ /* Kouremenos, D. A., C. D. Rakopoulos, et al. (1990). "A FORTRAN program */ /* for calculating the thermodynamic and transport properties of diesel */ /* fuel." Advances in Engineering Software (1978) 12(4): 190-196. */ /* % Constants for the fuel N-dodecane */ /* Boiling temperature at 1 atm in K */ /* Critical temperature in K */ /* Critical pressure in Pa */ /* Accentric factor */ /* % Calculation of reduced temperature and pressure */ memset(&T_R[0], 0, sizeof(double) << 3); T_R[0] = T / 658.1; for (i = 0; i < 6; i++) { T_R[i + 1] = T_R[i] * T_R[0]; } T_R[7] = log(T_R[0]); for (i = 0; i < 4; i++) { p_R[i] = 0.0; } p_R[0] = p / 1.817E+6; for (i = 0; i < 3; i++) { p_R[i + 1] = p_R[i] * p_R[0]; } /* % Calculation of vapor pressure */ dv7[0] = 1.0; dv7[1] = 1.0 / T_R[0]; dv7[2] = T_R[7]; dv7[3] = T_R[5]; d5 = 0.0; for (i7 = 0; i7 < 4; i7++) { d5 += a[i7] * dv7[i7]; } *p_v = exp(d5) * 1.817E+6; /* % Calculation of liquid density */ dv8[0] = 1.0; for (i7 = 0; i7 < 4; i7++) { dv8[i7 + 1] = p_R[i7]; } for (i7 = 0; i7 < 4; i7++) { b_a[i7] = 0.0; for (i8 = 0; i8 < 5; i8++) { b_a[i7] += c_a[i7 + (i8 << 2)] * dv8[i8]; } } dv7[0] = 1.0; for (i7 = 0; i7 < 3; i7++) { dv7[i7 + 1] = T_R[i7]; } d5 = 0.0; for (i7 = 0; i7 < 4; i7++) { d5 += b_a[i7] * dv7[i7]; } *rho_l = d5; /* % Liquid specific enthalpy */ T_RB = T / 489.43; T_RB2 = T_RB * T_RB; T_RB3 = T_RB2 * T_RB; dv9[0] = 1.0; dv9[1] = T_RB / 2.0; dv9[2] = T_RB2 / 3.0; dv9[3] = T_RB3 / 4.0; d5 = 0.0; for (i7 = 0; i7 < 4; i7++) { d5 += d_a[i7] * dv9[i7]; } *h_l = d5 * T; /* % Liquid specific isobaric heat capacity */ dv10[0] = 1.0; dv10[1] = T_RB; dv10[2] = T_RB2; dv10[3] = T_RB3; d5 = 0.0; for (i7 = 0; i7 < 4; i7++) { d5 += d_a[i7] * dv10[i7]; } *Cp_l = d5; /* % Latent heat of vaporization */ if (T_R[0] <= 0.4) { *h_fg = 52138.6 * rt_powd_snf(658.1 - T, 0.38); } else { dv11[0] = 1.0; for (i7 = 0; i7 < 7; i7++) { dv11[i7 + 1] = T_R[i7]; } d5 = 0.0; for (i7 = 0; i7 < 8; i7++) { d5 += e_a[i7] * dv11[i7]; } *h_fg = d5; } /* % Liquid absolute viscosity */ if (T < 493.57500000000005) { T_F = (T - 273.15) * 9.0 / 5.0 + 32.0; } else { T_F = 428.76500000000016; } dv12[0] = 1.0; dv12[1] = T_F; dv12[2] = T_F * T_F; dv12[3] = rt_powd_snf(T_F, 3.0); dv12[4] = rt_powd_snf(T_F, 4.0); dv12[5] = rt_powd_snf(T_F, 5.0); d5 = 0.0; for (i7 = 0; i7 < 6; i7++) { d5 += f_a[i7] * dv12[i7]; } *mu_l = d5 * exp(p / 6894.757 * (0.0239 + 0.01638 * rt_powd_snf(d5, 0.278)) / 1000.0) / 1000.0; /* % Liquid thermal conductivity */ if (p_R[0] <= 1.894) { *lambda_l = 1.729578 * (0.07727 - 4.558E-5 * T_F); } else { *lambda_l = 1.729578 * (0.07727 - 4.558E-5 * T_F) * (((17.77 + 0.65 * p_R[0]) - 7.764 * T_R[0]) - 2.054 * T_R[1] / exp(p_R[0] * 0.2)) / ((18.42 - 7.764 * T_R[0]) - 1.681673 * T_R[1]); } /* % Liquid surface tension */ if (T_R[0] <= 0.99) { *sigma_l = 0.0528806 * rt_powd_snf(1.0 - T_R[0], 1.232); } else { *sigma_l = 1.0E-5; } }
/* * function [lp]=gaussmixp(y,m,v,w) * y = cat(1, testSamples(1).mfcc{:}); * m = gmm.M; * v = gmm.V; * w = gmm.W; */ real_T gaussmixp(const real_T y[12], const real_T m[108], const real_T v[108], const real_T w[9]) { // printf("In gaussmixp\n"); // int kk = 0; // for (kk = 0; kk < 12; kk++) { // printf("%lf ", y[kk]); // } int32_T i; // static const char_T cv0[7] = { 'F', ':', '\\', 'T', 'E', 'M', 'P' }; // static const char_T cv1[18] = { 'E', ':', '\\', 'd', 'm', 'b', '\\', 'd', 'a', // 't', 'a', '\\', 's', 'p', 'e', 'e', 'c', 'h' }; // static const char_T cv2[18] = { 'C', ':', '\\', 'b', 'i', 'n', '\\', 's', 'h', // 'o', 'r', 't', 'e', 'n', '.', 'e', 'x', 'e' }; // static const char_T cv3[15] = { 'C', ':', '\\', 'b', 'i', 'n', '\\', 'f', 'l', // 'a', 'c', '.', 'e', 'x', 'e' }; // static const char_T cv4[28] = { 'F', ':', '\\', 'P', 'r', 'o', 'g', 'r', 'a', // 'm', ' ', 'F', 'i', 'l', 'e', 's', '\\', 'S', 'F', 'S', '\\', 'P', 'r', 'o', // 'g', 'r', 'a', 'm' }; // static const char_T cv5[4] = { '.', 'e', 'x', 'e' }; real_T b_y[108]; real_T x[9]; real_T b_x[108]; real_T b[9]; real_T km[9]; int32_T iacol; int32_T jcol; real_T c_y[108]; real_T py[9]; real_T mtmp; boolean_T exitg1; real_T ps; /* GAUSSMIXP calculate probability densities from a Gaussian mixture model */ /* */ /* Inputs: n data values, k mixtures, p parameters, q data vector size */ /* */ /* Y(n,q) = input data */ /* M(k,p) = mixture means for x(p) */ /* V(k,p) or V(p,p,k) variances (diagonal or full) */ /* W(k,1) = weights */ /* A(q,p), B(q) = transformation: y=x*a'+b' (where y and x are row vectors) */ /* if A is omitted, it is assumed to be the first q rows of the */ /* identity matrix. B defaults to zero. */ /* Note that most commonly, q=p and A and B are omitted entirely. */ /* */ /* Outputs */ /* */ /* LP(n,1) = log probability of each data point */ /* RP(n,k) = relative probability of each mixture */ /* KH(n,1) = highest probability mixture */ /* KP(n,1) = relative probability of highest probability mixture */ /* Copyright (C) Mike Brookes 2000-2009 */ /* Version: $Id: gaussmixp.m,v 1.3 2009/04/08 07:51:21 dmb Exp $ */ /* */ /* VOICEBOX is a MATLAB toolbox for speech processing. */ /* Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You can obtain a copy of the GNU General Public License from */ /* http://www.gnu.org/copyleft/gpl.html or by writing to */ /* Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* 'gaussmixp:49' [n,q]=size(y); */ /* 'gaussmixp:50' [k,p]=size(m); */ /* 'gaussmixp:51' memsize=voicebox('memsize'); */ /* VOICEBOX set global parameters for Voicebox functions Y=(FIELD,VAL) */ /* */ /* Inputs: F is a field name */ /* V is a new value for the field */ /* */ /* Outputs: Y is set equal to the structure of parameters if the */ /* f and v inputs are both present or both absent. If only */ /* input f is specified, then y is set to the value of the */ /* corresponding field or null if it doesn't exist. */ /* */ /* This routine contains default values for constants that are used by */ /* other functions in the VOICEBOX toolbox. Values in the first section below, */ /* entitled "System-dependent directory paths" should be set as follows: */ /* PP.dir_temp directory for storing temporary files */ /* PP.dir_data default directory to preappend to speech data file names */ /* when the "d" option is specified in READWAV etc. */ /* PP.shorten location of SHORTEN executable. SHORTEN is a proprietary file compression */ /* algorithm that is used for some SPHERE-format files. READSPH */ /* will try to call an external decoder if it is asked to */ /* read such a compressed file. */ /* PP.sfsbin location of Speech Filing Sysytem binaries. If the "c" option */ /* is given to READSFS, it will try to create a requested item */ /* if it is not present in the SFS file. This parameter tells it */ /* where to find the SFS executables. */ /* PP.sfssuffix suffix for Speech Filing Sysytem binaries. READSFS uses this paremeter */ /* to create the name of an SFS executable (see PP.sfsbin above). */ /* Other values defined in this routine are the defaults for specific algorithm constants. */ /* If you want to change these, please refer to the individual routines for a fuller description. */ /* Bugs/Suggestions */ /* (1) Could allow a * at the end of F to act as a wildcard and return/print a part structure */ /* Copyright (C) Mike Brookes 2003 */ /* Version: $Id: voicebox.m,v 1.17 2011/07/28 06:48:45 dmb Exp $ */ /* */ /* VOICEBOX is a MATLAB toolbox for speech processing. */ /* Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */ /* */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You can obtain a copy of the GNU General Public License from */ /* http://www.gnu.org/copyleft/gpl.html or by writing to */ /* Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* 'voicebox:57' if isempty(PP) */ // if (!PP_not_empty) { // /* System-dependent directory paths and constants */ // /* 'voicebox:61' PP.dir_temp='F:\TEMP'; */ // for (i = 0; i < 7; i++) { // PP.dir_temp[i] = cv0[i]; // } // PP_not_empty = TRUE; // /* directory for storing temporary files */ // /* 'voicebox:62' PP.dir_data='E:\dmb\data\speech'; */ // for (i = 0; i < 18; i++) { // PP.dir_data[i] = cv1[i]; // /* default directory to preappend to speech data file names */ // /* 'voicebox:63' PP.shorten='C:\bin\shorten.exe'; */ // PP.shorten[i] = cv2[i]; // } // /* location of shorten executable */ // /* 'voicebox:64' PP.flac='C:\bin\flac.exe'; */ // for (i = 0; i < 15; i++) { // PP.flac[i] = cv3[i]; // } // /* location of flac executable */ // /* 'voicebox:65' PP.sfsbin='F:\Program Files\SFS\Program'; */ // for (i = 0; i < 28; i++) { // PP.sfsbin[i] = cv4[i]; // } // /* location of Speech Filing Sysytem binaries */ // /* 'voicebox:66' PP.sfssuffix='.exe'; */ // for (i = 0; i < 4; i++) { // PP.sfssuffix[i] = cv5[i]; // } // /* suffix for Speech Filing Sysytem binaries */ // /* 'voicebox:67' PP.memsize=50e6; */ // PP.memsize = 5.0E+7; // /* Maximum amount of temporary memory to use (Bytes) */ // /* DYPSA glottal closure identifier */ // /* 'voicebox:71' PP.dy_cpfrac=0.3; */ // PP.dy_cpfrac = 0.3; // /* presumed closed phase fraction of larynx cycle */ // /* 'voicebox:72' PP.dy_cproj=0.2; */ // PP.dy_cproj = 0.2; // /* cost of projected candidate */ // /* 'voicebox:73' PP.dy_cspurt=-0.45; */ // PP.dy_cspurt = -0.45; // /* cost of a talkspurt */ // /* 'voicebox:74' PP.dy_dopsp=1; */ // PP.dy_dopsp = 1.0; // /* Use phase slope projection (1) or not (0)? */ // /* 'voicebox:75' PP.dy_ewdly=0.0008; */ // PP.dy_ewdly = 0.0008; // /* window delay for energy cost function term [~ energy peak delay from closure] (sec) */ // /* 'voicebox:76' PP.dy_ewlen=0.003; */ // PP.dy_ewlen = 0.003; // /* window length for energy cost function term (sec) */ // /* 'voicebox:77' PP.dy_ewtaper=0.001; */ // PP.dy_ewtaper = 0.001; // /* taper length for energy cost function window (sec) */ // /* 'voicebox:78' PP.dy_fwlen=0.00045; */ // PP.dy_fwlen = 0.00045; // /* window length used to smooth group delay (sec) */ // /* 'voicebox:79' PP.dy_fxmax=500; */ // PP.dy_fxmax = 500.0; // /* max larynx frequency (Hz) */ // /* 'voicebox:80' PP.dy_fxmin=50; */ // PP.dy_fxmin = 50.0; // /* min larynx frequency (Hz) */ // /* 'voicebox:81' PP.dy_fxminf=60; */ // PP.dy_fxminf = 60.0; // /* min larynx frequency (Hz) [used for Frobenius norm only] */ // /* 'voicebox:82' PP.dy_gwlen=0.0030; */ // PP.dy_gwlen = 0.003; // /* group delay evaluation window length (sec) */ // /* 'voicebox:83' PP.dy_lpcdur=0.020; */ // PP.dy_lpcdur = 0.02; // /* lpc analysis frame length (sec) */ // /* 'voicebox:84' PP.dy_lpcn=2; */ // PP.dy_lpcn = 2.0; // /* lpc additional poles */ // /* 'voicebox:85' PP.dy_lpcnf=0.001; */ // PP.dy_lpcnf = 0.001; // /* lpc poles per Hz (1/Hz) */ // /* 'voicebox:86' PP.dy_lpcstep=0.010; */ // PP.dy_lpcstep = 0.01; // /* lpc analysis step (sec) */ // /* 'voicebox:87' PP.dy_nbest=5; */ // PP.dy_nbest = 5.0; // /* Number of NBest paths to keep */ // /* 'voicebox:88' PP.dy_preemph=50; */ // PP.dy_preemph = 50.0; // /* pre-emphasis filter frequency (Hz) (to avoid preemphasis, make this very large) */ // /* 'voicebox:89' PP.dy_spitch=0.2; */ // PP.dy_spitch = 0.2; // /* scale factor for pitch deviation cost */ // /* 'voicebox:90' PP.dy_wener=0.3; */ // PP.dy_wener = 0.3; // /* DP energy weighting */ // /* 'voicebox:91' PP.dy_wpitch=0.5; */ // PP.dy_wpitch = 0.5; // /* DP pitch weighting */ // /* 'voicebox:92' PP.dy_wslope=0.1; */ // PP.dy_wslope = 0.1; // DP group delay slope weighting // /* 'voicebox:93' PP.dy_wxcorr=0.8; */ // PP.dy_wxcorr = 0.8; // /* DP cross correlation weighting */ // /* 'voicebox:94' PP.dy_xwlen=0.01; */ // PP.dy_xwlen = 0.01; // /* cross-correlation length for waveform similarity (sec) */ // /* RAPT pitch tracker */ // /* 'voicebox:98' PP.rapt_f0min=50; */ // PP.rapt_f0min = 50.0; // /* Min F0 (Hz) */ // /* 'voicebox:99' PP.rapt_f0max=500; */ // PP.rapt_f0max = 500.0; // /* Max F0 (Hz) */ // /* 'voicebox:100' PP.rapt_tframe=0.01; */ // PP.rapt_tframe = 0.01; // /* frame size (s) */ // /* 'voicebox:101' PP.rapt_tlpw=0.005; */ // PP.rapt_tlpw = 0.005; // /* low pass filter window size (s) */ // /* 'voicebox:102' PP.rapt_tcorw=0.0075; */ // PP.rapt_tcorw = 0.0075; // /* correlation window size (s) */ // /* 'voicebox:103' PP.rapt_candtr=0.3; */ // PP.rapt_candtr = 0.3; // /* minimum peak in NCCF */ // /* 'voicebox:104' PP.rapt_lagwt=0.3; */ // PP.rapt_lagwt = 0.3; // /* linear lag taper factor */ // /* 'voicebox:105' PP.rapt_freqwt=0.02; */ // PP.rapt_freqwt = 0.02; // /* cost factor for F0 change */ // /* 'voicebox:106' PP.rapt_vtranc=0.005; */ // PP.rapt_vtranc = 0.005; // /* fixed voice-state transition cost */ // /* 'voicebox:107' PP.rapt_vtrac=0.5; */ // PP.rapt_vtrac = 0.5; // /* delta amplitude modulated transition cost */ // /* 'voicebox:108' PP.rapt_vtrsc=0.5; */ // PP.rapt_vtrsc = 0.5; // /* delta spectrum modulated transition cost */ // /* 'voicebox:109' PP.rapt_vobias=0.0; */ // PP.rapt_vobias = 0.0; // /* bias to encourage voiced hypotheses */ // /* 'voicebox:110' PP.rapt_doublec=0.35; */ // PP.rapt_doublec = 0.35; // /* cost of exact doubling or halving */ // /* 'voicebox:111' PP.rapt_absnoise=0; */ // PP.rapt_absnoise = 0.0; // /* absolute rms noise level */ // /* 'voicebox:112' PP.rapt_relnoise=2; */ // PP.rapt_relnoise = 2.0; // /* rms noise level relative to noise floor */ // /* 'voicebox:113' PP.rapt_signoise=0.001; */ // PP.rapt_signoise = 0.001; // /* ratio of peak signal rms to noise floor (0.001 = 60dB) */ // /* 'voicebox:114' PP.rapt_ncands=20; */ // PP.rapt_ncands = 20.0; // /* max hypotheses at each frame */ // /* 'voicebox:115' PP.rapt_trms=0.03; */ // PP.rapt_trms = 0.03; // /* window length for rms measurement */ // /* 'voicebox:116' PP.rapt_dtrms=0.02; */ // PP.rapt_dtrms = 0.02; // /* window spacing for rms measurement */ // /* 'voicebox:117' PP.rapt_preemph=-7000; */ // PP.rapt_preemph = -7000.0; // /* s-plane position of preemphasis zero */ // /* 'voicebox:118' PP.rapt_nfullag=7; */ // PP.rapt_nfullag = 7.0; // /* number of full lags to try (must be odd) */ // /* now check some of the key values for validity */ // /* if exist(PP.dir_temp)~=7 % check that temp directory exists */ // /* PP.dir_temp = winenvar('temp'); % else use windows temp directory */ // /* end */ // /* */ // /* [fnp,fnn,fne]=fileparts(mfilename('fullpath')); */ // /* if exist(PP.shorten)~=2 % check that shorten executable exists */ // /* PP.shorten=fullfile(fnp,'shorten.exe'); % next try local directory */ // /* if exist(PP.shorten)~=2 % check if it exists in local directory */ // /* PP.shorten='shorten.exe'; % finally assume it is on the search path */ // /* end */ // /* end */ // /* */ // /* if exist(PP.flac)~=2 % check that flac executable exists */ // /* PP.flac=fullfile(fnp,'flac.exe'); % next try local directory */ // /* if exist(PP.flac)~=2 % check if it exists in local directory */ // /* PP.shorten='flac.exe'; % finally assume it is on the search path */ // /* end */ // /* end */ // } /* 'voicebox:142' if nargin==0 */ /* 'voicebox:160' elseif nargin==1 */ /* 'voicebox:161' if isfield(PP,f) */ /* 'voicebox:162' y=PP.(f); */ /* set memory size to use */ /* 'gaussmixp:53' lp=zeros(n,1); */ /* 'gaussmixp:54' wk=ones(k,1); */ /* 'gaussmixp:56' vi=-0.5*v.^(-1); */ for (i = 0; i < 108; i++) { b_y[i] = rt_powd_snf(v[i], -1.0); } /* data-independent scale factor in exponent */ /* 'gaussmixp:57' lvm=log(w)-0.5*sum(log(v),2); */ for (i = 0; i < 9; i++) { x[i] = log(w[i]); } for (i = 0; i < 108; i++) { b_x[i] = log(v[i]); } sum(b_x, b); /* log of external scale factor (excluding -0.5*q*log(2pi) term) */ /* 'gaussmixp:58' ii=1:n; */ /* 'gaussmixp:59' wnj=ones(1,n); */ /* 'gaussmixp:60' kk=repmat(ii,k,1); */ /* 'gaussmixp:61' km=repmat(1:k,1,n); */ i = 0; iacol = 0; for (jcol = 0; jcol < 9; jcol++) { km[i] = (real_T)(int8_T)(1 + (int8_T)iacol); i++; iacol++; } /* 'gaussmixp:62' py=reshape(sum((y(kk(:),:)-m(km(:),:)).^2.*vi(km(:),:),2),k,n)+lvm(:,wnj); */ for (i = 0; i < 12; i++) { for (iacol = 0; iacol < 9; iacol++) { b_x[iacol + 9 * i] = y[i] - m[((int32_T)km[iacol] + 9 * i) - 1]; } } for (i = 0; i < 108; i++) { c_y[i] = rt_powd_snf(b_x[i], 2.0); } for (i = 0; i < 12; i++) { for (iacol = 0; iacol < 9; iacol++) { b_x[iacol + 9 * i] = c_y[iacol + 9 * i] * (-0.5 * b_y[((int32_T)km[iacol] + 9 * i) - 1]); } } sum(b_x, km); for (i = 0; i < 9; i++) { py[i] = km[i] + (x[i] - 0.5 * b[i]); } /* 'gaussmixp:63' mx=max(py,[],1); */ i = 1; mtmp = py[0]; if (rtIsNaN(py[0])) { iacol = 2; exitg1 = 0U; while ((exitg1 == 0U) && (iacol < 10)) { i = iacol; if (!rtIsNaN(py[iacol - 1])) { mtmp = py[iacol - 1]; exitg1 = 1U; } else { iacol++; } } } if (i < 9) { while (i + 1 < 10) { if (py[i] > mtmp) { mtmp = py[i]; } i++; } } /* find normalizing factor for each data point to prevent underflow when using exp() */ /* 'gaussmixp:64' px=exp(py-mx(wk,:)); */ for (i = 0; i < 9; i++) { py[i] = exp(py[i] - mtmp); } /* find normalized probability of each mixture for each datapoint */ /* 'gaussmixp:65' ps=sum(px,1); */ ps = py[0]; for (i = 0; i < 8; i++) { ps += py[i + 1]; } /* total normalized likelihood of each data point */ /* 'gaussmixp:66' lp(ii)=log(ps)+mx; */ /* 'gaussmixp:67' lp=lp-0.5*q*log(2*pi); */ return (log(ps) + mtmp) - 11.027262398456072; }
/* * COMPOSEUMATRIX * U_SYM = COMPOSEUMATRIX(IN1,IN2,IN3) * Arguments : const double in1[9] * const double in2[6] * const double in3[8] * double U_sym[54] * Return Type : void */ void composeUMatrix(const double in1[9], const double in2[6], const double in3[8], double U_sym[54]) { double t2; double t3; double t4; double t8; double t10; double t11; double t12; double t13; double t14; double t15; double t18; double t19; double t20; double x[54]; /* This function was generated by the Symbolic Math Toolbox version 6.0. */ /* 16-May-2014 12:41:06 */ t2 = fabs(in2[0]); t3 = fabs(in2[1]); t4 = fabs(in2[2]); t8 = (t2 * t2 + t3 * t3) + t4 * t4; t10 = in3[5] * sqrt(t8) * 0.5; t11 = sin(t10); t12 = 1.0 / sqrt(t8); if (in2[0] < 0.0) { t13 = -1.0; } else if (in2[0] > 0.0) { t13 = 1.0; } else if (in2[0] == 0.0) { t13 = 0.0; } else { t13 = in2[0]; } t14 = 1.0 / rt_powd_snf(t8, 1.5); t15 = cos(t10); t10 = 1.0 / t8; if (in2[1] < 0.0) { t8 = -1.0; } else if (in2[1] > 0.0) { t8 = 1.0; } else if (in2[1] == 0.0) { t8 = 0.0; } else { t8 = in2[1]; } if (in2[2] < 0.0) { t18 = -1.0; } else if (in2[2] > 0.0) { t18 = 1.0; } else if (in2[2] == 0.0) { t18 = 0.0; } else { t18 = in2[2]; } t19 = in1[4] * t11 * t12; t20 = in1[6] * t11 * t12; x[0] = 0.0; x[1] = 0.0; x[2] = 0.0; x[3] = 0.0; x[4] = ((((((-in1[5] * t11 * t12 - in3[5] * in1[4] * t2 * t11 * t12 * t13 * 0.5) + in1[5] * t2 * t11 * t13 * t14 * in2[0]) + in1[6] * t2 * t11 * t13 * t14 * in2[1]) + in1[7] * t2 * t11 * t13 * t14 * in2[2]) - in3[5] * in1[5] * t2 * t13 * t15 * t10 * in2[0] * 0.5) - in3[5] * in1[6] * t2 * t13 * t15 * t10 * in2[1] * 0.5) - in3[5] * in1[7] * t2 * t13 * t15 * t10 * in2[2] * 0.5; x[5] = ((((((t19 - in3[5] * in1[5] * t2 * t11 * t12 * t13 * 0.5) - in1[4] * t2 * t11 * t13 * t14 * in2[0]) - in1[6] * t2 * t11 * t13 * t14 * in2 [2]) + in1[7] * t2 * t11 * t13 * t14 * in2[1]) + in3[5] * in1[4] * t2 * t13 * t15 * t10 * in2[0] * 0.5) + in3[5] * in1[6] * t2 * t13 * t15 * t10 * in2[2] * 0.5) - in3[5] * in1[7] * t2 * t13 * t15 * t10 * in2[1] * 0.5; x[6] = ((((((in1[7] * t11 * t12 - in3[5] * in1[6] * t2 * t11 * t12 * t13 * 0.5) - in1[4] * t2 * t11 * t13 * t14 * in2[1]) + in1[5] * t2 * t11 * t13 * t14 * in2[2]) - in1[7] * t2 * t11 * t13 * t14 * in2[0]) + in3[5] * in1[4] * t2 * t13 * t15 * t10 * in2[1] * 0.5) - in3[5] * in1[5] * t2 * t13 * t15 * t10 * in2[2] * 0.5) + in3[5] * in1[7] * t2 * t13 * t15 * t10 * in2[0] * 0.5; x[7] = ((((((-t20 - in3[5] * in1[7] * t2 * t11 * t12 * t13 * 0.5) - in1[4] * t2 * t11 * t13 * t14 * in2[2]) - in1[5] * t2 * t11 * t13 * t14 * in2[1]) + in1[6] * t2 * t11 * t13 * t14 * in2[0]) + in3[5] * in1[4] * t2 * t13 * t15 * t10 * in2[2] * 0.5) + in3[5] * in1[5] * t2 * t13 * t15 * t10 * in2[1] * 0.5) - in3[5] * in1[6] * t2 * t13 * t15 * t10 * in2[0] * 0.5; x[8] = 0.0; x[9] = 0.0; x[10] = 0.0; x[11] = 0.0; x[12] = 0.0; x[13] = ((((((-in1[6] * t11 * t12 - in3[5] * in1[4] * t3 * t11 * t12 * t8 * 0.5) + in1[5] * t3 * t11 * t14 * t8 * in2[0]) + in1[6] * t3 * t11 * t14 * t8 * in2[1]) + in1[7] * t3 * t11 * t14 * t8 * in2[2]) - in3[5] * in1[5] * t3 * t15 * t10 * t8 * in2[0] * 0.5) - in3[5] * in1[6] * t3 * t15 * t10 * t8 * in2[1] * 0.5) - in3[5] * in1[7] * t3 * t15 * t10 * t8 * in2[2] * 0.5; x[14] = ((((((-in1[7] * t11 * t12 - in3[5] * in1[5] * t3 * t11 * t12 * t8 * 0.5) - in1[4] * t3 * t11 * t14 * t8 * in2[0]) - in1[6] * t3 * t11 * t14 * t8 * in2[2]) + in1[7] * t3 * t11 * t14 * t8 * in2[1]) + in3[5] * in1[4] * t3 * t15 * t10 * t8 * in2[0] * 0.5) + in3[5] * in1[6] * t3 * t15 * t10 * t8 * in2[2] * 0.5) - in3[5] * in1[7] * t3 * t15 * t10 * t8 * in2[1] * 0.5; x[15] = ((((((t19 - in3[5] * in1[6] * t3 * t11 * t12 * t8 * 0.5) - in1[4] * t3 * t11 * t14 * t8 * in2[1]) + in1[5] * t3 * t11 * t14 * t8 * in2[2]) - in1[7] * t3 * t11 * t14 * t8 * in2[0]) + in3[5] * in1[4] * t3 * t15 * t10 * t8 * in2[1] * 0.5) - in3[5] * in1[5] * t3 * t15 * t10 * t8 * in2[2] * 0.5) + in3[5] * in1[7] * t3 * t15 * t10 * t8 * in2[0] * 0.5; x[16] = ((((((in1[5] * t11 * t12 - in3[5] * in1[7] * t3 * t11 * t12 * t8 * 0.5) - in1[4] * t3 * t11 * t14 * t8 * in2[2]) - in1[5] * t3 * t11 * t14 * t8 * in2[1]) + in1[6] * t3 * t11 * t14 * t8 * in2[0]) + in3 [5] * in1[4] * t3 * t15 * t10 * t8 * in2[2] * 0.5) + in3[5] * in1[5] * t3 * t15 * t10 * t8 * in2[1] * 0.5) - in3[5] * in1[6] * t3 * t15 * t10 * t8 * in2[0] * 0.5; x[17] = 0.0; x[18] = 0.0; x[19] = 0.0; x[20] = 0.0; x[21] = 0.0; x[22] = ((((((-in1[7] * t11 * t12 - in3[5] * in1[4] * t4 * t11 * t12 * t18 * 0.5) + in1[5] * t4 * t11 * t14 * t18 * in2[0]) + in1[6] * t4 * t11 * t14 * t18 * in2[1]) + in1[7] * t4 * t11 * t14 * t18 * in2[2]) - in3[5] * in1[5] * t4 * t15 * t10 * t18 * in2[0] * 0.5) - in3[5] * in1[6] * t4 * t15 * t10 * t18 * in2[1] * 0.5) - in3[5] * in1[7] * t4 * t15 * t10 * t18 * in2[2] * 0.5; x[23] = ((((((t20 - in3[5] * in1[5] * t4 * t11 * t12 * t18 * 0.5) - in1[4] * t4 * t11 * t14 * t18 * in2[0]) - in1[6] * t4 * t11 * t14 * t18 * in2[2]) + in1[7] * t4 * t11 * t14 * t18 * in2[1]) + in3[5] * in1[4] * t4 * t15 * t10 * t18 * in2[0] * 0.5) + in3[5] * in1[6] * t4 * t15 * t10 * t18 * in2[2] * 0.5) - in3[5] * in1[7] * t4 * t15 * t10 * t18 * in2[1] * 0.5; x[24] = ((((((-in1[5] * t11 * t12 - in3[5] * in1[6] * t4 * t11 * t12 * t18 * 0.5) - in1[4] * t4 * t11 * t14 * t18 * in2[1]) + in1[5] * t4 * t11 * t14 * t18 * in2[2]) - in1[7] * t4 * t11 * t14 * t18 * in2[0]) + in3[5] * in1[4] * t4 * t15 * t10 * t18 * in2[1] * 0.5) - in3[5] * in1[5] * t4 * t15 * t10 * t18 * in2[2] * 0.5) + in3[5] * in1[7] * t4 * t15 * t10 * t18 * in2[0] * 0.5; x[25] = ((((((t19 - in3[5] * in1[7] * t4 * t11 * t12 * t18 * 0.5) - in1[4] * t4 * t11 * t14 * t18 * in2[2]) - in1[5] * t4 * t11 * t14 * t18 * in2[1]) + in1[6] * t4 * t11 * t14 * t18 * in2[0]) + in3[5] * in1[4] * t4 * t15 * t10 * t18 * in2[2] * 0.5) + in3[5] * in1[5] * t4 * t15 * t10 * t18 * in2[1] * 0.5) - in3[5] * in1[6] * t4 * t15 * t10 * t18 * in2[0] * 0.5; x[26] = 0.0; x[27] = 0.0; x[28] = 0.0; x[29] = 0.0; x[30] = 0.0; x[31] = 0.0; x[32] = 0.0; x[33] = 0.0; x[34] = 0.0; x[35] = 0.0; x[36] = 0.0; x[37] = 0.0; x[38] = 0.0; x[39] = 0.0; x[40] = 0.0; x[41] = 0.0; x[42] = 0.0; x[43] = 0.0; x[44] = 0.0; x[45] = 0.0; x[46] = 0.0; x[47] = 0.0; x[48] = in3[5]; x[49] = 0.0; x[50] = 0.0; x[51] = 0.0; x[52] = 0.0; x[53] = 0.0; memcpy(&U_sym[0], &x[0], 54U * sizeof(double)); }
/* Function Definitions */ void quadrotorPropulsion(const real_T xin[4], const real_T uin[10], const PropulsionParameters parameter, real_T dt, real_T y[14], real_T xpred[4]) { real_T v_1[4]; int32_T i; real_T F_m[4]; real_T U[4]; real_T M_e[4]; real_T I[4]; real_T F[3]; real_T b_F_m; real_T temp; real_T d0; /* initialize vectors */ for (i = 0; i < 4; i++) { xpred[i] = xin[i]; /* motorspeed */ v_1[i] = 0.0; } memset(&y[0], 0, 14U * sizeof(real_T)); for (i = 0; i < 4; i++) { F_m[i] = 0.0; U[i] = 0.0; M_e[i] = 0.0; I[i] = 0.0; } for (i = 0; i < 3; i++) { F[i] = 0.0; } /* Input variables */ U[0] = uin[6]; U[1] = uin[7]; U[2] = uin[8]; U[3] = uin[9]; /* Constants */ v_1[0] = -uin[2] + parameter.l_m * uin[4]; v_1[1] = -uin[2] - parameter.l_m * uin[3]; v_1[2] = -uin[2] - parameter.l_m * uin[4]; v_1[3] = -uin[2] + parameter.l_m * uin[3]; /* calculate thrust for all 4 rotors */ for (i = 0; i < 4; i++) { /* if the flow speed at infinity is negative */ if (v_1[i] < 0.0) { b_F_m = (parameter.CT2s * rt_powd_snf(v_1[i], 2.0) + parameter.CT1s * v_1[i] * xin[i]) + parameter.CT0s * rt_powd_snf(xin[i], 2.0); /* if the flow speed at infinity is positive */ } else { b_F_m = (-parameter.CT2s * rt_powd_snf(v_1[i], 2.0) + parameter.CT1s * v_1[i] * xin[i]) + parameter.CT0s * rt_powd_snf(xin[i], 2.0); } /* sum up all rotor forces */ /* Identification of Roxxy2827-34 motor with 10x4.5 propeller */ /* temporarily used Expressions */ temp = (U[i] * parameter.beta_m - parameter.Psi * xin[i]) / (2.0 * parameter.R_A); temp += sqrt(rt_powd_snf(temp, 2.0) + U[i] * parameter.alpha_m / parameter.R_A); d0 = parameter.Psi * temp; /* electrical torque motor 1-4 */ /* new version */ /* old version */ /* fx = (Psi/R_A*(U-Psi*omega_m) - M_m)/J_M; */ /* A = -(Psi^2/R_A)/J_M; */ /* B(1) = Psi/(J_M*R_A); */ /* B(2) = -1/J_M; */ /* system outputs. Use euler solver to predict next time step */ /* predicted motor speed */ /* electric torque */ /* y = [M_e I]; */ /* system jacobian */ /* A = 1 + dt*A; */ /* input jacobian */ /* B = A*B*dt; */ M_e[i] = d0; I[i] = temp; xpred[i] = xin[i] + dt * (1.0 / parameter.J_M * (d0 - (parameter.k_t * b_F_m + parameter.k_m * xin[i]))); F_m[i] = b_F_m; F[2] += b_F_m; } /* System output, i.e. force and torque of quadrotor */ y[0] = 0.0; y[1] = 0.0; y[2] = F[2]; /* torque for rotating quadrocopter around x-axis is the mechanical torque */ y[3] = (F_m[3] - F_m[1]) * parameter.l_m; /* torque for rotating quadrocopter around y-axis is the mechanical torque */ y[4] = (F_m[0] - F_m[2]) * parameter.l_m; /* torque for rotating quadrocopter around z-axis is the electrical torque */ y[5] = ((-M_e[0] - M_e[2]) + M_e[1]) + M_e[3]; /* motor speeds (rad/s) */ for (i = 0; i < 4; i++) { y[i + 6] = xpred[i]; } /* motor current (A) */ for (i = 0; i < 4; i++) { y[i + 10] = I[i]; } /* M_e(1:4) / Psi; */ }
/* Function Definitions */ void GetCorrAirComp(double T_amb, double p_amb, double humid, double Mf_a, double Mf_a_corr[5], double Wf_a_corr[5], double *MW, double *H_a) { double M_f_a; double p_p_H2O; int k; double M_f_a_corr[5]; double y; double b_y; double c_y; double d_y; double e_y; double f_y[5]; double b_Mf_a_corr; static const double b[5] = { 31.9988, 28.011, 39.9481, 44.01, 18.01534 }; double b_MW[5]; int i5; static const double b_b[25] = { 31.9988, 0.0, 0.0, 0.0, 0.0, 0.0, 28.011, 0.0, 0.0, 0.0, 0.0, 0.0, 39.9481, 0.0, 0.0, 0.0, 0.0, 0.0, 44.01, 0.0, 0.0, 0.0, 0.0, 0.0, 18.01534 }; /* Calculate the corrected mole and mass fraction of molecules (Mf_a, Wf_a) */ /* in air with humidity, water content(w_H2O, g/kg) and molecular weight(MW) */ /* of air at given temperature in Kelvin and relative humidity in %. */ /* Vapor pressure of water at saturated condition(bar) is used from */ /* ISO 8178-1 Eqn (A.14), Wexler and Greenspan equation */ /* */ /* input */ /* T_amb : Ambient temperature [K] */ /* p_amb : Ambient pressure [Pa] */ /* humid : Relative humidity [%] */ /* Mf_a : Dry air composition mole ratio to oxygen (O2;N2;Ar;CO2) */ /* e.g. [1;3.7274;0.0444;0.0014] */ /* Output */ /* Mf_a_corr : Air composition mole ratio to oxigen (O2:N2:Ar:CO2:H2O) */ /* Wf_a_corr : Air composition weight ratio to oxigen (O2:N2:Ar:CO2:H2O) */ /* MW : Molecular weight */ /* H_a : water content (g H2O / kg Air) */ /* */ /* Created by Kevin Yum */ M_f_a = Mf_a / Mf_a; /* Vapor pressure of water at saturated condition(bar) */ /* ISO 8178-1 Eqn (A.14), Wexler and Greenspan equation */ /* Partial pressure of water */ p_p_H2O = humid / 100.0 * exp((((((((((-12.150799 * log(T_amb) - 8499.22 * rt_powd_snf(T_amb, -2.0)) - 7423.1865 * (1.0 / T_amb)) + 96.1635147) + 0.024917646 * T_amb) - 1.3160119E-5 * (T_amb * T_amb)) - 1.1460454E-8 * rt_powd_snf(T_amb, 3.0)) + 2.1701289E-11 * rt_powd_snf(T_amb, 4.0)) - 3.610258E-15 * rt_powd_snf(T_amb, 5.0)) + 3.8504519E-18 * rt_powd_snf(T_amb, 6.0)) - 1.4317E-21 * rt_powd_snf(T_amb, 7.0)); /* no. of mole of water for 1 mole of oxygen in the air */ /* Corrected mole & wt fraction including water content */ for (k = 0; k < 4; k++) { M_f_a_corr[k] = M_f_a; } M_f_a_corr[4] = M_f_a * p_p_H2O / (p_amb * 100.0 - p_p_H2O); y = M_f_a_corr[0]; b_y = M_f_a_corr[0]; c_y = M_f_a_corr[0]; d_y = M_f_a_corr[0]; e_y = M_f_a_corr[0]; for (k = 0; k < 4; k++) { y += M_f_a_corr[k + 1]; b_y += M_f_a_corr[k + 1]; c_y += M_f_a_corr[k + 1]; d_y += M_f_a_corr[k + 1]; e_y += M_f_a_corr[k + 1]; } f_y[0] = y; f_y[1] = b_y; f_y[2] = c_y; f_y[3] = d_y; f_y[4] = e_y; y = 0.0; for (k = 0; k < 5; k++) { b_Mf_a_corr = M_f_a_corr[k] / f_y[k]; y += b_Mf_a_corr * b[k]; Mf_a_corr[k] = b_Mf_a_corr; } *MW = y; b_MW[0] = y; b_MW[1] = y; b_MW[2] = y; b_MW[3] = y; b_MW[4] = y; for (k = 0; k < 5; k++) { f_y[k] = 0.0; for (i5 = 0; i5 < 5; i5++) { f_y[k] += Mf_a_corr[i5] * b_b[i5 + 5 * k]; } Wf_a_corr[k] = f_y[k] / b_MW[k]; } /* Humidity of the intake air (g water per kg dry air) */ *H_a = Mf_a_corr[4] * 18.01534 / (y - Mf_a_corr[4] * 18.01534) * 1000.0; }
/* Function Definitions */ double GetHTCoeffHTX(double p, double m_dot, double T, double D, double A) { double rho_a; double mu_a; double lambda; double unusedUe; double unusedUd; double d6; double unusedUc; double unusedUb; double unusedUa; double unusedU9; double unusedU8; double unusedU7; double unusedU6; double unusedU5; double unusedU4; double unusedU3; double unusedU2; double unusedU1; double unusedU0; double Re_D; double Pr; /* Calculate the heat transfer coeff of convectivity for charge air cooler */ /* exchanger (Cross-flow type) */ /* Input */ /* p : pressure (Pa) */ /* m_dot : mass flow (kg/s) */ /* T : temperature (K), should be mean value of the air and coolant */ /* D : Diameter of tube (coolant side) */ /* A : Effective sectional area of air path */ /* Output */ /* alpha : Heat transfer coefficient of convectivity (W/m2K) */ /* */ /* Created by Kevin Koosup Yum (25 March 2014) */ /* */ rho_a = GetAirDensity(p, T); mu_a = GetAirViscosity(rho_a, T); lambda = GetAirThermalConduct(rho_a, T); GetThdynCombGasZachV1(p, T, 0.0, 0.0683, &unusedU0, &unusedU1, &unusedU2, &unusedU3, &unusedU4, &unusedU5, &unusedU6, &unusedU7, &unusedU8, &unusedU9, &unusedUa, &unusedUb, &unusedUc, &d6, &unusedUd, &unusedUe); /* % */ Re_D = m_dot / rho_a / A * D * rho_a / mu_a; Pr = mu_a * d6 / lambda; /* { */ /* Nu_D1 = zeros(m,1); */ /* idx = find(Re_D <= 4); */ /* Nu_D1(idx) = 0.989*Re_D(idx).^0.330.*Pr(idx); */ /* idx = find(Re_D <= 40 & Re_D > 4); */ /* Nu_D1(idx) = 0.911*Re_D(idx).^0.385.*Pr(idx); */ /* idx = find(Re_D <= 4000 & Re_D > 40); */ /* Nu_D1(idx) = 0.683*Re_D(idx).^0.466.*Pr(idx); */ /* idx = find(Re_D <= 40000 & Re_D > 4000); */ /* Nu_D1(idx) = 0.193*Re_D(idx).^0.618.*Pr(idx); */ /* idx = find(Re_D <= 400000 & Re_D > 40000); */ /* Nu_D1(idx) = 0.027*Re_D(idx).^0.805.*Pr(idx); */ /* alpha1 = Nu_D1.*lambda/D; */ /* } */ return (0.3 + 0.62 * sqrt(Re_D) * rt_powd_snf(Pr, 0.333) / rt_powd_snf(1.0 + rt_powd_snf(0.4 / Pr, 0.666), 0.25) * rt_powd_snf(1.0 + rt_powd_snf (Re_D / 282000.0, 0.625), 0.8)) * lambda / D; }
/* * The function calculates the air density based on equation of state * proposed by Kadoya. * Input * p : pressure in Pa * T : Temperature in K * Output * rho_a : density of the air * Validity : 300~2000K and upto 100MPa. * Ref * Kadoya, K., N. Matsunaga, et al. (1985). "Viscosity and Thermal * Conductivity of Dry Air in the Gaseous Phase." J. Phys. Chem. Ref. Data 14(4). * Created by Kevin Koosup Yum (NTNU) on 23 May, 2013 * Arguments : double p * double T * Return Type : double */ double GetAirDensity(double p, double T) { double rho_a; double rho_ideal; double TT[6]; int i; double rho_error; double rho; double tau; static const double a[6] = { -3.4600925E-8, -4.5776295E-7, -3.4932E-6, -3.9930515E-5, 4.4292095E-5, -4.5598149999999997E-7 }; static const double b_a[4] = { 1.0518311175000001E-9, -2.3202380725E-9, 1.8055242775E-9, 5.028921625E-10 }; double varargin_1; /* Universal Gas constant J/(molK) */ rho_ideal = p / T / 8.314; /* (K) */ /* (10e-6m3/mol) */ for (i = 0; i < 6; i++) { TT[i] = 0.0; } rho_error = 1.0; rho = rho_ideal; tau = T / 340.0; TT[0] = 1.0 / rt_powd_snf(tau, 4.0); for (i = 0; i < 5; i++) { TT[i + 1] = TT[i] * tau; } while (rho_error > 0.001) { tau = 0.0; for (i = 0; i < 6; i++) { tau += a[i] * TT[i]; } rho_error = 0.0; for (i = 0; i < 4; i++) { rho_error += b_a[i] * TT[1 + i]; } varargin_1 = 0.1 * rho; tau = rho + -(((rho_ideal / rho - 1.0) - tau * rho) - rho_error * (rho * rho)) / ((-rho_ideal / (rho * rho) - tau) - 2.0 * rho_error * rho); if ((varargin_1 >= tau) || rtIsNaN(tau)) { tau = varargin_1; } rho_error = fabs(tau - rho) / rho; rho = tau; } rho_a = rho * 28.97 / 1000.0; /* end */ return rho_a; }
/* Model step function */ void calibrazione_acc_step(void) { real_T W[24]; real_T X[12]; real_T rtb_sinphi2; real_T rtb_Product4; real_T W_0[16]; real_T tmp[16]; int32_T i; real_T tmp_0[24]; real_T tmp_1[18]; int32_T i_0; int32_T i_1; /* Trigonometry: '<S2>/sin(phi)' incorporates: * Inport: '<Root>/position' */ rtb_sinphi2 = sin(calibrazione_acc_U.position[0]); /* Math: '<S2>/sin(phi)^2' */ rtb_sinphi2 *= rtb_sinphi2; /* Sum: '<S2>/Sum1' incorporates: * Constant: '<S2>/First Eccentricity' * Constant: '<S2>/One' * Math: '<S2>/eps^2' * Product: '<S2>/Product' */ rtb_Product4 = calibrazione_acc_P.One_Value - calibrazione_acc_P.FirstEccentricity_Value * calibrazione_acc_P.FirstEccentricity_Value * rtb_sinphi2; /* Math: '<S2>/Math Function1' incorporates: * Constant: '<S2>/1//2' */ if ((rtb_Product4 < 0.0) && (calibrazione_acc_P.u_Value > floor (calibrazione_acc_P.u_Value))) { rtb_Product4 = -rt_powd_snf(-rtb_Product4, calibrazione_acc_P.u_Value); } else { rtb_Product4 = rt_powd_snf(rtb_Product4, calibrazione_acc_P.u_Value); } /* End of Math: '<S2>/Math Function1' */ /* Product: '<S2>/Product4' incorporates: * Constant: '<S2>/Gravity at Equator' * Constant: '<S2>/Gravity formula const' * Constant: '<S2>/One' * Product: '<S2>/Product3' * Sum: '<S2>/Sum2' */ rtb_Product4 = (calibrazione_acc_P.Gravityformulaconst_Value * rtb_sinphi2 + calibrazione_acc_P.One_Value) * calibrazione_acc_P.GravityatEquator_Value / rtb_Product4; /* Fcn: '<S2>/g(phi,h)' incorporates: * Inport: '<Root>/position' */ rtb_sinphi2 = (rtb_Product4 - (3.0877e-006 - 4.4e-009 * rtb_sinphi2) * calibrazione_acc_U.position[2]) + 7.2e-014 * calibrazione_acc_U.position[2] * calibrazione_acc_U.position[2]; /* MATLAB Function Block: '<S1>/acc_calibration' incorporates: * Inport: '<Root>/w1' * Inport: '<Root>/w2' * Inport: '<Root>/w3' * Inport: '<Root>/w4' * Inport: '<Root>/w5' * Inport: '<Root>/w6' */ /* MATLAB Function 'calibrazione_acc/acc_calibration': '<S3>:1' */ /* '<S3>:1:3' */ /* '<S3>:1:10' */ W[0] = calibrazione_acc_U.w1[0]; W[6] = calibrazione_acc_U.w1[1]; W[12] = calibrazione_acc_U.w1[2]; W[18] = calibrazione_acc_U.w1[3]; W[1] = calibrazione_acc_U.w2[0]; W[7] = calibrazione_acc_U.w2[1]; W[13] = calibrazione_acc_U.w2[2]; W[19] = calibrazione_acc_U.w2[3]; W[2] = calibrazione_acc_U.w3[0]; W[8] = calibrazione_acc_U.w3[1]; W[14] = calibrazione_acc_U.w3[2]; W[20] = calibrazione_acc_U.w3[3]; W[3] = calibrazione_acc_U.w4[0]; W[9] = calibrazione_acc_U.w4[1]; W[15] = calibrazione_acc_U.w4[2]; W[21] = calibrazione_acc_U.w4[3]; W[4] = calibrazione_acc_U.w5[0]; W[10] = calibrazione_acc_U.w5[1]; W[16] = calibrazione_acc_U.w5[2]; W[22] = calibrazione_acc_U.w5[3]; W[5] = calibrazione_acc_U.w6[0]; W[11] = calibrazione_acc_U.w6[1]; W[17] = calibrazione_acc_U.w6[2]; W[23] = calibrazione_acc_U.w6[3]; /* '<S3>:1:11' */ for (i = 0; i < 4; i++) { for (i_0 = 0; i_0 < 4; i_0++) { W_0[i + (i_0 << 2)] = 0.0; for (i_1 = 0; i_1 < 6; i_1++) { W_0[i + (i_0 << 2)] = W[6 * i + i_1] * W[6 * i_0 + i_1] + W_0[(i_0 << 2) + i]; } } } calibrazione_acc_invNxN(W_0, tmp); for (i = 0; i < 4; i++) { for (i_0 = 0; i_0 < 6; i_0++) { tmp_0[i + (i_0 << 2)] = 0.0; tmp_0[i + (i_0 << 2)] = tmp_0[(i_0 << 2) + i] + tmp[i] * W[i_0]; tmp_0[i + (i_0 << 2)] = tmp_0[(i_0 << 2) + i] + tmp[i + 4] * W[i_0 + 6]; tmp_0[i + (i_0 << 2)] = tmp_0[(i_0 << 2) + i] + tmp[i + 8] * W[i_0 + 12]; tmp_0[i + (i_0 << 2)] = tmp_0[(i_0 << 2) + i] + tmp[i + 12] * W[i_0 + 18]; } } tmp_1[0] = 0.0; tmp_1[6] = 0.0; tmp_1[12] = rtb_sinphi2; tmp_1[1] = 0.0; tmp_1[7] = 0.0; tmp_1[13] = -rtb_sinphi2; tmp_1[2] = 0.0; tmp_1[8] = rtb_sinphi2; tmp_1[14] = 0.0; tmp_1[3] = 0.0; tmp_1[9] = -rtb_sinphi2; tmp_1[15] = 0.0; tmp_1[4] = rtb_sinphi2; tmp_1[10] = 0.0; tmp_1[16] = 0.0; tmp_1[5] = -rtb_sinphi2; tmp_1[11] = 0.0; tmp_1[17] = 0.0; for (i = 0; i < 4; i++) { for (i_0 = 0; i_0 < 3; i_0++) { X[i + (i_0 << 2)] = 0.0; for (i_1 = 0; i_1 < 6; i_1++) { X[i + (i_0 << 2)] = tmp_0[(i_1 << 2) + i] * tmp_1[6 * i_0 + i_1] + X [(i_0 << 2) + i]; } } } /* End of MATLAB Function Block: '<S1>/acc_calibration' */ /* Outport: '<Root>/G' incorporates: * MATLAB Function Block: '<S1>/acc_calibration' */ /* '<S3>:1:12' */ /* '<S3>:1:15' */ /* X=(inv(W'*W))*W'*Y; */ calibrazione_acc_Y.G[0] = X[0]; calibrazione_acc_Y.G[3] = X[4]; calibrazione_acc_Y.G[6] = X[8]; calibrazione_acc_Y.G[1] = X[1]; calibrazione_acc_Y.G[4] = X[5]; calibrazione_acc_Y.G[7] = X[9]; calibrazione_acc_Y.G[2] = X[2]; calibrazione_acc_Y.G[5] = X[6]; calibrazione_acc_Y.G[8] = X[10]; /* Outport: '<Root>/B' incorporates: * MATLAB Function Block: '<S1>/acc_calibration' */ calibrazione_acc_Y.B[0] = X[3]; calibrazione_acc_Y.B[1] = X[7]; calibrazione_acc_Y.B[2] = X[11]; }
/* Function Definitions */ void GetThermalPropertyHCVaporReal(double p, double T, double MW, double T_CR, double p_CR, double W, double *rho_v, double *Cp_v, double *Cv_v, double *lambda) { double p_R; double T_R; double v_R_ideal; double TT[5]; int i13; double d14; int i; static const double b[4] = { 0.1181193, -0.265728, -0.15479, -0.030323 }; double b_TT[3]; double d15; static const double b_b[3] = { 0.0236744, -0.0186984, 0.0 }; double D; double d16; static const double c_b[4] = { 0.2026579, -0.331511, -0.027655, -0.203488 }; double d17; static const double d_b[3] = { 0.0313385, -0.0503618, 0.016901 }; double D_h; double VV[6]; double VV_h[6]; double V_R_error; double V_R; double c43; int j; double c41; double y; double varargin_1; double V_R_temp; double z0; double V_R_h; double c41_h; double c43_h; static const double e_b[5] = { -0.077548, 4.5022582138, -1.70019347497797, 0.282256664878756, -0.0122278061244889 }; double dprdTr; double C_v_pe0; double Cp_pe0; double dprdTr_h; double C_v_peh; double L; double p_R4; double T_r5; double T_r9; double T_r16; double C_v_p; double expo; /* The function calculates the density, isobaric and isochronic specific heat */ /* capacity of the real hydrocarbon gases and thermal conductivity based on */ /* the %procudre 7A.1, 7D3.6, 7E1.6, 12B1.5 and 12B4.1 in API Technical Book */ /* of Petroleum Refining. */ /* Input */ /* p : pressure in Pa */ /* T : Temperature in K */ /* MW : Molecular weight in kg/kmol */ /* T_CR : Critical temperature in K */ /* p_CR : Critical pressure in Pa */ /* W : Acentric factor */ /* Output */ /* rho_v : Density of real gas in kg/m3 */ /* Cp_v : Isobaric specific heat capacity of the real gas in J/kg/K */ /* Cv_v : Isochoric specific heat capacity of the real gas in J/kg/K */ /* lambda : Thermal conductivity of the vapor in W/mK */ /* Reference */ /* API Technical Data Book - Petroleum Refining(1985) */ /* */ /* Created by Kevin Koosup Yum, 3 September 2013 */ /* % Consants */ /* Gas constant in J/kmolK */ p_R = p / p_CR; T_R = T / T_CR; v_R_ideal = rdivide(8314.0 * T, p) / (8314.0 * T_CR / p_CR); for (i13 = 0; i13 < 5; i13++) { TT[i13] = 0.0; } TT[0] = 1.0; d14 = 0.0; for (i = 0; i < 4; i++) { TT[i + 1] = TT[i] * T_R; d14 += 1.0 / TT[i] * b[i]; } for (i13 = 0; i13 < 2; i13++) { b_TT[i13] = TT[i13]; } b_TT[2] = TT[3]; d15 = 0.0; for (i13 = 0; i13 < 3; i13++) { d15 += 1.0 / b_TT[i13] * b_b[i13]; } D = 1.55488E-5 + rdivide(6.23689E-5, T_R); d16 = 0.0; for (i13 = 0; i13 < 4; i13++) { d16 += 1.0 / TT[i13] * c_b[i13]; } for (i13 = 0; i13 < 2; i13++) { b_TT[i13] = TT[i13]; } b_TT[2] = TT[3]; d17 = 0.0; for (i13 = 0; i13 < 3; i13++) { d17 += 1.0 / b_TT[i13] * d_b[i13]; } D_h = 4.8736E-5 + rdivide(7.40336E-6, T_R); for (i = 0; i < 6; i++) { VV[i] = 0.0; VV_h[i] = 0.0; } /* % Calculate the density of vapor */ /* Simple fluid calculation */ V_R_error = 1.0; V_R = v_R_ideal * 0.8; c43 = 0.0; while (V_R_error > 0.001) { VV[0] = V_R; for (j = 0; j < 5; j++) { VV[j + 1] = VV[j] * V_R; } c41 = 0.042724 / TT[3] / VV[1]; y = 0.060167 / VV[1]; c43 = exp(-0.060167 / VV[1]); varargin_1 = 0.1 * V_R; y = V_R - (p_R / T_R * V_R - ((((1.0 + d14 / V_R) + d15 / VV[1]) + D / VV[4]) + c41 * (0.65392 + y) * c43)) / (p_R / T_R - (((((-d14 / VV[1] - 2.0 * d15 / VV[2]) - 5.0 * D / VV[5]) + -0.085448 / TT[3] / VV[2] * (0.65392 + y) * c43) + c41 * (-0.120334 / VV[2]) * c43) + c41 * (0.65392 + y) * (0.120334 / VV[2] * c43))); if ((varargin_1 >= y) || rtIsNaN(y)) { V_R_temp = varargin_1; } else { V_R_temp = y; } V_R_error = fabs(V_R_temp - V_R) / V_R; V_R = V_R_temp; } z0 = p_R * V_R / T_R; /* Heavy Reference fluid calculation */ V_R_h = v_R_ideal * 0.8; V_R_error = 1.0; while (V_R_error > 0.001) { VV_h[0] = V_R_h; for (j = 0; j < 5; j++) { VV_h[j + 1] = VV_h[j] * V_R_h; } c41_h = 0.041577 / TT[3] / VV_h[1]; y = 0.03754 / VV_h[1]; c43_h = exp(-0.03754 / VV_h[1]); varargin_1 = 0.1 * V_R_h; y = V_R_h - (p_R / T_R * V_R_h - ((((1.0 + d16 / V_R_h) + d17 / VV_h[1]) + D_h / VV_h[4]) + c41_h * (1.226 + y) * c43_h)) / (p_R / T_R - (((((-d16 / VV_h[1] - 2.0 * d17 / VV_h[2]) - 5.0 * D_h / VV_h[5]) + -0.083154 / TT[3] / VV_h[2] * (1.226 + y) * c43_h) + c41_h * (-0.07508 / VV_h[2]) * c43_h) + c41_h * (1.226 + y) * (0.07508 / VV_h[2] * c43))); if ((varargin_1 >= y) || rtIsNaN(y)) { V_R_temp = varargin_1; } else { V_R_temp = y; } V_R_error = fabs(V_R_temp - V_R_h) / V_R_h; V_R_h = V_R_temp; } *rho_v = 1.0 / ((z0 + W / 0.3978 * (p_R * V_R_h / T_R - z0)) * 8314.0 * T / p) * MW; /* % Calculate the CP and Cv */ y = 0.0; for (i13 = 0; i13 < 5; i13++) { y += TT[i13] * e_b[i13]; } dprdTr = rdivide(1.0, VV[0]) * (1.0 + ((((0.1181193 + (-0.15479 * TT[1] + -0.060646) / TT[3]) * VV[3] + (0.0236744 - 0.0 / TT[3]) * VV[2]) + 1.55488E-5) - 0.085448 / TT[3] * VV[2] * ((0.65392 + 0.060167 / VV[1]) * exp (-0.060167 / VV[1]))) / VV[4]); C_v_pe0 = (2.0 * (-0.15479 + -0.090969 / TT[1]) / TT[2] / VV[0] + 0.0 / TT[3] / VV[1]) + 6.0 * (0.042724 / (2.0 * TT[3] * 0.060167) * (1.6539199999999998 - (1.6539199999999998 + 0.060167 / VV[1]) * exp (-0.060167 / VV[1]))); Cp_pe0 = (1.0 + T_R * (dprdTr * dprdTr) / (-TT[1] / VV[1] * (1.0 + (((2.0 * d14 * VV[3] + 3.0 * d15 * VV[2]) + 6.0 * D) + 0.042724 / TT[3] * VV[2] * (1.96176 + (5.0 - 2.0 * (0.65392 + 0.060167 / VV[1])) * 0.060167 / VV[1]) * exp(-0.060167 / VV[1])) / VV[4]))) + C_v_pe0; dprdTr_h = 1.0 / VV_h[0] * (1.0 + ((((0.2026579 + (-0.027655 * TT[1] + -0.406976) / TT[3]) * VV_h[3] + (0.0313385 - 0.033802 / TT[3]) * VV_h[2]) + 4.8736E-5) - 0.083154 / TT[3] * VV_h[2] * ((1.226 + 0.03754 / VV_h[1]) * exp (-0.03754 / VV_h[1]))) / VV_h[4]); C_v_peh = (2.0 * (-0.027655 + -0.610464 / TT[1]) / TT[2] / VV_h[0] + 0.050703 / TT[3] / VV_h[1]) + 6.0 * (0.041577 / (2.0 * TT[3] * 0.03754) * (2.226 - (2.226 + 0.03754 / VV_h[1]) * exp(-0.03754 / VV_h[1]))); *Cp_v = y - 8.314 / MW * (Cp_pe0 + W / 0.3978 * (((1.0 + T_R * (dprdTr_h * dprdTr_h) / (-TT[1] / VV_h[1] * (1.0 + (((2.0 * d16 * VV_h[3] + 3.0 * d17 * VV_h[2]) + 6.0 * D_h) + 0.041577 / TT[3] * VV_h[2] * (3.678 + (5.0 - 2.0 * (1.226 + 0.03754 / VV_h[1])) * 0.03754 / VV_h[1]) * exp(-0.03754 / VV_h[1])) / VV_h[4]))) + C_v_peh) - Cp_pe0)); /* in kJ/kgK */ *Cv_v = y - 8.314 / MW * (1.0 + (C_v_pe0 + W / 0.3978 * (C_v_peh - C_v_pe0))); /* in kJ/kgK */ /* % Calculate Thermal Conductivity */ L = 23.9712 * rt_powd_snf(T_CR, 0.1667) * sqrt(MW) / rt_powd_snf(p_CR / 1000.0, 0.6667); if (T_R < 1.0) { *lambda = 0.0004911 * T_R * *Cp_v * MW / L; } else { *lambda = 0.0001104 * rt_powd_snf(14.52 * T_R - 5.14, 0.6667) * *Cp_v * MW / L; } if (p > 345000.0) { p_R4 = rt_powd_snf(p_R, 4.0); /* p_r5 = p_r4*p_r; */ T_r5 = TT[4] * T_R; T_r9 = T_r5 * TT[4]; T_r16 = T_r9 * T_r5 * TT[2]; C_v_p = 20.79 - 8.314 * (1.0 + C_v_pe0); expo = exp(-0.0617 * exp(1.91 / T_r9) * rt_powd_snf(p_R, 2.29 * exp(1.34 / T_r16))); /* noncyclic compound */ *lambda *= (C_v_p * (1.0 + (4.18 + (0.537 * p_R * T_R * (1.0 - expo) + 0.51 * p_R * expo) * T_R) / TT[4]) + (*Cv_v * MW - C_v_p) * (1.0 + (p_R4 / (2.44 * (T_r16 * TT[4]) + p_R4) + 0.012 * p_R * TT[4]) / T_r5)) / (*Cv_v * MW); } *Cp_v *= 1000.0; *Cv_v *= 1000.0; }
/* Function Definitions */ void GetPTx(double m, const double N[12], double E, double V, double T_prev, double *P, double *T, double x[12]) { double y; int k; double d10; double b_x; static const double b[12] = { 1.00794, 15.9994, 14.0067, 2.01588, 17.00734, 28.0101, 30.0061, 31.9988, 18.01528, 44.0095, 28.0134, 39.948 }; double R; double dT; double T_err; double T_sq; double T_cb; double T_qt; double a_CO2[7]; double a_CO[7]; double a_O2[7]; double a_H2[7]; double a_H2O[7]; double a_OH[7]; double a_O[7]; double a_N2[7]; double a_N[7]; double a_NO[7]; static const double dv36[7] = { 4.6365111, 0.0027414569, -9.9589759E-7, 1.6038666E-10, -9.1619857E-15, -49024.904, -1.9348955 }; static const double dv37[7] = { 3.0484859, 0.0013517281, -4.8579405E-7, 7.8853644E-11, -4.6980746E-15, -14266.117, 6.0170977 }; static const double dv38[7] = { 3.66096083, 0.000656365523, -1.41149485E-7, 2.05797658E-11, -1.29913248E-15, -1215.97725, 3.41536184 }; static const double dv39[7] = { 2.9328305, 0.00082659802, -1.4640057E-7, 1.5409851E-11, -6.8879615E-16, -813.05582, -1.0243164 }; static const double dv40[7] = { 2.6770389, 0.0029731816, -7.7376889E-7, 9.4433514E-11, -4.2689991E-15, -29885.894, 6.88255 }; static const double dv41[7] = { 2.83853033, 0.00110741289, -2.94000209E-7, 4.20698729E-11, -2.4228989E-15, 3697.80808, 5.84494652 }; static const double dv42[7] = { 2.54363697, -2.73162486E-5, -4.1902952E-9, 4.95481845E-12, -4.79553694E-16, 29226.012, 4.92229457 }; static const double dv43[7] = { 2.95257637, 0.0013969004, -4.92631603E-7, 7.86010195E-11, -4.60755204E-15, -923.948688, 5.87188762 }; static const double dv44[7] = { 2.4159429, 0.00017489065, -1.1902369E-7, 3.0226244E-11, -2.0360983E-15, 56133.775, 4.6496095 }; static const double dv45[7] = { 3.26071234, 0.00119101135, -4.29122646E-7, 6.94481463E-11, -4.03295681E-15, 9921.43132, 6.36900518 }; static const double dv46[7] = { 2.356813, 0.0089841299, -7.1220632E-6, 2.4573008E-9, -1.4288548E-13, -48371.971, 9.9009035 }; static const double dv47[7] = { 3.5795335, -0.00061035369, 1.0168143E-6, 9.0700586E-10, -9.0442449E-13, -14344.086, 3.5084093 }; static const double dv48[7] = { 3.78245636, -0.00299673415, 9.847302E-6, -9.68129508E-9, 3.24372836E-12, -1063.94356, 3.65767573 }; static const double dv49[7] = { 2.3443029, 0.0079804248, -1.9477917E-5, 2.0156967E-8, -7.3760289E-12, -917.92413, 0.68300218 }; static const double dv50[7] = { 4.1986352, -0.0020364017, 6.5203416E-6, -5.4879269E-9, 1.771968E-12, -30293.726, -0.84900901 }; static const double dv51[7] = { 3.99198424, -0.00240106655, 4.61664033E-6, -3.87916306E-9, 1.36319502E-12, 3368.89836, -0.103998477 }; static const double dv52[7] = { 3.1682671, -0.00327931884, 6.64306396E-6, -6.12806624E-9, 2.11265971E-12, 29122.2592, 2.05193346 }; static const double dv53[7] = { 3.53100528, -0.000123660988, -5.02999433E-7, 2.43530612E-9, -1.40881235E-12, -1046.97628, 2.96747038 }; static const double dv54[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, 56104.638, 4.1939088 }; static const double dv55[7] = { 4.21859896, -0.00463988124, 1.10443049E-5, -9.34055507E-9, 2.80554874E-12, 9845.09964, 2.28061001 }; double a_H[84]; double dv56[7]; double d11; static const double b_a_H[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, 25473.66, -0.44668285 }; static const double a_Ar[7] = { 2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.3796749 }; double a_gas[7]; int i12; double d12; double d13; static const double a[12] = { 26219.035, 29968.7009, 56850.013, 0.0, 4486.1538, -13293.628, 10977.0882, 0.0, -29084.817, -47328.105, 0.0, 0.0 }; static const int b_a[12] = { -6197000, -6725000, -6197000, -8467000, -9172000, -8671000, -9192000, -8683000, -9904000, -9364000, -8670000, -6197000 }; double dv57[7]; /* Calculate the pressure, temperature and composition of the combustion gas */ /* from given internal energy, volume and mass of each gas specie. */ /* */ /* The calculation of the internal energy is based on the NASA 7 */ /* coefficient polynomial and T is found by using Newton-Raphson method. */ /* The gas is assumed to be idea gas. */ /* */ /* Input */ /* N : No. moles of each gas specie (kmol) */ /* N(1) = N_H; N(2) = N_O; N(3) = N_N; N(4) = N_H2; */ /* N(5) = N_OH; N(6) = N_CO; N(7) = N_NO; N(8) = N_O2; */ /* N(9) = N_H2O; N(10) = N_CO2;N(11) = N_N2; N(12) = N_Ar */ /* E : Internal energy of the gas */ /* V : Volume of the gas */ /* Output */ /* P : Pressure (Pa) */ /* T : Temperature (K) */ /* rho : Density (kg/m3) */ /* x : Mole fraction of each gas specie */ /* x(1) = x_H; x(2) = x_O; x(3) = x_N; x(4) = x_H2; x(5) = x_OH; */ /* x(6) = x_CO; x(7) = x_NO; x(8) = x_O2; x(9) = x_H2O; x(10) = x_CO2; */ /* x(11) = x_N2; x(12) = x_Ar */ /* */ /* Atomic weight calculation from NIST atomic weights */ /* Ref : http://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl */ /* */ /* The NASA 7-coefficients are obtained from the reference: */ /* Burcat, A., B. Ruscic, et al. (2005). Third millenium ideal gas and */ /* condensed phase thermochemical database for combustion with updates */ /* from active thermochemical tables, Argonne National Laboratory */ /* Argonne, IL. */ /* */ /* Created by Kevin Koosup Yum on 29 June */ /* % */ /* in J/kmol/K */ /* % Calculate the composition in mole fraction and gas constant */ y = N[0]; for (k = 0; k < 11; k++) { y += N[k + 1]; } d10 = 0.0; for (k = 0; k < 12; k++) { b_x = N[k] / y; d10 += b_x * b[k]; x[k] = b_x; } /* in kg/kmol */ R = 8314.4621 / d10; /* in J/kg/K */ /* % Calculate the temperature */ *T = T_prev; dT = 0.0; T_err = 1.0; while (T_err > 0.001) { *T -= dT; T_sq = *T * *T; T_cb = rt_powd_snf(*T, 3.0); T_qt = rt_powd_snf(*T, 4.0); if (*T >= 1000.0) { /* Valid upto */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ /* 1000~6000K */ for (k = 0; k < 7; k++) { a_CO2[k] = dv36[k]; a_CO[k] = dv37[k]; a_O2[k] = dv38[k]; a_H2[k] = dv39[k]; a_H2O[k] = dv40[k]; a_OH[k] = dv41[k]; a_O[k] = dv42[k]; a_N2[k] = dv43[k]; a_N[k] = dv44[k]; a_NO[k] = dv45[k]; } /* 1000~6000K */ } else { /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ /* 300~1000K */ for (k = 0; k < 7; k++) { a_CO2[k] = dv46[k]; a_CO[k] = dv47[k]; a_O2[k] = dv48[k]; a_H2[k] = dv49[k]; a_H2O[k] = dv50[k]; a_OH[k] = dv51[k]; a_O[k] = dv52[k]; a_N2[k] = dv53[k]; a_N[k] = dv54[k]; a_NO[k] = dv55[k]; } /* 300~1000K */ } /* (J/kmol / J/kmol/K) */ /* J/kmol */ y = R * *T; dv56[0] = 1.0; dv56[1] = *T / 2.0; dv56[2] = T_sq / 3.0; dv56[3] = T_cb / 4.0; dv56[4] = T_qt / 5.0; dv56[5] = 1.0 / *T; dv56[6] = 0.0; d11 = 0.0; for (k = 0; k < 7; k++) { a_H[12 * k] = b_a_H[k]; a_H[1 + 12 * k] = a_O[k]; a_H[2 + 12 * k] = a_N[k]; a_H[3 + 12 * k] = a_H2[k]; a_H[4 + 12 * k] = a_OH[k]; a_H[5 + 12 * k] = a_CO[k]; a_H[6 + 12 * k] = a_NO[k]; a_H[7 + 12 * k] = a_O2[k]; a_H[8 + 12 * k] = a_H2O[k]; a_H[9 + 12 * k] = a_CO2[k]; a_H[10 + 12 * k] = a_N2[k]; a_H[11 + 12 * k] = a_Ar[k]; a_gas[k] = 0.0; for (i12 = 0; i12 < 12; i12++) { a_gas[k] += x[i12] * a_H[i12 + 12 * k]; } d11 += y * a_gas[k] * dv56[k]; } d12 = 0.0; d13 = 0.0; for (k = 0; k < 12; k++) { d12 += a[k] * x[k]; d13 += (double)b_a[k] * x[k]; } dv57[0] = 1.0; dv57[1] = *T; dv57[2] = T_sq; dv57[3] = T_cb; dv57[4] = T_qt; dv57[5] = 0.0; dv57[6] = 0.0; y = 0.0; for (k = 0; k < 7; k++) { y += a_gas[k] * dv57[k]; } dT = (((d11 - (R * d12 + d13 / d10)) - R * *T) - E / m) / (R * (y - 1.0)); T_err = fabs(dT) / *T; } /* % Calculate the pressure */ *P = m / V * R * *T; }