Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 6.98 KB | None | 0 0
  1. clear all;
  2. close all;
  3. clc;
  4.  
  5. %% Taka inn gögn
  6. formatSpec = '%f %f';
  7. size = [2 4];
  8. %hola 1
  9. fileID = fopen('hola1.txt','r');
  10. % þessi loopa á basically að sækja töluna 1900kJ/kg, má taka út og setja
  11. % beint inn töluna?
  12. for i=1:5
  13.      line = fgetl(fileID);
  14.      if line(2) == 'V'
  15.         h1 = str2double(line(20:23)); %Enthalpy
  16.      end
  17. end
  18. hola_1 = fscanf(fileID,formatSpec, size);
  19. fclose(fileID);
  20.  
  21. %hola 2
  22. fileID = fopen('hola2.txt','r');
  23. for i=1:5
  24.      line = fgetl(fileID);
  25.      if line(2) == 'V'
  26.         h2 = str2double(line(20:23));   %Enthalpy
  27.      end
  28. end
  29. hola_2 = fscanf(fileID,formatSpec, size);
  30. fclose(fileID);
  31.  
  32. %hola 3
  33. fileID = fopen('hola3.txt','r');
  34. for i=1:5
  35.      line = fgetl(fileID);
  36.      if line(2) == 'V'
  37.         h3 = str2double(line(20:23));   %Enthalpy
  38.      end
  39. end
  40. hola_3 = fscanf(fileID,formatSpec, size);
  41. fclose(fileID);
  42.  
  43.  
  44. %p# = Array of pressures (bar)
  45. %m# = Array of mass flow (kg/s)
  46. %poly# = Constants of 2. degree polonomial
  47.  
  48. %hola1
  49. p_1 = hola_1(1,1:4);              
  50. m_1 = hola_1(2,1:4);              
  51. poly_1 = polyfit(p_1,m_1,2);
  52.  
  53. %hola2
  54. p_2 = hola_2(1,1:4);
  55. m_2 = hola_2(2,1:4);
  56. poly_2 = polyfit(p_2,m_2,2);
  57.  
  58. %hola3
  59. p_3 = hola_3(1,1:4);
  60. m_3 = hola_3(2,1:4);
  61. poly_3 = polyfit(p_3,m_3,2);
  62.  
  63.  
  64. %% 1-1 Find the optimal pressure to maximize the power of the plant
  65.  
  66. %Function handle for pressure and mass flow.
  67. mass_flow = @(p,poly) poly(1).*p.^2+poly(2).*p+poly(3);
  68.  
  69. %Variables set to zero
  70. big_w = 0;          %Work
  71. big_m = 0;          %Mass Flow
  72. big_p = 0;          %Pressure
  73. big_q = 0;          %Energy
  74. W_out_ideal = 0;    %Work with efficiency of 100%
  75. Q_in = 0;           %Energy into the turbine
  76. H_in = 0;           %Enthaply into the turbine
  77. H_out = 0;          %Enthalpy into the turbine
  78.  
  79. %The for loop iterates through pressures of 0 to 50 bar
  80. %and finds the optimal pressure to maximize work from the turbine.
  81. for p = linspace(0,50,800);
  82.    
  83.     %Finds enthalpy (hf, hg and Hfg) for the given pressure
  84.     %3.3 í Xsteam.pdf
  85.     hg = XSteam('hV_p',p);    
  86.     hf = XSteam('hL_p',p);
  87.     Hfg = hg - hf;
  88.    
  89.     %Finds steam quality of each flow
  90.     x1 = (h1-hf)/Hfg;
  91.     x2 = (h2-hf)/Hfg;
  92.     x3 = (h3-hf)/Hfg;
  93.    
  94.     %Finds total mass flow from all three wells
  95.     total_mass_flow = (mass_flow(p, poly_1)*x1)+(mass_flow(p, poly_2)*x2)+(mass_flow(p, poly_3)*x3);
  96.  
  97.     %Finds entropy of steam before entering the turbine
  98.     S_in = XSteam('sV_p',p);
  99.    
  100.     %We use that S_out = S_in because we have an isotropic efficiency of
  101.     %90% and we can take the efficiency into account later, when we calulate
  102.     %the work out of the turbine.
  103.     S_out = S_in;
  104.     Isotropic_efficiency = 0.9;
  105.    
  106.     %Pressure out of the turbine is given
  107.     p_out = 0.1;
  108.    
  109.     %Finds steam quality of output from turbine
  110.     S_g_out =XSteam('sV_p',p_out);
  111.     S_f_out =XSteam('sL_p',p_out);
  112.     S_fg_out = S_g_out - S_f_out;
  113.     x_cont = (S_out - S_f_out)/S_fg_out;
  114.    
  115.     %Finds enthalpy of output from turbine
  116.     H_out_current = XSteam('h_px',p_out,x_cont);
  117.    
  118.     %Finds work out of the turbine taking the isotropic efficiency into account
  119.     W_out = total_mass_flow*(hg - H_out_current)*Isotropic_efficiency;
  120.    
  121.     %If the work for the current pressure is the most up to this we update all variables
  122.     if(W_out > big_w)
  123.            big_w = W_out;
  124.            big_m = total_mass_flow;
  125.            big_p = p;
  126.            H_in = hg;
  127.            H_out = H_out_current;
  128.            big_q = total_mass_flow * H_in;
  129.            Q_in = total_mass_flow*hg;
  130.            W_out_ideal = total_mass_flow*(hg - H_out);
  131.                
  132.     end
  133. end
  134.  
  135. disp(['Holtoppsthrystingurinn ' , num2str(big_p) , ...
  136.     ' bar gefur virkjuninni mesta aflid, sem er: ' , ...
  137.     num2str(big_w) , ' kW.'])
  138.  
  139.  
  140. %% 2-2 Mass flow of the cooling water (kaelivatn)
  141.  
  142. %Finds the actual output of enthalpy
  143. H_out_actual = H_in - Isotropic_efficiency*(H_in-H_out);
  144.  
  145. %Temperature of condensed water (after going through the condenser)
  146. T_2 = XSteam('Tsat_p',0.1);
  147. %Enthalpy of condesed water (after going through the condenser)
  148. h_2 = XSteam('hL_p',0.1);
  149.  
  150. %Temperature of the coling water entering the condenser
  151. T_3 = 20;
  152. %Temperatur of the cooling water exiting the condenser
  153. T_4 = T_2 - 5;
  154. %Enthalpy of the cooling water entering the condenser
  155. h_3 = XSteam('hL_T',T_3);
  156. %Enthalpy of the cooling water exiting the condenser
  157. h_4 = XSteam('hL_T',T_4);
  158.  
  159. %Mass flow needed of the cooling water
  160. mass_flow_cooling_water = (big_m*(H_out_actual - h_2))/(h_4 - h_3);
  161.  
  162. disp(['Eimsvalinn tharf ', num2str(mass_flow_cooling_water), ' kg/s af kaelivatni.']);
  163.  
  164. %% 2-3 Thermal efficiency of the plant
  165.  
  166. %Work produced in proportion to work supplied to the turbine
  167. Thermal_efficiency = big_w/Q_in;
  168.  
  169. disp(['Varmafraedileg nytni virkjunarinnar er: ', num2str(Thermal_efficiency)]);
  170.  
  171. %% 2-4 Second law efficiency of the plant
  172.  
  173. %Temperature of the high-temperature reservoir (Input into turbine)
  174. T_in = XSteam('Tsat_p',big_p);
  175. %Temperature of the low-temperature reservoir (Output of turbine)
  176. T_out = XSteam('Tsat_p',p_out);
  177.  
  178. %Maximum efficiency of the two reservoirs
  179. Max_efficiency = (1 - ((T_out + 273)/(T_in + 273)));
  180.  
  181. %Thermal efficiency in proportion to the maximum efficiency
  182. Second_law_efficiency = Thermal_efficiency/Max_efficiency;
  183.  
  184. disp(['Annars logmals nytni virkjunarinner er: ', num2str(Second_law_efficiency)])
  185.  
  186. %% Kostnaðarútreikningar
  187.  
  188. %fjárhagslegar forsendur
  189. kostnadur_per_borun = 5000000;
  190. boranir = 4; %3 af 4 heppnast svo til að fa 3 þa væntum við þess að bora 4
  191. borkostnadur_total = kostnadur_per_borun*boranir;
  192.  
  193. kostn_raforkukerfi = 100;%USD/kW
  194. kostn_gufulagna = 250;%USD/kW
  195. kostn_annar = 1500;%USD/kW (startkostnaður á ári 0)
  196.  
  197. %Breytilegur kostnaður
  198. kostn_vidhald = 0.02; %USD/kWh
  199.  
  200. %Heildar startkostnaður reiknaður miðað við stærð virkjunar
  201. total_start = borkostnadur_total + big_w*(kostn_raforkukerfi + kostn_gufulagna + kostn_annar);
  202.  
  203.  
  204.  
  205. %Other information about the project
  206. nytingarstudull = 0.9;  
  207. r = 0.12;%ávöxtunarkrafa 12%
  208. liftimi = 30;
  209. klst_per_yr = 24*365;                  
  210.  
  211. %Afl eftir nýtingarstuðul
  212. power = big_w * nytingarstudull;
  213.  
  214. %Rekstrarkostnaður á ársgrundvelli
  215. rekstrarkostn_per_yr = kostn_vidhald * power * klst_per_yr;
  216.  
  217.  
  218.  
  219. %Find present value of variable cost through all 30 years with given
  220. %discount factor
  221. total_kostnadur = 0;
  222. for i = 0:liftimi
  223.     if (i==0)
  224.         total_kostnadur = total_kostnadur + total_start/((1+r).^i); %discount factor á ári 0 er bara 1
  225.     else
  226.         total_kostnadur = total_kostnadur + rekstrarkostn_per_yr/((1+r).^i);
  227.     end
  228. end
  229.  
  230.  
  231. %Annuity jafnan PV = PMT x ((1-(1/(1+r)^n))/r); PMT = arstekjur
  232. ars_tekjur = (total_kostnadur) / ((1 - (1/ (1 + r).^liftimi))/r);
  233.  
  234. %Find the pricing of kWh by dividing the annual revenue requried by total
  235. %kWh produced in one year
  236. verd_per_kWh = ars_tekjur/(klst_per_yr*power);
  237.  
  238. disp(['Raforkuverd sem skilar nullpunkti fyrir verkefnid er: ', num2str(verd_per_kWh)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement