{"id":954932,"date":"2024-12-27T02:06:34","date_gmt":"2024-12-26T18:06:34","guid":{"rendered":""},"modified":"2024-12-27T02:06:36","modified_gmt":"2024-12-26T18:06:36","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8refprop","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/954932.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u8c03\u7528refprop"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095005\/6e4a16bb-3124-436e-8412-e25f68c0a0e6.webp\" alt=\"python\u4e2d\u5982\u4f55\u8c03\u7528refprop\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8c03\u7528REFPROP\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c<strong>\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528ctypes\u5e93\u3001refpropwrapper\u6a21\u5757\u3001\u4ee5\u53caCoolProp\u5e93<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528ctypes\u5e93\u8c03\u7528REFPROP\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528ctypes\u5e93\u8c03\u7528REFPROP\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5REFPROP\u8f6f\u4ef6\u5e76\u5c06\u5176\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/li>\n<li>\u4f7f\u7528ctypes\u5e93\u52a0\u8f7dREFPROP\u7684\u52a8\u6001\u94fe\u63a5\u5e93\uff08DLL\uff09\u3002<\/li>\n<li>\u8c03\u7528REFPROP\u63d0\u4f9b\u7684\u51fd\u6570\u8fdb\u884c\u7269\u6027\u8ba1\u7b97\u3002<\/li>\n<\/ol>\n<p><h3>\u4e00\u3001\u5b89\u88c5REFPROP\u8f6f\u4ef6<\/h3>\n<\/p>\n<p><p>REFPROP\u662f\u7531\u7f8e\u56fd\u56fd\u5bb6\u6807\u51c6\u6280\u672f\u7814\u7a76\u6240\uff08NIST\uff09\u5f00\u53d1\u7684\u7269\u6027\u6570\u636e\u5e93\u8f6f\u4ef6\u3002\u9996\u5148\u9700\u8981\u4eceNIST\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5REFPROP\u8f6f\u4ef6\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u9700\u8981\u5c06REFPROP\u7684\u5b89\u88c5\u76ee\u5f55\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u5728Python\u4e2d\u53ef\u4ee5\u8bbf\u95ee\u5230REFPROP\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528ctypes\u5e93\u52a0\u8f7dREFPROP\u7684DLL<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>ctypes<\/code>\u5e93\u52a0\u8f7dREFPROP\u7684\u52a8\u6001\u94fe\u63a5\u5e93\uff08DLL\uff09\uff0c\u4ee5\u4fbf\u8c03\u7528\u5176\u4e2d\u7684\u51fd\u6570\u3002\u9996\u5148\uff0c\u9700\u8981\u5bfc\u5165ctypes\u5e93\uff0c\u7136\u540e\u4f7f\u7528<code>ctypes.cdll.LoadLibrary()<\/code>\u51fd\u6570\u52a0\u8f7dREFPROP\u7684DLL\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>import os<\/p>\n<h2><strong>\u6307\u5b9aREFPROP\u8def\u5f84<\/strong><\/h2>\n<p>refprop_path = r&#39;C:\\Program Files (x86)\\REFPROP&#39;  # \u8bf7\u6839\u636e\u5b9e\u9645\u5b89\u88c5\u8def\u5f84\u4fee\u6539<\/p>\n<h2><strong>\u5c06REFPROP\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p>os.environ[&#39;RPPREFIX&#39;] = refprop_path<\/p>\n<h2><strong>\u52a0\u8f7dREFPROP DLL\u6587\u4ef6<\/strong><\/h2>\n<p>refprop = ctypes.cdll.LoadLibrary(os.path.join(refprop_path, &#39;REFPRP64.DLL&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u8c03\u7528REFPROP\u63d0\u4f9b\u7684\u51fd\u6570<\/h3>\n<\/p>\n<p><p>REFPROP\u63d0\u4f9b\u4e86\u591a\u79cd\u51fd\u6570\u7528\u4e8e\u7269\u6027\u8ba1\u7b97\uff0c\u4f8b\u5982\u8ba1\u7b97\u7269\u8d28\u7684\u5bc6\u5ea6\u3001\u7113\u3001\u71b5\u7b49\u3002\u8fd9\u91cc\u4ee5\u8ba1\u7b97\u7eaf\u7269\u8d28\u7684\u7113\uff08enthalpy\uff09\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u8c03\u7528REFPROP\u7684\u51fd\u6570\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b9a\u4e49\u8c03\u7528REFPROP\u51fd\u6570\u6240\u9700\u7684\u53d8\u91cf\u548c\u53c2\u6570\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u63d0\u4f9b\u7269\u8d28\u540d\u79f0\u3001\u6e29\u5ea6\u3001\u538b\u529b\u7b49\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7269\u8d28\u540d\u79f0\u3001\u6e29\u5ea6\u548c\u538b\u529b<\/p>\n<p>substance = &#39;Water&#39;<\/p>\n<p>temperature = 300.0  # \u5355\u4f4d\uff1aK<\/p>\n<p>pressure = 101.325  # \u5355\u4f4d\uff1akPa<\/p>\n<h2><strong>\u5b9a\u4e49\u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u8ba1\u7b97\u7ed3\u679c<\/strong><\/h2>\n<p>enthalpy = ctypes.c_double()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u8c03\u7528REFPROP\u7684\u51fd\u6570\u8fdb\u884c\u8ba1\u7b97\u3002\u4ee5\u8ba1\u7b97\u7113\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u8c03\u7528<code>ENTHAL<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8c03\u7528REFPROP\u7684ENTHAL\u51fd\u6570\u8ba1\u7b97\u7113<\/p>\n<p>ierr = ctypes.c_long()<\/p>\n<p>herr = ctypes.create_string_buffer(255)<\/p>\n<p>refprop.ENTHAL(ctypes.c_char_p(substance.encode(&#39;ascii&#39;)),<\/p>\n<p>               ctypes.byref(ctypes.c_double(temperature)),<\/p>\n<p>               ctypes.byref(ctypes.c_double(pressure)),<\/p>\n<p>               ctypes.byref(enthalpy),<\/p>\n<p>               ctypes.byref(ierr),<\/p>\n<p>               herr,<\/p>\n<p>               ctypes.c_long(len(herr)))<\/p>\n<h2><strong>\u68c0\u67e5\u662f\u5426\u6709\u9519\u8bef<\/strong><\/h2>\n<p>if ierr.value != 0:<\/p>\n<p>    print(&#39;Error:&#39;, herr.value.decode(&#39;ascii&#39;))<\/p>\n<p>else:<\/p>\n<p>    print(&#39;Enthalpy:&#39;, enthalpy.value, &#39;kJ\/kg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u591a\u7ec4\u5206\u6df7\u5408\u7269<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u8ba1\u7b97\u7eaf\u7269\u8d28\u7684\u7269\u6027\uff0cREFPROP\u8fd8\u652f\u6301\u591a\u7ec4\u5206\u6df7\u5408\u7269\u7684\u8ba1\u7b97\u3002\u5bf9\u4e8e\u591a\u7ec4\u5206\u6df7\u5408\u7269\uff0c\u9700\u8981\u63d0\u4f9b\u7ec4\u5206\u540d\u79f0\u548c\u6469\u5c14\u5206\u6570\u7b49\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u7ec4\u5206\u540d\u79f0\u548c\u6469\u5c14\u5206\u6570<\/p>\n<p>components = [&#39;Methane&#39;, &#39;Ethane&#39;]<\/p>\n<p>mole_fractions = [0.8, 0.2]<\/p>\n<h2><strong>\u8f6c\u6362\u4e3actypes\u6570\u7ec4<\/strong><\/h2>\n<p>c_components = (ctypes.c_char_p * len(components))(*[c.encode(&#39;ascii&#39;) for c in components])<\/p>\n<p>c_mole_fractions = (ctypes.c_double * len(mole_fractions))(*mole_fractions)<\/p>\n<h2><strong>\u5b9a\u4e49\u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u8ba1\u7b97\u7ed3\u679c<\/strong><\/h2>\n<p>enthalpy_mix = ctypes.c_double()<\/p>\n<h2><strong>\u8c03\u7528REFPROP\u7684ENTHAL\u51fd\u6570\u8ba1\u7b97\u6df7\u5408\u7269\u7113<\/strong><\/h2>\n<p>refprop.ENTHAL(c_components,<\/p>\n<p>               ctypes.byref(ctypes.c_double(temperature)),<\/p>\n<p>               ctypes.byref(ctypes.c_double(pressure)),<\/p>\n<p>               ctypes.byref(c_mole_fractions),<\/p>\n<p>               ctypes.byref(enthalpy_mix),<\/p>\n<p>               ctypes.byref(ierr),<\/p>\n<p>               herr,<\/p>\n<p>               ctypes.c_long(len(herr)))<\/p>\n<h2><strong>\u68c0\u67e5\u662f\u5426\u6709\u9519\u8bef<\/strong><\/h2>\n<p>if ierr.value != 0:<\/p>\n<p>    print(&#39;Error:&#39;, herr.value.decode(&#39;ascii&#39;))<\/p>\n<p>else:<\/p>\n<p>    print(&#39;Enthalpy of mixture:&#39;, enthalpy_mix.value, &#39;kJ\/kg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u65b9\u6cd5\u8c03\u7528REFPROP<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528ctypes\u5e93\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5728Python\u4e2d\u8c03\u7528REFPROP\uff0c\u4f8b\u5982\u4f7f\u7528<code>refpropwrapper<\/code>\u6a21\u5757\u548c<code>CoolProp<\/code>\u5e93\u3002\u8fd9\u4e9b\u65b9\u6cd5\u901a\u5e38\u66f4\u7b80\u4fbf\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684\u63a5\u53e3\u3002\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003\u76f8\u5e94\u7684\u6587\u6863\u548c\u6559\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8c03\u7528REFPROP\u8fdb\u884c\u7269\u6027\u8ba1\u7b97\uff0c\u53ef\u4ee5\u901a\u8fc7<strong>\u4f7f\u7528ctypes\u5e93\u52a0\u8f7dREFPROP\u7684DLL\u6587\u4ef6\uff0c\u5e76\u8c03\u7528\u5176\u63d0\u4f9b\u7684\u51fd\u6570\u8fdb\u884c\u8ba1\u7b97<\/strong>\u3002\u5728\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u6ce8\u610f\u6b63\u786e\u5b89\u88c5\u548c\u914d\u7f6eREFPROP\u8f6f\u4ef6\uff0c\u8bbe\u7f6e\u6b63\u786e\u7684\u8def\u5f84\uff0c\u5e76\u6309\u8981\u6c42\u4f20\u9012\u53c2\u6570\u548c\u53d8\u91cf\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728Python\u73af\u5883\u4e2d\u5b9e\u73b0\u590d\u6742\u7684\u7269\u6027\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5RefProp\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u4f7f\u7528RefProp\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86RefProp\u8f6f\u4ef6\u3002\u53ef\u4ee5\u4eceNIST\u5b98\u7f51\u83b7\u53d6RefProp\u7684\u5b89\u88c5\u6587\u4ef6\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u786e\u4fdd\u5c06RefProp\u7684\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5<code>refprop<\/code> Python\u5e93\uff0c\u547d\u4ee4\u4e3a<code>pip install refprop<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u786e\u8ba4\u5e93\u662f\u5426\u6210\u529f\u5b89\u88c5\uff0c\u53ef\u4ee5\u5728Python\u73af\u5883\u4e2d\u5bfc\u5165\u5b83\uff1a<code>import RefProp<\/code>\u3002<\/p>\n<p><strong>RefProp\u5728Python\u4e2d\u652f\u6301\u54ea\u4e9b\u70ed\u529b\u5b66\u5c5e\u6027\u7684\u8ba1\u7b97\uff1f<\/strong><br \/>RefProp\u5e93\u53ef\u4ee5\u8ba1\u7b97\u591a\u79cd\u70ed\u529b\u5b66\u5c5e\u6027\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6c14\u4f53\u548c\u6db2\u4f53\u7684\u5bc6\u5ea6\u3001\u6bd4\u70ed\u3001\u7113\u3001\u71b5\u3001\u76f8\u5e73\u8861\u3001\u4e34\u754c\u70b9\u3001\u84b8\u53d1\u70ed\u7b49\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u7269\u8d28\u7684\u540d\u79f0\u6216\u5316\u5b66\u5f0f\uff0c\u8f7b\u677e\u83b7\u53d6\u5176\u7279\u5b9a\u6761\u4ef6\u4e0b\u7684\u70ed\u529b\u5b66\u6570\u636e\u3002\u8fd9\u5bf9\u4e8e\u4ece\u4e8b\u70ed\u529b\u5b66\u3001\u5316\u5b66\u5de5\u7a0b\u6216\u7269\u7406\u5b66\u7684\u7814\u7a76\u4eba\u5458\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528RefProp\u8fdb\u884c\u76f8\u5e73\u8861\u8ba1\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\u4f7f\u7528RefProp\u8fdb\u884c\u76f8\u5e73\u8861\u8ba1\u7b97\u76f8\u5bf9\u7b80\u5355\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528RefProp\u7684\u76f8\u5173\u51fd\u6570\uff0c\u8f93\u5165\u7269\u8d28\u7684\u7c7b\u578b\u3001\u6e29\u5ea6\u548c\u538b\u529b\u7b49\u53c2\u6570\u3002\u4f7f\u7528<code>RefProp<\/code>\u5e93\u7684<code>RPP<\/code>\u7c7b\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u83b7\u53d6\u4e0d\u540c\u76f8\u7684\u6027\u8d28\uff0c\u6bd4\u5982\u6c14\u76f8\u548c\u6db2\u76f8\u7684\u5bc6\u5ea6\u548c\u6bd4\u70ed\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import RefProp as rp\nfluid = &#39;Water&#39;\ntemperature = 300  # \u6e29\u5ea6\uff0c\u5355\u4f4d\u4e3aK\npressure = 101325  # \u538b\u529b\uff0c\u5355\u4f4d\u4e3aPa\nresult = rp.PropsSI(&#39;D&#39;, &#39;T&#39;, temperature, &#39;P&#39;, pressure, fluid)\nprint(f&#39;{fluid}\u5728{temperature} K\u548c{pressure} Pa\u4e0b\u7684\u5bc6\u5ea6\u4e3a{result} kg\/m\u00b3&#39;)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u8fdb\u884c\u5404\u79cd\u70ed\u529b\u5b66\u8ba1\u7b97\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8c03\u7528REFPROP\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528ctypes\u5e93\u3001refpropwrap [&hellip;]","protected":false},"author":3,"featured_media":954936,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954932"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=954932"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954932\/revisions"}],"predecessor-version":[{"id":954937,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954932\/revisions\/954937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/954936"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=954932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=954932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=954932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}