!二维欧拉方程
program NND2d
implicit real(a-h,o-z)
parameter(nx=400,ny=400,ighost=2)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real minmod
gama=1.4
dx=1.0/nx
dy=1.0/ny
call init(u,nx,ny,ighost,gama)
dt=CFL(u,dx,dy,nx,ny,ighost,gama)
dt=dx*dy
supt=0.08
t=0
do while(t.lt.supt)
if(t+dt.gt.supt) dt=supt-t
t=t+dt
write(*,*) 't=',t,'dt=',dt
call solveall(u,nx,ny,dt,dx,dy,ighost,gama)
call bound(u,nx,ny,ighost)
enddo
call output(u,nx,ny,dx,dy,ighost,gama)
end
!子程序
subroutine init(u,nx,ny,ighost,gama)!初始化
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
do i=-ighost,nx/2
do j=-ighost,ny/2
u(i,j,0)=0.5
u(i,j,1)=0.5*3.0
u(i,j,2)=0.5*1.0
u(i,j,3)=1.0/(gama-1)+0.5*0.5*10
enddo
enddo
do i=nx/2+1,nx+ighost
do j=-ighost,ny/2
u(i,j,0)=1.5
u(i,j,1)=1.5*3.0
u(i,j,2)=-1.5*1.0
u(i,j,3)=1.0/(gama-1)+0.5*1.5*10
enddo
enddo
do i=nx/2+1,nx+ighost
do j=ny/2+1,ny+ighost
u(i,j,0)=0.5
u(i,j,1)=-0.5*3.0
u(i,j,2)=-0.5*1.0
u(i,j,3)=1.0/(gama-1)+0.5*0.5*10
enddo
enddo
do i=-ighost,nx/2
do j=ny/2+1,ny+ighost
u(i,j,0)=1.5
u(i,j,1)=-1.5*3.0
u(i,j,2)=1.5*1.0
u(i,j,3)=1.0/(gama-1)+0.5*1.5*10
enddo
enddo
end
subroutine solveall(u,nx,ny,dt,dx,dy,ighost,gama)
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real gt(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ft(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
call Solvex(u,ft,nx,ny,ighost,gama)
call Solvey(u,gt,nx,ny,ighost,gama)
r1=dt/dx
r2=dt/dy
do i=-ighost+2,nx+ighost-2
do j=-ighost+2,ny+ighost-2
do k=0,3
u(i,j,k)=u(i,j,k)-r1*(ft(i,j,k)-ft(i-1,j,k))
& -r2*(gt(i,j,k)-gt(i,j-1,k))
enddo
enddo
enddo
end
subroutine Solvex(u,ft,nx,ny,ighost,gama)
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real fl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real fr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real dfl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real dfr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ffl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ffr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ft(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real minmod
eps=1e-6
do j=-ighost,ny+ighost
do i=-ighost,nx+ighost
p=(gama-1.0)*(u(i,j,3)-0.5*u(i,j,1)**2/u(i,j,0)
& -0.5*u(i,j,2)**2/u(i,j,0))
uu=u(i,j,1)/u(i,j,0)
c=sqrt(gama*p/u(i,j,0))
vv=u(i,j,2)/u(i,j,0)
H=c*c/(gama-1)+0.5*(uu**2+vv**2)
a1=uu
a2=uu-c
a3=uu+c
a1l=0.5*(a1+sqrt(a1*a1+eps*eps))
a2l=0.5*(a2+sqrt(a2*a2+eps*eps))
a3l=0.5*(a3+sqrt(a3*a3+eps*eps))
a1r=0.5*(a1-sqrt(a1*a1+eps*eps))
a2r=0.5*(a2-sqrt(a2*a2+eps*eps))
a3r=0.5*(a3-sqrt(a3*a3+eps*eps))
fr(i,j,0)=u(i,j,0)/2/gama*(2*(gama-1)*a1r+a2r+a3r)
fr(i,j,1)=u(i,j,0)/2/gama*(2*uu*(gama-1)*a1r+(uu-c)*a2r
& +(uu+c)*a3r)
fr(i,j,2)=u(i,j,0)*vv/2/gama*(2*(gama-1)*a1r
& +a2r+a3r)
fr(i,j,3)=u(i,j,0)/2/gama*(2*((gama-1)*H-c*c)*a1r
& +(H-c*uu)*a2r+(H+uu*c)*a3r)
fl(i,j,0)=u(i,j,0)/2/gama*(2*(gama-1)*a1l+a2l+a3l)
fl(i,j,1)=u(i,j,0)/2/gama*(2*uu*(gama-1)*a1l+(uu-c)*a2l
& +(uu+c)*a3l)
fl(i,j,2)=u(i,j,0)*vv/2/gama*(2*(gama-1)*a1l
& +a2l+a3l)
fl(i,j,3)=u(i,j,0)/2/gama*(2*((gama-1)*H-c*c)*a1l
& +(H-c*uu)*a2l+(H+uu*c)*a3l)
enddo
do i=-ighost+1,nx+ighost
do k=0,3
dfl(i,j,k)=fl(i,j,k)-fl(i-1,j,k)
dfr(i,j,k)=fr(i,j,k)-fr(i-1,j,k)
enddo
enddo
do i=-ighost+1,nx+ighost-1
do k=0,3
y=minmod(dfl(i,j,k),dfl(i+1,j,k))
ffl(i,j,k)=fl(i,j,k)+0.5*y
enddo
enddo
do i=-ighost+1,nx+ighost-2
do k=0,3
y=minmod(dfr(i+1,j,k),dfr(i+2,j,k))
ffr(i,j,k)=fr(i+1,j,k)-0.5*y
enddo
enddo
do i=-ighost+1,nx+ighost-2
do k=0,3
ft(i,j,k)=ffl(i,j,k)+ffr(i,j,k)
enddo
enddo
enddo
end
subroutine Solvey(u,gt,nx,ny,ighost,gama)
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real gl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real gr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real dgl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real dgr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ggl(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real ggr(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real gt(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
real minmod
eps=1e-6
do i=-ighost,nx+ighost
do j=-ighost,ny+ighost
p=(gama-1.0)*(u(i,j,3)-0.5*u(i,j,1)**2/u(i,j,0)
& -0.5*u(i,j,2)**2/u(i,j,0))
uu=u(i,j,1)/u(i,j,0)
c=sqrt(gama*p/u(i,j,0))
vv=u(i,j,2)/u(i,j,0)
H=c*c/(gama-1)+0.5*(uu**2+vv**2)
a1=vv
a2=vv-c
a3=vv+c
a1l=0.5*(a1+sqrt(a1*a1+eps*eps))
a2l=0.5*(a2+sqrt(a2*a2+eps*eps))
a3l=0.5*(a3+sqrt(a3*a3+eps*eps))
a1r=0.5*(a1-sqrt(a1*a1+eps*eps))
a2r=0.5*(a2-sqrt(a2*a2+eps*eps))
a3r=0.5*(a3-sqrt(a3*a3+eps*eps))
gl(i,j,0)=u(i,j,0)/2/gama*(2*(gama-1)*a1l+a2l+a3l)
gl(i,j,1)=u(i,j,0)/2/gama*(2*vv*(gama-1)*a1l
& +(vv-c)*a2l+(vv+c)*a3l)
gl(i,j,2)=u(i,j,0)*uu/2/gama*(2*(gama-1)*a1l
& +a2l+a3l)
gl(i,j,3)=u(i,j,0)/2/gama*(2*((gama-1)*H-c*c)*a1l
& +(H-c*vv)*a2l+(H+vv*c)*a3l)
gr(i,j,0)=u(i,j,0)/2/gama*(2*(gama-1)*a1r+a2r+a3r)
gr(i,j,2)=u(i,j,0)/2/gama*(2*vv*(gama-1)*a1r
& +(vv-c)*a2r+(vv+c)*a3r)
gr(i,j,1)=u(i,j,0)*uu/2/gama*(2*(gama-1)*a1r
& +a2r+a3r)
gr(i,j,3)=u(i,j,0)/2/gama*(2*((gama-1)*H-c*c)*a1r
& +(H-c*vv)*a2r+(H+vv*c)*a3r)
enddo
do j=-ighost+1,ny+ighost
do k=0,3
dgl(i,j,k)=gl(i,j,k)-gl(i,j-1,k)
dgr(i,j,k)=gr(i,j,k)-gr(i,j-1,k)
enddo
enddo
do j=-ighost+1,ny+ighost-1
do k=0,3
y=minmod(dgl(i,j,k),dgl(i,j+1,k))
ggl(i,j,k)=gl(i,j,k)+0.5*y
enddo
enddo
do j=-ighost+1,ny+ighost-2
do k=0,3
y=minmod(dgr(i,j+1,k),dgr(i,j+2,k))
ggr(i,j,k)=gr(i,j+1,k)-0.5*y
enddo
enddo
do j=-ighost+1,ny+ighost-2
do k=0,3
gt(i,j,k)=ggl(i,j,k)+ggr(i,j,k)
enddo
enddo
enddo
end
CFL=0.2*min(dx,dy)/dmaxvel
end
subroutine bound(u,nx,ny,ighost)
implicit real (a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
c=1.0/3.0
do k=0,3
do j=-ighost,ny+ighost
do i=-ighost+1,-ighost,-1
u(i,j,k)=c*(4*u(i+1,j,k)-u(i+2,j,k))
enddo
do i=nx+1,nx+ighost
u(i,j,k)=c*(4*u(i-1,j,k)-u(i-2,j,k))
enddo
enddo
do i=-ighost,nx+ighost
do j=-ighost+1,-ighost,-1
u(i,j,k)=c*(4*u(i,j+1,k)-u(i,j+2,k))
enddo
do j=ny+1,ny+ighost
u(i,j,k)=c*(4*u(i,j-1,k)-u(i,j-2,k))
enddo
enddo
end do
do k=0,3
u(-1,nx+1,k)=u(0,nx,k)
u(-2,nx+ighost,k)=u(-1,nx+1,k)
u(-1,-1,k)=u(0,0,k)
u(-2,-2,k)=u(-1,-1,k)
u(nx+1,-1,k)=u(nx,0,k)
u(nx+ighost,-2,k)=u(nx+1,-1,k)
u(nx+1,nx+1,k)=u(nx,nx,k)
u(nx+ighost,nx+ighost,k)=u(nx+1,nx+1,k)
enddo
end
real function minmod(x,y)
implicit real(a-h,o-z)
if(x*y.le.0.) then
minmod = 0.
elseif(abs(x).ge.abs(y)) then
minmod = y
else
minmod = x
endif
return
end
real function CFL(u,dx,dy,nx,ny,ighost,gama)
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
dmaxvel=1e-10
do i=1,nx
do j=1,ny
uu=u(i,j,1)/u(i,j,0)
vv=u(i,j,2)/u(i,j,0)
p=(gama-1)*(u(i,j,3)-0.5*u(i,j,0)*(uu**2+vv**2))
vel=sqrt(gama*p/u(i,j,0))+sqrt(uu**2+vv**2)
if(vel.gt.dmaxvel) dmaxvel=vel
enddo
enddo
subroutine output(u,nx,ny,dx,dy,ighost,gama)
implicit real(a-h,o-z)
real u(-ighost:nx+ighost,-ighost:ny+ighost,0:3)
open(unit=1,file='result.plt')
write(1,*)'TITLE = "EXAMPLE: 3D GEOMETRIES" '
write(1,*)'VARIABLES = "X ", "Y ", "rou" "u" "v" "p" "E"'
write(1,*)'ZONE T="Floor", I=',nx,' J=',ny,' F=POINT '
do i=1,nx
do j=1,ny
rou=u(i,j,0)
uu=u(i,j,1)/rou
vv=u(i,j,2)/rou
p=(gama-1)*(u(i,j,3)-0.5*rou*(uu*uu+vv*vv))
write(1,*) i*dx,j*dy,rou,uu,vv,p,u(i,j,3)
enddo
enddo
close(1)
end
可以和我交流,QQ121493418 |