-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4.c
128 lines (118 loc) · 4.12 KB
/
example4.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// calculation example of far-field intensity distributions.
#include "aw_msp_ivf.h"
int main(int argc,char *argv[])
{
AMSP ms;
FILE *fp1;
double complex p,v[3];
double th,ph,phd,dthd,dthr,dphr,dphd,ra,r[3],*ip,ipmax,mf;
int i,j,sn;
if(argc!=2 && argc!=4){
printf("Usage : %s datafile_name [sampling_number multplier_factor](optional)\n",argv[0]);
printf("default sampling number 360, multiplier factor 2000 (radius = 2000*lambda0)\n");
exit(0);
}
else if(argc==4){
sn=atoi(argv[2]);
mf=atof(argv[3]);
}
else{
sn=360;
mf=2000.0;
}
read_dat_amsp(argv[1],&ms); // read datafile
print_data_amsp(&ms); // print data
ra=mf*ms.aw.lambda0; // radius for calculation point
dthd=360.0/(double)sn; // delta theta [degree]
dthr=2.0*M_PI/(double)sn; // delta theta [radian]
dphd=180.0/(double)sn;
dphr=1.0*M_PI/(double)sn;
ip=(double *)m_alloc2(sn+1,sizeof(double),"example4.c,ie");
// x=0 plane, th=0 : +z-axis, th=270 : +y-axis
if((fp1=fopen("fsIp_yz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","## x=0 plane, theta=0 : +z-axis, theta=270 : +y-axis ");
fprintf(fp1,"%s %d, %s %g\n","## sampling number",sn,"multiplier factor",mf);
fprintf(fp1,"%s\n","# theta sound_pressure_intensity normalized_intensity");
ipmax=0.0;
for(i=0;i<sn;i++){
th=0.5*dthr+(double)i*dthr;
r[0]=0.0;
r[1]=-ra*sin(th);
r[2]= ra*cos(th);
scattered_pv_amsp(&p,v,r,&ms); // scattered field
ip[i]=creal(p*conj(p));
if(ip[i]>ipmax) ipmax=ip[i];
}
for(i=0;i<sn;i++){
th=0.5*dthd+(double)i*dthd;
fprintf(fp1,"%g %15.14e %15.14e\n",th,ip[i],ip[i]/ipmax);
}
fclose(fp1);
// y=0 plane, th=0 : +z-axis, th=90 : +x-axis
if((fp1=fopen("fsIp_xz.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","## y=0 plane, theta=0 : +z-axis, theta=90 : +x-axis ");
fprintf(fp1,"%s %d, %s %g\n","## sampling number",sn,"multiplier factor",mf);
fprintf(fp1,"%s\n","# theta sound_pressure_intensity normalized_intensity");
ipmax=0.0;
for(i=0;i<sn;i++){
th=0.5*dthr+(double)i*dthr;
r[0]=ra*sin(th);
r[1]=0.0;
r[2]=ra*cos(th);
scattered_pv_amsp(&p,v,r,&ms); // scattered field
ip[i]=creal(p*conj(p));
if(ip[i]>ipmax) ipmax=ip[i];
}
for(i=0;i<sn;i++){
th=0.5*dthd+(double)i*dthd;
fprintf(fp1,"%g %15.14e %15.14e\n",th,ip[i],ip[i]/ipmax);
}
fclose(fp1);
// z=0 plane, th=0 : +x-axis, th=90 : +y-axis
if((fp1=fopen("fsIp_xy.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","## z=0 plane, theta=0 : +x-axis, theta=90 : +y-axis ");
fprintf(fp1,"%s %d, %s %g\n","## sampling number",sn,"multiplier factor",mf);
fprintf(fp1,"%s\n","# theta sound_pressure_intensity normalized_intensity");
ipmax=0.0;
for(i=0;i<sn;i++){
th=0.5*dthr+(double)i*dthr;
r[0]=ra*cos(th);
r[1]=ra*sin(th);
r[2]=0.0;
scattered_pv_amsp(&p,v,r,&ms); // scattered field
ip[i]=creal(p*conj(p));
if(ip[i]>ipmax) ipmax=ip[i];
}
for(i=0;i<sn;i++){
th=0.5*dthd+(double)i*dthd;
fprintf(fp1,"%g %15.14e %15.14e\n",th,ip[i],ip[i]/ipmax);
}
fclose(fp1);
// 3d plot
if((fp1=fopen("fsIp_3d.txt","wt"))==NULL){ printf("Can not open the file.\n"); exit(1); }
fprintf(fp1,"%s\n","## 3d plot, x=r*sin(theta)*cos(phi), y=r*sin(theta)*sin(phi), z=r*cos(theta), r=multiplier_factor*lambda0");
fprintf(fp1,"%s %d, %s %g\n","## sampling number",sn,"multiplier factor",mf);
fprintf(fp1,"%s\n","# theta phi sound_pressure_intensity");
for(i=0;i<sn;i++){
ph =0.5*dphr+(double)i*dphr;
phd=0.5*dphd+(double)i*dphd;
#pragma omp parallel for schedule(dynamic) private(th,r,p,v)
for(j=0;j<=sn;j++){
th=(double)j*dthr;
r[0]=ra*sin(ph)*cos(th);
r[1]=ra*sin(ph)*sin(th);
r[2]=ra*cos(ph);
scattered_pv_amsp(&p,v,r,&ms); // scattered field
ip[j]=creal(p*conj(p));
}
for(j=0;j<=sn;j++){
th=(double)j*dthd;
fprintf(fp1,"%g %g %15.14e\n",phd,th,ip[j]);
}
fprintf(fp1,"\n");
}
fclose(fp1);
free(ip);
free_amsp(&ms);
return 0;
}