summaryrefslogtreecommitdiff
path: root/src/test/exerciceP11Test.cc
blob: fcb7bb5592cb0dc9d234f446a872b525364984b6 (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
117
118
/*
 * exerciceP11Test.cc
 *
 *  Created on: 5 mai 2011
 *      Author: christian
 */


#include <iostream>
#include "exceptions.h"
#include "Dipole.h"
#include "FODO.h"
#include "Accelerator.h"
#include "Particle.h"

using namespace std;
using namespace vhc;


// Construction par boucle à bannir car ne garantit pas que les entrées-sorties de séléments soient cohérents.
// De plus il n'extise aucune moyen d'initaliser ces attributs automatiquement.
Accelerator* creatAcc() {


	Accelerator* acc = new Accelerator();

	for(unsigned int i(0); i<4; ++i){

		FODO* fodo = new FODO(Vector3D(0,0,0),Vector3D(1, 0,0),	0.2	,	1.	,	1.2);
//									entry			exit		Re		l		b
		acc->add( *fodo );

		Dipole* d = new Dipole(Vector3D(0,0,0),Vector3D(1,2,0),	0.1,	1,	Vector3D(0,0,5.89158));
//								entry				exit				Re		Rc	B
		acc->add( *d );
	}
		acc->close();

	return acc;
}

Accelerator* creatAccChap() {

	Accelerator* acc = new Accelerator();

	FODO* fodo1 = new FODO(Vector3D(3,2,0),Vector3D(3,-2,0),		0.2	,	1.	,	1.2);
//									entry			exit			Re		l		b
	Dipole* d1 = new Dipole(Vector3D(3,-2,0),Vector3D(2,-3,0),		0.1,	1,	Vector3D(0,0,5.89158));
//									entry			exit			Re		Rc	B
	FODO* fodo2 = new FODO(Vector3D(2,-3,0),Vector3D(-2,-3,0),		0.2	,	1.	,	1.2);
//									entry			exit			Re		l		b
	Dipole* d2 = new Dipole(Vector3D(-2,-3,0),Vector3D(-3,-2,0),	0.1,	1,	Vector3D(0,0,5.89158));
//									entry			exit			Re		Rc	B
	FODO* fodo3 = new FODO(Vector3D(-3,-2,0),Vector3D(-3,2,0),		0.2	,	1.	,	1.2);
//									entry			exit			Re		l		b
	Dipole* d3 = new Dipole(Vector3D(-3,2,0),Vector3D(-2,3,0),		0.1,	1,	Vector3D(0,0,5.89158));
//									entry			exit			Re		Rc	B
	FODO* fodo4 = new FODO(Vector3D(-2,3,0),Vector3D(2,3,0),		0.2	,	1.	,	1.2);
//									entry			exit			Re		l		b
	Dipole* d4 = new Dipole(Vector3D(2,3,0),Vector3D(3,2,0),		0.1,	1,	Vector3D(0,0,5.89158));
//									entry			exit			Re		Rc	B

	acc->add(*fodo1); acc->add(*d1); acc->add(*fodo2); acc->add(*d2);
	acc->add(*fodo3); acc->add(*d3); acc->add(*fodo4); acc->add(*d4);

	acc->close();

	return acc;
}

void fillWithParts(Accelerator* acc){

	Particle* p1 = new Particle(
			Vector3D(3.01,0,0),//position
			constants::PROTON_MASS,//mass
			constants::E,//charge
			2*constants::GeV,//energy
			Vector3D(0,-1,0));//direction

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

	acc->add(*p1); acc->add(*p2);

	acc->close();

}

void makeTest(){

	Accelerator* a = creatAccChap();

	fillWithParts(a);


	cout<< *a << "\n";

	int it(4);

	cout<<"Beginning simulation...\n";

	for(unsigned int j(0); j<it; ++j){
		a->step(10E-11);
		cout<<"after "<<j+1<<" step :"<<endl<<"part 1 :"<< (a->getParticles().front()->toString()) <<endl;
		cout<<"after "<<j+1<<" step :"<<endl<<"part 2 :"<< (a->getParticles().back()->toString()) <<endl;
	}
}

int main() {

	makeTest();

	return 0;
}