FDTD电磁波算法的一些问题_电磁波2dfdtd代码-程序员宅基地

/* FDTD-1D-2.2.c  1D FDTD simulation of a lossy dielectric medium  */
/* Simulation of a sinusoidal wave or a Gauss pulse transmiting in a lossy dielectric medium exsiting in free space */ 

/*8888888888888  Using a new formulation and using flux density  8888888888888*/

/*    The Fourier Transform has been added        */

/*    1D FDTD simulation of a frequency dependent material    */

# include <math.h>
# include <stdlib.h>
# include <stdio.h>
# define KE 200         /* KE is the number of cells to be used   */
# define NF 10          /* NF is the number of the frequence in fourier transform */
# define Pi 3.1415926
void main ()
{
   
	double ex_low_m1, ex_low_m2,ex_high_m1,ex_high_m2;
	
	double dx[KE],ix[KE],ex[KE],hy[KE],sx[KE];
	double ga[KE],gb[KE],gc[KE];

	int n, m,k, kc,NSTEPS;
	int kstart_dielectric;                                        /* 介质的左边界*/
	int kend_dielectric;                                          /* 介质的右边界*/ 
	double T;
	double t0, spread,pulse, pulse1, freq_in,  pulse2;        /*pulse1 is Gauss pulse, Pulse2 is a sinusoidal wave */
	double epsilon_r,epsilon_0;                                    /* 介质的相对介电常数 和 真空介电常数*/   

	double sigma;                                                  /* 介质的电导率 */
    double ddx, dt;                                                /* The FDTD Cell size and the time interval */
    
	double freq[NF], arg[NF], ampn[NF][KE],phasen[NF][KE];
	double real_part[NF][KE], imag_part[NF][KE]; 
	double real_in[NF], imag_in[NF], amp_in[NF], phase_in[NF];
	double mag[KE] ;
	double tau, chil, del_exp;


	FILE *fp ;


	
	/* Initialize  */
	
	ddx=0.01;                                      /* Set the cell size to 1cm */ 
    dt=ddx/(2*3e8) ;                               /* calculate the time step */
    epsilon_0=8.85419e-12;
    
	
	
     
	kc=5;           /* 激励源所引入的位置 */
    t0= 50.0;          /* Center of the incident pulse */
	spread=10.0;         /* Width of the incident pulse  */
	T=0;
	NSTEPS=1;

	ex_low_m1=0;       /* 在n+1时存储左边界处前一个格点ex[1] 结果 */
	ex_low_m2=0;       /* 在n+2时存储左边界处前一个格点ex[1] 结果 */
	ex_high_m1=0;      /* 在n+1时存储右边界处前一个格点ex[KE-2] 结果 */
	ex_high_m2=0;      /* 在n+2时存储右边界处前一个格点ex[KE-2] 结果 */
	
	
	
	
	for (k=0; k<KE; k++)
	{    ga[k]=1.0;                               /* initialize to free space */
		 gb[k]=0.;
		 gc[k]=0;                                 /* initialize to free space */
		 ex[k]=0.;
	     hy[k]=0.; 
		 dx[k]=0.;
		 ix[k]=0;
		 sx[k]=0;
		 mag[k]=0;
	

        for (m=0;m<=2;m++)
		{  real_part[m][k]=0.;           /* Real and imaginary parts of fourier transform */
	       imag_part[m][k]=0.;
	       ampn[m][k]=0.;                /* Amplituds and phase of the fourier transform */
	       phasen[m][k]=0.;
	   }
	}

	for (m=0;m<=2;m++)
	{   real_in[m]=0.;             /* Fourier Trans. of input pulse */
	    imag_in[m]=0.;
	}

/* Parameters for the Fourier Transform  */
	
	freq[0]=50.e6;
	freq[1]=200.e6;
	freq[2]=500.e6;

	
    for (m=0;m<=2;m++)
	{    arg[m]=2*Pi*freq[m]*dt;
	printf("%2d %6.2f MHz %7.5f \n ", m, freq[m]*1e-6,arg[m]);
	}

    
	/* These parameters specify the input pulse */
//	 printf("input frequence (MHz) -->");
//     scanf("%lf", &freq_in);
//     freq_in=freq_in*1e6;
//	 printf("%8.0f \n",freq_in);

	printf("Dielectric start at  kstart_dielectric -->");
     scanf("%d", &kstart_dielectric);

	 printf("Dielectric end at  kend_dielectric -->");
     scanf("%d", &kend_dielectric);

     printf("Epsilon_r -->");
     scanf("%lf", &epsilon_r);  
	 
	 printf("Conductivity -->");
     scanf("%lf", &sigma);

	 printf("chil----->");
	 scanf("%lf", &chil);

     

	 tau=1000.;                   /* Make sure tau is >0.    */
     if (chil>0.0001)
	 {printf("tau (in microseconds)--->"); scanf("%lf",&tau); del_exp=exp(-dt/tau);}
	 
	
    printf ("%d %d %f  %f %f %f \n", kstart_dielectric,kend_dielectric,epsilon_r, sigma,tau,chil);
     tau=1.e-6*tau;
	 
	  printf("del_exp= %f \n",del_exp) ;         


     for (k=kstart_dielectric; k<=kend_dielectric;k++)
	 {   ga[k]=1/(epsilon_r+sigma*dt/epsilon_0+chil*dt/tau);
		 gb[k]=sigma*dt/epsilon_0;               /* initialize to dielectric medium */
		 gc[k]=chil*dt/tau;
	 }
     
	 for (k=0;k<KE;k++)
	 { printf("%2d %4.2f %4.2f \n",k,ga[k],gb[k]); }
	
	
	 
	 /* Main part of program */
	 
	 while (NSTEPS>0) 
	{	printf("NSTEPS -->");     /* NSTEPS is the number of times that the Main loop has executed */
		scanf("%d", &NSTEPS);  
		printf ("%d \n", NSTEPS);
	
 printf("程序正在运行,请稍侯! \n");
   
 for (n=1; n<=NSTEPS; n++)
	{
		T=T+1;                   /* T keeps track of the total number of times the main loop is executed */

	/* Main FDTD Loop  */

		/* Calculate the Dx field   */

		for (k=1; k<KE; k++)
		{ dx[k]=dx[k]+ 0.5*(hy[k-1]-hy[k]); }


		/* Put a sinusoidal wave or the Gauss pulse at the cell kc */

	    pulse1=exp(-0.5*(pow((t0-T)/spread,2.0)));
//		pulse2=sin(2*Pi*freq_in*dt*T);
		
		pulse=pulse1;                                            /* 脉冲的类型由pulse1和pulse2两个变量来选择 */
		
		dx[kc]=dx[kc]+pulse;
		printf("%5.1f %f %6.2f \n", T,pulse,dx[kc]);
        
     /* Calculate the Ex from the Dx */
	
		for (k=0;k<KE;k++)
		{     ex[k]=ga[k]*(dx[k]-ix[k]-sx[k]);
		      ix[k]=ix[k]+gb[k]*ex[k];
			  sx[k]=del_exp*sx[k]+gc[k]*ex[k];
		}
		
		/* Calculate the fourier trasform of Ex */

		for (k=0;k<KE;k++)
		{   for (m=0;m<=2;m++)
			{   real_part[m][k]=real_part[m][k]+cos(arg[m]*T)*ex[k];
			    imag_part[m][k]=imag_part[m][k]-sin(arg[m]*T)*ex[k];
			}
		}

		/* Fourier Transform of the input pulse */
		if (T<100)
		{
		      for (m=0;m<=2;m++)
			  {   real_in[m]=real_in[m]+cos(arg[m]*T)*ex[10];
			      imag_in[m]=imag_in[m]-sin(arg[m]*T)*ex[10];
			  }
		}
		      
		
		/* Absorbing boundary conditions */

		ex[0]=ex_low_m2;
		ex_low_m2=ex_low_m1;
		ex_low_m1=ex[1];


		ex[KE-1]=ex_high_m2;
		ex_high_m2=ex_high_m1;
		ex_high_m1=ex[KE-2];               
		


		/* Calculate the hy field */
		for (k=0; k<KE-1;k++)
		{ hy[k]=hy[k]+0.5*(ex[k]-ex[k+1]); }		
	}
	/* End of the Main FDTD Loop */
	    
	    /* At the end of the calculation, print out the Ex and Hy field */
	    for (k=0; k<KE; k++)
		{    printf("%3d %6.2f %6.2f \n", k, ex[k], hy[k]);
		}
        

		/* Write the E field out to a file "Ex"  */

		fp=fopen("Ex.txt","w");
		fprintf(fp, "T=%5.0f \n", T); 
		for (k=0;k<KE;k++)
		{  
			fprintf (fp," %5d %6.2f %6.2f \n", k,dx[k],ex[k]);
		}

		fclose(fp);


		/* Write the H field out to a file "Hy" */
		fp=fopen("Hy.txt","w");
		
		 fprintf(fp, "T=%5.0f \n", T); 
		for (k=0;k<KE;k++)
		{  
			fprintf (fp,"%5d  %6.2f \n",k, hy[k]);
		}

		fclose(fp);

        printf(" %5.0f \n", T);
        
		/* calculate the amplitude and phase of each frequency */

		/* Amplitude and the phase of the input pulse */

		for (m=0; m<=2;m++)
		{   amp_in[m]=sqrt(pow(imag_in[m],2.0)+pow(real_in[m],2.0));
		    phase_in[m]=atan2(imag_in[m],real_in[m]);
			printf("%d Input pulse: %8.4f %8.4f %8.4f %7.2f \n", m,real_in[m],imag_in[m],amp_in[m],(180.0/Pi)*phase_in[m]);
			for(k=0;k<KE;k++)
			{   ampn[m][k]=(1.0/amp_in[m]*sqrt(pow(real_part[m][k],2.0)+pow(imag_part[m][k],2.0)));
			    phasen[m][k]=atan2(imag_part[m][k],real_part[m][k])-phase_in[m];
			}
		}
			/* write the amplitude field out to a files "amp "  */
			fp=fopen ("amp0.txt","w");
			for (k=0;k<KE;k++)
			{ fprintf(fp,"%d %8.5f \n ", k,ampn[0][k] ); }
			fclose(fp);
			fp=fopen ("amp1.txt","w");
			for (k=0;k<KE;k++)
			{ fprintf(fp,"%d %8.5f \n ", k,ampn[1][k] ); }
			fclose(fp);
			fp=fopen ("amp2.txt","w");
			for (k=0;k<KE;k++)
			{ fprintf(fp,"%d %8.5f \n ", k,ampn[2][k] ); }
			fclose(fp);
		

		 

}
printf("程序运行完毕 \n");
}




运行之后出现如下错误

root@gallup-virtual-machine:/home/source# gcc -Wall  li.c -o li 

li.c:7:6: 警告: ‘main’的返回类型不是‘int’ [-Wmain]
li.c: 在函数‘main’中:
li.c:28:9: 警告: 变量‘mag’被设定但未被使用 [-Wunused-but-set-variable]
li.c:25:41: 警告: 变量‘phasen’被设定但未被使用 [-Wunused-but-set-variable]
li.c:19:45: 警告: 未使用的变量‘pulse2’ [-Wunused-variable]
li.c:19:35: 警告: 未使用的变量‘freq_in’ [-Wunused-variable]
/tmp/ccwrACyT.o: In function `main':
li.c:(.text+0x3fb): undefined reference to `exp'
li.c:(.text+0x6a3): undefined reference to `exp'
li.c:(.text+0x860): undefined reference to `cos'
li.c:(.text+0x8cb): undefined reference to `sin'
li.c:(.text+0x986): undefined reference to `cos'
li.c:(.text+0x9d0): undefined reference to `sin'
li.c:(.text+0xcfe): undefined reference to `sqrt'
li.c:(.text+0xd3a): undefined reference to `atan2'
li.c:(.text+0xe1e): undefined reference to `sqrt'
li.c:(.text+0xe7e): undefined reference to `atan2'
collect2: ld 返回 1

root@gallup-virtual-machine:/home/source# 

解决方法:

1、 root@gallup-virtual-machine:/home/source# gcc   li.c  -lm -o li 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/liugallup/article/details/8890931

智能推荐

使用nginx解决浏览器跨域问题_nginx不停的xhr-程序员宅基地

文章浏览阅读1k次。通过使用ajax方法跨域请求是浏览器所不允许的,浏览器出于安全考虑是禁止的。警告信息如下:不过jQuery对跨域问题也有解决方案,使用jsonp的方式解决,方法如下:$.ajax({ async:false, url: 'http://www.mysite.com/demo.do', // 跨域URL ty..._nginx不停的xhr

在 Oracle 中配置 extproc 以访问 ST_Geometry-程序员宅基地

文章浏览阅读2k次。关于在 Oracle 中配置 extproc 以访问 ST_Geometry,也就是我们所说的 使用空间SQL 的方法,官方文档链接如下。http://desktop.arcgis.com/zh-cn/arcmap/latest/manage-data/gdbs-in-oracle/configure-oracle-extproc.htm其实简单总结一下,主要就分为以下几个步骤。..._extproc

Linux C++ gbk转为utf-8_linux c++ gbk->utf8-程序员宅基地

文章浏览阅读1.5w次。linux下没有上面的两个函数,需要使用函数 mbstowcs和wcstombsmbstowcs将多字节编码转换为宽字节编码wcstombs将宽字节编码转换为多字节编码这两个函数,转换过程中受到系统编码类型的影响,需要通过设置来设定转换前和转换后的编码类型。通过函数setlocale进行系统编码的设置。linux下输入命名locale -a查看系统支持的编码_linux c++ gbk->utf8

IMP-00009: 导出文件异常结束-程序员宅基地

文章浏览阅读750次。今天准备从生产库向测试库进行数据导入,结果在imp导入的时候遇到“ IMP-00009:导出文件异常结束” 错误,google一下,发现可能有如下原因导致imp的数据太大,没有写buffer和commit两个数据库字符集不同从低版本exp的dmp文件,向高版本imp导出的dmp文件出错传输dmp文件时,文件损坏解决办法:imp时指定..._imp-00009导出文件异常结束

python程序员需要深入掌握的技能_Python用数据说明程序员需要掌握的技能-程序员宅基地

文章浏览阅读143次。当下是一个大数据的时代,各个行业都离不开数据的支持。因此,网络爬虫就应运而生。网络爬虫当下最为火热的是Python,Python开发爬虫相对简单,而且功能库相当完善,力压众多开发语言。本次教程我们爬取前程无忧的招聘信息来分析Python程序员需要掌握那些编程技术。首先在谷歌浏览器打开前程无忧的首页,按F12打开浏览器的开发者工具。浏览器开发者工具是用于捕捉网站的请求信息,通过分析请求信息可以了解请..._初级python程序员能力要求

Spring @Service生成bean名称的规则(当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致)_@service beanname-程序员宅基地

文章浏览阅读7.6k次,点赞2次,收藏6次。@Service标注的bean,类名:ABDemoService查看源码后发现,原来是经过一个特殊处理:当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致public class AnnotationBeanNameGenerator implements BeanNameGenerator { private static final String C..._@service beanname

随便推点

二叉树的各种创建方法_二叉树的建立-程序员宅基地

文章浏览阅读6.9w次,点赞73次,收藏463次。1.前序创建#include&lt;stdio.h&gt;#include&lt;string.h&gt;#include&lt;stdlib.h&gt;#include&lt;malloc.h&gt;#include&lt;iostream&gt;#include&lt;stack&gt;#include&lt;queue&gt;using namespace std;typed_二叉树的建立

解决asp.net导出excel时中文文件名乱码_asp.net utf8 导出中文字符乱码-程序员宅基地

文章浏览阅读7.1k次。在Asp.net上使用Excel导出功能,如果文件名出现中文,便会以乱码视之。 解决方法: fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);_asp.net utf8 导出中文字符乱码

笔记-编译原理-实验一-词法分析器设计_对pl/0作以下修改扩充。增加单词-程序员宅基地

文章浏览阅读2.1k次,点赞4次,收藏23次。第一次实验 词法分析实验报告设计思想词法分析的主要任务是根据文法的词汇表以及对应约定的编码进行一定的识别,找出文件中所有的合法的单词,并给出一定的信息作为最后的结果,用于后续语法分析程序的使用;本实验针对 PL/0 语言 的文法、词汇表编写一个词法分析程序,对于每个单词根据词汇表输出: (单词种类, 单词的值) 二元对。词汇表:种别编码单词符号助记符0beginb..._对pl/0作以下修改扩充。增加单词

android adb shell 权限,android adb shell权限被拒绝-程序员宅基地

文章浏览阅读773次。我在使用adb.exe时遇到了麻烦.我想使用与bash相同的adb.exe shell提示符,所以我决定更改默认的bash二进制文件(当然二进制文件是交叉编译的,一切都很完美)更改bash二进制文件遵循以下顺序> adb remount> adb push bash / system / bin /> adb shell> cd / system / bin> chm..._adb shell mv 权限

投影仪-相机标定_相机-投影仪标定-程序员宅基地

文章浏览阅读6.8k次,点赞12次,收藏125次。1. 单目相机标定引言相机标定已经研究多年,标定的算法可以分为基于摄影测量的标定和自标定。其中,应用最为广泛的还是张正友标定法。这是一种简单灵活、高鲁棒性、低成本的相机标定算法。仅需要一台相机和一块平面标定板构建相机标定系统,在标定过程中,相机拍摄多个角度下(至少两个角度,推荐10~20个角度)的标定板图像(相机和标定板都可以移动),即可对相机的内外参数进行标定。下面介绍张氏标定法(以下也这么称呼)的原理。原理相机模型和单应矩阵相机标定,就是对相机的内外参数进行计算的过程,从而得到物体到图像的投影_相机-投影仪标定

Wayland架构、渲染、硬件支持-程序员宅基地

文章浏览阅读2.2k次。文章目录Wayland 架构Wayland 渲染Wayland的 硬件支持简 述: 翻译一篇关于和 wayland 有关的技术文章, 其英文标题为Wayland Architecture .Wayland 架构若是想要更好的理解 Wayland 架构及其与 X (X11 or X Window System) 结构;一种很好的方法是将事件从输入设备就开始跟踪, 查看期间所有的屏幕上出现的变化。这就是我们现在对 X 的理解。 内核是从一个输入设备中获取一个事件,并通过 evdev 输入_wayland

推荐文章

热门文章

相关标签