Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

C Codes of Dennis M. Sullivan

Status
Not open for further replies.

Sadabat

Member level 3
Joined
Dec 21, 2005
Messages
65
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,832
dennis m. sullivan fdtd

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
 

appcad

Newbie level 6
Joined
Apr 11, 2005
Messages
13
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,355
dennis m sullivan

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

    Sadabat

    points: 2
    Helpful Answer Positive Rating

lqkhai

Junior Member level 3
Joined
Mar 7, 2006
Messages
31
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,478
java applet fdtd

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
 

    Sadabat

    points: 2
    Helpful Answer Positive Rating

Sadabat

Member level 3
Joined
Dec 21, 2005
Messages
65
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,832
dennis sullivan code

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.
 

lqkhai

Junior Member level 3
Joined
Mar 7, 2006
Messages
31
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,478
dennis sullivan c programs book

Java Applet FDTD code from 1.2 to 1.4.

Good luck
 

    Sadabat

    points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top