summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-04-12 17:42:39 +0000
committerJakob Odersky <jodersky@gmail.com>2011-04-12 17:42:39 +0000
commit38eee03034f777fbe05d8d0ca948375a4f5ab74c (patch)
tree96a40331832124bda373d8bb1b82bc2888786188 /src/test
parentae67598b211734f60a2e9f82622a84699eac4e45 (diff)
downloadvhc-38eee03034f777fbe05d8d0ca948375a4f5ab74c.tar.gz
vhc-38eee03034f777fbe05d8d0ca948375a4f5ab74c.tar.bz2
vhc-38eee03034f777fbe05d8d0ca948375a4f5ab74c.zip
Debut de creation d'une classe scene pour la simulation graphique.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/AccelTest.cc7
-rw-r--r--src/test/ParticleTest.cc48
2 files changed, 37 insertions, 18 deletions
diff --git a/src/test/AccelTest.cc b/src/test/AccelTest.cc
index e3c40cd..d7cbe79 100644
--- a/src/test/AccelTest.cc
+++ b/src/test/AccelTest.cc
@@ -6,17 +6,16 @@
*/
-#include "Accelerator.h"
+//#include "Accelerator.h"
#include <iostream>
#include <string>
#include <vector>
-using namespace vhc;
using namespace std;
/** lance le test*/
//TODO test avec un accélérateur initialisé
int main() {
- Accelerator a();
- cout << a << endl;
+ //Accelerator a();
+ //cout << a << endl;
return 0;
}
diff --git a/src/test/ParticleTest.cc b/src/test/ParticleTest.cc
index 30cd93a..d30aab0 100644
--- a/src/test/ParticleTest.cc
+++ b/src/test/ParticleTest.cc
@@ -8,6 +8,7 @@
#include <iostream>
#include <string>
#include <vector>
+#include "constants.h"
#include "StraightElement.h"
#include "Dipole.h"
#include "Quadrupole.h"
@@ -17,24 +18,41 @@
using namespace vhc;
using namespace std;
-Particle particle(Vector3D(0,0,0), 5.1, constants::e, 150, Vector3D::i);
-Element* element;
+Element* element = NULL;
+Particle* particle = NULL;
void step(double h);
+double toKg(double mGeV) {
+ return constants::e / constants::c2 * 1E9 * mGeV;
+}
+
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;
+ Vector3D entry = Vector3D(0, 10, 0);
+ Vector3D exit = Vector3D(10, 0, 0);
+ double sectionRadius = 0.2;
+ double curvature = 0.1;
+ Vector3D direction = entry.cross(Vector3D::k);
+
+ double mass = 5.1E-4; //GeV
+ double charge = constants::e; //C
+ double energy = 1; //GeV
+
+ particle = new Particle(entry, mass, charge, energy, direction);
+ double Bz = particle->getGamma() * particle->getMassKg() * curvature * particle->getVelocity().norm() / particle->getCharge();
+ cout << Bz << endl;
+ element = new Dipole(entry, exit, sectionRadius, curvature, Vector3D::k * Bz);
+
+ cout << *element << endl;
double t = 0;
- double h = 1E-9;
+ double h = 1E-12;
char c('0');
bool hit = false;
do {
- if (element->isOutside(particle)) hit = true;
+ if (element->isOutside(*particle)) hit = true;
+ cout << "t = " << t << endl;
step(h);
t += h;
cin.get(c);
@@ -45,17 +63,19 @@ int main() {
}
+
+ delete particle;
delete element;
return 0;
}
void step(double h) {
- particle.applyMagneticForce(element->magneticFieldAt(particle.getPosition()), 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);
+ Vector3D a = particle->getForce() / (particle->getGamma() * particle->getMassKg());
+ particle->setVelocity(particle->getVelocity() + a * h);
+ particle->setPosition(particle->getPosition() + particle->getVelocity() * h);
+ cout << *particle << endl;
+ particle->setForce(Vector3D::Null);
}