微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 电磁仿真讨论 > dennis m. sullivan fdtd

dennis m. sullivan fdtd

时间:03-25 整理:3721RD 点击:
My friends if you have ready written programs form Sullivan's Book can you upload them here now i have witten in 1D and upload the program by the original name as in the book this is the firts proram from the page 13 of the book please if you have others written lets upload them and make help to each other Thanks

there are some problems in some Codes of Dennis M. Sullivan

I'll say. The problems come from 3D code.

Anyway, 1D code is ok. I also converted C code into Java Applet as following

Code:
/*FDTD1_1.java*/
/*<APPLET CODE="FDTD1_1.class" WIDTH="1024" HEIGHT="700">
</APPLET>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;

public class FDTD1_1 extends Applet implements Runnable,ActionListener
{Thread thread=null;
Graphics g;private Graphics display;private Image image;Button n11=new Button("Start");Button n12=new Button("Stop");

int W=500;int H=500;int n,k,kc;int T,MAX=501;double ex[]=new double[MAX];double hy[]=new double[MAX];
double pulse,spread;double t0;int NSTEPS=1;int mode=0;double PI=3.14159;
public void init(){	Canvas can=new Canvas();	can.setBounds(10,10,W+1,H+1);	add(can);	setLayout(null);	g=can.getGraphics();	can.setBackground(Color.white);		image=createImage(W+1,H+1);	display=image.getGraphics();
	display.setColor(Color.white);	display.fillRect(0,0,W+1,H+1);		display.setColor(Color.black);
	n11.setBounds(W,H/2+10,100,30);	n11.setBackground(Color.yellow);	n12.setBounds(W,H/2+50,100,30);	n12.setBackground(Color.yellow);		this.add(n11);	this.add(n12);
	n11.addActionListener(this);	n12.addActionListener(this);
	initialstate(ex,hy);	
	thread=null;	mode=0;	/*Initialize*/	kc=MAX/2;	/*Center of the prolem space*/	t0=40.0;	/*Center of the incident pulse*/	spread=12;	/*Width of the incident pule*/	T=0;	NSTEPS=1;	n=0;}public void actionPerformed(ActionEvent e){	Object o=e.getSource();	if(o==n11)	{		mode=0;		thread.start();	}	else	{		thread.stop();		//thread=new Thread();		//thread.start();		mode=1;	}
}public void run(){	while(thread!=null)	{		try		{			Thread.sleep(1);		}catch(InterruptedException exc)		{		}		fdtd1_1(ex,hy);		drawWave(ex,100,100);		drawWave(hy,300,100);		
	}}public void initialstate(double Ex[],double Hy[]){	for(k=0;k<MAX;k++)		{			Ex[k]=0.;			Hy[k]=0.;		}}/****************************************************************************/public void fdtd1_1(double Ex[],double Hy[]){	for(n=1;n<=NSTEPS;n++)		{				T=T+1; // T keeps track of the total number of times the main loop is excuted
		/*Main FDTD loop*/
		/*Caculate the Ex field*/			for(k=1;k<MAX;k++)			{				Ex[k]=Ex[k]+.5*(Hy[k-1]-Hy[k]);			}		/*Put a Gaussian pulse in the middle*/			pulse=Math.exp(-.5*Math.pow((t0-T)/spread,2.0));			Ex[kc]=pulse;						for(k=0;k<MAX-1;k++)			{				Hy[k]=Hy[k]+ .5*(Ex[k]-Ex[k+1]);			}		/*End of FDTD loop*/		}
}/****************************************************************************/public void drawWave(double a[],int x,int Amplitude){	display.setColor(Color.white);	display.fillRect(0,0,W+1,H+1);	display.setColor(Color.black);	for(k=1;k<MAX;k++)	{		display.drawLine(k-1,x-(int)(Amplitude*a[k-1]),k,x-(int)(Amplitude*a[k]));	}	g.drawImage(image,0,0,this);}public void start()
    {	if(thread==null)    {		thread=new Thread(this);		//thread.start();    }	
    }/****************************************************************************/
    public void stop()
    {
    		thread=null;	
    }
}
/*<APPLET CODE="FDTD1_1.class" WIDTH="1024" HEIGHT="700">
</APPLET>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;

public class FDTD1_1 extends Applet implements Runnable,ActionListener
{Thread thread=null;
Graphics g;private Graphics display;private Image image;Button n11=new Button("Start");Button n12=new Button("Stop");

int W=500;int H=500;int n,k,kc;int T,MAX=501;double ex[]=new double[MAX];double hy[]=new double[MAX];
double pulse,spread;double t0;int NSTEPS=1;int mode=0;double PI=3.14159;
public void init(){	Canvas can=new Canvas();	can.setBounds(10,10,W+1,H+1);	add(can);	setLayout(null);	g=can.getGraphics();	can.setBackground(Color.white);		image=createImage(W+1,H+1);	display=image.getGraphics();
	display.setColor(Color.white);	display.fillRect(0,0,W+1,H+1);		display.setColor(Color.black);
	n11.setBounds(W,H/2+10,100,30);	n11.setBackground(Color.yellow);	n12.setBounds(W,H/2+50,100,30);	n12.setBackground(Color.yellow);		this.add(n11);	this.add(n12);
	n11.addActionListener(this);	n12.addActionListener(this);
	initialstate(ex,hy);	
	thread=null;	mode=0;	/*Initialize*/	kc=MAX/2;	/*Center of the prolem space*/	t0=40.0;	/*Center of the incident pulse*/	spread=12;	/*Width of the incident pule*/	T=0;	NSTEPS=1;	n=0;}public void actionPerformed(ActionEvent e){	Object o=e.getSource();	if(o==n11)	{		mode=0;		thread.start();	}	else	{		thread.stop();		//thread=new Thread();		//thread.start();		mode=1;	}
}public void run(){	while(thread!=null)	{		try		{			Thread.sleep(1);		}catch(InterruptedException exc)		{		}		fdtd1_1(ex,hy);		drawWave(ex,100,100);		drawWave(hy,300,100);		
	}}public void initialstate(double Ex[],double Hy[]){	for(k=0;k<MAX;k++)		{			Ex[k]=0.;			Hy[k]=0.;		}}/****************************************************************************/public void fdtd1_1(double Ex[],double Hy[]){	for(n=1;n<=NSTEPS;n++)		{				T=T+1; // T keeps track of the total number of times the main loop is excuted
		/*Main FDTD loop*/
		/*Caculate the Ex field*/			for(k=1;k<MAX;k++)			{				Ex[k]=Ex[k]+.5*(Hy[k-1]-Hy[k]);			}		/*Put a Gaussian pulse in the middle*/			pulse=Math.exp(-.5*Math.pow((t0-T)/spread,2.0));			Ex[kc]=pulse;						for(k=0;k<MAX-1;k++)			{				Hy[k]=Hy[k]+ .5*(Ex[k]-Ex[k+1]);			}		/*End of FDTD loop*/		}
}/****************************************************************************/public void drawWave(double a[],int x,int Amplitude){	display.setColor(Color.white);	display.fillRect(0,0,W+1,H+1);	display.setColor(Color.black);	for(k=1;k<MAX;k++)	{		display.drawLine(k-1,x-(int)(Amplitude*a[k-1]),k,x-(int)(Amplitude*a[k]));	}	g.drawImage(image,0,0,this);}public void start()
    {	if(thread==null)    {		thread=new Thread(this);		//thread.start();    }	
    }/****************************************************************************/
    public void stop()
    {
    		thread=null;	
    }
}
I also have FDTD1.2,1.3,1.4,...
I will upload them if anybody really need my java applet code.

cheers,

lqkhai

My frineds this the code from Sullivan's book for 2D PML it wroks correctly it is on page 67 in the Sullivan's book.

Java Applet FDTD code from 1.2 to 1.4.

Good luck

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top