﻿{"id":1943,"date":"2022-11-10T08:10:00","date_gmt":"2022-11-10T08:10:00","guid":{"rendered":"http:\/\/81.70.49.155\/?p=1943"},"modified":"2022-11-10T08:10:00","modified_gmt":"2022-11-10T08:10:00","slug":"lbm%e9%80%9a%e9%81%93%e6%b5%81-c%e7%89%88-2022%e8%87%aa%e7%bc%96","status":"publish","type":"post","link":"http:\/\/81.70.49.155\/?p=1943","title":{"rendered":"LBM\u901a\u9053\u6d41 C++\u7248 [2022\u81ea\u7f16]"},"content":{"rendered":"<p>\n\t<img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/11\/20221110160857_26277.png\" alt=\"\" \/>\n<\/p>\n<p>\n\t\n<\/p>\n<p>\n\t\/\/Program By Yuanqing XU-2022-11-10\n<\/p>\n<p>\n#include \"stdafx.h\"<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;cmath&gt;<br \/>\n#include &lt;cstdlib&gt;<br \/>\n#include &lt;iomanip&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &lt;sstream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nusing namespace std;<\/p>\n<p>\/\/\u57fa\u672c\u53c2\u6570\uff0c\u9700\u8981\u4ece\u8f6f\u4ef6\u524d\u7aef\u8bbe\u7f6e<br \/>\nconst int&nbsp; &nbsp; &nbsp; &nbsp; Lx = 200;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/x\u65b9\u5411\u7f51\u683c\u6570&nbsp; \uff08\u53c2\u65701\uff09<br \/>\nconst int&nbsp; &nbsp; &nbsp; &nbsp; Ly = 50;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/y\u65b9\u5411\u7f51\u683c\u6570&nbsp; \uff08\u53c2\u65702\uff09<br \/>\nconst int&nbsp; &nbsp; &nbsp; &nbsp; MaxT = 3000;&nbsp; &nbsp; &nbsp;\/\/\u8fed\u4ee3\u6b21\u6570&nbsp; &nbsp; &nbsp; &nbsp;\uff08\u53c2\u65703\uff09<br \/>\nconst int&nbsp; &nbsp; &nbsp; &nbsp; OutN = 200;&nbsp; &nbsp; &nbsp; &nbsp; \/\/\u8f93\u51fa\u95f4\u9694&nbsp; &nbsp; &nbsp; &nbsp;\uff08\u53c2\u65704\uff09<br \/>\nconst double&nbsp; Uin = 0.1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u5165\u53e3\u901f\u5ea6&nbsp; &nbsp; &nbsp; &nbsp;\uff08\u53c2\u65705\uff09<br \/>\ndouble&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Re = 30;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \u96f7\u8bfa\u6570&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (\u53c2\u65706)<br \/>\nconst char *const PathD = \"..\\\\DataOut\\\\U_\";&nbsp; \/\/ \u6570\u636e\u5b58\u653e\u8def\u5f84 (\u53c2\u65707)<br \/>\nconst double&nbsp; pi = 3.14159265;<\/p>\n<p>\/\/LBM\u53c2\u6570&nbsp;<br \/>\nconst int&nbsp; Q = 9;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/D2Q9\u6a21\u578b<br \/>\ndouble&nbsp; &nbsp; rho0 = 1.0;<br \/>\ndouble&nbsp; &nbsp; nu = Uin*Ly \/ Re;<br \/>\ndouble&nbsp; &nbsp; tau = 3.0*nu + 0.5;<\/p>\n<p>\/\/\u53d8\u91cf\u521d\u59cb\u5316<br \/>\nint i, j, k, ip, jp, tStep, ii, jj;<br \/>\nint e[Q][2] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 }, { 1, 1 }, { -1, 1 }, { -1, -1 }, { 1, -1 } };<br \/>\ndouble w[Q] = { 4.0 \/ 9, 1.0 \/ 9, 1.0 \/ 9, 1.0 \/ 9, 1.0 \/ 9, 1.0 \/ 36, 1.0 \/ 36, 1.0 \/ 36, 1.0 \/ 36 };<br \/>\ndouble rho[Ly + 1][Lx + 1], F[Ly + 1][Lx + 1][Q], FEQM[Ly + 1][Lx + 1][Q], U[Ly + 1][Lx + 1][2];<br \/>\ndouble F0[Ly + 1][Lx + 1][Q];<\/p>\n<p>\/\/\u51fd\u6570\u521d\u59cb\u5316<br \/>\ndouble feq(int k, double rho, double u[2]);<br \/>\nvoid Initialization();<br \/>\nvoid Outputdata(int m);<\/p>\n<p>\/\/\u4e3b\u7a0b\u5e8f<br \/>\nint&nbsp; main()<br \/>\n{<br \/>\n<span> <\/span>using namespace std;<\/p>\n<p><span> <\/span>Initialization();<\/p>\n<p><span> <\/span>for (tStep = 1; tStep &lt;= MaxT; tStep++)<br \/>\n<span> <\/span>{<\/p>\n<p>\n<span> <\/span>\/\/1- \u8fc1\u79fb\uff08\u4e0d\u5305\u542b\u8fb9\u754c\uff09<br \/>\n<span> <\/span>for (i = 1; i &lt; Lx; i++)<br \/>\n<span> <\/span>for (j = 1; j &lt; Ly; j++)<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>ii = i - e[k][0];&nbsp; &nbsp;jj = j - e[k][1];<br \/>\n<span> <\/span>F[j][i][k] = F0[jj][ii][k];<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<\/p>\n<p><span> <\/span>\/\/2- \u8ba1\u7b97\u5b8f\u89c2\u91cf<br \/>\n<span> <\/span>for (i = 1; i &lt; Lx; i++)<br \/>\n<span> <\/span>for (j = 1; j &lt; Ly; j++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>rho[j][i] = 0;<br \/>\n<span> <\/span>U[j][i][0] = 0;<br \/>\n<span> <\/span>U[j][i][1] = 0;<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>rho[j][i] += F[j][i][k];<br \/>\n<span> <\/span>U[j][i][0] += e[k][0] * F[j][i][k];<br \/>\n<span> <\/span>U[j][i][1] += e[k][1] * F[j][i][k];<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>U[j][i][0] \/= rho[j][i];<br \/>\n<span> <\/span>U[j][i][1] \/= rho[j][i];<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<\/p>\n<p><span> <\/span>\/\/\u5de6\u53f3\u5b8f\u89c2\u8fb9\u754c<br \/>\n<span> <\/span>for (j = 1; j &lt; Ly; j++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>U[j][0][0] = Uin;&nbsp; &nbsp;U[j][0][1] = 0;<br \/>\n<span> <\/span>U[j][Lx][0] = U[j][Lx - 1][0];&nbsp; &nbsp;U[j][Lx][1] = 0;<br \/>\n<span> <\/span>rho[j][0] = rho[j][1];&nbsp; rho[j][Lx] = rho0;<br \/>\n<span> <\/span>}<\/p>\n<p><span> <\/span>\/\/\u4e0a\u4e0b\u58c1\u9762<br \/>\n<span> <\/span>for (i = 0; i &lt;= Lx; i++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>U[0][i][0] = 0;&nbsp; &nbsp;U[0][i][1] = 0;<br \/>\n<span> <\/span>U[Ly][i][0] = 0;&nbsp; &nbsp;U[Ly][i][1] = 0;<br \/>\n<span> <\/span>rho[0][i] = rho[1][i];<br \/>\n<span> <\/span>rho[Ly][i] = rho[Ly - 1][i];<br \/>\n<span> <\/span>}<\/p>\n<p>\/\/4- \u78b0\u649e\uff08\u4e0d\u5305\u542b\u8fb9\u754c\uff09<br \/>\n<span> <\/span>for (i = 1; i &lt; Lx; i++)<br \/>\n<span> <\/span>for (j = 1; j &lt; Ly; j++)<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>F0[j][i][k] = F[j][i][k] - 1 \/ tau*(F[j][i][k] - feq(k, rho[j][i], U[j][i]));<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<\/p>\n<p>\n\/\/5- \u5fae\u89c2\u8fb9\u754c\u5904\u7406\uff08\u4e0d\u9700\u8981\u5224\u65ad\u7c7b\u578b\u548c\u65b9\u5411\uff0c\u5904\u7406\u90fd\u4e00\u6837\uff09<br \/>\n<span> <\/span>\/\/\u5de6\u53f3\u5fae\u89c2\u8fb9\u754c<br \/>\n<span> <\/span>for (j = 1; j &lt; Ly; j++)<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>F0[j][0][k] = feq(k, rho[j][0], U[j][0]) + F0[j][1][k] - feq(k, rho[j][1], U[j][1]);&nbsp; \/\/\u5165\u53e3<br \/>\n<span> <\/span>F0[j][Lx][k] = feq(k, rho[j][Lx], U[j][Lx]) + F0[j][Lx - 1][k] - feq(k, rho[j][Lx - 1], U[j][Lx - 1]); \/\/\u51fa\u53e3<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>\/\/\u4e0a\u4e0b\u5fae\u89c2\u8fb9\u754c<br \/>\n<span> <\/span>for (i = 1; i &lt; Lx; i++)<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>F0[0][i][k] = feq(k, rho[0][i], U[0][i]) + F0[1][i][k] - feq(k, rho[1][i], U[1][i]);&nbsp; \/\/\u4e0b\u8fb9\u754c<br \/>\n<span> <\/span>F0[Ly][i][k] = feq(k, rho[Ly][i], U[Ly][i]) + F0[Ly - 1][i][k] - feq(k, rho[Ly - 1][i], U[Ly - 1][i]); \/\/\u4e0a\u8fb9\u754c<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<\/p>\n<p>\n\/\/6 \u8f93\u51fa\u6570\u636e\u548c\u663e\u793a<br \/>\n<span> <\/span>if (tStep % OutN == 0)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>cout &lt;&lt; \"\u5165\u53e3\u4e2d\u70b9\u901f\u5ea6\uff1a\" &lt;&lt; U[25][1][0] &lt;&lt; \"&nbsp; &nbsp; &nbsp;NO.\" &lt;&lt;tStep&lt;&lt; \"---Steps\" &lt;&lt; endl;<br \/>\n<span> <\/span>Outputdata(tStep);<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>return 0;<br \/>\n}<br \/>\n\/\/ \u4e3b\u7a0b\u5e8f\u7ed3\u675f~~~~~~~~~~~<\/p>\n<p>\/\/\u5b50\u7a0b\u5e8f\u4e0e\u51fd\u6570======================================================================<br \/>\n\/\/\u5b50\u7a0b\u5e8f1&nbsp; &nbsp;\u521d\u59cb\u5316\u51fd\u6570<br \/>\nvoid Initialization()<br \/>\n{<br \/>\n<span> <\/span>for (i = 0; i &lt;= Lx; i++)<br \/>\n<span> <\/span>for (j = 0; j &lt;= Ly; j++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>U[j][i][0] = 0;<span> <\/span>U[j][i][1] = 0;<br \/>\n<span> <\/span>rho[j][i] = 1;&nbsp; <span> <\/span>U[j][0][0] = Uin;<br \/>\n<span> <\/span>for (k = 0; k &lt; Q; k++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>F[j][i][k] = feq(k, rho[j][i], U[j][i]);<br \/>\n<span> <\/span>F0[j][i][k] = feq(k, rho[j][i], U[j][i]);<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>}<br \/>\n<span> <\/span>U[0][0][0] = 0;<br \/>\n<span> <\/span>U[Ly][0][0] = 0;<br \/>\n}<\/p>\n<p>\n\/\/\/\/\u5b50\u7a0b\u5e8f2&nbsp; &nbsp;\u8ba1\u7b97\u8f93\u51fa\u901f\u5ea6\u573a\u51fd\u6570<br \/>\nvoid Outputdata(int m)<br \/>\n{<br \/>\n<span> <\/span>ostringstream name;<br \/>\n<span> <\/span>name &lt;&lt; PathD<span> <\/span>&lt;&lt; m &lt;&lt; \".dat\";&nbsp; \/\/\u6570\u636e\u5b58\u50a8\u5730\u5740<br \/>\n<span> <\/span>ofstream out(name.str().c_str());<br \/>\n<span> <\/span>out &lt;&lt; \"Title=\\\"LBM Channel Flow\\\"\\n\"<br \/>\n<span> <\/span>&lt;&lt; \"VARIABLES=\\\"X\\\",\\\"Y\\\",\\\"U\\\",\\\"V\\\"\\n\"<br \/>\n<span> <\/span>&lt;&lt; \"ZONE T= \\\"BOX\\\", I= \"<br \/>\n<span> <\/span>&lt;&lt; Lx + 1 &lt;&lt; \", J=\" &lt;&lt; Ly + 1 &lt;&lt; \", F=POINT\" &lt;&lt; endl;<br \/>\n<span> <\/span>for (j = 0; j &lt;= Ly; j++)<br \/>\n<span> <\/span>for (i = 0; i &lt;= Lx; i++)<br \/>\n<span> <\/span>{<br \/>\n<span> <\/span>out &lt;&lt; double(i) &lt;&lt; \" \" &lt;&lt; double(j) &lt;&lt; \" \"<br \/>\n<span> <\/span>&lt;&lt; U[j][i][0] &lt;&lt; \" \" &lt;&lt; U[j][i][1] &lt;&lt; endl;<br \/>\n<span> <\/span>}<br \/>\n}<\/p>\n<p>\/\/\u51fd\u65701&nbsp; &nbsp;\u8ba1\u7b97\u5e73\u8861\u6001\u5206\u5e03\u51fd\u6570<br \/>\ndouble feq(int k, double rho, double u[2])<br \/>\n{<br \/>\n<span> <\/span>double eu, uv, feq;<br \/>\n<span> <\/span>eu = (e[k][0] * u[0] + e[k][1] * u[1]);<br \/>\n<span> <\/span>uv = (u[0] * u[0] + u[1] * u[1]);<br \/>\n<span> <\/span>feq = w[k] * rho*(1.0 + 3.0*eu + 4.5*eu*eu - 1.5*uv);<br \/>\n<span> <\/span>return feq;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/Program By Yuanqing XU-2022-11-10 #include \"stdafx.h\" &hellip; <a href=\"http:\/\/81.70.49.155\/?p=1943\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cLBM\u901a\u9053\u6d41 C++\u7248 [2022\u81ea\u7f16]\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"views":815,"_links":{"self":[{"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/posts\/1943"}],"collection":[{"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/81.70.49.155\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1943"}],"version-history":[{"count":1,"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/posts\/1943\/revisions"}],"predecessor-version":[{"id":1944,"href":"http:\/\/81.70.49.155\/index.php?rest_route=\/wp\/v2\/posts\/1943\/revisions\/1944"}],"wp:attachment":[{"href":"http:\/\/81.70.49.155\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/81.70.49.155\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1943"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/81.70.49.155\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}