-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.c
executable file
·121 lines (100 loc) · 5.83 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
#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
field *particle_field(double x, double y, grid *grid_all, double scale_x, double scale_y, int GRID_X, int GRID_Y)
{
/*field for the current particle */
field *curr=(field*)malloc(sizeof(field));
double delta_x, delta_y, e_x, e_y, e_z, b_x, b_y, b_z, dx_help, dy_help;
int x_abs, y_abs;
x_abs=(int)(x*scale_x);
y_abs=(int)(y*scale_y);
delta_x=x*scale_x-x_abs-0.5;
delta_y=y*scale_y-y_abs-0.5;
/*interpolating fields at the particle location */
/*****************************************/
if(delta_y>0)
{
dy_help=-(0.5-delta_y);
e_x=((moving_frame_get(grid_all->grid_ex, x_abs, y_abs))*(0.5-delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ex, x_abs+1, y_abs))*(0.5+delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ex, x_abs, y_abs+1))*(0.5-delta_x)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_ex, x_abs+1, y_abs+1))*(0.5+delta_x)*(0.5+dy_help));
}
else
{
dy_help=(0.5+delta_y);
e_x=(moving_frame_get(grid_all->grid_ex, x_abs, y_abs-1)*(0.5-delta_x)*(0.5-dy_help)+moving_frame_get(grid_all->grid_ex, x_abs+1, y_abs-1)*(0.5+delta_x)*(0.5-dy_help)+moving_frame_get(grid_all->grid_ex, x_abs, y_abs)*(0.5-delta_x)*(0.5+dy_help)+moving_frame_get(grid_all->grid_ex, x_abs+1, y_abs)*(0.5+delta_x)*(0.5+dy_help));
}
/*****************************************/
if(delta_x>0)
{
dx_help=-(0.5-delta_x);
e_y=((moving_frame_get(grid_all->grid_ey, x_abs, y_abs))*(0.5-dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs+1, y_abs))*(0.5+dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs, y_abs+1))*(0.5-dx_help)*(0.5+delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs+1, y_abs+1))*(0.5+dx_help)*(0.5+delta_y));
}
else
{
dx_help=(0.5+delta_x);
e_y=((moving_frame_get(grid_all->grid_ey, x_abs-1, y_abs))*(0.5-dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs, y_abs))*(0.5+dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs-1, y_abs+1))*(0.5-dx_help)*(0.5+delta_y)+(moving_frame_get(grid_all->grid_ey, x_abs, y_abs+1))*(0.5+dx_help)*(0.5+delta_y));
}
/*****************************************/
if(delta_x>0)
{
if(delta_y>0)
{
dx_help=-(0.5-delta_x);
dy_help=-(0.5-delta_y);
e_z=((moving_frame_get(grid_all->grid_ez, x_abs, y_abs))*(0.5-dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs+1, y_abs))*(0.5+dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs+1))*(0.5-dx_help)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs+1, y_abs+1))*(0.5+dx_help)*(0.5+dy_help));
}
else
{
dx_help=-(0.5-delta_x);
dy_help=0.5+delta_y;
e_z=((moving_frame_get(grid_all->grid_ez, x_abs, y_abs-1))*(0.5-dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs+1, y_abs-1))*(0.5+dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs))*(0.5-dx_help)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs+1, y_abs))*(0.5+dx_help)*(0.5+dy_help));
}
}
else
{
if(delta_y>0)
{
dx_help=0.5+delta_x;
dy_help=-(0.5-delta_y);
e_z=((moving_frame_get(grid_all->grid_ez, x_abs-1, y_abs))*(0.5-dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs))*(0.5+dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs-1, y_abs+1))*(0.5-dx_help)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs+1))*(0.5+dx_help)*(0.5+dy_help));
}
else
{
dx_help=0.5+delta_x;
dy_help=0.5+delta_y;
e_z=((moving_frame_get(grid_all->grid_ez, x_abs-1, y_abs-1))*(0.5-dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs-1))*(0.5+dx_help)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs-1, y_abs))*(0.5-dx_help)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_ez, x_abs, y_abs))*(0.5+dx_help)*(0.5+dy_help));
}
}
/*****************************************/
if(delta_x>0)
{
dx_help=-(0.5-delta_x);
b_x=((moving_frame_get(grid_all->grid_bx, x_abs, y_abs))*(0.5-dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs+1, y_abs))*(0.5+dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs, y_abs+1))*(0.5-dx_help)*(0.5+delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs+1, y_abs+1))*(0.5+dx_help)*(0.5+delta_y));
}
else
{
dx_help=(0.5+delta_x);
b_x=((moving_frame_get(grid_all->grid_bx, x_abs-1, y_abs))*(0.5-dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs, y_abs))*(0.5+dx_help)*(0.5-delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs-1, y_abs+1))*(0.5-dx_help)*(0.5+delta_y)+(moving_frame_get(grid_all->grid_bx, x_abs, y_abs+1))*(0.5+dx_help)*(0.5+delta_y));
}
/*****************************************/
if(delta_y>0)
{
dy_help=-(0.5-delta_y);
b_y=((moving_frame_get(grid_all->grid_by, x_abs, y_abs))*(0.5-delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_by, x_abs+1, y_abs))*(0.5+delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_by, x_abs, y_abs+1))*(0.5-delta_x)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_by, x_abs+1, y_abs+1))*(0.5+delta_x)*(0.5+dy_help));
}
else
{
dy_help=(0.5+delta_y);
b_y=((moving_frame_get(grid_all->grid_by, x_abs, y_abs-1))*(0.5-delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_by, x_abs+1, y_abs-1))*(0.5+delta_x)*(0.5-dy_help)+(moving_frame_get(grid_all->grid_by, x_abs, y_abs))*(0.5-delta_x)*(0.5+dy_help)+(moving_frame_get(grid_all->grid_by, x_abs+1, y_abs))*(0.5+delta_x)*(0.5+dy_help));
}
/*****************************************/
b_z=(moving_frame_get(grid_all->grid_bz, x_abs, y_abs)*(0.5-delta_x)*(0.5-delta_y)+moving_frame_get(grid_all->grid_bz, x_abs+1, y_abs)*(0.5+delta_x)*(0.5-delta_y)+moving_frame_get(grid_all->grid_bz, x_abs, y_abs+1)*(0.5-delta_x)*(0.5+delta_y)+moving_frame_get(grid_all->grid_bz, x_abs+1, y_abs+1)*(0.5+delta_x)*(0.5+delta_y));
/*****************************************/
curr->ex=e_x;
curr->ey=e_y;
curr->ez=e_z;
curr->bx=b_x;
curr->by=b_y;
curr->bz=b_z;
return curr;
}