summaryrefslogtreecommitdiff
path: root/src/test/AccelTest.cc
blob: dc5b9c423894fc5fb79b755c6d31dba3ea1de8ac (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
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
/*
 * testAccel1.cc
 *
 *  Created on: 23 mars 2011
 *      Author: christian
 */


#include "Accelerator.h"
#include "Dipole.h"
#include "FODO.h"
#include <iostream>
#include <string>
#include <vector>


using namespace std;
using namespace vhc;

//TODO erreur sur l'affichage des particules en général  ===> "NAN"  <=========

/** Test d'affichage.*/
void printTest() {

	cout<<"This is the print test running."<<endl;

	Accelerator a;

	Dipole* d = new Dipole(Vector3D(1,0,0), Vector3D(0,-1,0), 0.1, 1, Vector3D(0,0,7), NULL);
	Particle* p1 = new Particle(
			Vector3D( 1.00984,-0.191837,0 ),//position
			constants::PROTON_MASS,//mass
			constants::E,//charge
			2*constants::GeV,//energy
			Vector3D(-1,-1,0));//direction

	Particle* p2 = new Particle(
			Vector3D(0.99016,-0.191837,0),
			constants::PROTON_MASS,//mass
			constants::E,//charge
			2*constants::GeV,//energy
			Vector3D(1,-1,0));//direction

	a.add(*d);
	a.add(*p1);
	a.add(*p2);

	Accelerator b;

	b.add(*d);

	Accelerator empty;


	//TODO la maille FODO n'est pas comptée comme un seul élément qui en contient d'autres, mais comme un seul.
	cout << "Inspecting first accelerator..." << endl
		 << a << endl
		 << "Inspecting second accelerator..." << endl
		 << b << endl
		 << "Inspecting third accelerator..." << endl
		 << empty << endl;

	a.clear();
	b.clear();
}

/** Construit un accélérateur standard sans particule et renvoie un pointeur dessus.*/
Accelerator* standardAccelerator() {
	FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.2, 1.0, 5.0);
	Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.2, 1);
	FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.2, 1, 5.0);
	Dipole e4 = Dipole(e3.getExitPosition(), Vector3D(-3, -2, 0), 0.2, 1);
	FODO e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.2, 1.0, 5.0);
	Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.2, 1);
	FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.2, 1.0, 5.0);
	Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.2, 1);
	Accelerator* acc = new Accelerator();
	acc->add(e1);
	acc->add(e2);
	acc->add(e3);
	acc->add(e4);
	acc->add(e5);
	acc->add(e6);
	acc->add(e7);
	acc->add(e8);

	acc->close();

	return acc;
}

/** Test de simulateur.*/
void simulatorTest() {

	cout<<"This is the simulator test running."<<endl;

	Accelerator* a = standardAccelerator();

	Particle p1 (a->getElements().front()->getEntryPosition(), 9.11E-31, constants::E);

	a->step(1.);

	a->clear();

	delete a;
}

/** Lance les tests.*/
int main() {

	simulatorTest();

	printTest();

	return 0;
}