Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all; clear all; clc
- %% To make sure that matlab will find the functions. You must change it to your situation
- abspath_to_generalfolder='My folder; % absolute reference to General folder
- addpath(abspath_to_generalfolder);
- %% Load Nasadatabase
- TdataBase=fullfile('General','Nasa','NasaThermalDatabase');
- load(TdataBase);
- fuel = 'Gasoline';
- addpath('General\Nasa')
- iSp = myfind({Sp.Name},{fuel,'C2H5OH','O2','CO2','H2O','N2'}); % Find indexes of these species
- SpS=Sp(iSp); % Subselection of the database in the order according to {'Gasoline','O2','CO2','H2O','N2'}
- NSp = length(SpS);
- Mi = [SpS.Mass];
- %% Values should not be changed. Ready for use
- global Runiv Pref
- Runiv=8.314472;
- [T0, a0, P0, rho0] = atmosisa(0); % Official ambient pressure at ground level
- %% Start composition
- V_gas = 1; % volume fraction gasoline
- V_eth = 1 - V_gas; % volume fraction ethanol
- m_fuel = 7.22e-06; % Mass of fuel for one cycle
- N_gas = V_gas*m_fuel/Mi(1); % moles fuel
- N_eth = V_eth*m_fuel/Mi(2); % moles ethanol
- % C2H5OH + 3(O2+ 3.76N2) = 2CO2 + 3H2O + 11.28N2
- Neth1=[0,N_eth, 3*N_eth, 0, 0, (0.79*3*N_eth)/0.21];
- % C8H18+ 12.5(O2+ 3.76N2) = 8CO2+ 9H2O+ 47N2 (SSA Victor)
- Ngas1=[N_gas,0, 12.5*N_gas, 0, 0, 12.5*3.67*N_gas];
- N1tot=Neth1+Ngas1; % Moles at start
- m_gas(1:659) = N_gas*Mi(1); % Initial mass of gasoline
- m_eth(1:659) = N_eth*Mi(2); % Initial mass of ethanol
- m_O2(1:659) = (Neth1(3)+Ngas1(3))/Mi(3); % Initial mass of oxygen
- Mtot1 = N1tot*Mi'; % Total Mass
- X1_tot = N1tot/sum(N1tot); % X (mole) fraction
- Y1_tot = N1tot.*Mi/Mtot1; % Y (mass) fraction at start
- %% After combustion
- % C2H5OH + 3(O2+ 3.76N2) = 2CO2 + 3H2O + 11.28N2
- Neth2=[0,0,0, 2*N_eth,3*N_eth,(0.79*3*N_eth)/0.21];
- % C8H18+ 12.5(O2+ 3.76N2) = 8CO2+ 9H2O+ 47N2 (SSA Victor)
- Ngas2=[0,0,0,8*N_gas,9*N_gas, 12.5*3.67*N_gas];
- N2tot=Neth2+Ngas2; % molefractions of the mixture after combustion
- Mtot2 = N2tot*Mi'; % Mass of components after combustion of 1 mole fuel and 1 mole ethanol
- X2_tot = N2tot/sum(N2tot); % X (mole) fraction
- Y2_tot = N2tot.*Mi/Mtot2; % Massfractions of the mixture after combustion
- %% Begin conditions
- Mair = 28.96e-3; % Molair mass air
- Rg = Runiv/Mair; % specific gas constant of air
- p(1)=P0;T(1)=T0; % Initial pressure and temperature values
- Ca(1)=0.0;V(1)=Vcyl(Ca(1)); % Initial crank angle and volume
- m1(1)= p(1)*V(1)/(Rg*T(1)); % Initial mass
- k = 1.4; % Simple k for the Poisson relations (from air)(only used for motorized mass)
- Cv = 718; % Cv air
- dCa=0.5; % Stepsize
- Tw = 647; % Temperature of the wall(?)
- V_d = 2.2281e-04-2.9300e-05; % Displaced volume (maximum volume change)
- r_c = 2.2281e-04/2.9300e-05; % Compression ratio
- B = 0.0678; % Bore
- S = 0.0536; % Stroke
- S_p = 2*S*3000/60; % Average piston speed
- c = 0.0064; % Height of cylinder head
- E = sqrt(1-((c^2)/((0.5*B)^2))); % Eccencitry
- A = pi*B*S + pi * (0.5*B)^2 + 2*pi *(0.5*B)^2 + pi * (c^2)/E * log((1+E)/(1-E)); %Area
- dt = dCa/(3000*360/60); % Time difference for every stepsize (used for temperature change)
- Qlhv_eth = 26.952*10^6; % LHV of ethanol [J/kg]
- Qlhv_gas = 43.448*10^6; % LHV of gasoline [J/kg]
- Comb_rate_gas = m_gas(1)/55; % Combustion rate of gasoline [kg/deg]
- Comb_rate_eth = m_eth(1)/55; % Combustion rate of ethanol [kg/deg]
- %% Fuel intake
- dm = (Mtot1-m1(1))/(2.2281e-04-(V(1))); % Mass change per unit of volume
- for i=2:360
- Ca(i) = Ca(i-1)+dCa; % Compute new angle
- V(i) = Vcyl(Ca(i)); % Cylinder volume for current crank-angle
- p(i) = p(i-1); % Pressure is constant
- m1(i) = m1(i-1) + dm*(V(i)-V(i-1)); % Compute mass for new volume
- T(i) = T(i-1); % Temperature is constant
- end
- %% Compression
- M_av1 = sum(X1_tot.*Mi); % Molar mass of gas mixture
- for i = 361:720
- if i>= 660; % Initial point of combustion
- C1 = 2.28; % Constant for velocity w
- C2 = 3.24e-03; % Constant for velocity w
- Ca(i)=Ca(i-1)+dCa; % Compute new angle
- V(i)=Vcyl(Ca(i)); % Compute new volume
- Qc(i) = Qlhv_gas*Comb_rate_gas*dCa + Qlhv_eth*Comb_rate_eth*dCa; % Combustion heat
- pm = (((r_c*V_d)/(r_c - 1))^k * P0)/(V(660)^k); % Motorized pressure
- w = C1*S_p + C2*((V_d*(T(660-1)))/(p(660-1)*V(660)))*(p(660-1)-pm); % Average cylinder gas velocity
- Hc(i) = 3.26*B^-0.2*p(i-1)^0.8*(T(i-1))^-0.55*w^0.8; % Compute heat transfer coefficient for current temperature and pressure
- dQ(i) = Hc(i)*A*((T(i-1))-Tw)*dt; % Heat loss
- m_added_CO2(i) = ((Comb_rate_gas*dCa*Mi(1)*8) + (Comb_rate_eth*dCa*Mi(2)*2))/Mi(4);
- % Change in mass of CO2 by combustion
- m_CO2(i) = sum(m_added_CO2); % Total mass of CO2
- m_added_H2O(i) = ((Comb_rate_gas*dCa*Mi(1)*9) + (Comb_rate_eth*dCa*Mi(2)*3))/Mi(5);
- % Change in mass of H2O by combustion
- m_H2O(i) = sum(m_added_H2O); % Total mass of H2O
- m_added_O2(i) = -((Comb_rate_gas*dCa*Mi(1)*12.5) + (Comb_rate_eth*dCa*Mi(2)*3))/Mi(3);
- % Change in mass of O2 by combustion
- m_O2(i) = m_O2(i-1) + sum(m_added_O2(i)); % Total mass of O2
- m_gas(i) = m_gas(i-1) - Comb_rate_gas*dCa; % Total mass of gasoline
- m_eth(i) = m_eth(i-1) - Comb_rate_eth*dCa; % Total mass of ethanol
- m_N2(i) = Y1_tot(6)*m1(1); % Total mass of N2
- m1(i) = m1(i-1)-Comb_rate_gas*dCa - Comb_rate_eth*dCa + m_added_CO2(i) + m_added_H2O(i) + m_added_O2(i);
- % Compute new total mass
- Cv(i) = (m_gas(i)/m1(i))*CvNasa((T(i-1)),SpS(1)) + (m_eth(i)/m1(i))*CvNasa((T(i-1)),SpS(2)) + (m_O2(i)/m1(i))*CvNasa((T(i-1)),SpS(3)) + (m_CO2(i)/m1(i))*CvNasa((T(i-1)),SpS(4)) + (m_H2O(i)/m1(i))*CvNasa((T(i-1)),SpS(5)) + (m_N2(i)/m1(i))*CvNasa((T(i-1)),SpS(6));
- % Specific heat capacity for current temperature
- T(i) = (T(i-1)) + (-dQ(i) + Qc(i) - p(i-1)*(V(i)-V(i-1)))/(Cv(i)*m1(i));% Compute new temperature using 1st law of thermodynamics
- p(i) = m1(i)*(Runiv/M_av1)*T(i)/V(i); % Compute new pressure using ideal gas law
- else % Loop before combustion
- C1 = 2.28; % Constant for velocity w
- C2 = 0; % Constant for velocity w
- Ca(i)=Ca(i-1)+dCa; % Compute new angle
- V(i)=Vcyl(Ca(i)); % Compute new volume
- pm = (((r_c*V_d)/(r_c - 1))^k * P0)/(V(360)^k); % Motorized pressure
- w = C1*S_p + C2*((V_d*(T(360)))/(p(360)*V(360)))*(p(360)-pm); % Average cylinder gas velocity
- Hc(i) = 3.26*B^-0.2*p(i-1)^0.8*(T(i-1))^-0.55*w^0.8; % Compute heat transfer coefficient for current temperature and pressure
- dQ(i) = Hc(i)*A*((T(i-1))-Tw)*dt; % Heat loss
- Cv(i) = Y1_tot(1)*CvNasa((T(i-1)),SpS(1)) + Y1_tot(2)*CvNasa((T(i-1)),SpS(2)) + Y1_tot(3)*CvNasa((T(i-1)),SpS(3)) + Y1_tot(4)*CvNasa((T(i-1)),SpS(4)) + Y1_tot(5)*CvNasa((T(i-1)),SpS(5)) + Y1_tot(6)*CvNasa((T(i-1)),SpS(6));
- % Specific heat capacity for current temperature
- m1(i) = m1(i-1); % Compute new mass
- T(i) = (T(i-1)) + (-dQ(i) - p(i-1)*(V(i)-V(i-1)))/(Cv(i)*m1(i)); % Compute new temperature using 1st law of thermodynamics
- p(i) = m1(i)*(Runiv/M_av1)*T(i)/V(i); % Compute new pressure using idael gas law
- end
- end
- %% Combustion (OLD VERSION)
- % pm(2) = (((r_c*V_d)/(r_c - 1))^k * P0)/(V(719)^k); % Compute motorized pressure for new phase
- %
- % C1 = 2.28; % Constant for w (velocity)
- % C2 = 3.24e-03; % Constant for w (velocity)
- % w = C1*S_p + C2*(((V(720)-V(719))*(T(719)))/(p(719)*V(719)))*(p(719)-pm(2));% Average cylinder velocity
- % Hc(720) = 3.26*B^-0.2*p(720-1)^0.8*(T(720-1))^-0.55*w^0.8; % Heat transfer coefficient
- % dQ(720) = Hc(720)*A*((T(720-1))-Tw)*dt; % Heat losses
- %
- % Qh = Y1_tot(1)*Qlhv_gas + Y1_tot(2)*Qlhv_eth -dQ(720); % Combustion heat
- %
- % Cv(720) = CvNasa((T(719)),SpS(1)); % Specific heat capacity for current temperature
- % m1(720) = Mtot2; % Current mass
- % M_av2 = sum(X2_tot.*Mi); % Molucular mass of gas mixture
- % T(720) = (Qh)/(sum(Y2_tot)*Cv(720))+T(719); % Compute current temperature
- % p(720) = m1(720)*(Runiv/M_av2)*T(720)/V(720); % Current pressure
- %% Expansion
- M_av2 = sum(X2_tot.*Mi); % Molucular mass of gas mixture
- C1 = 2.28; % Constant for w (velocity)
- C2 = 3.24e-03; % Constant for w (velocity)
- for i = 721:1080
- if i<= 770 % Last part of combustion
- Ca(i) = Ca(i-1)+dCa; % Compute new angle
- V(i) = Vcyl(Ca(i)); % Compute new volume
- Qc(i) = Qlhv_gas*Comb_rate_gas*dCa + Qlhv_eth*Comb_rate_eth*dCa; % Combustion heat
- pm = (((r_c*V_d)/(r_c - 1))^k * P0)/(V(721)^k); % Motorized pressure
- w = C1*S_p + C2*((V_d*(T(721-1)))/(p(721-1)*V(721)))*(p(721-1)-pm); % Average cylinder gas velocity
- Hc(i) = 3.26*B^-0.2*p(i-1)^0.8*T(i-1)^-0.55*w^0.8; % Compute heat transfer coefficient for current temperature and pressure
- dQ(i) = Hc(i)*A*(T(i-1)-Tw)*dt; % Heat losses
- m_added_CO2(i) = ((Comb_rate_gas*dCa*Mi(1)*8) + (Comb_rate_eth*dCa*Mi(2)*2))/Mi(4);
- % Change in mass of CO2 by combustion
- m_CO2(i) = sum(m_added_CO2); % Total mass of CO2
- m_added_H2O(i) = ((Comb_rate_gas*dCa*Mi(1)*9) + (Comb_rate_eth*dCa*Mi(2)*3))/Mi(5);
- % Change in mass of H2O by combustion
- m_H2O(i) = sum(m_added_H2O); % Total mass of H2O
- m_added_O2(i) = -((Comb_rate_gas*dCa*Mi(1)*12.5) + (Comb_rate_eth*dCa*Mi(2)*3))/Mi(3);
- % Change in mass of O2 by combustion
- m_O2(i) = m_O2(i-1) + sum(m_added_O2(i)); % Total mass of O2
- m_gas(i) = m_gas(i-1) - Comb_rate_gas*dCa; % Total mass of gasoline
- m_eth(i) = m_eth(i-1) - Comb_rate_eth*dCa; % Total mass of ethanol
- m_N2(i) = Y1_tot(6)*m1(1); % Total mass of N2
- m1(i) = m1(i-1)-Comb_rate_gas*dCa - Comb_rate_eth*dCa + m_added_CO2(i) + m_added_H2O(i) + m_added_O2(i);
- % Compute new mass
- Cv(i) = (m_gas(i)/m1(i))*CvNasa((T(i-1)),SpS(1)) + (m_eth(i)/m1(i))*CvNasa((T(i-1)),SpS(2)) + (m_O2(i)/m1(i))*CvNasa((T(i-1)),SpS(3)) + (m_CO2(i)/m1(i))*CvNasa((T(i-1)),SpS(4)) + (m_H2O(i)/m1(i))*CvNasa((T(i-1)),SpS(5)) + (m_N2(i)/m1(i))*CvNasa((T(i-1)),SpS(6));
- % Specific heat capacity for current temperature
- T(i) = T(i-1) + (-dQ(i) + Qc(i) - p(i-1)*(V(i)-V(i-1)))/(Cv(i)*m1(i)); % Compute new temperature
- p(i) = m1(i)*(Runiv/M_av2)*T(i)/V(i); % Compute new pressure
- else
- Ca(i)=Ca(i-1)+dCa; % Compute new angle
- V(i)=Vcyl(Ca(i)); % Compute new volume
- pm = (((r_c*V_d)/(r_c - 1))^k * P0)/(V(720)^k); % Motorized pressure
- w = C1*S_p + C2*(((V(720)-V(719))*T(720))/(p(720)*V(720)))*(p(720)-pm); % Average cylinder gas velocity
- Hc(i) = 3.26*B^-0.2*p(i-1)^0.8*T(i-1)^-0.55*w^0.8; % Compute heat transfer coefficient for current temperature and pressure
- dQ(i) = Hc(i)*A*(T(i-1)-Tw)*dt; % Heat lossed
- Cv(i) = Y2_tot(1)*CvNasa((T(i-1)),SpS(1)) + Y2_tot(2)*CvNasa((T(i-1)),SpS(2)) + Y2_tot(3)*CvNasa((T(i-1)),SpS(3)) + Y2_tot(4)*CvNasa((T(i-1)),SpS(4)) + Y2_tot(5)*CvNasa((T(i-1)),SpS(5)) + Y2_tot(6)*CvNasa((T(i-1)),SpS(6));
- % Specific heat capacity for current temperature
- m1(i) = m1(i-1); % Compute new mass
- T(i) = T(i-1) + (-dQ(i) - p(i-1)*(V(i)-V(i-1)))/(Cv(i)*m1(i)); % Compute new temperature
- p(i) = m1(i)*(Runiv/M_av2)*T(i)/V(i); % Compute new pressure
- end
- end
- %% Exhaust
- for i=1080:1440
- Ca(i)=Ca(i-1)+dCa; % Compute new angle
- V(i)=Vcyl(Ca(i)); % Compute new volume
- T(i)=T0; % Compute new temperature
- p(i)=P0; % Compute new pressure
- end
- %% Plot
- figure(1) % Create figure
- plot(V,p) % Create plot
- xlabel('Volume [m^3]') % xLabel figure
- ylabel('Pressure [Pa]') % yLabel figure
- title('p-V diagram')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement