/*
* Solves the Schroedinger equation for a wavepacket inside
* a square-well.
* Observe how the dymanical development of the wavefunction
* displays the several square-well energy components of the wave.
* Sqwell.html:
* by C.A. Bertulani, 08/15/2000
*/
import java.awt.*;
import java.applet.*;
public class HeatDiff extends Applet implements Runnable {
Thread runstring;
private Image offScreenImage;
int ixmesh0, ixmeshN;
double y0, yN;
double Stretchxx,Coefxx,Stretchyy,Coefyy,pi,k0,dx;
double ro,sph,diffk,cons,dt,el,xx;
double thk,divi,u[][];
int AppletHeight, AppletWidth;
// Labels in applet
String graphLabel1 = "Two bars with different temperatures in contact";
String graphLabel2 = "(watch and see evolution of heat diffusion)";
// Font for caption
Font smallArialFont = new Font("Arial", Font.PLAIN, 15);
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();
//Erase the previous image
Dimension d = size();
offScreenGraphics.setColor(getBackground());
offScreenGraphics.fillRect(0,0,AppletWidth,AppletHeight);
offScreenGraphics.setColor(g.getColor());
//Paint the frame into the image
paint(offScreenGraphics);
g.drawImage(offScreenImage,0,0,this);
}
private int pixx(int ivalue) {
// Given the index of the mesh-xpoint return the pixel equivalent
int jvalue = (int)(Stretchxx*ivalue + Coefxx);
return jvalue;
}
private int pixy(double yvalue) {
// Given the y-value in desired scale, return the pixel equivalent
int jvalue = (int)(Stretchyy*yvalue + Coefyy);
return jvalue;
}
void CoordUndo(double ixmesh0,double ixmeshN,double y0,double yN)
{ // changes x-mesh-indexing and y-coordinate definition into
// java applet coordinate system of pixels
double W = AppletWidth;
double H = AppletHeight;
// put graph within a margin from applet window
double margin = 0.2; // percent used in margin
double xxmax = (1.0-margin)*W; // right x-pixel-limit
double xxmin = margin*W; // left x-pixel-limit
double yymin = (1.0-margin)*H; // upper y-pixel-limit
double yymax = margin*H; // lower y-pixel-limit
// fit data within graph axis
// first transform mesh indices into x-window-pixel coordinates
Stretchxx = (xxmax-xxmin)/(ixmeshN-ixmesh0);
Coefxx = (xxmin*ixmeshN-xxmax*ixmesh0)/(ixmeshN-ixmesh0);
// now transform graph y-values to y-window-pixel coordinates
Stretchyy = (yymax-yymin)/(yN-y0);
Coefyy = (yymin*yN-yymax*y0)/(yN-y0);
}
void axisg(int ix1,int ix2,double y1,double y2,Graphics g)
{
// Plot the axis with desired cordinates
int xpix1,xpix2,ypix1,ypix2;
xpix1 = pixx(ix1);
xpix2 = pixx(ix2);
ypix1 = pixy(y1);
ypix2 = pixy(y2);
int dtick = AppletHeight/50;
g.drawLine(xpix1,ypix1,xpix2,ypix1);
g.drawLine(xpix1,ypix1,xpix1,ypix2);
double yincr = (y1-y2)/5.0;
// ticks, marks and label in vertical axis
for (int i=0; i<6; i++){
int tick = pixy(y2+yincr*i);
g.drawLine(xpix1-dtick,tick,xpix1,tick);
double ytick = y2+yincr*i;
if(Math.abs(ytick)<0.01)ytick=0.0;
g.drawString(Double.toString(ytick),xpix1-5*dtick,tick);
g.drawString("Temperature in C",xpix1-5*dtick,ypix2-3*dtick);
}
}
public void HeatDiffplot(Graphics g, int jj)
{
int j;
int nmaxi,k,i,il,km,ii;
int pixx1,pixx2,pixy1,pixy2,tone;
// At t=0 ( j=0) all points are at 100 C
for(i=0;i=ixmeshN/2)u[i][0]=yN;
if(i0){
tone=(int)(2.55*u[i][1]);
Color redi=new Color(tone,0,0);
g.setColor(redi);
// transform coordinates to pixel coordinates
pixx1=pixx(i-1);
pixx2=pixx(i);
pixy1=pixy(u[i-1][1]);
pixy2=pixy(u[i][1]);
g.drawLine(pixx1,pixy1,pixx2,pixy2); // plot it
}
} //for i
}
// recycle, new values are now old.
for(i=0;i