【浅水流方程式】HLL法で周期境界条件の場合のダム崩壊問題を解きます 動画とC++コード付き
【浅水流方程式】サイトマップ(ここから関連記事が探せます)
http://mathlang.hatenablog.com/entry/2018/12/18/213650
今回は、HLL法(Harten, Lax, van Leer法)を用いて周期境界条件でダム崩壊問題を解いてみました。解いている方程式は、摩擦、勾配を無視した1次元浅水流方程式(Shallow Water Equations)です。
領域の真ん中だけちょっと水位が高くなっています。境界条件は周期境界条件、すなわち右端と左端がつながっています。
参考文献としてはToroの"Shock-Capturing Methods for Free-Surface Shallow Flows"のpp.179-181です。まさにバイブルです。波速を推定するための手法としては、Exact Depth Positivity Riemann Solver (EDPRS)、Two-Rarefaction Riemann Solver (TRRS)、Two-Shock Riemann Solver (TSRS) を選べるようになっています。
Shock-Capturing Methods for Free-Surface Shallow Flows
- 作者: Eleuterio F. Toro
- 出版社/メーカー: Wiley
- 発売日: 2001/03/23
- メディア: ハードカバー
- この商品を含むブログを見る
こちらが計算結果です。青い線が水深です。
では計算コードです。BCに注目。
#include <iostream> #include <cmath> #include <fstream> #include <iomanip> #include <sstream> using namespace std; const double g=9.8; //celerity// inline double a(double h) { return sqrt(g*h); } //function for TRRS// inline double gk(double h0, double hlr) { return sqrt(g/2.0*(h0+hlr)/(h0*hlr)); } //Riemann Solver Based on Exact Depth Positivity// inline void EDPRS(double &hst, double &ust, double hL, double hR, double qL, double qR) { double aL=a(hL); double aR=a(hR); double uL=qL/hL; double uR=qR/hR; hst=(hL+hR)/2.0-(uR-uL)*(hL+hR)/4.0/(aL+aR); ust=(uL+uR)/2.0-(hR-hL)*(aL+aR)/(hL+hR); } //Two-Rarefaction Riemann Solver// inline void TRRS(double &hst, double &ust, double hL, double hR, double qL, double qR) { double aL=a(hL); double aR=a(hR); double uL=qL/hL; double uR=qR/hR; hst=1.0/g*((aL+aR)/2.0+(uL-uR)/4.0)*((aL+aR)/2.0+(uL-uR)/4.0); ust=(uL+uR)/2.0+aL-aR; } //Two-Shock Riemann Solver// inline void TSRS(double &hst, double &ust, double hL, double hR, double qL, double qR) { double uL=qL/hL; double uR=qR/hR; TRRS(hst,ust,hL,hR,qL,qR); //EDPRS(hst,ust,hL,hR,qL,qR); double hcon=hst; hst=(gk(hst,hL)*hL+gk(hst,hR)*hR+uL-uR)/(gk(hst,hL)+gk(hst,hR)); ust=(uL+uR)/2.0+((hcon-hR)*gk(hcon,hR)-(hcon-hL)*gk(hcon,hL))/2.0; } //function for HLL// inline double qk(double hst, double hlr) { double qk=1.0; if(hst>hlr) qk=sqrt((hst+hlr)*hst/(hlr*hlr)/2.0); return qk; } //left wave estimation// inline double SLeft(double hst, double hL, double qL) { double uL=qL/hL; return uL-a(hL)*qk(hst,hL); } //right wave estimation// inline double SRight(double hst, double hR, double qR) { double uR=qR/hR; return uR+a(hR)*qk(hst,hR); } //flux for continuity equation// inline double Fluxcon(double h, double q) { return q; } //flux for momentum equation// inline double Fluxmom(double h, double q) { return q*q/h+g*h*h/2.0; } //hll flux// inline void HLLFlux(double FLR[], double hL, double hR, double qL, double qR) { double hst,ust; //estimastion of hst and ust// TRRS(hst,ust,hL,hR,qL,qR); //TSRS(hst,ust,hL,hR,qL,qR); //EDPRS(hst,ust,hL,hR,qL,qR); //wave speed estimation// double SL=SLeft(hst,hL,qL); double SR=SRight(hst,hR,qR); if(SL>=0) { FLR[0]=Fluxcon(hL,qL); FLR[1]=Fluxmom(hL,qL); } else if(SR<=0) { FLR[0]=Fluxcon(hR,qR); FLR[1]=Fluxmom(hR,qR); } else { FLR[0]=(SR*Fluxcon(hL,qL)-SL*Fluxcon(hR,qR)+SR*SL*(hR-hL))/(SR-SL); FLR[1]=(SR*Fluxmom(hL,qL)-SL*Fluxmom(hR,qR)+SR*SL*(qR-qL))/(SR-SL); } } inline void output(double h[], double z[], int Node, double dx) { stringstream ss; string name; ofstream fo; static int count=0; ss<<count; name=ss.str(); name="h_" + name + ".txt"; fo.open(name.c_str ()); for(int i=0;i<Node;i++) { fo<<dx*float(i)<<" "<<h[i]+z[i]<<endl; } fo<<endl; fo<<endl; for(int i=0;i<Node;i++) { fo<<dx*float(i)<<" "<<z[i]<<endl; } count+=1; } int main() { const int n=200;//number of cells const int Node=n+1; double L=1.0; double dx=L/double(n); double dt=0.0001; double TotalTime=2.0; int div=50;//for output double q[Node]; double h[Node]; double qn[Node]; double hn[Node]; double FL[2],FR[2]; double InithL=0.5; double InithR=1.0; double z[Node]; double I[Node]; double mn=0.01; //IC// for(int i=0;i<Node;i++) { q[i]=0.0; h[i]=InithL; } for(int i=Node/3;i<Node*2/3;i++) { q[i]=0.0; h[i]=InithR; } //bottom// for(int i=0;i<Node;i++) { z[i]=0.0; double a=0.1-3.0*(float(i)*dx-0.5)*(float(i)*dx-0.5); if(a>0.0) z[i]=a; z[i]=0.0; } //slope// for(int i=1;i<Node-1;i++) { I[i]=-(z[i]-z[i-1])/dx; } //at boundary// I[0]=-(z[1]-z[0])/dx; I[Node-1]=-(z[Node-1]-z[Node-2])/dx; //IC output// output(h,z,Node,dx); //time step// for(int k=1;double(k)*dt<=TotalTime;k++) { //inner cells// for(int i=1;i<Node-1;i++) { //left flux, between i-1 and i// HLLFlux(FL,h[i-1],h[i],q[i-1],q[i]); //right flux, between i and i+1// HLLFlux(FR,h[i],h[i+1],q[i],q[i+1]); hn[i]=h[i]-dt/dx*(FR[0]-FL[0]); qn[i]=q[i]-dt/dx*(FR[1]-FL[1])+dt*g*h[i]*(I[i]-mn*mn*q[i]*abs(q[i])/pow(h[i],10.0/3.0)); } //BC// HLLFlux(FL,h[Node-1],h[0],q[Node-1],q[0]); HLLFlux(FR,h[0],h[1],q[0],q[1]); hn[0]=h[0]-dt/dx*(FR[0]-FL[0]); qn[0]=q[0]-dt/dx*(FR[1]-FL[1])+dt*g*h[0]*(I[0]-mn*mn*q[0]*abs(q[0])/pow(h[0],10.0/3.0)); HLLFlux(FL,h[Node-2],h[Node-1],q[Node-2],q[Node-1]); HLLFlux(FR,h[Node-1],h[0],q[Node-1],q[0]); hn[Node-1]=h[Node-1]-dt/dx*(FR[0]-FL[0]); qn[Node-1]=q[Node-1]-dt/dx*(FR[1]-FL[1]);//+dt*g*h[Node-1]*(I[Node-1]-mn*mn*q[Node-1]*abs(q[Node-1])/pow(h[Node-1],10.0/3.0)); //update// for(int i=0;i<Node;i++) { q[i]=qn[i]; h[i]=hn[i]; } //output// if(k%div==0) { output(h,z,Node,dx); cout<<"t="<<double(k)*dt<<endl; } } return 0; }
こちらもどうぞ