-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample_ExB.cpp
More file actions
41 lines (38 loc) · 882 Bytes
/
sample_ExB.cpp
File metadata and controls
41 lines (38 loc) · 882 Bytes
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
#include <particle.h>
#include <stdio.h>
vector3 E( const vector3& _r ){
vector3 _E( 0.0, 0.5, 0.0 );
return _E;
}
vector3 B( const vector3& _r ){
vector3 _B( 0.0, 0.0, 1.0 );
return _B;
}
vector3 F( const vector3& _r, const vector3& _v,
const double& _t, const double& _q ){
return _q * ( E(_r) + _v * B(_r) );
}
int main()
{
particle p;
p.sett(0);
p.setm(1);
p.setq(1);
// p.setq(-1);
p.setr(0.0,0.0,0.0);
p.setv(0.3,0.0,0.1);
// rewinding
for( int i=0;p.gett()>-10; i++ ){
// printf( "%f %f %f %f %f %f\n",
// p.r.x, p.r.y, p.r.z,
// p.v.x, p.v.y, p.v.z );
p.rk6(-0.2); // nonrelativistic motion
}
// marching in time
for( int i=0;p.gett()<50; i++ ){
printf( "%f %f %f %f %f %f\n",
p.r.x, p.r.y, p.r.z, p.v.x, p.v.y, p.v.z );
p.rk6(0.2); // nonrelativistic motion
}
return 0;
}