/Volume.m

http://freesteamplus.googlecode.com/ · MATLAB · 318 lines · 270 code · 0 blank · 48 comment · 56 complexity · e911ec191e6f7bd787c1e0d02eb1d8d2 MD5 · raw file

  1. function output = Volume(material,prop1,units1,value1,varargin)%,prop2,units2,value2)
  2. value1 = CheckUnits(prop1,units1,value1);
  3. switch lower(material)
  4. case {'water','steam'}
  5. %% Water
  6. error(nargchk(7, 7, nargin, 'struct'))
  7. prop2 = varargin{1};
  8. units2 = varargin{2};
  9. value2 = varargin{3};
  10. value2 = CheckUnits(prop2,units2,value2);
  11. if strcmpi(prop1,'v')
  12. output = value1;
  13. return;
  14. elseif strcmpi(prop2,'v')
  15. output = value2;
  16. return;
  17. end
  18. pressure = Pressure(material,prop1,'',value1,prop2,'',value2);
  19. temperature = Temperature(material,prop1,'',value1,prop2,'',value2);
  20. output = Corr_Water_Volume(pressure,temperature);
  21. case {'saturated water','saturatedwater','saturated steam','saturatedsteam'}
  22. %% Saturated Water
  23. error(nargchk(4, 4, nargin, 'struct'))
  24. if strcmpi(prop1,'v')
  25. output = value1;
  26. return;
  27. end
  28. temperature = Temperature('saturated water',prop1,'',value1);
  29. pressure = Pressure('saturated water',prop1,'',value1);
  30. output = Corr_SaturatedWater_Volume(pressure,temperature);
  31. case {'refrigerant','r-134a','r134a','hfc-134a','hfc134a',...
  32. '1,1,1,2-tetrafluoroethane','tetrafluoroethane'}
  33. %% Refrigerant
  34. error(nargchk(7, 7, nargin, 'struct'))
  35. prop2 = varargin{1};
  36. units2 = varargin{2};
  37. value2 = varargin{3};
  38. value2 = CheckUnits(prop2,units2,value2);
  39. if strcmpi(prop1,'v')
  40. output = value1;
  41. return;
  42. elseif strcmpi(prop2,'v')
  43. output = value2;
  44. return;
  45. end
  46. switch lower(prop1)
  47. case 't'
  48. temperature = value1;
  49. switch lower(prop2)
  50. case 'p'
  51. pressure = value2;
  52. volume = fzero(@(volume) Corr_Refrigerant_Pressure(temperature,volume)-pressure,1/1000);
  53. case 's'
  54. entropy = value2;
  55. volume = fzero(@(volume) Corr_Refrigerant_Entropy(temperature,volume)-entropy,1/1000);
  56. case 'h'
  57. enthalpy = value2;
  58. volume = fzero(@(volume) Corr_Refrigerant_Enthalpy(temperature,volume)-enthalpy,1/1000);
  59. otherwise
  60. error('Therm:corr','No correlation found for given properties')
  61. end
  62. case 'p'
  63. pressure = value1;
  64. switch lower(prop2)
  65. case 't'
  66. temperature = value2;
  67. volume = fzero(@(volume) Corr_Refrigerant_Pressure(temperature,volume)-pressure,1/1000);
  68. % case 's'
  69. % entropy = value2;
  70. % x = fsolve(@(x) [Corr_Refrigerant_Pressure(x(1),x(2))-pressure;...
  71. % Corr_Refrigerant_Entropy_pt(x(1),x(2))-entropy],...
  72. % [[0 4.520795660].*611.2;1/1000]);
  73. % temperature = x(1);
  74. % case 'h'
  75. % enthalpy = value2;
  76. % x = fsolve(@(x) [Corr_Refrigerant_Volume_pt(x(1),x(2))-volume;...
  77. % Corr_Refrigerant_Enthalpy_pt(x(1),x(2))-enthalpy],...
  78. % [[0 4.520795660].*611.2;1/1000]);
  79. % temperature = x(2);
  80. otherwise
  81. error('Therm:corr','No correlation found for given properties')
  82. end
  83. case 's'
  84. entropy = value1;
  85. switch lower(prop2)
  86. case 't'
  87. temperature = value2;
  88. volume = fzero(@(volume) Corr_Refrigerant_Entropy(temperature,volume)-entropy,1/1000);
  89. % case 'p'
  90. % volume = value2;
  91. % x = fsolve(@(x) [Corr_Refrigerant_Entropy_pt(x(1),x(2))-entropy;...
  92. % Corr_Refrigerant_Volume_pt(x(1),x(2))-volume],...
  93. % [[0 4.520795660].*611.2;1/1000]);
  94. % temperature = x(2);
  95. % case 'h'
  96. % enthalpy = value2;
  97. % x = fsolve(@(x) [Corr_Refrigerant_Entropy_pt(x(1),x(2))-entropy;...
  98. % Corr_Refrigerant_Enthalpy_pt(x(1),x(2))-enthalpy],...
  99. % [[0 4.520795660].*611.2;1/1000]);
  100. % temperature = x(2);
  101. otherwise
  102. error('Therm:corr','No correlation found for given properties')
  103. end
  104. case 'h'
  105. enthalpy = value1;
  106. switch lower(prop2)
  107. case 't'
  108. temperature = value2;
  109. volume = fzero(@(volume) Corr_Refrigerant_Enthalpy(temperature,volume)-enthalpy,1/1000);
  110. % case 'p'
  111. % volume = value2;
  112. % x = fsolve(@(x)
  113. % [Corr_Refrigerant_Enthalpy_pt(x(1),x(2))-enthalpy;...
  114. % Corr_Refrigerant_Volume_pt(x(1),x(2))-volume],...
  115. % [[0 4.520795660].*611.2;1/1000]);
  116. % temperature = x(2);
  117. % case 's'
  118. % entropy = value2;
  119. % x = fsolve(@(x) [Corr_Refrigerant_Enthalpy_pt(x(1),x(2))-enthalpy;...
  120. % Corr_Refrigerant_Entropy_pt(x(1),x(2))-entropy],...
  121. % [[0 4.520795660].*611.2;1/1000]);
  122. % temperature = x(2);
  123. otherwise
  124. error('Therm:corr','No correlation found for given properties')
  125. end
  126. otherwise
  127. error('Therm:corr','No correlation found for given properties')
  128. end
  129. output = volume;
  130. case {'saturated refrigerant','saturated r-134a','saturated r134a','saturated hfc-134a',...
  131. 'saturated hfc134a','saturated 1,1,1,2-tetrafluoroethane','saturated tetrafluoroethane',...
  132. 'saturatedrefrigerant','saturatedr-134a','saturatedr134a','saturatedhfc-134a',...
  133. 'saturatedhfc134a','saturated1,1,1,2-tetrafluoroethane','saturatedtetrafluoroethane'}
  134. %% Saturated Refrigerant
  135. error(nargchk(4, 4, nargin, 'struct'))
  136. switch lower(prop1)
  137. case 'v'
  138. volume = value1;
  139. case 't'
  140. temperature = value1;
  141. pressure = Corr_Refrigerant_SatPressure(temperature);
  142. volume = [Corr_Refrigerant_Volume_liquid(temperature) Volume(material,'t','',temperature,'p','',pressure)];
  143. otherwise
  144. error('Therm:corr','No correlation found for given properties')
  145. end
  146. output = volume;
  147. case 'air'
  148. %% Air
  149. error(nargchk(4, 7, nargin, 'struct'))
  150. if ((nargin > 4) && (nargin < 7))
  151. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  152. end
  153. if strcmpi(prop1,'v')
  154. output = value1;
  155. return;
  156. end
  157. if nargin == 7
  158. prop2 = varargin{1};
  159. units2 = varargin{2};
  160. value2 = varargin{3};
  161. value2 = CheckUnits(prop2,units2,value2);
  162. varargin{2} = '';
  163. if strcmpi(prop2,'v')
  164. output = value2;
  165. return;
  166. end
  167. end
  168. pressure = Pressure(material,prop1,'',value1,varargin{:});
  169. temperature = Temperature(material,prop1,'',value1,varargin{:});
  170. output = Corr_Air_Volume(pressure,temperature);
  171. case {'carbon dioxide','co2'}
  172. %% Carbon Dioxide
  173. error(nargchk(4, 7, nargin, 'struct'))
  174. if ((nargin > 4) && (nargin < 7))
  175. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  176. end
  177. if strcmpi(prop1,'v')
  178. output = value1;
  179. return;
  180. end
  181. if nargin == 7
  182. prop2 = varargin{1};
  183. units2 = varargin{2};
  184. value2 = varargin{3};
  185. value2 = CheckUnits(prop2,units2,value2);
  186. varargin{2} = '';
  187. if strcmpi(prop2,'v')
  188. output = value2;
  189. return;
  190. end
  191. end
  192. pressure = Pressure(material,prop1,'',value1,varargin{:});
  193. temperature = Temperature(material,prop1,'',value1,varargin{:});
  194. output = Corr_CarbonDioxide_Volume(pressure,temperature);
  195. case {'hydrogen','h2'}
  196. %% Hydrogen
  197. error(nargchk(4, 7, nargin, 'struct'))
  198. if ((nargin > 4) && (nargin < 7))
  199. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  200. end
  201. if strcmpi(prop1,'v')
  202. output = value1;
  203. return;
  204. end
  205. if nargin == 7
  206. prop2 = varargin{1};
  207. units2 = varargin{2};
  208. value2 = varargin{3};
  209. value2 = CheckUnits(prop2,units2,value2);
  210. varargin{2} = '';
  211. if strcmpi(prop2,'v')
  212. output = value2;
  213. return;
  214. end
  215. end
  216. pressure = Pressure(material,prop1,'',value1,varargin{:});
  217. temperature = Temperature(material,prop1,'',value1,varargin{:});
  218. output = Corr_Hydrogen_Volume(pressure,temperature);
  219. case {'helium','he'}
  220. %% Helium
  221. error(nargchk(4, 7, nargin, 'struct'))
  222. if ((nargin > 4) && (nargin < 7))
  223. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  224. end
  225. if strcmpi(prop1,'v')
  226. output = value1;
  227. return;
  228. end
  229. if nargin == 7
  230. prop2 = varargin{1};
  231. units2 = varargin{2};
  232. value2 = varargin{3};
  233. value2 = CheckUnits(prop2,units2,value2);
  234. varargin{2} = '';
  235. if strcmpi(prop2,'v')
  236. output = value2;
  237. return;
  238. end
  239. end
  240. pressure = Pressure(material,prop1,'',value1,varargin{:});
  241. temperature = Temperature(material,prop1,'',value1,varargin{:});
  242. output = Corr_Helium_Volume(pressure,temperature);
  243. case {'nitrogen','n2'}
  244. %% Nitrogen
  245. error(nargchk(4, 7, nargin, 'struct'))
  246. if ((nargin > 4) && (nargin < 7))
  247. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  248. end
  249. if strcmpi(prop1,'v')
  250. output = value1;
  251. return;
  252. end
  253. if nargin == 7
  254. prop2 = varargin{1};
  255. units2 = varargin{2};
  256. value2 = varargin{3};
  257. value2 = CheckUnits(prop2,units2,value2);
  258. varargin{2} = '';
  259. if strcmpi(prop2,'v')
  260. output = value2;
  261. return;
  262. end
  263. end
  264. pressure = Pressure(material,prop1,'',value1,varargin{:});
  265. temperature = Temperature(material,prop1,'',value1,varargin{:});
  266. output = Corr_Nitrogen_Volume(pressure,temperature);
  267. case {'oxygen','o2'}
  268. %% Oxygen
  269. error(nargchk(4, 7, nargin, 'struct'))
  270. if ((nargin > 4) && (nargin < 7))
  271. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  272. end
  273. if strcmpi(prop1,'v')
  274. output = value1;
  275. return;
  276. end
  277. if nargin == 7
  278. prop2 = varargin{1};
  279. units2 = varargin{2};
  280. value2 = varargin{3};
  281. value2 = CheckUnits(prop2,units2,value2);
  282. varargin{2} = '';
  283. if strcmpi(prop2,'v')
  284. output = value2;
  285. return;
  286. end
  287. end
  288. pressure = Pressure(material,prop1,'',value1,varargin{:});
  289. temperature = Temperature(material,prop1,'',value1,varargin{:});
  290. output = Corr_Oxygen_Volume(pressure,temperature);
  291. case {'propane','c3h8'}
  292. %% Propane
  293. error(nargchk(4, 7, nargin, 'struct'))
  294. if ((nargin > 4) && (nargin < 7))
  295. error('Therm:nargchk:improperNumberOfInputs','Improper number of input arguments.')
  296. end
  297. if strcmpi(prop1,'v')
  298. output = value1;
  299. return;
  300. end
  301. if nargin == 7
  302. prop2 = varargin{1};
  303. units2 = varargin{2};
  304. value2 = varargin{3};
  305. value2 = CheckUnits(prop2,units2,value2);
  306. varargin{2} = '';
  307. if strcmpi(prop2,'v')
  308. output = value2;
  309. return;
  310. end
  311. end
  312. pressure = Pressure(material,prop1,'',value1,varargin{:});
  313. temperature = Temperature(material,prop1,'',value1,varargin{:});
  314. output = Corr_Propane_Volume(pressure,temperature);
  315. otherwise
  316. error('Therm:matChk', 'Unknown material')
  317. end
  318. return