import java.awt.*; import java.applet.*; // copyright, M Paez, 1999, U of Antioquia, r Landau OSU public class Twobars extends Applet implements Runnable { Thread runstring; private Image offScreenImage; double mxx,bxx,myy,byy; int jj; public void start() { if(runstring==null); { runstring=new Thread(this); runstring.start(); } } public void stop() { if(runstring != null){ runstring.stop(); runstring=null; } } public void run() { while(true){ repaint(); try{ Thread.sleep(350); } catch(InterruptedException e){ } } } public void update(Graphics g) { //To avoid flicker Graphics offScreenGraphics=offScreenImage.getGraphics(); offScreenGraphics.setColor(getBackground()); offScreenGraphics.fillRect(0,0,size().width,size().height); offScreenGraphics.setColor(g.getColor()); paint(offScreenGraphics); g.drawImage(offScreenImage,0,0,this); } void coormundo(double xiz,double ysu,double xde,double yinf) { double maxx,maxy,xxfin,xxcom,yyin,yysu; maxx=600; maxy=450; xxcom=maxx/12.0; xxfin=11.0*maxx/12.0; yyin=0.8*maxy; yysu=0.2*maxy; mxx=(xxfin-xxcom)/(xde-xiz); bxx=0.5*(xxcom+xxfin-mxx*(xiz+xde)); myy=(yyin-yysu)/(yinf-ysu); byy=0.5*(yysu+yyin-myy*(yinf+ysu)); } void ejes(double xmz,double yms,double xmd,double ymi,Graphics g) { //Grafica los ejes // La entrada esta en coordenadas 0.0 a 1.0 int i,mp,xpi,xpd,yps,ypi,xdiv,ydiv,ypcen; double yincr,xincr,yte; //char nhorz[3],nver[15]; char nver; int sig=4; ydiv=1; xpi=(int)(mxx*xmz+bxx); xpd=(int)(mxx*xmd+bxx); yps=(int)(myy*yms+byy); ypi=(int)(myy*ymi+byy); ypcen=(int)byy; g.drawLine(xpi,ypcen-30,xpd,ypcen-30); g.drawLine(xpi,yps-30,xpi,ypi-30); yincr=(ymi-yms)/5.0; xincr=(xmd-xmz)/8.0; //rayas y marcas en eje vertical for (i=0;i<6;i++){ ydiv=(int)(myy*(yms+yincr*i)+byy-30); g.drawLine(xpi-10,ydiv,xpi,ydiv); yte=yms+yincr*i; if(Math.abs(yte)<0.01)yte=0.0; g.drawString(Double.toString(yte),xpi,ydiv-5); g.drawString("Temperature",xpi,yps-50); } } public void Twobarsplot(Graphics g, int jj) { double ro,sph,diffk,cons,dx,dt,el,xx; double thk,divi,u[][]; int j,ngrid; int nmaxi,k,i,il,km,ii; int peo,peyo,pex,peye,tone; ngrid=101; u=new double[101][2]; /* specific heat, thermal conductivity and density for iron next three comments. */ sph=0.217; thk=0.49; ro=2.7; diffk=thk/(sph*ro); el=50.0; if(jj==1){ coormundo(0,120.0,100.0,0.0); } /*the bar is divided in 100 parts (divi) */ divi=100.0; cons=0.1; dx=el/divi; dt=cons*dx*dx/diffk ; /* At t=0 ( j=0) all points are at 100 C */ for(i=0;i=50)u[i][0]=100.0; if(i<50)u[i][0]=50.0; } /* in i=0 and i=100 (ends) U=0 for all times*/ for(j=0;j<2;j++){ u[0][j]=0.0; u[ngrid-1][j]=0.0; } /*solves numerically the heat partial differential equation el,ro,sph,thk,diffk,cons,dx,dt */ /* loop over time */ for(k=1;k0){ tone=(int)(2.55*u[i][1]); Color redi=new Color(tone,0,0); g.setColor(redi); peo=(int)(mxx*(i-1)+bxx); peyo=(int)(myy*u[i-1][1]+byy-30); pex=(int)(mxx*i+bxx); peye=(int)(myy*u[i][1]+byy-30); g.drawLine(peo,peyo,pex,peye); } } //for i } /*recycle, new values are now old. */ for(i=0;i