📄 part_2.br
字号:
int main(int argc, char* argv[]) {
// Initialize Variables
int i, j, N, nx, ny, xsize, ysize, insizex, insizey;
int iPML, kappa, m;
float sigmax, sigmay, amax;
float sig1, sig2, a1, a2, k1, k2,ii;
float eps0, mu0, c, pi, dx, dy, dx2, dy2, dfactor;
float dt, Nc, tau, t0,fmax, ce;
float* t=NULL;
float* gauss=NULL;
float* outputPort=NULL;
float* aHx=NULL;
float* aHy=NULL;
float* aEz=NULL;
float* aCeze=NULL;
float* aChxh=NULL;
float* aChyh=NULL;
float* aCezh=NULL;
float* aChxe=NULL;
float* aChye=NULL;
float* aCs=NULL;
float* outputEz = NULL;
float* outputHx = NULL;
float* outputHy = NULL;
float* aKex=NULL;
float* aKey=NULL;
float* aKhx=NULL;
float* aKhy=NULL;
float* abex=NULL;
float* abey=NULL;
float* acex=NULL;
float* acey=NULL;
float* abhx=NULL;
float* abhy=NULL;
float* achx=NULL;
float* achy=NULL;
float* apsi=NULL;
FILE* pFile;
FILE* pFile2;
FILE* pFile3;
// Define Constants
pi=3.14159265;
c=2.998e8;
// Broken Down because of floating point
// problems with certain compliers
eps0=8.854;
eps0=eps0*1e-6;
eps0=eps0*1e-6;
mu0= 4*pi;
mu0= mu0*1e-4;
mu0= mu0*1e-3;
// Define dx & dy
dx=1e-3;
dy=1e-3;
dx2=(1/dx)*(1/dx);
dy2=(1/dy)*(1/dy);
// Define timesteps and domain size
// N,xsize,ysize are all defined
// By runtime arguments
N = atoi(argv[1]);
xsize = atoi(argv[2]);
ysize = atoi(argv[3]);
nx=(int) xsize;
ny=(int) ysize;
dfactor=.9;
dt=(1/( c* sqrt( dx2 + dy2)))*dfactor;
ce=dt/(2*eps0);
// Define source waveform constants
Nc=25;
tau=(Nc*dt)/(2*sqrt(2.0));
t0=4.5*tau;
fmax=1/(tau);
// Define PML Constants
iPML=10;
kappa=8;
m=4;
sigmax = (0.8*m+1) / (150*pi*dx);
sigmay = (0.8*m+1) / (150*pi*dy);
amax = (fmax/2.1)*2*pi*(eps0/10);
// Print out Constants for Checking
pFile = fopen ("InputData.txt","wt");
fprintf (pFile,"pi=%f eps0=%e mu0=%e c=%f \n",pi,eps0,mu0,c);
fprintf (pFile,"dx=%e dy=%e dx2=%e dy2=%e \n",dx,dy,dx2,dy2);
fprintf (pFile,"dt=%e tau=%e t0=%e \n",dt,tau,t0);
// Dynamically Allocate Arrays to Allow matrix size to be
// Set at Runtime
gauss= (float*)malloc(N*sizeof(float));
t= (float*)malloc(N*sizeof(float));
outputPort= (float*)malloc(1*sizeof(float));
aHx= (float*)malloc(xsize*ysize*sizeof(float));
aHy= (float*)malloc(xsize*ysize*sizeof(float));
aEz= (float*)malloc(xsize*ysize*sizeof(float));
aCeze= (float*)malloc(xsize*ysize*sizeof(float));
aChxh= (float*)malloc(xsize*ysize*sizeof(float));
aChyh= (float*)malloc(xsize*ysize*sizeof(float));
aCezh= (float*)malloc(xsize*ysize*sizeof(float));
aChxe= (float*)malloc(xsize*ysize*sizeof(float));
aChye= (float*)malloc(xsize*ysize*sizeof(float));
aCs= (float*)malloc(xsize*ysize*sizeof(float));
outputEz= (float*)malloc(xsize*ysize*sizeof(float));
outputHx= (float*)malloc(xsize*ysize*sizeof(float));
outputHy= (float*)malloc(xsize*ysize*sizeof(float));
// PML Arrays
aKex = (float*)malloc(xsize*sizeof(float));
aKhx = (float*)malloc(xsize*sizeof(float));
aKey = (float*)malloc(ysize*sizeof(float));
aKhy = (float*)malloc(ysize*sizeof(float));
abex = (float*)malloc(xsize*sizeof(float));
abhx = (float*)malloc(xsize*sizeof(float));
abey = (float*)malloc(ysize*sizeof(float));
abhy = (float*)malloc(ysize*sizeof(float));
acex = (float*)malloc(xsize*sizeof(float));
achx = (float*)malloc(xsize*sizeof(float));
acey = (float*)malloc(ysize*sizeof(float));
achy = (float*)malloc(ysize*sizeof(float));
apsi = (float*)malloc(xsize*ysize*sizeof(float));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -