⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initial.c

📁 FDTD 模拟 天线 包含 近场-远场 外推程序(时谐场)
💻 C
字号:
/************************************************
*                                               *
*      This file is used to input all           *
*   parameters of model and initialize          *
*************************************************
*/

# include "polygon.h"
# include "initial.h"
# include "dfree.h"
# include "my_malloc.h"


void InputData(void)
{
   
   printf("Input the number of lattice in x,y,z (Nx,Ny,Nz) (fmax): \n");
   scanf("%d%d%d",&Nx,&Ny,&Nz);

   printf("Input the step size of x,y,z -axis (mm):\n");
   scanf("%lf%lf%lf",&dhx,&dhy,&dhz);

   dhx*=1.0e-3; dhy*=1.0e-3; dhz*=1.0e-3; 

   printf("Input the total iteration times (N_NT) :\n");
   scanf("%d",&N_NT);

   printf("Input the frequency-band (Fre_Min Fre_Max Fre_Step)(GHz) \n");
   scanf("%lf%lf%lf",&Fre_Min,&Fre_Max,&Fre_Step);

   Fre_Min*=1.0e9; Fre_Max*=1.0e9; Fre_Step*=1.0e9;

   printf("Input the 2th Dispersive Constants: erff1 erff2 \n");
   scanf("%lf%lf",&erff1,&erff2);



}


void Pre_Process(MODULE *pModule)
{

  double Er_Min,Velocity_Max;

  Er_Min=Min_Array(pModule->nLayerNum,pModule->pPermit);
    
  Velocity_Max=C/sqrt(Er_Min);


  dt=1.0/Velocity_Max/sqrt(1.0/dhx/dhx+1.0/dhy/dhy+1.0/dhz/dhz);

  dt=0.5*dt;  

/*  T=10.0*sqrt(1.9)*dhy/1.732/Velocity_Max/dt;  */

  T=42.0;  

  t0=4.0*T;

  printf("dt=%lf T=%lf t0=%lf \n",dt,T,t0);
  printf("dt*C/dhy=%lf\n",dt*C/dhy); 


}


double Min_Array(int N,double *pA)
{
  int i;
  double temp;

  temp=pA[0];

  for(i=0;i<N;i++)
   {

      if(temp>pA[i]) 
         {
            temp=pA[i];
         }

    }

   return temp;

}

void Initial(MODULE *pModule)
{
    int i,j,k,l,m;
    char * face[6]={"Up","Down","Left","Right","Front","Back"};	

/*-----------------------各层信息---start---------------------*/  

    printf("Input the parameters of the Excitation Plane:\n");
    printf("\nInput the location of Excite Plane :\n");
    scanf("%d",&pModule->Excite.nLocation); /* 端口在左右或前后 */
    printf(" Input the permittivity:\n");
    scanf("%lf",&pModule->Excite.per); 
    printf("Input the size of Excite (w_start ,l_start,w_end,l_end):\n");
    scanf("%d%d%d%d",&pModule->Excite.nFw_start,
                         &pModule->Excite.nFl_start,
                         &pModule->Excite.nFw_end,
                         &pModule->Excite.nFl_end); /* 端口上下左右范围 */


    printf("\nHow many layers in this structure:\n");
    scanf("%d",&pModule->nLayerNum); /* 层数 */

    printf("Input the most area's permittivity of each layer:\n");
    pModule->pPermit=dmalloc_1(pModule->nLayerNum);
    for (i=0; i<pModule->nLayerNum; i++)
    {
        printf("In %d Layer\n",i+1);       
        scanf("%lf",&pModule->pPermit[i]);  /* 各层介电常数 */
    }
    

    pModule->pLayer=LAYER_malloc(pModule->nLayerNum);

    printf("Now Input the parameters of each Layer \n");	

    for (i=0; i<pModule->nLayerNum; i++)
    {
	printf("---In %d Layer---\n",i+1);

	printf("\nInput the size of Layer (z_start z_end):\n");
	scanf("%d%d",&pModule->pLayer[i].z_start,&pModule->pLayer[i].z_end);
                     /* 各层的高度 */

	printf("How many polygon metal strips in this layer:\n");
	scanf("%d",&pModule->pLayer[i].nCondPolyNum); /* 多边形导体数 */

        pModule->pLayer[i].pCondPoly
                      =POLYGON_malloc(pModule->pLayer[i].nCondPolyNum);
		
        for (j=0; j<pModule->pLayer[i].nCondPolyNum; j++)
        {
            printf("In %d polygon conductor:\n",j+1);
            printf("How many Vertexes in this Conductor:\n");
	    scanf("%d",&pModule->pLayer[i].pCondPoly[j].nVertex); 
                               /* 各导体顶点数 */

            pModule->pLayer[i].pCondPoly[j].pVertex
                     =POINT_malloc(pModule->pLayer[i].pCondPoly[j].nVertex);
				  
            for (k=0; k<pModule->pLayer[i].pCondPoly[j].nVertex; k++)
            {
	        printf("Input Coordinate of the %d point \n",k+1);
	        scanf("%lf%lf",&pModule->pLayer[i].pCondPoly[j].pVertex[k].x,
		       &pModule->pLayer[i].pCondPoly[j].pVertex[k].y);
                       /* 顺时针方向输入各导体顶点 */
	    }	
        }
    }        
  
/*-----------------------各层信息----end----------------------*/  

/*-----------------------端口信息---start---------------------*/

       printf("Input the parameters of the Ports:\n");

        printf("\nInput the location of Port \n");
        scanf("%d",&pModule->pPort.nLocation); /* 端口在左右或前后 */
           /* 端口介电常数 */
	printf("Input the size of port (w_start ,l_start,w_end,l_end):\n");
        scanf("%d%d%d%d",&pModule->pPort.nFw_start,
                         &pModule->pPort.nFl_start,
                         &pModule->pPort.nFw_end,
                         &pModule->pPort.nFl_end); /* 端口上下左右范围 */

/*-----------------------端口信息----end----------------------*/
 


/*-----------------------边界信息---start---------------------*/
    printf("Input the boundary of entire area:\n");
    printf("Note: The Left must be a excitation Port!!\n");
    printf("0--Electric Wall  1--Magnetic Wall  2--ABC  3--Port\n");
    printf("Note:The second port must locate in the right or front!\n"); 
    for (i=0; i<6; i++)
    {
	printf("\n%s :",face[i]);
	scanf("%d",&pModule->nSurf[i]); /* 各边界性质 */
    }

/*-----------------------边界信息----end----------------------*/

/*-----------------------介质信息---start---------------------*/


} 
        


void ClearInputMemory(MODULE *pModule)
{
   int i,j,k;
          
   dfree_1(pModule->pPermit);
                    		 
   if (pModule->pLayer != NULL)
   {
      for (i=0; i<pModule->nLayerNum; i++)
      {
          if (pModule->pLayer[i].pCondPoly != NULL)
          {
             for (j=0; j<pModule->pLayer[i].nCondPolyNum; j++)
             {
                 if (pModule->pLayer[i].pCondPoly[j].pVertex != NULL)
                    free(pModule->pLayer[i].pCondPoly[j].pVertex);
             }
             free(pModule->pLayer[i].pCondPoly);     
  	  }		 

      }

       free(pModule->pLayer);
     }
}    	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -