Square plate version 3 (iPhones & iPads)

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Square plate version 3 (iPhones & iPads)

Post by Henko »

This version also has a selectable mesh size, and runs on all iPhones and iPads.

Code: Select all

' Temperature distribution in a thin, square plate (version 3)
' 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 on the plate.
' The number of rows and columns must be entered upon startup.
' The strength of the heat sources 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.
' programmed by "Henko", march 2014
'
input "Mesh size (minimum=7): ": nb ! nb=max(nb,7) ! nb1=nb+1
graphics ! graphics clear .8,.8,.8
fill color .8,.8,.8 ! draw color 0,0,0
sw=screen_width() ! b=floor((sw-20)/nb) ! st=floor((sw-b*nb)/2)
dim to(nb+2,nb+2),q(nb1,nb1),in(nb1,nb1)
q_in=75 ! labda=0.1 ! cv=1 ! tmax=300 ! in(4,5)=1 ! in(5,3)=1
for i=1 to nb ! for j=1 to nb
  to(i,j)=20 ! q(i,j)=20*cv
  next j ! next i
for i=0 to nb1
  to(0,i)=0 ! to(nb1,i)=0 ! to(i,0)=0 ! to(i,nb1)=0
  next i
rad=(sw-2*st)/52 ! sp=5*rad ! stu=2*st+b*nb
if sw<500 then draw font size 12
for i=0 to 10
  t=i/10 ! t_color(t) ! fill circle st+rad+sp*i,stu+rad size rad
  draw text n2a$(i*tmax/10,3,0) at sp*i,stu+2.5*rad
  next i
if sw<500 then draw font size 12 else draw font size 16
ht=stu+5*rad
slider "heat" value .5 at st,stu+6*rad hsize sw-2*st
draw text "heat source" at sw/2-50,ht
draw text "zero" at st,ht ! draw text "max" at sw-st-40,ht
if sw<500 then fac=13 else fac=10 ! ht=stu+(fac-1)*rad
slider "cond" value .5 at st,stu+fac*rad hsize sw-2*st
draw text "thermal conductivity" at sw/2-80,ht
draw text "zero" at st,ht ! draw text "max" at sw-st-40,ht
draw color .3,.3,.3
loop:
disp(to)
for i=1 to nb ! for j=1 to nb
  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 nb ! for j=1 to nb ! 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>st and xt<sw-st and yt>st and yt<sw-st then
  x=floor((xt-st)/b)+1 ! y=floor((yt-st)/b)+1 ! 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
if .sw<500 then draw font size 10 else draw font size 16
for i=1 to .nb ! for j=1 to .nb
  x=.st+.b*(i-1) ! y=.st+.b*(j-1)
  t_color(t(i,j)/.tmax)! fill rect x,y to x+.b,y+.b
  if .nb<20 then draw text int(t(i,j)) at x+.b/5,y+.b/4
  next j ! next i
slen=.st+.nb*.b
for s=.st to slen step .b
  draw line .st,s to slen,s ! draw line s,.st to s,slen
  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

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Square plate version 3 (iPhones & iPads)

Post by Mr. Kibernetik »

Yes, grid size setting is very handy!

I have some comments:
1) Maybe is will be better to remove default heaters, because now it is possible to set it easily by hand, and because with different grid size their current position may be not the best.
2) When performing heat explosions, I have noticed that heat distributions is not smooth. Please look at heat distribution on this screenshot:
фотография.jpg
фотография.jpg (219.58 KiB) Viewed 2426 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Square plate version 3 (iPhones & iPads)

Post by Mr. Kibernetik »

Also I would suggest to add "reset" button to clear all heat sources, to add switch to turn on/off text numbers.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Square plate version 3 (iPhones & iPads)

Post by Henko »

1. The current default heatspots are within the minimum meshsize, so they are always correct. But of course they can be removed, or replaced by only one heatspot in the centre of the chosen mesh size.
2. I already noticed, that the iteration starts oscillating when slider settings change too sudden. The solution is to move the sliders a little more slowly. Another common solution is to use a relaxation (slowing down) factor in the iteration proces; I will try that and see if the simulation does not become too slow.
3. A switch for switching of the numbers is a nice suggestion. I will do that if there is enough space on the lower iPhone models.

Thanks for your comments, version 4 coming up soon.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Square plate version 3 (iPhones & iPads)

Post by Mr. Kibernetik »

More ideas:
I think that if "reset" will be available then default heaters are fine!
Sliders can be shortened to get extra space.

Post Reply