-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircleModel.c
More file actions
53 lines (43 loc) · 1.24 KB
/
Copy pathcircleModel.c
File metadata and controls
53 lines (43 loc) · 1.24 KB
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
#include <math.h>
#include "circleModel.h"
#include "field.h"
static double radius;
static double epsilon;
static double posx;
static double posy;
static double eps(double, double, int, int);
double (*circleModel_EPS(double x, double y, double r))(double, double, int , int)
{
radius = r;
posx = x;
posy = y;
epsilon = 1.6*1.6*EPSILON_0_S;
return eps;
}
//col : D_Xモード, row : D_Yモード
static double eps(double x, double y, int col, int row)
{
if(x < N_PML || y < N_PML || x > N_X+N_PML || y > N_Y + N_PML)
return EPSILON_0_S;
double dx = x-posx;
double dy = y-posy;
//2乗距離
double len = dx*dx+dy*dy;
//中心との距離がr+1セル以上なら,そのセルは完全に媒質の外
if(len >= (radius+1)*(radius+1))
return EPSILON_0_S;
//中心との距離がr-1セル以下なら,そのセルは完全に媒質の外
if(len <= (radius-1)*(radius-1))
return epsilon;
//さらに32*32分割し媒質内と媒質外の数を求めepsilonを決定する
double sum=0;
double i,j;
for(i=-16+0.5; i<16; i+=1){
for(j=-16+0.5; j<16; j+=1){
if(pow(dx+col*i/32.0, 2.0) + pow(dy+row*j/32.0, 2.0) <= radius*radius)
sum+=1;
}
}
sum /= 32.0*32.0;
return epsilon*sum + EPSILON_0_S*(1-sum);
}