summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2011-05-01 14:07:41 +0000
committerJakob Odersky <jodersky@gmail.com>2011-05-01 14:07:41 +0000
commit2ade21c3d97189d26f9dc18e2e805a0b05a4eaaf (patch)
treede48758990e96b1fec8a6e097656bb0b59dfa4fc
parent9b765d14760bddc1caac167e938670031d70a864 (diff)
downloadvhc-2ade21c3d97189d26f9dc18e2e805a0b05a4eaaf.tar.gz
vhc-2ade21c3d97189d26f9dc18e2e805a0b05a4eaaf.tar.bz2
vhc-2ade21c3d97189d26f9dc18e2e805a0b05a4eaaf.zip
Changements importants dans l'accelerateur. Nous travaillons maintenant avec une list au lieu d'un vector. Ceci pour pouvoir supprimer une particule a temps constant qui aurait heurte le bord d'un element. On ne peut donc plus acceder a un element quelconque de la liste mais il faut l'iterer!
Mais comme, de toutes facons, on ne fait que d'iterer sur une liste lors d'une simulation deterministe ceci convient. Peut-etre il faudra adapter cette conception pour une simulation monte-carlo.
-rw-r--r--reponses.lyx32
-rw-r--r--src/gui/Main.cc50
-rw-r--r--src/gui/Stage.cc21
-rw-r--r--src/main/Accelerator.cc121
-rw-r--r--src/main/Accelerator.h134
-rw-r--r--src/main/CompositeElement.cc8
-rw-r--r--src/main/FODO.cc4
-rw-r--r--src/main/Quadrupole.cc6
-rw-r--r--src/main/Stepper.cc16
-rw-r--r--src/main/Stepper.h27
-rw-r--r--src/test/ElementTest.cc33
11 files changed, 257 insertions, 195 deletions
diff --git a/reponses.lyx b/reponses.lyx
index f73b117..cc63b8c 100644
--- a/reponses.lyx
+++ b/reponses.lyx
@@ -559,10 +559,11 @@ Question P8.1
En termes de POO, cela signifie que la méthode
\family typewriter
\size small
-hasHit
+heurte_bord
\family default
\size default
- est virtuelle (même virtuelle pure à l'intérieur de la classe
+ (`isBeside' dans notre cas) est virtuelle (même virtuelle pure à l'intérieur
+ de la classe
\family typewriter
\size small
Element
@@ -583,9 +584,9 @@ Element
\family default
\size default
est
-\shape italic
+\emph on
abstraite
-\shape default
+\emph default
.
\end_layout
@@ -594,28 +595,7 @@ Question P8.3
\end_layout
\begin_layout Standard
-La méthode
-\family typewriter
-\size small
-Printable
-\family default
-\size default
- est elle aussi
-\shape italic
-abstraite
-\shape default
-, on y a implément une méthode générique
-\family typewriter
-\size small
-toString
-\family default
-\size default
-.
- Cette méthode est
-\shape italic
-virtuelle pure
-\shape default
-.
+La méthode `dessine' est elle aussi virtuelle pure dans la classe dessinable.
\end_layout
\begin_layout Section*
diff --git a/src/gui/Main.cc b/src/gui/Main.cc
index e966a18..79242ca 100644
--- a/src/gui/Main.cc
+++ b/src/gui/Main.cc
@@ -85,14 +85,16 @@ Une particule :
*
*/
- FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.1, 1.0, 1.2);
- Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.1, 1, Vector3D(0, 0, 5.89158));
- FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.1, 1, 1.2);
- Dipole e4 = Dipole(e3.getExitPosition(), Vector3D(-3, -2, 0), 0.1, 1, Vector3D(0, 0, 5.89158));
- FODO e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.1, 1.0, 1.2);
- Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.1, 1, Vector3D(0, 0, 5.89158));
- FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.1, 1.0, 1.2);
- Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.1, 1, Vector3D(0, 0, 5.89158));
+ double B = 5.8915820038873;
+ double b = 1.2;
+ FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.1, 1.0, b);
+ Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.1, 1, Vector3D(0, 0, B));
+ FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.1, 1, b);
+ Dipole e4 = Dipole(e3.getExitPosition(), Vector3D(-3, -2, 0), 0.1, 1, Vector3D(0, 0, B));
+ FODO e5 = FODO(e4.getExitPosition(), Vector3D(-3, 2, 0), 0.1, 1.0, b);
+ Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.1, 1, Vector3D(0, 0, B));
+ FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.1, 1.0, b);
+ Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.1, 1, Vector3D(0, 0, B));
Accelerator* acc = new Accelerator();
acc->add(e1);
acc->add(e2);
@@ -103,7 +105,7 @@ Une particule :
acc->add(e7);
acc->add(e8);
- Particle p1 = Particle(Vector3D(3.01, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j);
+ Particle p1 = Particle(Vector3D(3.00, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j);
Particle p2 = Particle(Vector3D(2.99, 0, 0), constants::PROTON_MASS, constants::E, 2 * constants::GeV, -Vector3D::j);
acc->add(p1);
acc->add(p2);
@@ -143,16 +145,20 @@ Accelerator* standardAccelerator() {
}
Accelerator* linear() {
- FODO element = FODO(Vector3D(0, 0, 0), Vector3D(4, 0, 0), 0.2, 0.2, 120);
Accelerator* acc = new Accelerator();
- Element* celement = acc->add(element);
- Particle e(Vector3D(0, 0.15, 0.01), constants::ELECTRON_MASS, constants::E, 14E9 * constants::E, Vector3D::i);
- Particle* ce = acc->add(e);
- ce->setElement(celement);
+
+ for(int i = 0; i < 10; ++i) {
+ FODO e = FODO(Vector3D(4, 0, 0) * i, Vector3D(4, 0, 0) * (i + 1), 0.1, 1, 1.2);
+ acc->add(e);
+ }
+
+ Particle e(Vector3D(0, 0.05, 0.01), constants::PROTON_MASS, constants::E, 2 * constants::GeV, Vector3D::i);
+ acc->add(e);
+ acc->close();
return acc;
}
-
+/*
Accelerator* singleDipole() {
Vector3D entry = Vector3D(0, 2, 0);
Vector3D exit = Vector3D(2, 0, 0);
@@ -172,7 +178,7 @@ Accelerator* singleDipole() {
Accelerator* acc = new Accelerator();
- Element* celement = acc->add(element);
+ Element*\ celement = acc->add(element);
std::vector< Particle > ps = createParticles(element.getEntryPosition(), 10, constants::ELECTRON_MASS, constants::E, energy, direction);
@@ -184,7 +190,7 @@ Accelerator* singleDipole() {
Particle* cparticle = acc->add(particle);
cparticle->setElement(celement);
return acc;
-}
+}*/
int main(int argc, char *argv[])
@@ -199,18 +205,16 @@ int main(int argc, char *argv[])
cout.flush();
window.accelerator = acc;
+ window.setWindowTitle("Virtual Hadron Collider");
+ window.resize(QSize(500, 500));
+ window.show();
window.showFullScreen();
- //window.resize(QSize(500, 500));
- window.setWindowTitle("Virtual Hadron Collider");
- window.show();
-
+ //app.setActiveWindow(&window);
return app.exec();
- delete acc; acc = NULL;
-
} catch (Exception& ex){
std::cerr << ex.toString() << "\n";
}
diff --git a/src/gui/Stage.cc b/src/gui/Stage.cc
index 6dec091..13c3411 100644
--- a/src/gui/Stage.cc
+++ b/src/gui/Stage.cc
@@ -6,9 +6,12 @@
*/
#include <iostream>
+#include <list>
+#include <algorithm>
#include "util.h"
#include "Stage.h"
+using namespace std;
using namespace vhc::util;
namespace vhc {
@@ -22,14 +25,14 @@ Stage::Stage(QWidget* parent):
displayMode(FILL),
keys(0),
frameTime(0),
- h(1E-11),
+ h(1E-12),
paused(true) {
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
- timer->start(1000.0/60);
+ timer->start(1000.0/100);
setMouseTracking(true);
}
@@ -65,6 +68,8 @@ void Stage::paintGL() {
renderText(0,24,QString("camera coordinates: ") + camera.getPosition().toString().c_str());
renderText(0,36,QString("heading: ") + QString::number(camera.getHeading()));
renderText(0,48,QString("pitch: ") + QString::number(camera.getPitch()));
+ //renderText(0,60,QString("") + accelerator->getParticle(0)->getElement()->magneticFieldAt(accelerator->getParticle(0)->getPosition()).toString().c_str());
+ //renderText(0,72,QString("") + accelerator->getParticle(0)->toString().c_str());
axes();
@@ -73,7 +78,6 @@ void Stage::paintGL() {
glColor3d(0.5, 0.5, 0.5);
grid(20);
glPopMatrix();
-
// glScaled (100.0, 100.0, 100.0);
@@ -98,15 +102,16 @@ void Stage::paintGL() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
- for (unsigned int i = 0; i < accelerator->getElements().size(); ++i) {
- elementRenderer.render(*(accelerator->getElements()[i]));
+ for (list<Element*>::const_iterator i = accelerator->getElements().begin(); i != accelerator->getElements().end(); ++i) {
+ elementRenderer.render(**i);
}
+
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glColor3d(0, 0, 1);
- for (unsigned int i = 0; i < accelerator->getParticles().size(); ++i) {
- particleRenderer.render(*(accelerator->getParticles()[i]));
+ for (list<Particle*>::const_iterator i = accelerator->getParticles().begin(); i != accelerator->getParticles().end(); ++i) {
+ particleRenderer.render(**i);
}
}
@@ -123,7 +128,7 @@ void Stage::paintGL() {
camera.move(mv);
}
- if (!paused) accelerator->step(h * frameTime / 1000 * 100);
+ if (!paused) for (int i = 0; i < 100; ++i) accelerator->step(h);
glColor3d(1,1,0);
util::crosshair();
diff --git a/src/main/Accelerator.cc b/src/main/Accelerator.cc
index 0405d59..124cec1 100644
--- a/src/main/Accelerator.cc
+++ b/src/main/Accelerator.cc
@@ -5,10 +5,119 @@
* Author: christian
*/
+#include <iostream>
#include "Accelerator.h"
+#include "exceptions.h"
+
+using namespace std;
namespace vhc {
+Element& Accelerator::add(const Element& element) {
+ Element* e = element.clone();
+ elementCollec.push_back(e);
+ return *e;
+}
+
+Particle& Accelerator::add(const Particle& particle) {
+ Particle* p = particle.clone();
+ particleCollec.push_back(p);
+ return *p;
+}
+
+const list<Element*>& Accelerator::getElements() const { return elementCollec;}
+
+const list<Particle*>& Accelerator::getParticles() const { return particleCollec;}
+
+void Accelerator::close() {
+ for (list<Element*>::iterator current = elementCollec.begin(); current != elementCollec.end(); ++current) {
+
+ list<Element*>::iterator next = current;
+ ++next;
+ if (next == elementCollec.end()) next = elementCollec.begin();
+
+
+ // est-ce que les elements se suivent?
+ if (Vector3D::ae((*current)->getExitPosition(), (*next)->getEntryPosition())) {
+ (**current).setNext(*next);
+ (**next).setPrevious(*current);
+ } else
+ throw UnsupportedOperationException("Cannot close accelerator. Two succeeding elements are not physically connected! (not close enough)");
+ }
+
+ //rajouter les particules dans leurs elements respectifs
+ for (list<Particle*>::iterator i = particleCollec.begin(); i != particleCollec.end(); ++i) {
+
+ for (list<Element*>::iterator j = elementCollec.begin(); j != elementCollec.end(); ++j) {
+ if ((**j).contains(**i)) {
+ (**i).setElement(*j);
+ break;
+ }
+ }
+
+ //si une particule n'est pas contenue dans un element elle est supprimee
+ if ((**i).getElement() == NULL) {
+ delete *i;
+ i = particleCollec.erase(i);
+ --i;
+ std::cout << "Particle hit wall. Removed from simulation" << std::endl;
+ }
+
+ }
+
+}
+
+
+void Accelerator::updateParticles() {
+ for (list<Particle*>::iterator i = particleCollec.begin(); i != particleCollec.end(); ++i) {
+ Particle& particle = **i;
+ if (particle.getElement()->isBeside(particle)) {
+ std::cout << "Particle hit wall. Removed from simulation" << std::endl;
+ delete *i;
+ i = particleCollec.erase(i);
+ --i;
+ } else if (particle.getElement()->isAfter(particle)) {
+ if (particle.getElement()->getNext() == NULL) throw Exception("Element in accelerator not connected to next.");
+ else particle.setElement(particle.getElement()->getNext());
+ } else if (particle.getElement()->isBefore(particle)) {
+ if (particle.getElement()->getPrevious() == NULL) throw Exception("Element in accelerator not connected to previous.");
+ else particle.setElement(particle.getElement()->getPrevious());
+ }
+ }
+}
+
+void Accelerator::clear() {
+ for (list<Particle*>::iterator i = particleCollec.begin(); i != particleCollec.end(); ++i) {
+ delete *i;
+ *i = NULL;
+ }
+ particleCollec.clear();
+
+ for (list<Element*>::iterator i = elementCollec.begin(); i != elementCollec.end(); ++i) {
+ delete *i;
+ *i = NULL;
+ }
+ elementCollec.clear();
+}
+
+void Accelerator::step(double dt) {
+
+ for (list<Particle*>::iterator i = particleCollec.begin(); i != particleCollec.end(); ++i) {
+ Particle& particle = **i;
+
+ particle.applyMagneticForce(particle.getElement()->magneticFieldAt(particle.getPosition()), dt);
+
+ Vector3D a = particle.getForce() / (particle.getGamma() * particle.getMass());
+ particle.setVelocity(particle.getVelocity() + a * dt);
+
+ particle.translate(particle.getVelocity() * dt);
+ particle.setForce(Vector3D::Null);
+ }
+
+
+ updateParticles();
+}
+
/** Cf. Accelerator.h */
std::string Accelerator::toString() const {
std::stringstream s;
@@ -17,11 +126,11 @@ std::string Accelerator::toString() const {
s << "This accelerator doesn't contain anything."<<"\n";
} else if (elementCollec.size()==1) {
s << "This accelerator is made of the following element :" << "\n";
- s << elementCollec[0]->toString()<<"\n";
+ s << elementCollec.front()->toString()<<"\n";
} else {
s << "This accelerator is made of the " << elementCollec.size() << " following elements :" << "\n";
- for (int i(0); i < elementCollec.size(); ++i){
- s << elementCollec[i]->toString() << "\n";
+ for (list<Element*>::const_iterator i = elementCollec.begin(); i != elementCollec.end(); ++i) {
+ s << (*i)->toString() << "\n";
}
}
@@ -29,11 +138,11 @@ std::string Accelerator::toString() const {
s << "This accelerator doesn't contain any particle." << "\n";
} else if (particleCollec.size() == 1) {
s << "This accelerator contains the following particle :" << "\n";
- s << particleCollec[0]->toString() << "\n";
+ s << particleCollec.front()->toString() << "\n";
}else{
s << "This accelerator contains the " << particleCollec.size() << " following particles :"<<"\n";
- for (int i(0); i < particleCollec.size(); ++i){
- s << particleCollec[i]->toString() << "\n";
+ for (list<Particle*>::const_iterator i = particleCollec.begin(); i != particleCollec.end(); ++i) {
+ s << (*i)->toString() << "\n";
}
}
diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h
index deeaf69..d3c26e0 100644
--- a/src/main/Accelerator.h
+++ b/src/main/Accelerator.h
@@ -7,10 +7,7 @@
#ifndef ACCELERATOR_H_
#define ACCELERATOR_H_
-#include <iostream>
-#include <vector>
-#include <limits>
-#include "exceptions.h"
+#include <list>
#include "Vector3D.h"
#include "Particle.h"
#include "Element.h"
@@ -19,7 +16,7 @@ namespace vhc {
/** Représente un accélérateur. Cette classe contient en particulier une méthode
* qui fait évoluer les particules qu'elle contient. */
-class Accelerator: public Printable{
+class Accelerator: public Printable {
private :
/** Constructeur de copie ne faisant rien. */
@@ -30,13 +27,12 @@ private :
protected:
- /*Attributs d'un accélérateur : une collection d'éléments, et une de particules. */
-
/** Collection d'elements contenus dans cet accelerateur. */
- std::vector< Element * > elementCollec;
+ std::list< Element * > elementCollec;
/** Collection de particules contenus danc cet accelerateur. */
- std::vector< Particle *> particleCollec;
+ std::list< Particle *> particleCollec;
+
public:
@@ -48,125 +44,31 @@ public:
virtual ~Accelerator() {clear();}
- /** Retourne un pointeur sur un élément de l'accélérateur.*/
- Element *const getElement(int rank) const { return elementCollec[rank];}
-
- /* Retourne un pointeur sur une particule de l'accélérateur.*/
- Particle *const getParticle(int rank) const { return particleCollec[rank];}
-
- /** Retourne une représentation en chaîne de caractères de cet accélérateur. */
- virtual std::string toString() const;
-
/** Copie un élément dans l'accélérateur. */
- Element *const add(const Element& element) {
- Element* e = element.clone();
- elementCollec.push_back(e);
- return e;
- }
+ Element& add(const Element& element);
/** Copie une particule dans l'accélérateur. */
- Particle *const add(const Particle& particle){
- Particle* p = particle.clone();
- particleCollec.push_back(p);
- return p;
- }
-
- /** Ferme l'accelerateur. */
- void close() {
- for (int i = 0; i < elementCollec.size(); ++i) {
- //element i
- Element* current = elementCollec[i];
-
- //element i+1
- Element* next = elementCollec[(i+1) % elementCollec.size()];
-
- // est-ce que les elements se suivent?
- if (Vector3D::ae(current->getExitPosition(), next->getEntryPosition())) {
- current->setNext(next);
- next->setPrevious(current);
- } else throw UnsupportedOperationException("Cannot close accelerator. Two succeeding elements are not physically connected! (not close enough)");
- }
-
-
- //rajouter les particules dans leurs elements respectifs
- for (int i = 0; i < particleCollec.size(); ++i) {
+ Particle& add(const Particle& particle);
- for (int j = 0; j < elementCollec.size(); ++j) {
+ /** Retourne la liste d'elements contenus dans cet accelerateur. */
+ const std::list<Element*> & getElements() const;
- if (elementCollec[j]->contains(*particleCollec[i])) {
- particleCollec[i]->setElement(elementCollec[j]);
- break;
- }
- }
+ /** Retourne la liste des particules contenus dans cet accelerateur. */
+ const std::list<Particle*> & getParticles() const;
- //si une particule n'est pas contenue dans un element elle est supprimee
- if (particleCollec[i]->getElement() == NULL) {
- delete particleCollec[i];
- particleCollec[i] = particleCollec[particleCollec.size() - 1];
- particleCollec.pop_back();
- --i;
- }
-
- }
-
- }
+ /** Ferme l'accelerateur. */
+ void close();
/** Efface tous les éléments et les particules. */
- void clear() {
- for (unsigned int i = 0; i < particleCollec.size(); ++i) {
- delete particleCollec[i];
- particleCollec[i] = NULL;
- }
- particleCollec.clear();
-
- for (unsigned int i = 0; i < elementCollec.size(); ++i) {
- delete elementCollec[i];
- elementCollec[i] = NULL;
- }
- elementCollec.clear();
- }
-
- /** Retourne la liste des éléments de l'accélérateur.*/
- const std::vector< Element* >& getElements() const {
- return elementCollec;
- }
-
- /** Retourne la liste des particules de l'accélérateur.*/
- const std::vector< Particle* >& getParticles() const {
- return particleCollec;
- }
+ void clear();
+ void updateParticles();
/** Fait évoluer l'accélérateur d'un laps de temps dt. */
- void step(double dt) {
-
- for (int i = 0; i < particleCollec.size(); ++i) {
- Particle& particle = *particleCollec[i];
-
- particle.applyMagneticForce(particle.getElement()->magneticFieldAt(particle.getPosition()), dt);
-
- Vector3D a = particle.getForce() / (particle.getGamma() * particle.getMass());
- particle.setVelocity(particle.getVelocity() + a * dt);
-
- particle.translate(particle.getVelocity() * dt);
- particle.setForce(Vector3D::Null);
+ void step(double dt);
- if (particle.getElement()->isBeside(particle)) std::cout << "Particle hit wall!" << std::endl;
- if (particle.getElement()->isAfter(particle)) { // si la particule est passee, qui sait si elle est dans l'element suivant?
- if (!particle.getElement()->isConnected()) throw Exception("Element in accelerator not connected.");
- else particle.setElement(particle.getElement()->getNext());
- }
- }
-
- }
-
- /*
- void* stepMonteCarlo();
-
- void* stepDeterministBackUp();
-
- void* stepDeterminist();
-*/
+ /** Retourne une représentation en chaîne de caractères de cet accélérateur. */
+ virtual std::string toString() const;
};
}
diff --git a/src/main/CompositeElement.cc b/src/main/CompositeElement.cc
index 47f0363..3e4a216 100644
--- a/src/main/CompositeElement.cc
+++ b/src/main/CompositeElement.cc
@@ -33,17 +33,17 @@ bool CompositeElement::isAfter(const Vector3D& position) const {
}
Vector3D CompositeElement::magneticFieldAt(const Vector3D& position) const {
- Vector3D b = Vector3D::Null;
+ MutableVector3D b = Vector3D::Null;
for (int i(0); i < elements.size(); i++) {
- b = b + elements[i]->magneticFieldAt(position);
+ b += elements[i]->magneticFieldAt(position);
}
return b;
}
Vector3D CompositeElement::electricFieldAt(const Vector3D& position) const {
- Vector3D e = Vector3D::Null;
+ MutableVector3D e = Vector3D::Null;
for (int i(0); i < elements.size(); i++) {
- e = e + elements[i]->electricFieldAt(position);
+ e += elements[i]->electricFieldAt(position);
}
return e;
}
diff --git a/src/main/FODO.cc b/src/main/FODO.cc
index 9424e3f..f8ed892 100644
--- a/src/main/FODO.cc
+++ b/src/main/FODO.cc
@@ -29,13 +29,13 @@ FODO::FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, do
Vector3D d = getDiagonal().unit();
- focalizingQuadrupole = new Quadrupole(entry, entry + d * l, sectionRadius, focalizingCoefficient);
+ focalizingQuadrupole = new Quadrupole(entry, entry + d * l, sectionRadius, this->focalizingCoefficient);
elements.push_back(focalizingQuadrupole);
straightElement1 = new StraightElement(focalizingQuadrupole->getExitPosition(), focalizingQuadrupole->getExitPosition() + d * L, sectionRadius);
elements.push_back(straightElement1);
- defocalizingQuadrupole = new Quadrupole(straightElement1->getExitPosition(), straightElement1->getExitPosition() + d * l, sectionRadius, -focalizingCoefficient);
+ defocalizingQuadrupole = new Quadrupole(straightElement1->getExitPosition(), straightElement1->getExitPosition() + d * l, sectionRadius, -this->focalizingCoefficient);
elements.push_back(defocalizingQuadrupole);
straightElement2 = new StraightElement(defocalizingQuadrupole->getExitPosition(), exit, sectionRadius);
diff --git a/src/main/Quadrupole.cc b/src/main/Quadrupole.cc
index 2d65dc4..3507221 100644
--- a/src/main/Quadrupole.cc
+++ b/src/main/Quadrupole.cc
@@ -19,12 +19,12 @@ Quadrupole::Quadrupole(const Vector3D& entry, const Vector3D& exit, double secti
Quadrupole::~Quadrupole() {};
Vector3D Quadrupole::magneticFieldAt(const Vector3D& position) const {
- if (!Quadrupole::contains(position)) return Vector3D::Null;
+ if (!contains(position)) return Vector3D::Null;
Vector3D x = position - getEntryPosition();
Vector3D d = getDiagonal().unit();
- Vector3D y = x - x.dot(d) * d;
+ Vector3D y = x - (x.dot(d) * d);
Vector3D u = Vector3D::k.cross(d);
- return focalizingCoefficient * (y.dot(u) * Vector3D::k + position.getZ() * u);
+ return focalizingCoefficient * (y.dot(u) * Vector3D::k + x.getZ() * u);
}
double Quadrupole::getFocalizingCoefficient() const {
diff --git a/src/main/Stepper.cc b/src/main/Stepper.cc
new file mode 100644
index 0000000..acc1ee9
--- /dev/null
+++ b/src/main/Stepper.cc
@@ -0,0 +1,16 @@
+/*
+ * Stepper.cc
+ *
+ * Created on: Apr 24, 2011
+ * Author: jakob
+ */
+
+#include "Stepper.h"
+
+namespace vhc {
+
+Stepper::Stepper() {}
+
+Stepper::~Stepper() {}
+
+}
diff --git a/src/main/Stepper.h b/src/main/Stepper.h
new file mode 100644
index 0000000..cbc31b9
--- /dev/null
+++ b/src/main/Stepper.h
@@ -0,0 +1,27 @@
+/*
+ * Stepper.h
+ *
+ * Created on: Apr 24, 2011
+ * Author: jakob
+ */
+
+#ifndef STEPPER_H_
+#define STEPPER_H_
+
+#include <vector>
+#include "Accelerator.h"
+
+namespace vhc {
+
+class Stepper {
+
+public:
+ Stepper();
+ virtual ~Stepper();
+
+ virtual void step(const std::vector< Element* > & elements, const std::vector< Particle* > & particles, double dt) = 0;
+};
+
+}
+
+#endif /* STEPPER_H_ */
diff --git a/src/test/ElementTest.cc b/src/test/ElementTest.cc
index a17e0bb..45e0041 100644
--- a/src/test/ElementTest.cc
+++ b/src/test/ElementTest.cc
@@ -7,8 +7,11 @@
#include <iostream>
#include <assert.h>
+#include "exceptions.h"
+#include "CurvedElement.h"
#include "Dipole.h"
#include "FODO.h"
+#include "Quadrupole.h"
#include "Vector3D.h"
using namespace std;
@@ -25,22 +28,38 @@ int main() {
cout << *fodo << endl;
delete fodo; fodo = NULL;
-/*
- CurvedElement* c = new CurvedElement(Vector3D(0,1,0), Vector3D(1,0,0), 0.2, 1);
- cout << *c << endl;
- delete c; c = NULL;
-
//test d'initialisation illegale
bool caught = false;
try {
- CurvedElement(Vector3D(0,0,0), Vector3D(1,0,0), 0.2, 1.0 / 0.4);
+ Dipole(Vector3D(0,0,0), Vector3D(1,0,0), 0.2, 1.0 / 0.4, Vector3D(1,2,3));
// ^ le rayon de courbure est trop petit
} catch (Exception& e) {
caught = true;
};
assert(caught);
-*/
+ Quadrupole* fq = new Quadrupole(Vector3D(0,0,0), Vector3D(1, 0, 0), 0.1, 1.2);
+
+ //containement test
+ assert(fq->isBefore(Vector3D(-0.1,0,0)));
+ assert(fq->isBefore(Vector3D(-0.1,0.2,0)));
+ assert(fq->isBefore(Vector3D(-0.1,3,5)));
+
+ assert(fq->isBeside(Vector3D(0.1,0.2,0)));
+ assert(fq->isBeside(Vector3D(0.3,0,3)));
+ assert(fq->isBeside(Vector3D(0.5,-2,-4)));
+
+ assert(fq->isAfter(Vector3D(1.1,0,0)));
+ assert(fq->isAfter(Vector3D(1.3,0.3,-0.2)));
+ assert(fq->isAfter(Vector3D(1.001,-0.04,0.02)));
+
+ assert(fq->contains(Vector3D(0.5,0,0)));
+ assert(fq->contains(Vector3D(0.99,0.1, 0)));
+ assert(fq->contains(Vector3D(0.1,0.02,-0.02)));
+
+ delete fq; fq = NULL;
+
+
return 0;
}