Page 1 of 1

Square plate version 2

Posted: Fri Mar 07, 2014 8:01 am
by Henko
A second version, where every position of the plate can be toggled on and off as a heat source.
Also a slight mod for pre-OS7 users.

Code: Select all

' Temperature distribution in a thin, square plate.
' The plate is isolated on both sides, heat can only
' escape along the edges. Heat sources warm up the plate
' in one or more points; these points may be toggled on/off by
' tapping somewhere on the plate.
' The strenght of the heat source can be regulated by the slider.
' The other slider sets the thermal conductivity, which is a material
' property. The temperature distribution is shown in colors and in
' numbers.
' The "outside" temperature along the edges is fixed on 0 degrees.
'
graphics ! graphics clear .8,.8,.8
fill color .8,.8,.8 ! draw color 0,0,0
dim to(13,13),q(12,12),in(12,12)
q_in=75 ! labda=0.1 ! cv=1 ! tmax=300 ! in(4,7)=1 ! in(5,3)=1
for i=1 to 11 ! for j=1 to 11
  to(i,j)=20 ! q(i,j)=20*cv
  next j ! next i
for i=0 to 12
  to(0,i)=0 ! to(12,i)=0 ! to(i,0)=0 ! to(i,12)=0
  next i
for i=0 to 10
  t=i/10 ! t_color(t) ! fill circle 85+60*i,750 size 15
  draw text n2a$(i*tmax/10,3,0) at 55+60*i,770
  next i
draw font size 16
slider "heat" value .5 at 70,820 hsize 630
draw text "heat source" at 330,800
draw text "zero" at 70,800 ! draw text "max" at 670,800
slider "cond" value .5 at 70,880 hsize 630
draw text "thermal conductivity" at 285,860
draw text "zero" at 70,860 ! draw text "max" at 670,860
draw color .3,.3,.3
loop:
disp(to)
for i=1 to 11 ! for j=1 to 11
  q(i,j) += labda*(to(i-1,j)+to(i+1,j)+to(i,j-1)+to(i,j+1)-4*to(i,j))
  q(i,j) += q_in*in(i,j)
  next j ! next i
for i=1 to 11 ! for j=1 to 11 ! to(i,j)=q(i,j)/cv ! next j ! next i
if slider_changed("heat") then q_in=150*slider_value("heat")
if slider_changed("cond") then labda=0.25*slider_value("cond")
get touch 0 as xt,yt
if xt>0 and xt>50 and xt<720 and yt>50 and yt<720 then
  x=floor((xt+10)/60) ! y=floor((yt+10)/60) ! in(x,y)=1-in(x,y)
  end if
goto loop
end

def t_color(t)
if t<0 then t=0 ! if t>1 then t=1
if t<0.2 then
  r=0 ! g=0 ! b=5*t
  else
  if t<0.7 then
    r=2*(t-0.2) ! g=0 ! b=2*(0.7-t)
    else
    if t<0.9 then
      r=1 ! g=5*(t-0.7) ! b=0
      else
      r=1 ! g=1 ! b=10*(t-0.9)
      end if
    end if
  end if
fill color r,g,b
end def

def disp (t(,))
graphics lock
for i=1 to 11 ! for j=1 to 11
  x=50+60*(i-1) ! y=50+60*(j-1)
  t_color(t(i,j)/.tmax)! fill rect x,y to x+60,y+60
  draw text floor(t(i,j)) at x+10,y+20
  next j ! next i
for s=50 to 710 step 60 
  draw line 50,s to 710,s ! draw line s,50 to s,710
  next s
graphics unlock
end def

def n2a$(num,lang,dec)
b$="               "
fac=10^dec
num$=floor(fac*num+.5)/fac
tot=lang-len(num$)
if tot<1 then tot=1
a$=substr$(b$,1,tot) & num$
n2a$=a$
end def

Re: Square plate version 2

Posted: Fri Mar 07, 2014 9:37 am
by Mr. Kibernetik
Very advanced version!

I have noticed that if thermal conductivity is 0 then any minimal heat source value increases temperature infinitely. Is this theoretically correct?

Re: Square plate version 2

Posted: Fri Mar 07, 2014 10:13 am
by Henko
Theoretically (in this model) it is correct, the added heat cannot escape. In practice, the material would melt, and if kept together by some means, the liquid would become gaz and end up in a plasma.

A nice simulation of an exploding nuclear device as follows:
1. Start the program
2. Toggle both heat sources OFF ; toggle the centre square ON
3. Set heat source slider to zero, set conductivity slider to max
4. Wait until entire plate is dark ( temperatures near to zero )
5. Set the conductivity slider to zero ; set the heat source slider to max (in that order)
6. Wait until the temperature of the centre square exceeds 50.000 (nuke is building up)
7. Set the heat source slider to zero
8. Set the conductivity slider to max and watch the nuclear explosion :lol:

Re: Square plate version 2

Posted: Fri Mar 07, 2014 11:30 am
by Mr. Kibernetik
Henko wrote:and watch the nuclear explosion :lol:
Yes, I am exploding it since 1st version... :lol: