/*
 * @(#)Graph.java	1.9 99/08/04
 * MODIFS PYL juillet Aout 2005!!!!!!!!!!
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */
//javac guiChal.java Kul.java ;java guiChal  
//javac guiChal.java Kul.java; open index.html       


import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

 
 
 
class Kul extends Thread    
 {
 public double t;
 private double dt=0;
 public double dx,dy;
 public double T[][];
 public double To[][];
 public double Ti[][];
 public double T0=0;
 public double T1=0;
 public double Ts=0;
 public double q=0;
 public double Bi=0;
  public double omega,relax,alpha,beta;
 public int n;
 public int cours=0;
// public tridiag tridiagC;
 boolean pleaseWait = true;
 
private int property;
public int getProperty  (         ){ return property; }
public void setProperty (int value){ property = value; }
public void setdt (double value){ dt = value;System.out.println("------------>>>dt"+dt); }
public double getdt  (         ){/*System.out.println("-------------<<<dt"+dt);*/return dt; }

public void Kul( )
 {    
 }
 
 public void cl00( )
 {    
 T0=0;
 T1=0;
 Ts=0;
 q=0; 
 }

 
 public void prems()
 { int i,j;
    //pleaseWait = true;
    t=0;
	n=50;
	dx=1./n;
	dy=1./n;
	omega=0;
   System.out.println(" initialize "+dx); 
   To = new double[n+1][n+1];
   T  = new double[n+1][n+1];
   Ti = new double[n+1][n+1];
   for(i=0;i<=n;i++){
      for(j=0;j<=n;j++)
		{To[i][j]=0;T[i][j]=To[i][j];Ti[i][j]=To[i][j];}}
    for(i=0;i<=n;i++){T[i][0]=1;}
	
	alpha=dy*dy/(2*(dx*dx+dy*dy));
	beta=dx*dx/(2*(dx*dx+dy*dy));
 
    }
 
   public void run() {
   int i,j,it=0;
   double phase=0,relax=1.5,Tij;
   System.out.println("params " + beta + " " + alpha+ " "+ dx +" dt/dx^2="+(dt/dx/dx));
	
	while (!interrupted()) {
	//System.out.println(pleaseWait);
	    
		if(dt>0){
		phase=phase+omega*dt;
		t=0; 
   for(i=1;i<n;i++){
      for(j=1;j<n;j++)
		{ //GAUSS SIEDEL
		Tij=(1-relax)*T[i][j] + 
		  relax*(alpha*(T[i+1][j]+T[i-1][j])+beta*(T[i][j+1]+T[i][j-1]));
		 t=t+(T[i][j]-Tij)*(T[i][j]-Tij); 
		 T[i][j]=Tij; 
		  }} 
		  t=t*10000;
		  // System.out.println(t);
		  
		
		 				}
		
		try {
		Thread.sleep(1);
	    } catch (InterruptedException e) {}
				// Do work
                // Check if should wait
                synchronized (this) {
                    while (pleaseWait) {
                        try {
                            wait();
                        } catch (Exception e) {}
                    }
                }
    }
                // Do work http://javaalmanac.com/egs/java.lang/PauseThread.html?l=rel
}
		
 }