一维导热

open "a1.dat" for output as #1
ni=22:nim1=ni-1
dim x(ni),sew(ni),dxep(ni),dxpw(ni)
dim ae(ni),aw(ni),ap0(ni),ap1(ni),ap(ni)
dim t0(ni),t1(ni),su(ni),sp(ni),den0(ni),cp0(ni)
dim lam(ni),den1(ni),cp1(ni),p(ni),q(ni)
dx=0.5
x(1)=-dx/2
for i=2 to ni
x(i)=x(i-1)+dx
next
print #1,ni
for i=1 to ni
print #1,using"##.####";x(i)
next
dxpw(1)=0.0
dxep(ni)=0.0
for i=1 to nim1
dxep(i)=x(i+1)-x(i)
dxpw(i+1)=dxep(i)
next 
sew(1)=0.0
sew(ni)=0.0
for i=2 to nim1
sew(i)=0.5*(dxep(i)+dxpw(i))
next
tf=1000:t0=20:lamda0=20:alafa=2320:b=0.0:eps=0.01
densit=7000:cp0=15:dt=1:sel=1 //sel=1时为隐式,sel=2时为显式
for i=2 to nim1
t0(i)=t0
next i
time=0
10 time=time+dt
for i=2 to nim1
lam(i)=lamda0*(1+b*t0(i))
den0(i)=densit
cp0(i)=cp0
den1(i)=densit
cp1(i)=cp0
next i
for i=2 to nim1
ae(i)=2*lam(i)*lam(i+1)/(lam(i)+lam(i+1))/dxep(i)
aw(i)=2*lam(i)*lam(i-1)/(lam(i)+lam(i-1))/dxpw(i)
ap0(i)=den0(i)*cp0(i)/dt*sew(i)
ap1(i)=den1(i)*cp1(i)/dt*sew(i)
su(i)=0
sp(i)=0
next i
i=2
aw(i)=0
t1(1)=t1(2)
t0(i)=t0(2)
i=nim1
ae(i)=alfa
t1(ni)=tf
t0(ni)=tf
if sel=1 then
for i=2 to nim1
ap(i)=ap1(i)+ae(i)+aw(i)-sp(i)*sew(i)
next i
p(2)=ae(2)/ap(2)
q(2)=(aw(2)*tf+ap0(2)*t0(2)+su(2)*sew(2))/ap(2)
for i=3 to nim1
p(i)=ae(i)/(ap(i)-aw(i)*p(i-1))
q(i)=(aw(i)*q(i-1)+ap0(i)*t0(i)+su(i)*sew(i))/(ap(i)-aw(i)*p(i-1))
next i
t1(nim1)=q(nim1)
for i=ni-2 to 2 step -1
t1(i)=p(i)*t1(i+1)+q(i)
next i
end if
if sel=2 then
for i=2 to nim1
ap(i)=ap0(i)-ae(i)-aw(i)+sp(i)*sew(i)
if ap(i)<0 then stop
t1(i)=(ae(i)*t0(i+1)+aw(i)*t0(i-1)+su(i)*sew(i)+ap(i)*t0(i))/ap1(i)
next i
end if
print using"####.##";time,t1(2),t1(nim1)
print #1,time
for i=2 to nim1
print #1,using"####.##";t1(i)
next i
print #1,
for i=2 to nim1
t0(i)=t1(i)
next i
if time<3600 then 10
print time
for i=2 to nim1
print #1,using"####.##";t1(i)
next i
end

二维导热计算

open "a1.dat" for output as #1
open "a2.dat" for output as #2
ni=42:nj=42:nim1=ni-1:njm1=nj-1
dim x(ni),y(nj),sew(ni),sns(nj),dxep(ni),dxpw(ni),dynp(nj),dyps(nj)
dim ae(ni,nj),aw(ni,nj),as1(ni,nj),an(ni,nj),ap(ni,nj)
dim t0(ni,nj),t1(ni,nj),su(ni,nj),sp(ni,nj),lam(ni,nj)
dx1=0.2:dx2=0.3:dx3=0.01:dy1=0.05:dy2=0.05
x(1)=-dx1/2
for i=2 to 10
x(i)=x(i-1)+dx1
next i
for i=11 to 18
x(i)=x(i-1)+dx2
next i
for i=19 to ni
x(i)=x(i-1)+dx3
next i
y(1)=-dy1/2
for j=2 to 5
y(j)=y(j-1)+dy1
next j
for j=6 to nj
y(j)=y(j-1)+dy2
next j
print #1,ni,nj
for i=1 to ni
print using"##.####";x(i)
next i
for j=1 to nj
print #1,using"##.####";y(j)
next j
for i=2 to nim1
dxep(i)=x(i+1)-x(i)
dxpw(i)=x(i)-x(i-1)
next i
for j=2 to njm1
dynp(j)=y(j+1)-y(j)
dyps(j)=y(j)-y(j-1)
next j
for i=2 to nim1
sew(i)=0.5*(dxep(i)+dxpw(i))
next i
for j=2 to njm1
sns(j)=0.5*(dynp(j)+dyps(j))
next j
tf=1000:t0=100
lamda0=20:alfa=200:b=0.1:eps=0.01
niter=0
for i=2 to nim1
for j=2 to njm1
t0(i,j)=t0
next j,i
10 niter=niter+1
for i=2 to nim1
for j=2 to njm1
lam(i,j)=lamda0*(1+b*t0(i,j))
mext j,i
ae(i,j)=2*lam(i,j)*lam(i+1,j)/(lam(i,j)+lam(i+1,j))*sns(j)/dxep(i)
aw(i,j)=2*lam(i,j)*lam(i-1,j)/(lam(i,j)+lam(i-1,j))*sns(j)/dxpw(i)
as1(i,j)=2*lam(i,j)*lam(i,j-1)/(lam(i,j)+lam(i,j-1))*sew(i)/dyps(j)
an(i,j)=2*lam(i,j)*lam(i,j+1)/(lam(i,j)+lam(i,j+1))*sew(i)/dynp(j)
su(i,j)=0
sp(i,j)=0
next j,i
i=2
for j=2 to njm1
su(i,j)=1.0E30*100
sp(i,j)=-1.0E30
next j
i=nim1
for j=2 to njm1
su(i,j)=1.0E30*300
sp(i,j)=-1.0E30
next j
j=2
for i=2 to nim1
as1(i,j)=0
t0(i,1)=t0(i,j)
next i
j=njm1
for i=2 to nim1
an(i,j)=alfa*sew(i)
t0(1,nj)=tf
next i
for i=2 to nim1
for j=2 to njm1
ap(i,j)=ae(i,j)+aw(i,j)+as1(i,j)+an(i,j)-sp(i,j)*sew(i)*sns(j)
t1=ae(i,j)*t0(i+1,j)+aw(i,j)*t0(i-1,j)+as1(i,j)*t0(i,j-1)
t1=t1+an(i,j)*t0(i,j+1)+su(i,j)*sew(i)*sns(j)
t1(i,j)=t1/ap(i,j)
next j,i
num=0
for i=2 to nim1
for j=2 to njm1
if abs(t1(i,j)-t0(i,j))>eps then num=num+1
t0(i,j)=t1(i,j)
next j,i
print suing"###################";niter;num
if num>10 then goto 10
for j=njm1 to 2 step -1
for i=2 to nim1
print using"####.#";t1(i,j)
print #2,using"####.####";y(j),x(i),t1(i,j)
next 
print
next
end
Last modification:February 4th, 2020 at 02:07 pm
如果觉得我的文章对你有用,请随意赞赏