-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfield.c
261 lines (208 loc) · 5.36 KB
/
field.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "field.h"
#include "models.h"
#include "function.h"
int N_X;
int N_Y;
int N_CELL;
int H;
int N_PML;
int N_PX;
int N_PY;
static double time;
static double ray_coef; //波をゆっくり入れる為の係数;
static double waveAngle;
static double lambda_s; //波長
static double k_s; //波数
static double w_s; //角周波数
static double T_s; //周期
static void (*defaultWave)(double complex* p, double* eps);
static double maxTime;
static ntffInfo ntff_info;
//:public------------------------------------//
double field_toCellUnit(const double phisycalUnit)
{
return phisycalUnit/H; //セル単位に変換
}
double field_toPhisycalUnit(const double cellUnit)
{
return cellUnit*H; //物理単位(nm)に変換
}
void setField(const int wid, const int hei, const int _h, const int pml, const double lambda, const int wave_angle,double maxstep)
{
H = _h;
N_X = wid / _h;
N_Y = hei/_h;
N_PML = pml;
N_PX = N_X + 2*N_PML;
N_PY = N_Y + 2*N_PML;
N_CELL = N_PX * N_PY; //全セル数
time = 0;
maxTime = maxstep;
lambda_s = field_toCellUnit(lambda);
k_s = 2*M_PI/lambda_s;
w_s = LIGHT_SPEED_S*k_s;
T_s = 2*M_PI/w_s;
ray_coef = 0;
waveAngle = wave_angle;
/* NTFF設定 */
ntff_info.top = N_PY - N_PML - 5;
ntff_info.bottom = N_PML + 5;
ntff_info.left = N_PML + 5;
ntff_info.right = N_PX - N_PML - 5;
double len = (ntff_info.top - ntff_info.bottom + 1)/2;
ntff_info.RFperC = len*2;
ntff_info.step = maxTime + 4*ntff_info.RFperC;
}
//-------------------getter-------------------//
double field_getLambda()
{
return lambda_s;
}
double field_getWaveAngle()
{
return waveAngle;
}
double field_getTime()
{
return time;
}
double field_getMaxTime()
{
return maxTime;
}
double field_getOmega(void)
{
return w_s;
}
double field_getK(void)
{
return k_s;
}
double field_getRayCoef(void)
{
return ray_coef;
}
ntffInfo field_getNTFFInfo()
{
return ntff_info;
}
//----------------------------------------//
double field_sigmaX(const double x, const double y)
{
const int M = 2;
if(x<N_PML)
return pow(1.0*(N_PML-x)/N_PML, M);
else if(N_PML <= x && x < (N_X+N_PML))
return 0;
else
return pow(1.0*(x - (N_PX-N_PML-1))/N_PML, M);
}
double field_sigmaY(const double x, double y)
{
const int M = 2;
if(y<N_PML)
return pow(1.0*(N_PML - y)/N_PML,M);
else if(y>=N_PML && y<(N_Y+N_PML))
return 0.0;
else
return pow(1.0*(y - (N_PY-N_PML-1))/N_PML,M);
}
//pml用の係数のひな形 Δt = 1
//ep_mu εかμ(Eの係数->ε, Hの係数-> μ
//sig σ
double field_pmlCoef(double ep_mu, double sig)
{
return (1.0 - sig/ep_mu)/(1.0+sig/ep_mu);
}
double field_pmlCoef_LXY(double ep_mu, double sig)
{
return 1.0/(ep_mu + sig);
// return 1.0/ep_mu/(1.0 + sig/ep_mu);
}
//1次元配列に変換
int ind(const int i, const int j)
{
// return i*N_PY + j;
return i*N_PY + j;
}
//------------------getter-------------------------//
//------------------light method----------------------//
//点光源を返す
double complex field_pointLight(void)
{
return ray_coef * (cos(w_s*time) + sin(w_s*time)*I);
}
//点光源を中心に入れる
void field_pointLightWave(double complex *p, double *eps)
{
p[ind(N_PX/2, N_PY/2)] += ray_coef * (cos(w_s*time) + sin(w_s*time)*I);
}
//Standard Scattered Wave
void field_scatteredWave(double complex *p, double *eps){
double rad = waveAngle*M_PI/180; //ラジアン変換
double ks_cos = cos(rad)*k_s, ks_sin = sin(rad)*k_s; //毎回計算すると時間かかりそうだから,代入しておく
int i,j;
for(i=N_PML; i<N_X+N_PML; i++){
for(j=N_PML; j<N_Y+N_PML; j++){
double ikx = i*ks_cos + j*ks_sin; //k_s*(i*cos + j*sin)
p[ind(i,j)] += ray_coef*(EPSILON_0_S/eps[ind(i,j)] - 1)*(cos(ikx-w_s*time) + I*sin(ikx-w_s*time));
}
}
}
//Nonstandard Scattered Wave
void field_setDefaultIncidence(enum WAVE_MODE wm)
{
defaultWave = (wm == SCATTER ? field_scatteredWave : field_pointLightWave);
}
void field_defaultIncidence(double complex* p, double *eps)
{
(*defaultWave)(p, eps);
}
//------------------light method----------------------//
bool field_nextStep(void){
time+=1.0;
ray_coef = 1.0*(1.0 - exp(-0.0001*time*time));
return time >= maxTime;
}
//---------------output method---------------//
void field_outputElliptic(const char *fileName, double complex* data, double ox, double oy, double r)
{ //file open
FILE *fp;
int ang;
printf("output start\n");
if( (fp=fopen(fileName, "w") ) == NULL){
printf("cannot open file %s \n", fileName);
exit(2);
}
printf("file %s \n",fileName);
for(ang=0; ang <=180; ang++){
double rad = ang*M_PI/180.0;
double x = 1.2*lambda_s*cos(rad)+N_PX/2.0;
double y = 1.2*lambda_s*sin(rad)+N_PY/2.0;
double norm = cnorm(cbilinear(data,x,y,N_PX,N_PY));
fprintf(fp, "%d %lf \n", 180-ang, norm);
}
fclose(fp);
printf("output end\n");
}
void field_outputAllData(const char *fileName, double complex* data)
{
printf("output start\n");
//file open
FILE *fp;
int i,j;
if( (fp=fopen(fileName, "w") ) == NULL){
printf("cannot open file %s \n", fileName);
exit(2);
}
printf("file %s \n",fileName);
for(i=0; i<N_PX; i++)
for(j=0; j<N_PY; j++)
fprintf(fp, "%lf\n", cnorm(data[ind(i,j)]));
fclose(fp);
printf("output end\n");
}