summaryrefslogtreecommitdiff
path: root/src/test/ParticleTest.cc
blob: 30cd93a3ef0b75be9d41114db423011898d125f7 (plain) (blame)
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
/*
 * ParticleTest.cc
 *
 *  Created on: Mar 16, 2011
 *      Author: jakob
 */

#include <iostream>
#include <string>
#include <vector>
#include "StraightElement.h"
#include "Dipole.h"
#include "Quadrupole.h"
#include "Particle.h"
#include "Vector3D.h"

using namespace vhc;
using namespace std;

Particle particle(Vector3D(0,0,0), 5.1, constants::e, 150, Vector3D::i);
Element* element;


void step(double h);

int main() {
	//Particle p(Vector3D::Null, 0, 0);
	//cout << p << endl;
	element = new Dipole(Vector3D::Null, Vector3D::i-Vector3D::j, 0.2, 1.0, Vector3D(0, 0, 1) * particle.getGamma() * particle.getMass() * 1 * particle.getVelocity().norm() / particle.getCharge());
	cout << *element << endl;

	double t = 0;
	double h = 1E-9;
	char c('0');
	bool hit = false;
	do {
		if (element->isOutside(particle)) hit = true;
		step(h);
		t += h;
		cin.get(c);
	} while (c != 'c' && !hit);

	if (hit) {
		cout << "Particle hit the wall!!!" << endl;
	}


	delete element;
	return 0;
}

void step(double h) {
	particle.applyMagneticForce(element->magneticFieldAt(particle.getPosition()), h);

	Vector3D a = particle.getForce() / (particle.getGamma() * particle.getMass());
	particle.setVelocity(particle.getVelocity() + a * h);
	particle.setPosition(particle.getPosition() + particle.getVelocity() * h);
	cout << particle << endl;
	particle.setForce(Vector3D::Null);
}