|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
所指要的界面是指熔体与熔体、熔体与气体之间的界面,这些界面随着流体的流动而移动。我了解到有采用VOF(流体体积法)的,也有采用CV(控制体积法),CV是在VOF上发展起来的。不知是否有人做过这方面的编程?<BR><BR>参考程序<BR>8.1. 1D FORTRAN code. A sample code for solving 1D hyperbolic system of conservation<BR>laws is provided below. The users are asked to provide their own PDE solvers, such as ENO<BR>schemes, central schemes and BGK methods, to form a subroutine PDES . Inthe following code,<BR>GAMA is the ratio of specied heat capacities of the uid, GAM1 = GAMA-1 , and IADAP is a switch<BR>parameter. If IADAP < 0, then PDEs are solved on uniform mesh, otherwise on adaptive mesh.<BR><BR><BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>C 1D FORTRAN Code of Adaptive Algorithm<BR>C Main Program<BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>PARAMETER(NX=3000)<BR>COMMON/COM1/UO(3,NX),UN(3,NX)<BR>& ,XO(NX),XN(NX)<BR>COMMON/COM2/NPX,NXI<BR>COMMON/EULER/GAMA,GAM1<BR>DATA NPX,NXI/103,103/<BR>DATA XLEFT,XRIGHT,XPO,GAMA<BR>& ,GAM1/0.,1.,.5,1.4,.4/<BR>TSTOP=0.2<BR>C<BR>C Initial partition and initial data<BR>C X: x-coordinate, old, N: new<BR>DX=(XRIGHT-XLEFT)/(NPX-3)<BR>DO J=1,NPX+4<BR>XO(J)=XLEFT+(J-3)*DX<BR>XN(J)=XO(J)<BR>ENDDO<BR>CALL INITIAL_DATA<BR>WRITE(*,*)' IADAP<0 or >0'<BR>READ(*,*) IADAP<BR>C<BR>C Move mesh and solve PDEs<BR>IT=0<BR>TIME=0.0<BR>100 IF(TIME.GT.TSTOP) GOTO 200<BR>CALL AMMM1D(IADAP)<BR>CALL PDES(DT)<BR>IT=IT+1<BR>TIME=TIME+DT<BR>WRITE(*,*) IT,TIME<BR>GOTO 100<BR>C Output the final results<BR>200 CALL OUTPUT<BR>END<BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>C Mesh-moving & solution-updating<BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>SUBROUTINE AMMM1D(IADAP)<BR>PARAMETER(NX=3000)<BR>IMPLICIT REAL*8 (A-H,O-Z)<BR>COMMON/COM1/UO(3,NX),UN(3,NX)<BR>& ,XO(NX),XN(NX)<BR>COMMON/COM2/NPX,NXI<BR>COMMON/EULER/GAMA,GAM1<BR>DIMENSION WO(NNX), WN(NNX)<BR>&,DUX(3,NX),DUU(NX),DUS(NX)<BR>DATA ALPHA,BETA/100.,100./<BR>FMON(X,DX,ALPHA,BETA)=SQRT(1.<BR>& +ALPHA*X*X+BETA*DX*DX)<BR>IF(IADAP.LT.0) RETURN<BR>DO J=1,NXI+2<BR>XN(J)=XO(J)<BR>DO L=1,3<BR>UN(L,J)=UO(L,J)<BR>ENDDO<BR>ENDDO<BR>IT=0<BR>900 IT=IT+1<BR>C<BR>C DEFINE MONITOR FUNCTION<BR>SUU=0.0<BR>SUS=0.0<BR>DO J=2,NXI+1<BR>RHOP1=UO(1,J+1)<BR>UXP1 =UO(2,J+1)/RHOP1<BR><BR>PREP1=GAM1*(UO(3,J+1)-.5<BR>& *RHOP1*UXP1*UXP1)<BR>RHOM1=UO(1,J-1)<BR>UXM1 =UO(2,J-1)/RHOM1<BR>PREM1=GAM1*(UO(3,J-1)-0.5<BR>& *RHOM1*UXM1*UXM1)<BR>DUU(J)=(UXP1-UXM1)/2.0<BR>DUS(J)=((PREP1/RHOP1**GAMA)<BR>& -(PREM1/RHOM1**GAMA))/2.0<BR>SUU=MAX(SUU,DUU(J))<BR>SUS=MAX(SUS,DUS(J))<BR>ENDDO<BR>DO J=2,NXI+1<BR>UU=DUU(J)/(SUU+1.0E-10)<BR>DU=DUS(J)/(SUS+1.0E-10)<BR>WO(J)=FMON(UU,DU,ALPHA,BETA)<BR>ENDDO<BR>DO 100 IJK=1,4<BR>DO J=2,NXI+1<BR>WN(J)=WO(J)<BR>IF(J.GT.2.and.J.LT.NXI+1) THEN<BR>WN(J)=(WO(J+1)+2.*WO(J)<BR>& +WO(J-1))/4.<BR>ENDIF<BR>ENDDO<BR>DO J=3,NXI<BR>WO(J)=WN(J)<BR>ENDDO<BR>100 CONTINUE<BR>C<BR>C update mesh<BR>DO J=3,NXI<BR>XN(J)=(WO(J)*XO(J+1)+WO(J-1)<BR>& *XN(J-1))/(WO(J)+WO(J-1))<BR>ENDDO<BR>C<BR>C compute the iteration error<BR>SUM=0.0<BR>DO J=1,NXI<BR>SUM=SUM+ABS(XN(J)-XO(J))<BR>ENDDO<BR>SUM=SUM/NXI<BR>C<BR>C update solution using upwinding flux<BR>DO L=1,3<BR>DO J=3,NXI<BR>DUL=UO(L,J)-UO(L,J-1)<BR>DUR=UO(L,J+1)-UO(L,J)<BR>DUX(L,J)=(SIGN(1.,DUL)+SIGN(1.,<BR>& DUR))*ABS(DUL*DUR)/(ABS(DUL)<BR>& +ABS(DUR)+1.E-10)<BR>ENDDO<BR>DUX(L,2)=0.0<BR>DUX(L,NXI+1)=0.0<BR>ENDDO<BR>C<BR>C XIX: area of control volume<BR>C old; N: new<BR>DO J=NIA,NIB<BR>XIXO=XO(J+1)-XO(J)<BR>XIXN=XN(J+1)-XN(J)<BR>SP1=(XO(J+1)-XN(J+1))/XIXN<BR>SP2=(XO(J)-XN(J))/XIXN<BR>DO L=1,3<BR>UJP1=(UO(L,J+1)-0.5*DUX(L,J+1))<BR>UJP0=UO(L,J )-0.5*DUX(L,J)<BR>UJM1=UO(L,J-1)+0.5*DUX(L,J-1)<BR>UJM0=UO(L,J )+0.5*DUX(L,J)<BR>UN(L,J)=UO(L,J)*XIXO/XIXN-.5*(<BR>& SP1*(UJP1+UJM0)-SP2*(UJP0+UJM1))<BR>& +.5*(ABS(SP1)*(UJP1-UJM0)<BR>& -ABS(SP2)*(UJP0-UJM1))<BR>ENDDO<BR>ENDDO<BR>IF(SUM.GE.1.0E-6) THEN<BR>DO J=3,NXI<BR>DO L=1,3<BR>UO(L,J)=UN(L,J)<BR>ENDDO<BR>XO(J)=XN(J)<BR>ENDDO<BR>GOTO 900<BR>ENDIF<BR>RETURN<BR>END<BR><BR><BR>8.2. 2D code. A sample code for solving 2D Riemann problem is provided below. Again the<BR>users are asked to provide their own PDE solver to form a PDE solution subroutine PDES .<BR><BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>C 2D FORTRAN Code of Adaptive Algorithm<BR>C Main Program<BR>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC<BR>PARAMETER(NX=100,NY=100)<BR>COMMON/C1/UO(4,NX,NY),UN(4,NX,NY)<BR>COMMON/C2/XO(NX,NY),YO(NX,NY)<BR>COMMON/C3/NPX,NPY,NXI,NET<BR>COMMON/C4/GAMA,PI<BR>COMMON/C5/RHOA,UXA,UYA,PREA<BR>& ,RHOB,UXB,UYB,PREB<BR>DATA NPX,NPY,NXI,NET/53,53,53,53/<BR>DATA XLEFT,YLEFT,XRIGHT,YRIGHT<BR>& ,GAMA/0.,0.,1.,1.,1.4/<BR>PI=ASIN(1.0)*2.0<BR>TSTOP=0.2<BR>C<BR>C Initial partition and initial data<BR>DX=(XRIGHT-XLEFT)/(NPX-3)<BR>DY=(YRIGHT-YLEFT)/(NPY-3)<BR>DO J=1,NPX+4<BR>DO K=1,NPY+4<BR>XO(J,K)=XLEFT+(J-3)*DX<BR>YO(J,K)=YLEFT+(K-3)*DY<BR>XN(J,K)=XO(J,K)<BR>YN(J,K)=YO(J,K)<BR>ENDDO<BR>ENDDO<BR>CALL INITIAL_DATA<BR>WRITE(*,*) ' IADAP<0 or > 0'<BR>READ(*,*) IADAP<BR>C<BR>C Move mesh and solve PDEs<BR>IT=0<BR>TIME=0.0<BR>100 IF(TIME.GT.TSTOP) GOTO 200<BR>CALL AMMM1D(IADAP)<BR>CALL PDES(DT)<BR>IT=IT+1<BR>TIME=TIME+DT<BR>WRITE(*,*) IT,TIME<BR>GOTO 100<BR>C<BR>C Output the final results<BR>200 CALL OUTPUT<BR>END<BR><BR><BR><BR>SUBROUTINE AMMM2D(IADAP)<BR>PARAMETER(NX=100,NY=100)<BR>COMMON/C1/UO(4,NX,NY),UN(4,NX,NY)<BR>COMMON/C2/XO(NX,NY),YO(NX,NY)<BR>COMMON/C3/NPX,NPY,NXI,NET<BR>COMMON/C4/GAMA,PI<BR>COMMON/C5/RHOA,UXA,UYA,PREA<BR>& ,RHOB,UXB,UYB,PREB<BR>DIMENSION WO(NX,NY),WN(NX,NY),<BR>& FLUX(4,NX,NY),FLUY(4,NX,NY)<BR>DIMENSION XN(NX,NY),YN(NX,NY),<BR>& DUX(4,NNX)<BR>DATA ALPHA,BETA,EP/0.,500.,1.E-10/<BR>FMON(x,DX,DY,ALPHA,BETA)=SQRT(1.0<BR>& +ALPHA*X*X+BETA*(DX*DX+DY*DY) )<BR>IF(IADAP.LT.0) RETURN<BR>NIA=4<BR>NIB=NXI-1<BR>NTA=4<BR>NTB=NET-1<BR>NXA=3<BR>NXB=NPX-1<BR>NYA=3<BR>NYB=NPY-1<BR>DO 100 J=1,NXI+2<BR>DO 100 K=1,NET+2<BR>XN(J,K)=XO(J,K)<BR>YN(J,K)=YO(J,K)<BR>100 CONTINUE<BR>DO 110 J=NXA-2,NXB+2<BR>DO 110 K=NYA-2,NYB+2<BR>DO 110 L=1,4<BR>UN(L,J,K)=UO(L,J,K)<BR>110 CONTINUE<BR>IT=0<BR>120 IT=IT+1<BR>C<BR>C give monitor function<BR>DO 130 J=NXA-1,NXB+1<BR>DO 130 K=NYA-1,NYB+1<BR>UU=UO(1,J,K)<BR>DUXI=.5*(UO(1,J+1,K)-UO(1,J-1,K))<BR>DUET=.5*(UO(1,J,K+1)-UO(1,J,K-1))<BR>WO(J,K)=FMON(UU,DUXI,DUET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<BR>ENDDO<BR>ENDDO<BR>190 CONTINUE<BR>C<BR>C y-direction flux<BR>DO 200 J=NXA,NXB<BR>DO L=1,4<BR>DO K=NYA,NYB<BR>DUL=(UO(L,J,K)-UO(L,J,K-1))<BR>& /(YO(J,K)-YO(J,K-1))<BR>DUR=(UO(L,J,K+1)-UO(L,J,K))<BR>& /(YO(J,K+1)-YO(J,K))<BR>DUX(L,K)=(SIGN(1.,DUL)+<BR>& SIGN(1.,DUR))*ABS(DUL*DUR)<BR>& /(ABS(DUL)+ABS(DUR)+EP)<BR>ENDDO<BR>DUX(L,NYA-1)=0.0<BR>DUX(L,NYB+1)=0.0<BR>ENDDO<BR>DO K=NYA-1,NYB<BR>DTX=XO(j,k+1)-XO(j+1,k+1)<BR>DTY=YO(j,k+1)-YO(j+1,k+1)<BR>ALENG=SQRT(DTX**2+DTY**2)<BR>SZTAK=DTY/ALENG<BR>CZTAK=DTX/ALENG<BR>SPX=.5*(XO(J,K+1)+XO(J+1,K+1)<BR>& -XN(J,K+1)-XN(J+1,K+1))<BR>SPY=.5*(YO(J,K+1)+YO(J+1,K+1)<BR>& -YN(J,K+1)-YN(J+1,K+1))<BR>SPN=SZTAK*SPX-CZTAK*SPY<BR>DO L=1,4<BR>UUL=UO(L,J,K)+.5*(YO(J,K+1)<BR>& -YO(J,K))*DUX(L,K)<BR>UUR=UO(L,J,K+1)-.5*(YO(J,K+1)<BR>& -YO(J,K))*DUX(L,K+1)<BR>FLUY(L,J,K)=.5*(SPN*(UUR+UUL)<BR>& -ABS(SPN)*(UUR-UUL))*ALENG<BR>ENDDO<BR>ENDDO<BR>200 CONTINUE<BR>C<BR>C areas of control volumes<BR>C and update the solution values<BR>DO 210 K=NYA,NYB<BR>DO 210 J=NXA,NXB<BR>AREAO=.5*((XO(j,k)-XO(j+1,k+1))<BR>& *(YO(j+1,k)-YO(j,k+1))<BR>& -(YO(j,k)-YO(j+1,k+1))<BR>& *(XO(j+1,k)-XO(j,k+1)))<BR>AREAN=0.5*((XN(j,k)-XN(j+1,k+1))<BR>& *(YN(j+1,k)-YN(j,k+1))<BR>& - (YN(j,k)-YN(j+1,k+1))<BR>& *(XN(j+1,k)-XN(j,k+1)))<BR>DO L=1,4<BR>UNN=UO(L,J,K)*AREAO-(FLUX(L,J,K)<BR>& -FLUX(L,J-1,K))-(FLUY(L,J,K)<BR>& -FLUY(L,J,K-1))<BR>UN(L,J,K)=UNN/AREAN<BR>ENDDO<BR>210 CONTINUE<BR>IF (SUM.GE.1.E-5) THEN<BR>DO 220 J=NXA,NXB<BR>DO 220 K=NYA,NYB<BR>DO 220 L=1,4<BR>UO(L,J,K)=UN(L,J,K)<BR>220 CONTINUE<BR>DO 230 J=NXA-1,NXB+1<BR>DO 230 K=NYA-1,NYB+1<BR>XO(J,K)=XN(J,K)<BR>YO(J,K)=YN(J,K)<BR>230 CONTINUE<BR>GOTO 120<BR>ENDIF<BR>RETURN<BR>END<BR> |
|