
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class Dielectric extends DielectricGUI {

  double criterion = 1.0e-4;

  void solve(){
    double maxdiff = 1.0;
    int iteration = 0;
    double e1 = 1.0, e2 = 1.0, e3 = 1.0, e4 = 1.0;
    do {
      maxdiff = 0.0;
      for (int n = 1; n <= 20; n++){
        for (int i = 1; i < Nx; i++){
          for (int j =1 ; j < Ny; j++){
            if (State[i][j] > NormalState) continue;
            double oldphi = phi[i][j];
   /* this code checks whether the queried site has dielectric
      and assigns the value of the dielectric constant accordingly   */
            e1 = (State[i][j] == DielectricState) ?  epsilon : 1.0;
            e2 = (State[i+1][j] == DielectricState) ?  epsilon : 1.0;
            e3 = (State[i][j+1] == DielectricState) ?  epsilon : 1.0;
            e4 = (State[i+1][j+1] == DielectricState) ?  epsilon : 1.0;
   /* put something more sensible here:  */
	    double newphi = 33.0;
            phi[i][j] = newphi;
            double delta = Math.abs(newphi-oldphi);
            if (delta > maxdiff) maxdiff = delta;
          }
        }
        iteration++;
    } 
    refreshPicture();
    Legend.write("max. diff : "+maxdiff+ "      "+iteration);
    if (timetostop) break;
    } while ( maxdiff > criterion);
  }

  double Energy(){
     return 0.0;
  }
}

