📄 farfield.c
字号:
for(i=0; i<col; i++)
{
free(FFT[i]);
}
free(FFT);
}
void fourier_transform_Lx_Ey(int row, int col, int dir, float **Lx_real, float **Lx_imag, float **efieldy_real, float **efieldy_imag)
{
int i, j;
struct COMPLEX **FFT; // FFT input and output
int FFT_return;
FFT = (struct COMPLEX **)malloc(sizeof(struct COMPLEX *)*col);
for(i=0; i<col; i++)
FFT[i] = (struct COMPLEX *)malloc(sizeof(struct COMPLEX)*row);
printf("FFT allocation complete....\n");
///------------( Lx calculation )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
FFT[i][j].real = efieldy_real[i][j];
FFT[i][j].imag = efieldy_imag[i][j];
}
}
printf("starting Lx caculation (FFT)...\n");
FFT_return = FFT2D(FFT, col, row, dir);
printf("FFT check... (FFT_return=%d)\n",FFT_return);
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
Lx_real[i][j] = FFT[i][j].real;
Lx_imag[i][j] = FFT[i][j].imag;
}
}
for(i=0; i<col; i++)
{
free(FFT[i]);
}
free(FFT);
}
void fourier_transform_Ly_Ex(int row, int col, int dir, float **Ly_real, float **Ly_imag, float **efieldx_real, float **efieldx_imag)
{
int i, j;
struct COMPLEX **FFT; // FFT input and output
int FFT_return;
FFT = (struct COMPLEX **)malloc(sizeof(struct COMPLEX *)*col);
for(i=0; i<col; i++)
FFT[i] = (struct COMPLEX *)malloc(sizeof(struct COMPLEX)*row);
printf("FFT allocation complete....\n");
///------------( Ly calculation )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
FFT[i][j].real = efieldx_real[i][j];
FFT[i][j].imag = efieldx_imag[i][j];
}
}
printf("starting Ly caculation (FFT)...\n");
FFT_return = FFT2D(FFT, col, row, dir);
printf("FFT check... (FFT_return=%d)\n",FFT_return);
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
Ly_real[i][j] = -FFT[i][j].real;
Ly_imag[i][j] = -FFT[i][j].imag;
}
}
for(i=0; i<col; i++)
{
free(FFT[i]);
}
free(FFT);
}
//////////////////////////////
/// Data shifting ///
//////////////////////////////
void data_shifting_Nx(int row, int col, float **Nx_real, float **Nx_imag)
{
int i,j;
int m,n;
float **temp_real, **temp_imag;
int half_row, half_col;
half_col = (int)(col/2);
half_row = (int)(row/2);
temp_real = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_real[i] = (float *)malloc(sizeof(float)*(row+1));
temp_imag = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_imag[i] = (float *)malloc(sizeof(float)*(row+1));
printf("Nx shifting\n");
///------------( Nx shifting )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
temp_real[i][j] = Nx_real[i][j];
temp_imag[i][j] = Nx_imag[i][j];
}
}
for(j=row; j>=0; j--)
{
for(i=0; i<(col+1); i++)
{
m = i-half_col;
n = j-half_row;
if(m>=0 && n>=0)
{
Nx_real[i][j] = temp_real[m][n];
Nx_imag[i][j] = temp_imag[m][n];
}
if(m>=0 && n<0)
{
Nx_real[i][j] = temp_real[m][row+n];
Nx_imag[i][j] = temp_imag[m][row+n];
}
if(m<0 && n>=0)
{
Nx_real[i][j] = temp_real[col+m][n];
Nx_imag[i][j] = temp_imag[col+m][n];
}
if(m<0 && n<0)
{
Nx_real[i][j] = temp_real[col+m][row+n];
Nx_imag[i][j] = temp_imag[col+m][row+n];
}
}
}
for(i=0; i<(col+1); i++)
{
free(temp_real[i]); free(temp_imag[i]);
}
free(temp_real); free(temp_imag);
}
void data_shifting_Ny(int row, int col, float **Ny_real, float **Ny_imag)
{
int i,j;
int m,n;
float **temp_real, **temp_imag;
int half_row, half_col;
half_col = (int)(col/2);
half_row = (int)(row/2);
temp_real = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_real[i] = (float *)malloc(sizeof(float)*(row+1));
temp_imag = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_imag[i] = (float *)malloc(sizeof(float)*(row+1));
printf("Ny shifting\n");
///------------( Ny shifting )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
temp_real[i][j] = Ny_real[i][j];
temp_imag[i][j] = Ny_imag[i][j];
}
}
for(j=row; j>=0; j--)
{
for(i=0; i<(col+1); i++)
{
m = i-half_col;
n = j-half_row;
if(m>=0 && n>=0)
{
Ny_real[i][j] = temp_real[m][n];
Ny_imag[i][j] = temp_imag[m][n];
}
if(m>=0 && n<0)
{
Ny_real[i][j] = temp_real[m][row+n];
Ny_imag[i][j] = temp_imag[m][row+n];
}
if(m<0 && n>=0)
{
Ny_real[i][j] = temp_real[col+m][n];
Ny_imag[i][j] = temp_imag[col+m][n];
}
if(m<0 && n<0)
{
Ny_real[i][j] = temp_real[col+m][row+n];
Ny_imag[i][j] = temp_imag[col+m][row+n];
}
}
}
for(i=0; i<(col+1); i++)
{
free(temp_real[i]); free(temp_imag[i]);
}
free(temp_real); free(temp_imag);
}
void data_shifting_Lx(int row, int col, float **Lx_real, float **Lx_imag)
{
int i,j;
int m,n;
float **temp_real, **temp_imag;
int half_row, half_col;
half_col = (int)(col/2);
half_row = (int)(row/2);
temp_real = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_real[i] = (float *)malloc(sizeof(float)*(row+1));
temp_imag = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_imag[i] = (float *)malloc(sizeof(float)*(row+1));
printf("Lx shifting\n");
///------------( Lx shifting )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
temp_real[i][j] = Lx_real[i][j];
temp_imag[i][j] = Lx_imag[i][j];
}
}
for(j=row; j>=0; j--)
{
for(i=0; i<(col+1); i++)
{
m = i-half_col;
n = j-half_row;
if(m>=0 && n>=0)
{
Lx_real[i][j] = temp_real[m][n];
Lx_imag[i][j] = temp_imag[m][n];
}
if(m>=0 && n<0)
{
Lx_real[i][j] = temp_real[m][row+n];
Lx_imag[i][j] = temp_imag[m][row+n];
}
if(m<0 && n>=0)
{
Lx_real[i][j] = temp_real[col+m][n];
Lx_imag[i][j] = temp_imag[col+m][n];
}
if(m<0 && n<0)
{
Lx_real[i][j] = temp_real[col+m][row+n];
Lx_imag[i][j] = temp_imag[col+m][row+n];
}
}
}
for(i=0; i<(col+1); i++)
{
free(temp_real[i]); free(temp_imag[i]);
}
free(temp_real); free(temp_imag);
}
void data_shifting_Ly(int row, int col, float **Ly_real, float **Ly_imag)
{
int i,j;
int m,n;
float **temp_real, **temp_imag;
int half_row, half_col;
half_col = (int)(col/2);
half_row = (int)(row/2);
temp_real = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_real[i] = (float *)malloc(sizeof(float)*(row+1));
temp_imag = (float **)malloc(sizeof(float *)*(col+1));
for(i=0; i<(col+1); i++)
temp_imag[i] = (float *)malloc(sizeof(float)*(row+1));
printf("Ly shifting\n");
///------------( Ly shifting )------------
for(j=row-1; j>=0; j--)
{
for(i=0; i<col; i++)
{
temp_real[i][j] = Ly_real[i][j];
temp_imag[i][j] = Ly_imag[i][j];
}
}
for(j=row; j>=0; j--)
{
for(i=0; i<(col+1); i++)
{
m = i-half_col;
n = j-half_row;
if(m>=0 && n>=0)
{
Ly_real[i][j] = temp_real[m][n];
Ly_imag[i][j] = temp_imag[m][n];
}
if(m>=0 && n<0)
{
Ly_real[i][j] = temp_real[m][row+n];
Ly_imag[i][j] = temp_imag[m][row+n];
}
if(m<0 && n>=0)
{
Ly_real[i][j] = temp_real[col+m][n];
Ly_imag[i][j] = temp_imag[col+m][n];
}
if(m<0 && n<0)
{
Ly_real[i][j] = temp_real[col+m][row+n];
Ly_imag[i][j] = temp_imag[col+m][row+n];
}
}
}
for(i=0; i<(col+1); i++)
{
free(temp_real[i]); free(temp_imag[i]);
}
free(temp_real); free(temp_imag);
}
//////////////////////////////
/// Data shrink ///
//////////////////////////////
void Nx_data_shrink(int row, int col, float **Nx_real, float **Nx_imag, float **Nx_s_real, float **Nx_s_imag, float Nfree, float k)
{
int i,j;
int half_row, half_col;
int row_s, col_s; //shrinked row & col
int half_row_s, half_col_s;
half_col = (int)(col/2);
half_row = (int)(row/2);
row_s = (int)(10*Nfree*k);
col_s = (int)(10*Nfree*k);
half_col_s = (int)(col_s/2);
half_row_s = (int)(row_s/2);
for(j=(half_row)+(half_row_s); j>=(half_row)-(half_row_s); j--)
{
for(i=(half_col)-(half_col_s); i<=(half_col)+(half_col_s); i++)
{
Nx_s_real[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Nx_real[i][j];
Nx_s_imag[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Nx_imag[i][j];
}
}
}
void Ny_data_shrink(int row, int col, float **Ny_real, float **Ny_imag, float **Ny_s_real, float **Ny_s_imag, float Nfree, float k)
{
int i,j;
int half_row, half_col;
int row_s, col_s; //shrinked row & col
int half_row_s, half_col_s;
half_col = (int)(col/2);
half_row = (int)(row/2);
row_s = (int)(10*Nfree*k);
col_s = (int)(10*Nfree*k);
half_col_s = (int)(col_s/2);
half_row_s = (int)(row_s/2);
for(j=(half_row)+(half_row_s); j>=(half_row)-(half_row_s); j--)
{
for(i=(half_col)-(half_col_s); i<=(half_col)+(half_col_s); i++)
{
Ny_s_real[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Ny_real[i][j];
Ny_s_imag[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Ny_imag[i][j];
}
}
}
void Lx_data_shrink(int row, int col, float **Lx_real, float **Lx_imag, float **Lx_s_real, float **Lx_s_imag, float Nfree, float k)
{
int i,j;
int half_row, half_col;
int row_s, col_s; //shrinked row & col
int half_row_s, half_col_s;
half_col = (int)(col/2);
half_row = (int)(row/2);
row_s = (int)(10*Nfree*k);
col_s = (int)(10*Nfree*k);
half_col_s = (int)(col_s/2);
half_row_s = (int)(row_s/2);
for(j=(half_row)+(half_row_s); j>=(half_row)-(half_row_s); j--)
{
for(i=(half_col)-(half_col_s); i<=(half_col)+(half_col_s); i++)
{
Lx_s_real[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Lx_real[i][j];
Lx_s_imag[i-(half_col)+(half_col_s)][j-(half_row)+(half_row_s)] = Lx_imag[i][j];
}
}
}
void Ly_data_shrink(int row, int col, float **Ly_real, float **Ly_imag, float **Ly_s_real, float **Ly_s_imag, float Nfree, float k)
{
int i,j;
int half_row, half_col;
int row_s, col_s; //shrinked row & col
int half_row_s, half_col_s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -