Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.94 KB | None | 0 0
  1. %% Read data from files
  2. clear all;
  3. close all;
  4. clc;
  5.  
  6. %Read hola1.txt
  7. fileID = fopen('hola1.txt','r');
  8. formatSpec = '%f %f';
  9. Asize = [2 4];
  10. for i=1:5
  11. line = fgetl(fileID);
  12. if line(2) == 'V'
  13. h1 = str2double(line(20:23)); %Enthalpy
  14. end
  15. end
  16. A = fscanf(fileID,formatSpec, Asize);
  17. fclose(fileID);
  18.  
  19. %Read hola2.txt
  20. fileID = fopen('hola2.txt','r');
  21. formatSpec = '%f %f';
  22. Bsize = [2 4];
  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. B = fscanf(fileID,formatSpec, Bsize);
  30. fclose(fileID);
  31.  
  32. %Read hola3.txt
  33. fileID = fopen('hola3.txt','r');
  34. formatSpec = '%f %f';
  35. Csize = [2 4];
  36. for i=1:5
  37. line = fgetl(fileID);
  38. if line(2) == 'V'
  39. h3 = str2double(line(20:23)); %Enthalpy
  40. end
  41. end
  42. C = fscanf(fileID,formatSpec, Csize);
  43. fclose(fileID);
  44.  
  45.  
  46. %p# = Array of pressures (bar)
  47. %m# = Array of mass flow (kg/s)
  48. %poly# = Constants of 2. degree polonomial
  49.  
  50. %hola1
  51. p1 = A(1,1:4); %(bar)
  52. m1 = A(2,1:4); %(kg/s)
  53. poly1 = polyfit(p1,m1,2);
  54.  
  55. %hola2
  56. p2 = B(1,1:4);
  57. m2 = B(2,1:4);
  58. poly2 = polyfit(p2,m2,2);
  59.  
  60. %hola3
  61. p3 = C(1,1:4);
  62. m3 = C(2,1:4);
  63. poly3 = polyfit(p3,m3,2);
  64.  
  65.  
  66. %% 1-1 Find the optimal pressure to maximize the power of the plant
  67.  
  68. %Function handle for pressure and mass flow.
  69. mass_flow = @(p,poly) poly(1).*p.^2+poly(2).*p+poly(3);
  70.  
  71. %Variables set to zero
  72. big_w = 0; %Work
  73. big_m = 0; %Mass Flow
  74. big_p = 0; %Pressure
  75. big_q = 0; %Energy
  76. W_out_ideal = 0; %Work with efficiency of 100%
  77. Q_in = 0; %Energy into the turbine
  78. H_in = 0; %Enthaply into the turbine
  79. H_out = 0; %Enthalpy into the turbine
  80.  
  81. %The for loop iterates through pressures of 0 to 50 bar
  82. %and finds the optimal pressure to maximize work from the turbine.
  83. for p = linspace(0,50,800);
  84.  
  85. %Finds enthalpy (hf, hg and Hfg) for the given pressure
  86. hf = XSteam('hL_p',p);
  87. hg = XSteam('hV_p',p);
  88. Hfg = hg - hf;
  89.  
  90. %Finds steam quality of each flow
  91. x1 = (h1-hf)/Hfg;
  92. x2 = (h2-hf)/Hfg;
  93. x3 = (h3-hf)/Hfg;
  94.  
  95. %Finds total mass flow from all three wells
  96. total_mass_flow = mass_flow(p, poly1)*x1 ...
  97. + mass_flow(p, poly2)*x2 ...
  98. + mass_flow(p, poly3)*x3;
  99.  
  100. %Finds entropy of steam before entering the turbine
  101. S_in = XSteam('sV_p',p);
  102.  
  103. %We use that S_out = S_in because we have an isotropic efficiency of
  104. %90% and we can take the efficiency into account later, when we calulate
  105. %the work out of the turbine.
  106. S_out = S_in;
  107. Iso_efficiency = 0.9;
  108.  
  109. %Pressure out of the turbine is given
  110. p_out = 0.1;
  111.  
  112. %Finds steam quality of output from turbine
  113. S_g_out =XSteam('sV_p',p_out);
  114. S_f_out =XSteam('sL_p',p_out);
  115. S_fg_out = S_g_out - S_f_out;
  116. x_cont = (S_out - S_f_out)/S_fg_out;
  117.  
  118. %Finds enthalpy of output from turbine
  119. H_out_current = XSteam('h_px',p_out,x_cont);
  120.  
  121. %Finds work out of the turbine taking the isotropic efficiency into account
  122. W_out = total_mass_flow*(hg - H_out_current)*Iso_efficiency;
  123.  
  124. %If the work for the current pressure is the most up to this we update all variables
  125. if(W_out > big_w)
  126. big_w = W_out;
  127. big_m = total_mass_flow;
  128. big_p = p;
  129. H_in = hg;
  130. H_out = H_out_current;
  131. big_q = total_mass_flow * H_in;
  132. Q_in = total_mass_flow*hg;
  133. W_out_ideal = total_mass_flow*(hg - H_out);
  134.  
  135. end
  136. end
  137.  
  138. disp(['Holtoppsthrystingurinn ' , num2str(big_p) , ...
  139. ' bar gefur virkjuninni mesta aflid, sem er: ' , ...
  140. num2str(big_w) , ' kW.'])
  141.  
  142.  
  143. %% 2-2 Mass flow of the cooling water (kaelivatn)
  144.  
  145. %Finds the actual output of enthalpy
  146. H_out_actual = H_in - Iso_efficiency*(H_in-H_out);
  147.  
  148. %Temperature of condensed water (after going through the condenser)
  149. T_2 = XSteam('Tsat_p',0.1);
  150. %Enthalpy of condesed water (after going through the condenser)
  151. h_2 = XSteam('hL_p',0.1);
  152.  
  153. %Temperature of the coling water entering the condenser
  154. T_3 = 20;
  155. %Temperatur of the cooling water exiting the condenser
  156. T_4 = T_2 - 5;
  157. %Enthalpy of the cooling water entering the condenser
  158. h_3 = XSteam('hL_T',T_3);
  159. %Enthalpy of the cooling water exiting the condenser
  160. h_4 = XSteam('hL_T',T_4);
  161.  
  162. %Mass flow needed of the cooling water
  163. mass_flow_cooling_water = (big_m*(H_out_actual - h_2))/(h_4 - h_3);
  164.  
  165. disp(['Eimsvalinn tharf ', num2str(mass_flow_cooling_water), ' kg/s af kaelivatni.']);
  166.  
  167. %% 2-3 Thermal efficiency of the plant
  168.  
  169. %Work produced in proportion to work supplied to the turbine
  170. Thermal_efficiency = big_w/Q_in;
  171.  
  172. disp(['Varmafraedileg nytni virkjunarinnar er: ', num2str(Thermal_efficiency)]);
  173.  
  174. %% 2-4 Second law efficiency of the plant
  175.  
  176. %Temperature of the high-temperature reservoir (Input into turbine)
  177. T_in = XSteam('Tsat_p',big_p);
  178. %Temperature of the low-temperature reservoir (Output of turbine)
  179. T_out = XSteam('Tsat_p',p_out);
  180.  
  181. %Maximum efficiency of the two reservoirs
  182. Max_efficiency = (1 - ((T_out + 273)/(T_in + 273)));
  183.  
  184. %Thermal efficiency in proportion to the maximum efficiency
  185. Second_law_efficiency = Thermal_efficiency/Max_efficiency;
  186.  
  187. disp(['Annars logmals nytni virkjunarinner er: ', num2str(Second_law_efficiency)])
  188.  
  189. %% Cost of electric power
  190.  
  191. format long
  192.  
  193. %Fixed cost
  194. drill_one_hole = 5000000;
  195. drill_holes = drill_one_hole *4;
  196.  
  197. electric_system = 100; %USD/kW
  198. steam_piping = 250; %USD/kW
  199. other_cost = 1500; %USD/kW
  200.  
  201. %Total fixed cost of the project
  202. total_fixed = (electric_system + steam_piping + other_cost)*big_w + drill_holes;
  203.  
  204. %Variable cost
  205. MaintenanceCost = 0.02; %USD/kWh
  206.  
  207. %Other information about the project
  208. capacity_factor = 0.9;
  209. discount_factor = 0.12;
  210. lifetime = 30;
  211.  
  212. %Hours in a year
  213. hours_per_year = 24*365; %h
  214.  
  215. %Power of the plant when the capacity factor is considered
  216. power = big_w * capacity_factor;
  217.  
  218. %Cost of running the plant for one year
  219. CostPerYear = MaintenanceCost * power * hours_per_year;
  220.  
  221. %Set the total variable cost to zero
  222. total_variable = 0;
  223.  
  224. %Find present value of variable cost through all 30 years with given
  225. %discount factor
  226. for i = 1:lifetime
  227. total_variable = total_variable + CostPerYear/((1+discount_factor).^i);
  228. end
  229.  
  230. %Present value of total cost of the project
  231. total_cost = total_variable + total_fixed;
  232.  
  233. %Find annual revenue required to reach breakeven point by using present
  234. %value equation of annuity(timabundins sjodstreymis)
  235. Annual_Revenue = (total_cost * discount_factor) / (1 - (1/ (1 + discount_factor).^lifetime));
  236.  
  237. %Find the pricing of kWh by dividing the annual revenue requried by total
  238. %kWh produced in one year
  239. Price_of_kWh = Annual_Revenue/(power*hours_per_year);
  240.  
  241. disp(['Raforkuverd sem skilar nullpunkti fyrir verkefnid er: ', num2str(Price_of_kWh)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement