-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample2.c
112 lines (102 loc) · 3.54 KB
/
example2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// calculation example for electromagnetic field intensity distribution
#include <stdio.h>
#include <stdlib.h>
#include "multi_fbeam.h"
#include "my_utils.h"
int main()
{
Bobj bm;
FILE *fp1,*fp2;
double complex e[3],h[3];
double x[3],rang,dr,*ie,*ih;
int max,i,j;
init_mfb(&bm);
read_data_mfb(&bm);
print_data_mfb(&bm);
setup_mfb(&bm);
max=200;
rang=4.0*bm.lambda_0;
dr=rang*2/(double)(max-1);
ie=(double *)m_alloc2(max,sizeof(double),"example2.c,ie");
ih=(double *)m_alloc2(max,sizeof(double),"example2.c,ih");
// x=0 plane
if((fp1=fopen("Ie_yz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","# y z electric_field_intensity");
if((fp2=fopen("Ih_yz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp2,"%s\n","# y z magnetic_field_intensity");
x[0]=0.0;
for(i=0;i<max;i++){
x[1]=-rang+(double)i*dr;
#pragma omp parallel for schedule(dynamic) firstprivate(x) private(e,h) // omp parallel
for(j=0;j<max;j++){
x[2]=-rang+(double)j*dr;
calc_mfb_EH(e,h,x,&bm);
ie[j]=creal(e[0]*conj(e[0]))+creal(e[1]*conj(e[1]))+creal(e[2]*conj(e[2]));
ih[j]=creal(h[0]*conj(h[0]))+creal(h[1]*conj(h[1]))+creal(h[2]*conj(h[2]));
}
for(j=0;j<max;j++){
x[2]=-rang+(double)j*dr;
fprintf(fp1,"%g %g %15.14e\n",x[1],x[2],ie[j]);
fprintf(fp2,"%g %g %15.14e\n",x[1],x[2],ih[j]);
}
fprintf(fp1,"\n");
fprintf(fp2,"\n");
}
fclose(fp1);
fclose(fp2);
// y=0 plane
if((fp1=fopen("Ie_xz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","# x z electric_field_intensity");
if((fp2=fopen("Ih_xz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp2,"%s\n","# x z magnetic_field_intensity");
x[1]=0.0;
for(i=0;i<max;i++){
x[0]=-rang+(double)i*dr;
#pragma omp parallel for schedule(dynamic) firstprivate(x) private(e,h) // omp parallel
for(j=0;j<max;j++){
x[2]=-rang+(double)j*dr;
calc_mfb_EH(e,h,x,&bm);
ie[j]=creal(e[0]*conj(e[0]))+creal(e[1]*conj(e[1]))+creal(e[2]*conj(e[2]));
ih[j]=creal(h[0]*conj(h[0]))+creal(h[1]*conj(h[1]))+creal(h[2]*conj(h[2]));
}// end parallel
for(j=0;j<max;j++){
x[2]=-rang+(double)j*dr;
fprintf(fp1,"%g %g %15.14e\n",x[0],x[2],ie[j]);
fprintf(fp2,"%g %g %15.14e\n",x[0],x[2],ih[j]);
}
fprintf(fp1,"\n");
fprintf(fp2,"\n");
}
fclose(fp1);
fclose(fp2);
// z=0 plane
if((fp1=fopen("Ie_xy.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","# x y electric_field_intensity");
if((fp2=fopen("Ih_xy.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp2,"%s\n","# x y electric_field_intensity");
x[2]=0.0;
for(i=0;i<max;i++){
x[0]=-rang+(double)i*dr;
#pragma omp parallel for schedule(dynamic) firstprivate(x) private(e,h) // omp parallel
for(j=0;j<max;j++){
x[1]=-rang+(double)j*dr;
calc_mfb_EH(e,h,x,&bm);
ie[j]=creal(e[0]*conj(e[0]))+creal(e[1]*conj(e[1]))+creal(e[2]*conj(e[2]));
ih[j]=creal(h[0]*conj(h[0]))+creal(h[1]*conj(h[1]))+creal(h[2]*conj(h[2]));
}
for(j=0;j<max;j++){
x[1]=-rang+(double)j*dr;
fprintf(fp1,"%g %g %15.14e\n",x[0],x[1],ie[j]);
fprintf(fp2,"%g %g %15.14e\n",x[0],x[1],ih[j]);
}
fprintf(fp1,"\n");
fprintf(fp2,"\n");
}
fclose(fp1);
fclose(fp2);
printf("intensity plot is finished\n");
free(ie);
free(ih);
free_mfb(&bm);
return 0;
}