/* beam splitter fdtd 2D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2003.03.26 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class beamSplitter extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice cm1; Button bt_reset, bt_start, bt_stop; Scrollbar scr,sl1,sgp; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 50; double scrVar = 15.0; int dispMode = 0; int gap = 8; int started = 1; int dgX, dgY, dgXb,dgYb; double scale = 2.0; int cx = (int)(100.0/scale); int cy = (int)(100.0/scale); int cz = (int)(100.0/scale); double viewTheta = -15.0*3.14/180.0; double viewFai = -72.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double cosTh = Math.cos(viewTheta); double sinTh = Math.sin(viewTheta); double cosFi = Math.cos(viewFai); double sinFi = Math.sin(viewFai); double t = 0.0; double dt = 1.0; int NNx = 241; int NNy = 201; double Ez[][] = new double[NNx+1][NNy+1]; double Hx[][] = new double[NNx+1][NNy+1]; double Hy[][] = new double[NNx+1][NNy+1]; int material[][] = new int[NNx+1][NNy+1]; double nIndex = 2.0; double eps = nIndex*nIndex; double reg = 30.0; double sgm = 1.0/reg; double omega = Math.PI/16.0; double theta = 0.0; double omega2 = Math.PI/16.0; double theta2 = 0.0; int dispWidth = 500; int dispHeight = 250; int NN = 241+2; int xpts[] = new int[NN]; int ypts[] = new int[NN]; int pmat[] = new int[NN]; /* ----------------------------- applet control ------ */ public void init() { resize(dispWidth+100,dispHeight); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); bt_reset= new Button("reset"); add(bt_reset); bt_reset.addActionListener(this); bt_start= new Button("start"); add(bt_start); bt_start.addActionListener(this); bt_stop = new Button("stop"); add(bt_stop); bt_stop.addActionListener(this); addMouseListener(this); addMouseMotionListener(this); sl1= new Scrollbar(Scrollbar.HORIZONTAL,16,10,8,110); add(new Label("lambda=")); add(sl1); sl1.addAdjustmentListener(this); sgp= new Scrollbar(Scrollbar.HORIZONTAL,8,10,0,34); add(new Label("gap=")); add(sgp); sgp.addAdjustmentListener(this); scr= new Scrollbar(Scrollbar.HORIZONTAL,15,10,0,110); add(new Label("height=")); add(scr); scr.addAdjustmentListener(this); cm1 = new Choice(); cm1.addItem("Ez wave"); cm1.addItem("Hxy line"); add(new Label("view=")); add(cm1); cm1.addItemListener(this); setInitialCondition(); repaint(); } public void start() { if (th == null) { th = new Thread(this); th.start(); } } public void stop() { if (th != null) { th.stop(); th = null; } } public void itemStateChanged(ItemEvent ev){ if (ev.getSource() == cm1){ dispMode = cm1.getSelectedIndex(); repaint(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ started = 0; setInitialCondition(); offPaint(); repaint(); } else if(ev.getSource() == bt_start){ if (started==0) { started = 1; } else if (started==1) { theta = 0.0; } offPaint(); repaint(); } else if(ev.getSource() == bt_stop){ started = 0; } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sl1) { omega = Math.PI/((double)sl1.getValue()); repaint(); } else if(ev.getSource() == sgp) { gap = sgp.getValue(); setMaterial(); repaint(); } else if(ev.getSource() == scr) { scrVar = 1.0*(double)(scr.getValue()); repaint(); } } public void mousePressed(MouseEvent ev){ } public void mouseReleased(MouseEvent ev){ dgXb = 0; dgYb = 0; dgX = 0; dgY = 0; } public void mouseClicked(MouseEvent ev){ } public void mouseEntered(MouseEvent ev){ } public void mouseExited (MouseEvent ev){ } public void mouseMoved (MouseEvent ev){ } public void mouseDragged(MouseEvent ev){ dgXb = dgX; dgYb = dgY; dgX=ev.getX(); dgY=ev.getY(); if (dgXb==0 && dgYb==0) { dgXb = dgX; dgYb = dgY; } viewTheta += 0.5*3.14/180.0*(dgX-dgXb); viewFai += 0.5*3.14/180.0*(dgY-dgYb); cosTh = Math.cos(viewTheta); sinTh = Math.sin(viewTheta); cosFi = Math.cos(viewFai); sinFi = Math.sin(viewFai); } public void run() { while (th != null) { try { timeEvolution(); offPaint(); repaint(); Thread.sleep(sleepTime); } catch (InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(imgOff,0,0,this); } /* ----------------------------- offPaint -------------------- */ void offPaint() { int i,j; double z,px,py,pz; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); if (dispMode==0) { for(j=0; jj) { material[i+ix][j+iy] = 1; } } } } void fdtd2D() { t = t + 0.5*dt; EzEvolution(); EzGenerator(); HxyEvolution(); } void EzGenerator() { int j; double Ezt; theta += omega*0.5*dt; Ezt = Math.sin(theta); if (theta<3.1416*2.0) { for(j=0;j