diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 20:05:38 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 20:05:38 +0000 |
commit | 964f0f8a7c88c1128c2edbef1fb36a86ed9864cf (patch) | |
tree | 38ef5ce1e578e7a40f3b08d30cee8666f0bea2e4 | |
parent | 064e27d5e7bf451542cc89ee0a05a06447acdc88 (diff) | |
download | vhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.tar.gz vhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.tar.bz2 vhc-964f0f8a7c88c1128c2edbef1fb36a86ed9864cf.zip |
Migration de tous les implementations dans les fichier .h vers les fichiers .cc
35 files changed, 593 insertions, 363 deletions
@@ -1491,7 +1491,7 @@ HIDE_UNDOC_RELATIONS = YES # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) -HAVE_DOT = NO +HAVE_DOT = YES # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is # allowed to run in parallel. When set to 0 (the default) doxygen will diff --git a/src/gui/Camera.h b/src/gui/Camera.h index dc5b614..f5ce954 100644 --- a/src/gui/Camera.h +++ b/src/gui/Camera.h @@ -9,7 +9,7 @@ #define CAMERA_H_ #include <cmath> #include <QtOpenGL> -#include "exception.h" +#include "exceptions.h" #include "Vector3D.h" namespace vhc { diff --git a/src/gui/ElementRenderer.cc b/src/gui/ElementRenderer.cc index 5066a5d..f4012ea 100644 --- a/src/gui/ElementRenderer.cc +++ b/src/gui/ElementRenderer.cc @@ -51,7 +51,7 @@ void ElementRenderer::visit(const StraightElement* straight) const { } void ElementRenderer::visit(const Quadrupole* quadrupole) const { - if (quadrupole->getFocusingCoefficient() > 1) + if (quadrupole->getFocalizingCoefficient() > 1) glColor4d(0.4, 0, 0, 0.9); else glColor4d(0.4, 0.2, 0.2, 0.9); diff --git a/src/gui/Makefile b/src/gui/Makefile index e2266af..b9bd9e6 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: $(BINDIR)/gui/gui -# Generated by qmake (2.01a) (Qt 4.7.0) on: Sat Apr 16 22:07:50 2011 +# Generated by qmake (2.01a) (Qt 4.7.0) on: Sun Apr 17 21:55:28 2011 # Project: gui.pro # Template: app # Command: /usr/bin/qmake -o Makefile gui.pro diff --git a/src/gui/Stage.cc b/src/gui/Stage.cc index c3b09fc..8f5f729 100644 --- a/src/gui/Stage.cc +++ b/src/gui/Stage.cc @@ -26,7 +26,7 @@ Stage::Stage(QWidget* parent): connect(timer, SIGNAL(timeout()), this, SLOT(update())); - timer->start(1.0/60); + timer->start(1000.0/60); setMouseTracking(true); } @@ -122,29 +122,8 @@ void Stage::paintGL() { - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - double vp[4]; - glGetDoublev(GL_VIEWPORT, vp); - glOrtho(vp[0], vp[1], vp[2], vp[3],-1,1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); glColor3d(1,1,0); - - glBegin(GL_LINES); - glVertex3d(-0.01, 0,0); - glVertex3d(0.01, 0, 0); - glVertex3d(0,-0.01,0); - glVertex3d(0, 0.01, 0); - glEnd(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + util::crosshair(); frameTime = time.restart(); } diff --git a/src/gui/util.cc b/src/gui/util.cc index 11ac013..e460e36 100644 --- a/src/gui/util.cc +++ b/src/gui/util.cc @@ -80,6 +80,41 @@ void grid(int divisions) { glEnd(); } +void crosshair() { + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + double vp[4]; + glGetDoublev(GL_VIEWPORT, vp); + glOrtho(vp[0], vp[2], vp[1], vp[3],-1,1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + glLoadIdentity(); + glTranslated(vp[2] / 2, vp[3] / 2, 0); + + glBegin(GL_LINES); + glVertex3d(-5, 0,0); + glVertex3d(-2, 0, 0); + + glVertex3d(2, 0, 0); + glVertex3d(5, 0, 0); + + glVertex3d(0,-5,0); + glVertex3d(0, -2, 0); + + glVertex3d(0, 2,0); + glVertex3d(0, 5, 0); + glEnd(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} } } diff --git a/src/gui/util.h b/src/gui/util.h index e83b4d9..866ef96 100644 --- a/src/gui/util.h +++ b/src/gui/util.h @@ -9,29 +9,45 @@ #define UTIL_H_ namespace vhc { + +/** Contient des fonctions utilitaires. */ namespace util { -/** Dessine un tore autour de l'origine +/** Dessine un tore autour de l'origine, sur le plan xy. * @param R rayon du tore * @param r rayon du "cylindre" du tore - * @param fraction fraction de tore a dessiner (1 = un tour) + * @param fraction fraction du tore a dessiner (1 = un tour) * @param slices nombre de cotes du "cylindre" du tore * @param stacks nombre de cotes du tore */ void torus(double R, double r, double fraction, int slices = 12, int stacks = 20); +/** Dessine un cylindre partant de l'origine, direction de l'axe z. + * @param base rayon de la base du cylindre + * @param top rayon du haut du cylindre + * @param height hauteur du cylindre + * @param slices cotes laterales du cylindre + * @param stacks divisions en hauteur du cylindre */ void cylinder(double base, double top, double height, int slices = 12, int stacks = 20); + +/** Dessine une sphere centree a l'origine. + * @param radius rayon de la sphere + * @param slices cotes laterales de la sphere + * @param stacks divisions en hauteur de la sphere */ void sphere(double radius, int slices = 12, int stacks = 20); /** Dessine les axes unitaires d'un repere cartesien. - * Les axes ont les couleurs suivantes: x -> rouge, y -> vert, z -> bleu */ + * Les axes Ox, Oy et Oz ont les couleurs respectifs suivantes rouge, vert et bleu. */ void axes(); -/** Dessine une grille sur le plan XY entre les coordonnees -1 et 1 des deux axes. +/** Dessine une grille sur le plan xy entre les coordonnees -1 et 1 des deux axes. * Cette grille comporte <code>divisions</code> divisions.*/ void grid(int divisions); +/** Dessine une croix de visee au milieu du viewport. */ +void crosshair(); + } } diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h index c8f57ca..c2df021 100644 --- a/src/main/Accelerator.h +++ b/src/main/Accelerator.h @@ -19,10 +19,10 @@ class Accelerator { private : /** Constructeur de copie ne faisant rien. */ - Accelerator (Accelerator const& autre) {} + Accelerator (Accelerator const& other) {} /** Opérateur '=' ne faisant rien. */ - void operator= (Accelerator const& autre) const {} + void operator= (Accelerator const& other) const {} protected: @@ -88,9 +88,10 @@ public: } - /** Fait évoluer l'accélérateur d'un lapse de temps dt . */ + /** Fait évoluer l'accélérateur d'un lapse de temps dt. */ void step(double dt) { + } diff --git a/src/main/CompositeElement.cc b/src/main/CompositeElement.cc index 0c62a19..3b1a709 100644 --- a/src/main/CompositeElement.cc +++ b/src/main/CompositeElement.cc @@ -27,5 +27,35 @@ bool CompositeElement::isPast(const Particle& particle) const { else return false; } +Vector3D CompositeElement::magneticFieldAt(const Vector3D& position) const { + Vector3D b = Vector3D::Null; + for (int i(0); i < elements.size(); i++) { + b = b + elements[i]->magneticFieldAt(position); + } + return b; +} +Vector3D CompositeElement::electricFieldAt(const Vector3D& position) const { + Vector3D e = Vector3D::Null; + for (int i(0); i < elements.size(); i++) { + e = e + elements[i]->electricFieldAt(position); + } + return e; +} + +void CompositeElement::accept(const ElementVisitor& v) const { + for (int i(0); i < elements.size(); ++i) { + elements[i]->accept(v); + } } + +std::string CompositeElement::toString() const { + std::stringstream s; + for (int i(0); i < elements.size(); ++i) { + s << elements[i]->toString() << "\n"; + } + return s.str(); +} + + +} //vhc diff --git a/src/main/CompositeElement.h b/src/main/CompositeElement.h index 638e74a..ce274b1 100644 --- a/src/main/CompositeElement.h +++ b/src/main/CompositeElement.h @@ -38,35 +38,13 @@ public: /** Determine si une particule a passe cet element, donc passe le dernier element composant. */ virtual bool isPast(const Particle& particle) const; - virtual Vector3D magneticFieldAt(const Vector3D& position) const { - Vector3D b = Vector3D::Null; - for (int i(0); i < elements.size(); i++) { - b = b + elements[i]->magneticFieldAt(position); - } - return b; - } - - virtual Vector3D electricFieldAt(const Vector3D& position) const { - Vector3D e = Vector3D::Null; - for (int i(0); i < elements.size(); i++) { - e = e + elements[i]->electricFieldAt(position); - } - return e; - } - - virtual void accept(const ElementVisitor& v) const { - for (int i(0); i < elements.size(); ++i) { - elements[i]->accept(v); - } - } - - virtual std::string toString() { - std::stringstream s; - for (int i(0); i < elements.size(); ++i) { - s << elements[i]->toString() << "\n"; - } - return s.str(); - } + virtual Vector3D magneticFieldAt(const Vector3D& position) const; + + virtual Vector3D electricFieldAt(const Vector3D& position) const; + + virtual void accept(const ElementVisitor& v) const; + + virtual std::string toString() const; }; diff --git a/src/main/CurvedElement.cc b/src/main/CurvedElement.cc index 16816d9..1afae38 100644 --- a/src/main/CurvedElement.cc +++ b/src/main/CurvedElement.cc @@ -5,9 +5,9 @@ * Author: jakob */ -#include <assert.h> #include <math.h> -#include "exception.h" +#include <sstream> +#include "exceptions.h" #include "CurvedElement.h" using namespace std; @@ -15,7 +15,6 @@ namespace vhc { /** Cf. CurvedElement.h */ CurvedElement::CurvedElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next): - Element(entry, exit, sectionRadius, next), curvature(curvature), curvatureCenter(Vector3D::Null) { @@ -31,4 +30,35 @@ CurvedElement::CurvedElement(const Vector3D& entry, const Vector3D& exit, double curvatureCenter = midpoint + 1 / k * sqrt(1.0 - (k * k) / 4 * getDiagonal().normSquare()) * (getDiagonal().unit().cross(Vector3D::k)); } +CurvedElement::~CurvedElement() {}; + +double CurvedElement::getCurvature() const {return curvature;} + +Vector3D CurvedElement::getCurvatureCenter() const {return curvatureCenter;} + +double CurvedElement::getAngle() const { + return acos((entryPosition - curvatureCenter).unit().dot((exitPosition - curvatureCenter).unit())); +} + +bool CurvedElement::hasHit(const Particle& particle) const { + Vector3D x(particle.getPosition() - entryPosition); + if (x == Vector3D::Null) return false; + else return (x - Vector3D(x.getX(), x.getY(), 0).unit() / fabs(curvature)).norm() > sectionRadius; } + +bool CurvedElement::isPast(const Particle& particle) const { + Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(entryPosition - curvatureCenter); + return (particle.getPosition() - exitPosition).dot(out) > 0; +} + +std::string CurvedElement::getType() const {return "Curved Element";} +std::string CurvedElement::toString() const { + std::stringstream s; + s << Element::toString() << "\n"; + s << "\tcurvature: " << getCurvature() << "\n"; + s << "\tcurvature radius: " << 1.0 / getCurvature() << "\n"; + s << "\tcurvature center: " << getCurvatureCenter(); + return s.str(); +} + +} //vhc diff --git a/src/main/CurvedElement.h b/src/main/CurvedElement.h index 0c76541..03be522 100644 --- a/src/main/CurvedElement.h +++ b/src/main/CurvedElement.h @@ -42,38 +42,24 @@ public: CurvedElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, Element* next = NULL); - virtual ~CurvedElement() {}; + virtual ~CurvedElement(); //virtual CurvedElement* clone() const {return new CurvedElement(*this);} - virtual bool hasHit(const Particle& particle) const { - Vector3D x(particle.getPosition() - entryPosition); - if (x == Vector3D::Null) return false; - else return (x - Vector3D(x.getX(), x.getY(), 0).unit() / fabs(curvature)).norm() > sectionRadius; - } + virtual bool hasHit(const Particle& particle) const; - virtual bool isPast(const Particle& particle) const { - Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(entryPosition - curvatureCenter); - return (particle.getPosition() - exitPosition).dot(out) > 0; - } + virtual bool isPast(const Particle& particle) const; /** Retourne la courbure. */ - double getCurvature() const {return curvature;} + double getCurvature() const; /** Retourne le centre de courbure. */ - Vector3D getCurvatureCenter() const {return curvatureCenter;} + Vector3D getCurvatureCenter() const; /** Retourne l'angle entre la position d'entree, le centre de courbure et la position de sortie. */ - double getAngle() const {return acos((entryPosition - curvatureCenter).unit().dot((exitPosition - curvatureCenter).unit()));} - - virtual std::string getType() const {return "Curved Element";} - virtual std::string toString() const { - std::stringstream s; - s << Element::toString() << "\n"; - s << "\tcurvature: " << getCurvature() << "\n"; - s << "\tcurvature radius: " << 1.0 / getCurvature() << "\n"; - s << "\tcurvature center: " << getCurvatureCenter(); - return s.str(); - } + double getAngle() const; + + virtual std::string getType() const; + virtual std::string toString() const; }; diff --git a/src/main/Dipole.cc b/src/main/Dipole.cc index a2305bc..a313d12 100644 --- a/src/main/Dipole.cc +++ b/src/main/Dipole.cc @@ -5,17 +5,39 @@ * Author: jakob */ +#include <sstream> #include "Dipole.h" namespace vhc { -/*Dipole::Dipole() { - +Dipole::Dipole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, const Vector3D& magneticField, Element* next): + CurvedElement(entry, exit, sectionRadius, curvature, next), + _magneticField(magneticField) { } -Dipole::~Dipole() { +Dipole::~Dipole() {} + +Vector3D Dipole::getMagneticField() const {return _magneticField;} + +void Dipole::setMagneticField(const Vector3D& field) {_magneticField = field;} + +Vector3D Dipole::magneticFieldAt(const Vector3D& position) const {return _magneticField;} -}*/ +std::string Dipole::getType() const {return "Dipole";} +std::string Dipole::toString() const { + std::stringstream s; + s << CurvedElement::toString() << "\n"; + s << "\tB: " << getMagneticField(); + s << "\t|B|: " << getMagneticField().norm(); + return s.str(); } + +void Dipole::accept(const ElementVisitor& v) const {v.visit(this);} + +Dipole* Dipole::clone() const { + return new Dipole(getEntryPosition(), getExitPosition(), getSectionRadius(), getCurvature(), _magneticField); +} + +} //vhc diff --git a/src/main/Dipole.h b/src/main/Dipole.h index a455b36..7c9c24c 100644 --- a/src/main/Dipole.h +++ b/src/main/Dipole.h @@ -9,7 +9,6 @@ #define DIPOLE_H_ #include <string> -#include <sstream> #include "CurvedElement.h" #include "Vector3D.h" #include "ElementVisitor.h" @@ -35,41 +34,25 @@ public: * @param magneticField champ magnetique du dipole * @param next pointeur sur l'element prochain * @see vhc::Element*/ - Dipole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, const Vector3D& magneticField = Vector3D::Null, Element* next = NULL): - CurvedElement(entry, exit, sectionRadius, curvature, next), - _magneticField(magneticField) {}; + Dipole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double curvature, const Vector3D& magneticField = Vector3D::Null, Element* next = NULL); - virtual ~Dipole() {}; + virtual ~Dipole(); /** Retourne le champ magnetique a l'interieur de ce dipole. */ - Vector3D getMagneticField() const { - return _magneticField; - } + Vector3D getMagneticField() const; /** Modifie le champ magnetique de ce dipole. * Ceci correspondrait en realite a une correction du champ a l'aide d'electroaimants. */ - void setMagneticField(const Vector3D& field) { - _magneticField = field; - } - - virtual Vector3D magneticFieldAt(const Vector3D& position) const { - return _magneticField; - } - - virtual std::string getType() const {return "Dipole";} - virtual std::string toString() const { - std::stringstream s; - s << CurvedElement::toString() << "\n"; - s << "\tB: " << getMagneticField(); - s << "\t|B|: " << getMagneticField().norm(); - return s.str(); - } - - virtual void accept(const ElementVisitor& v) const {v.visit(this);} - - virtual Dipole* clone() const { - return new Dipole(getEntryPosition(), getExitPosition(), getSectionRadius(), getCurvature(), _magneticField); - } + void setMagneticField(const Vector3D& field); + + virtual Vector3D magneticFieldAt(const Vector3D& position) const; + + virtual std::string getType() const; + virtual std::string toString() const; + + virtual void accept(const ElementVisitor& v) const; + + virtual Dipole* clone() const; }; diff --git a/src/main/Element.cc b/src/main/Element.cc index a4e7647..ed66d94 100644 --- a/src/main/Element.cc +++ b/src/main/Element.cc @@ -6,13 +6,49 @@ */ +#include <sstream> #include "Element.h" namespace vhc { -//Element::Element(const Vector3D& entryPosition) { - // Auto-generated constructor stub +Element::Element(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next): + entryPosition(entry), + exitPosition(exit), + sectionRadius(sectionRadius), + next(next) { -//} +} + +Element::~Element() {}; + +Vector3D Element::magneticFieldAt(const Vector3D& position) const {return Vector3D::Null;} + +Vector3D Element::electricFieldAt(const Vector3D& position) const {return Vector3D::Null;} + +Vector3D Element::getDiagonal() const {return exitPosition - entryPosition;} + +Vector3D Element::getEntryPosition() const {return entryPosition;} + +Vector3D Element::getExitPosition() const {return exitPosition;} +double Element::getSectionRadius() const {return sectionRadius;} + +Element* Element::getNext() const {return next;} + +void Element::setNext(Element* n) {next = n;} + +bool Element::isConnected() const {return next != NULL;} + +std::string Element::getType() const {return "Element";} + +std::string Element::toString() const { + std::stringstream s; + s << getType() << ":\n"; + s << "\tentry: " << getEntryPosition() << "\n"; + s << "\texit: " << getExitPosition() << "\n"; + s << "\tsection radius: " << getSectionRadius() << "\n"; + s << "\tconnected: " << (isConnected() ? "true" : "false"); + return s.str(); } + +} //vhc diff --git a/src/main/Element.h b/src/main/Element.h index 32ba2db..8f8ffa1 100644 --- a/src/main/Element.h +++ b/src/main/Element.h @@ -9,7 +9,6 @@ #define ELEMENT_H_ #include <string> -#include <sstream> #include "Vector3D.h" #include "Particle.h" #include "Printable.h" @@ -43,15 +42,6 @@ protected: * NULL si aucun element n'existe. */ Element *next; - /* Intensité (constante) du champ. - * à améliorer - double fieldIntensity; - Vector3D magneticField - - * Direction du champ magnétique, invariant dans l'espace. - Vector3D fieldDirection; - */ - public: /** Constructeur d'elements. @@ -59,13 +49,9 @@ public: * @param exit position de face de sortie * @param sectionRadius rayon de section de la chambre a vide * @param next pointeur sur l'element suivant */ - Element(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL): - entryPosition(entry), - exitPosition(exit), - sectionRadius(sectionRadius), - next(next) {}; + Element(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL); - virtual ~Element() {}; + virtual ~Element(); /** Copie l'element sur le heap et renvoye un pointeur sur la copie. * En copiant un element, le pointeur sur l'element suivant est remis a zero. @@ -79,60 +65,48 @@ public: virtual bool isPast(const Particle& particle) const = 0; /** Retourne le champ magnetique, a l'interieur de cet element a la position donnee. */ - virtual Vector3D magneticFieldAt(const Vector3D& position) const { - return Vector3D::Null; - } + virtual Vector3D magneticFieldAt(const Vector3D& position) const; /** Retourne le champ electrique, a l'interieur de cet element a la position donnee. */ - virtual Vector3D electricFieldAt(const Vector3D& position) const { - return Vector3D::Null; - } + virtual Vector3D electricFieldAt(const Vector3D& position) const; /** Retourne la diagonale, c'est-a-dire le vecteur de la position d'entree * a la position de sortie. */ - Vector3D getDiagonal() const {return exitPosition - entryPosition;} + Vector3D getDiagonal() const; /** Retourne la position d'entree. */ - Vector3D getEntryPosition() const {return entryPosition;} + Vector3D getEntryPosition() const; /** Assigne la position d'entree. */ //void setEntryPosition(const Vector3D& newPos) {entryPosition = newPos;} /** Retourne la position de sortie. */ - Vector3D getExitPosition() const {return exitPosition;} + Vector3D getExitPosition() const; /** Assigne la position de sortie. */ //void setExitPosition(const Vector3D& newPos) {exitPosition = newPos;} /** Retourne le rayon de la section de cet element. */ - double getSectionRadius() const {return sectionRadius;} + double getSectionRadius() const; /** Assigne le rayon de la section de cet element. */ - void setSectionRadius(double r) {sectionRadius = r;} + //void setSectionRadius(double r) {sectionRadius = r;} /** Retourne un pointeur l'element suivant. NULL s'il n'existe pas. */ - Element* getNext() const {return next;} + Element* getNext() const; /** Assigne un pointeur sur l'element suivant. */ - void setNext(Element* n) {next = n;} + void setNext(Element* n); /** Retourne vrai si cet element est connecte a un element suivant, faux sinon. */ - bool isConnected() const {return next != NULL;} + bool isConnected() const; /** Retourne une representation en chaine du type de cet element, i.e. du nom de la classe. * Cette methode est utilisee principalement pour changer le comportement de <code>toString()</code> * dans des implementations concretes. */ - virtual std::string getType() const {return "Element";} - - virtual std::string toString() const { - std::stringstream s; - s << getType() << ":\n"; - s << "\tentry: " << getEntryPosition() << "\n"; - s << "\texit: " << getExitPosition() << "\n"; - s << "\tsection radius: " << getSectionRadius() << "\n"; - s << "\tconnected: " << (isConnected() ? "true" : "false"); - return s.str(); - } + virtual std::string getType() const; + + virtual std::string toString() const; virtual void accept(const ElementVisitor& v) const = 0; }; diff --git a/src/main/ElementVisitor.cc b/src/main/ElementVisitor.cc index 9b82a01..1cbbe76 100644 --- a/src/main/ElementVisitor.cc +++ b/src/main/ElementVisitor.cc @@ -9,13 +9,8 @@ namespace vhc { -ElementVisitor::ElementVisitor() { +ElementVisitor::ElementVisitor() {} - -} - -ElementVisitor::~ElementVisitor() { - -} +ElementVisitor::~ElementVisitor() {} } diff --git a/src/main/ElementVisitor.h b/src/main/ElementVisitor.h index 89de7d7..126c9ce 100644 --- a/src/main/ElementVisitor.h +++ b/src/main/ElementVisitor.h @@ -8,15 +8,9 @@ #ifndef ELEMENTVISITOR_H_ #define ELEMENTVISITOR_H_ -//#include "StraightElement.h" -//#include "Quadrupole.h" -//#include "CurvedElement.h" -//#include "Dipole.h" -//#include "CompositeElement.h" -//#include "Element.h" - namespace vhc { + class StraightElement; class Quadrupole; class CurvedElement; diff --git a/src/main/FODO.cc b/src/main/FODO.cc index 7188e23..59eb91b 100644 --- a/src/main/FODO.cc +++ b/src/main/FODO.cc @@ -10,16 +10,16 @@ #include "StraightElement.h" #include "Quadrupole.h" #include "Vector3D.h" -#include "exception.h" +#include "exceptions.h" namespace vhc { -FODO::FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double straightLength, double focalisingCoefficient, Element* next): +FODO::FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double straightLength, double focalizingCoefficient, Element* next): CompositeElement(entry, exit, sectionRadius, next), straightLength(straightLength), - focalisingCoefficient(focalisingCoefficient), - focalisingQuadrupole(NULL), - defocalisingQuadrupole(NULL), + focalizingCoefficient(focalizingCoefficient), + focalizingQuadrupole(NULL), + defocalizingQuadrupole(NULL), straightElement1(NULL), straightElement2(NULL) { @@ -28,13 +28,13 @@ FODO::FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, do if (l < 0) throw IllegalArgumentException("Length of straight elements must be less than half of FODO length."); Vector3D d = getDiagonal().unit(); - focalisingQuadrupole = new Quadrupole(entry, entry + d * l, sectionRadius, focalisingCoefficient); - elements.push_back(focalisingQuadrupole); - straightElement1 = new StraightElement(focalisingQuadrupole->getExitPosition(), focalisingQuadrupole->getExitPosition() + d * L, sectionRadius); + focalizingQuadrupole = new Quadrupole(entry, entry + d * l, sectionRadius, focalizingCoefficient); + elements.push_back(focalizingQuadrupole); + straightElement1 = new StraightElement(focalizingQuadrupole->getExitPosition(), focalizingQuadrupole->getExitPosition() + d * L, sectionRadius); elements.push_back(straightElement1); - defocalisingQuadrupole = new Quadrupole(straightElement1->getExitPosition(), straightElement1->getExitPosition() + d * l, sectionRadius, -focalisingCoefficient); - elements.push_back(defocalisingQuadrupole); - straightElement2 = new StraightElement(defocalisingQuadrupole->getExitPosition(), defocalisingQuadrupole->getExitPosition() + d * L, sectionRadius); + defocalizingQuadrupole = new Quadrupole(straightElement1->getExitPosition(), straightElement1->getExitPosition() + d * l, sectionRadius, -focalizingCoefficient); + elements.push_back(defocalizingQuadrupole); + straightElement2 = new StraightElement(defocalizingQuadrupole->getExitPosition(), defocalizingQuadrupole->getExitPosition() + d * L, sectionRadius); elements.push_back(straightElement2); //connection des elements @@ -53,7 +53,7 @@ FODO::~FODO() { } FODO* FODO::clone() const { - return new FODO(getEntryPosition(), getExitPosition(), getSectionRadius(), straightLength, focalisingCoefficient); + return new FODO(getEntryPosition(), getExitPosition(), getSectionRadius(), straightLength, focalizingCoefficient); } } diff --git a/src/main/FODO.h b/src/main/FODO.h index 0375fe5..924849d 100644 --- a/src/main/FODO.h +++ b/src/main/FODO.h @@ -18,14 +18,14 @@ class FODO: public CompositeElement { private: double straightLength; - double focalisingCoefficient; - Quadrupole* focalisingQuadrupole; - Quadrupole* defocalisingQuadrupole; + double focalizingCoefficient; + Quadrupole* focalizingQuadrupole; + Quadrupole* defocalizingQuadrupole; StraightElement* straightElement1; StraightElement* straightElement2; public: - FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double straightLength, double focalisingCoefficient, Element* next = NULL); + FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double straightLength, double focalizingCoefficient, Element* next = NULL); virtual ~FODO(); diff --git a/src/main/Makefile b/src/main/Makefile index 2acfab3..90e7ac7 100644 --- a/src/main/Makefile +++ b/src/main/Makefile @@ -14,7 +14,7 @@ LOCALDIR = main # Si un objet nécessite une compilation non-standard (i.e. pas de règle du style Foo.o : Foo.cc Foo.h), rajouter # cette règle. LOCALOBJS = Vector3D.o Particle.o Printable.o Element.o CurvedElement.o StraightElement.o \ - CompositeElement.o Dipole.o Quadrupole.o FODO.o ElementVisitor.o Cloneable.o Accelerator.o + CompositeElement.o Dipole.o Quadrupole.o FODO.o ElementVisitor.o Cloneable.o Accelerator.o exceptions.o OBJS=$(addprefix $(BINDIR)/$(LOCALDIR)/,$(LOCALOBJS)) .PHONY = all checkdirs lib diff --git a/src/main/Particle.cc b/src/main/Particle.cc index 2c24134..a3f80cd 100644 --- a/src/main/Particle.cc +++ b/src/main/Particle.cc @@ -9,4 +9,73 @@ namespace vhc { +Particle::Particle(const Vector3D& position, double mass, double charge): + position(position), + velocity(0, 0, 0), + force(0, 0, 0), + mass(mass), + charge(charge) + //element(NULL) + {}; + + +Particle::Particle(const Vector3D& position, double mass, double charge, double energy, const Vector3D& direction): + position(position), + velocity(constants::C * sqrt(1 - (mass * mass * constants::C2 * constants::C2) / (energy * energy)) * direction.unit()), + gamma(energy / (mass * constants::C2)), + force(0, 0, 0), + mass(mass), + charge(charge) +// element(NULL) + {}; + +Vector3D Particle::getPosition() const {return position;} + +void Particle::setPosition(const Vector3D& pos) {position = pos;} + +Vector3D Particle::getForce() const {return force;} + +void Particle::setForce(const Vector3D& f) {force = f;} + +void Particle::applyForce(const Vector3D& f) {force = force + f;} + +void Particle::applyMagneticForce(const Vector3D& b, double dt) { + if (b != Vector3D::Null) { + Vector3D f = charge * velocity.cross(b); + force = force + f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * mass * velocity.norm())); + } } + +double Particle::getMass() const {return mass;} + +double Particle::getCharge() const {return charge;} + + +Vector3D Particle::getVelocity() const {return velocity;} + +void Particle::setVelocity(const Vector3D& v) { + velocity = v; + gamma = 1.0 / sqrt(1.0 - v.normSquare() / constants::C2); +} + +double Particle::getEnergy() const {return gamma * mass * constants::C2;} + +double Particle::getGamma() const {return gamma;} + +std::string Particle::toString() const { + std::stringstream s; + s << "Particle:" << "\n"; + s << "\tposition: " << position << "\n"; + s << "\tvelocity: " << velocity << "\n"; + s << "\t|v|: " << velocity.norm() << "\n"; + s << "\tgamma: " << gamma << "\n"; + s << "\tmass: " << mass << "\n"; + s << "\tcharge: " << charge << "\n"; + s << "\tforce: " << force; + return s.str(); +} + +Particle* Particle::clone() const {return new Particle(*this);} + + +} //vhc diff --git a/src/main/Particle.h b/src/main/Particle.h index 3e69f4e..bc2d67a 100644 --- a/src/main/Particle.h +++ b/src/main/Particle.h @@ -43,6 +43,8 @@ private: /** Facteur gamma de cette particule. [1] */ double gamma; + //Element* element; + public: @@ -50,13 +52,7 @@ public: * @param position position * @param mass masse <b>[kg]</b> * @param charge charge [C] */ - Particle(const Vector3D& position, double mass, double charge): - position(position), - velocity(0, 0, 0), - force(0, 0, 0), - mass(mass), - charge(charge) - {}; + Particle(const Vector3D& position, double mass, double charge); /** Cree une nouvelle particule avec les parametres donnees. * @param position position @@ -64,80 +60,53 @@ public: * @param charge charge [C] * @param energy energie <b>[J]</b> * @param direction direction de mouvement de la particule (la longueur du vecteur n'a aucune importance) */ - Particle(const Vector3D& position, double mass, double charge, double energy, const Vector3D& direction): - position(position), - velocity(constants::c * sqrt(1 - (mass * mass * constants::c2 * constants::c2) / (energy * energy)) * direction.unit()), - gamma(energy / (mass * constants::c2)), - force(0, 0, 0), - mass(mass), - charge(charge) - {}; + Particle(const Vector3D& position, double mass, double charge, double energy, const Vector3D& direction); /** Retourne la position de cette particule. [m] */ - Vector3D getPosition() const {return position;} + Vector3D getPosition() const; /** Affecte la position de cette particule. [m] */ - void setPosition(const Vector3D& pos) {position = pos;} + void setPosition(const Vector3D& pos); /** Retourne la force résultante sur cette particule. [N] */ - Vector3D getForce() const {return force;} + Vector3D getForce() const; /** Affecte la force résultante sur cette particule. [N] */ - void setForce(const Vector3D& f) {force = f;} + void setForce(const Vector3D& f); /** Applique une force sur cette particule. [N] */ - void applyForce(const Vector3D& f) {force = force + f;} + void applyForce(const Vector3D& f); /** Applique un champ magnetique sur cette particule durant un lapse de temps dt. * Cette application change la force resultante de la particule. [T], [s] */ - void applyMagneticForce(const Vector3D& b, double dt) { - if (b != Vector3D::Null) { - Vector3D f = charge * velocity.cross(b); - force = force + f.rotate(velocity.cross(f), (dt * f.norm()) / (2 * gamma * mass * velocity.norm())); - } - } + void applyMagneticForce(const Vector3D& b, double dt); /** Retourne la masse de cette particule. [kg] */ - double getMass() const {return mass;} - - ///** Retourne la masse de cette particule en Kg. */ - //double getMassGeV() const {return mass * 1E-9 * constants::e / constants::c2;} + double getMass() const; /** Retourne la charge de cette particule. [C] */ - double getCharge() const {return charge;} + double getCharge() const; /** Retourne la vitesse de cette particule. [m/s]*/ - Vector3D getVelocity() const {return velocity;} + Vector3D getVelocity() const; /** Affecte vitesse de cette particule. [m/s] */ - void setVelocity(const Vector3D& v) { - velocity = v; - gamma = 1.0 / sqrt(1.0 - v.normSquare() / constants::c2); - } + void setVelocity(const Vector3D& v); /** Retourne l'energie de cette particlue. [J] */ - double getEnergy() const {return gamma * mass * constants::c2;} + double getEnergy() const; /** Retourne le facteur gamma de cette particule. [1] */ - double getGamma() const {return gamma;} + double getGamma() const; /** Retourne une représentation en chaîne de cette particule. */ - virtual std::string toString() const { - std::stringstream s; - s << "Particle:" << "\n"; - s << "\tposition: " << position << "\n"; - s << "\tvelocity: " << velocity << "\n"; - s << "\t|v|: " << velocity.norm() << "\n"; - s << "\tgamma: " << gamma << "\n"; - s << "\tmass: " << mass << "\n"; - s << "\tcharge: " << charge << "\n"; - s << "\tforce: " << force; - return s.str(); - } - - virtual Particle* clone() const {return new Particle(*this);} + virtual std::string toString() const; + + virtual Particle* clone() const; + //void setElement(Element* element) {element = element;} + //Element* getElement() const {return element;} }; diff --git a/src/main/Quadrupole.cc b/src/main/Quadrupole.cc index 7236150..2d73fbb 100644 --- a/src/main/Quadrupole.cc +++ b/src/main/Quadrupole.cc @@ -9,6 +9,34 @@ namespace vhc { +Quadrupole::Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focusingCoefficient, Element* next): + StraightElement(entry, exit, sectionRadius, next), + focalizingCoefficient(focusingCoefficient) + {}; + +Quadrupole::~Quadrupole() {}; + +Vector3D Quadrupole::magneticFieldAt(const Vector3D& position) { + Vector3D x = position - getEntryPosition(); + Vector3D d = getDiagonal().unit(); + Vector3D y = x - x.dot(d) * d; + Vector3D u = Vector3D::k.cross(d); + return focalizingCoefficient * (y.dot(u) * Vector3D::k + position.getZ() * u); +} + +double Quadrupole::getFocalizingCoefficient() const { + return focalizingCoefficient; +} + +void Quadrupole::setFocalizingCoefficient(double value) { + focalizingCoefficient = value; +} + +std::string Quadrupole::getType() const {return "Quadrupole";} + +void Quadrupole::accept(const ElementVisitor& v) const {v.visit(this);} + +Quadrupole* Quadrupole::clone() const {return new Quadrupole(getEntryPosition(), getExitPosition(), getSectionRadius(), focalizingCoefficient);} } diff --git a/src/main/Quadrupole.h b/src/main/Quadrupole.h index 32eac23..0f28537 100644 --- a/src/main/Quadrupole.h +++ b/src/main/Quadrupole.h @@ -18,37 +18,24 @@ namespace vhc { class Quadrupole: public StraightElement { private: - double focusingCoefficient; + double focalizingCoefficient; public: - Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focusingCoefficient, Element* next = NULL): - StraightElement(entry, exit, sectionRadius, next), - focusingCoefficient(focusingCoefficient) - {}; + Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focalizingCoefficient, Element* next = NULL); - virtual ~Quadrupole() {}; + virtual ~Quadrupole(); - virtual Vector3D magneticFieldAt(const Vector3D& position) { - Vector3D x = position - getEntryPosition(); - Vector3D d = getDiagonal().unit(); - Vector3D y = x - x.dot(d) * d; - Vector3D u = Vector3D::k.cross(d); - return focusingCoefficient * (y.dot(u) * Vector3D::k + position.getZ() * u); - } + virtual Vector3D magneticFieldAt(const Vector3D& position); - double getFocusingCoefficient() const { - return focusingCoefficient; - } + double getFocalizingCoefficient() const; - void setFocusingCoefficient(double value) { - focusingCoefficient = value; - } + void setFocalizingCoefficient(double value); - virtual std::string getType() const {return "Quadrupole";} + virtual std::string getType() const; - virtual void accept(const ElementVisitor& v) const {v.visit(this);} + virtual void accept(const ElementVisitor& v) const; - virtual Quadrupole* clone() const {return new Quadrupole(getEntryPosition(), getExitPosition(), getSectionRadius(), focusingCoefficient);} + virtual Quadrupole* clone() const; }; } diff --git a/src/main/StraightElement.cc b/src/main/StraightElement.cc index fb74a03..1739486 100644 --- a/src/main/StraightElement.cc +++ b/src/main/StraightElement.cc @@ -9,4 +9,33 @@ namespace vhc { +StraightElement::StraightElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next): + Element(entry, exit, sectionRadius, next) + {}; + +StraightElement::~StraightElement() {}; + + +bool StraightElement::hasHit(const Particle& particle) const { + Vector3D a(particle.getPosition() - entryPosition); + const Vector3D b = (particle.getPosition() - entryPosition); + return (a.cross(b)).norm() / getDiagonal().norm() > sectionRadius; +}; + +bool StraightElement::isPast(const Particle& particle) const { + const Vector3D v(particle.getPosition() - entryPosition); + return getDiagonal().dot(v) > getDiagonal().dot(getDiagonal()); +} + +std::string StraightElement::getType() const {return "Straight Element";} +std::string StraightElement::toString() const { + std::stringstream s; + s << Element::toString(); + return s.str(); +} + +void StraightElement::accept(const ElementVisitor& v) const {v.visit(this);} + +StraightElement* StraightElement::clone() const {return new StraightElement(getEntryPosition(), getExitPosition(), getSectionRadius());} + } diff --git a/src/main/StraightElement.h b/src/main/StraightElement.h index dc7603b..6de596a 100644 --- a/src/main/StraightElement.h +++ b/src/main/StraightElement.h @@ -20,35 +20,20 @@ class StraightElement: public Element { public: - StraightElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL): - Element(entry, exit, sectionRadius, next) - {}; + StraightElement(const Vector3D& entry, const Vector3D& exit, double sectionRadius, Element* next = NULL); - virtual ~StraightElement() {}; + virtual ~StraightElement(); - //virtual StraightElement* clone() const {return new StraightElement(*this);} + virtual bool hasHit(const Particle& particle) const; - virtual bool hasHit(const Particle& particle) const { - Vector3D a(particle.getPosition() - entryPosition); - const Vector3D b = (particle.getPosition() - entryPosition); - return (a.cross(b)).norm() / getDiagonal().norm() > sectionRadius; - }; + virtual bool isPast(const Particle& particle) const; - virtual bool isPast(const Particle& particle) const { - const Vector3D v(particle.getPosition() - entryPosition); - return getDiagonal().dot(v) > getDiagonal().dot(getDiagonal()); - } + virtual std::string getType() const; + virtual std::string toString() const; - virtual std::string getType() const {return "Straight Element";} - virtual std::string toString() const { - std::stringstream s; - s << Element::toString(); - return s.str(); - } + virtual void accept(const ElementVisitor& v) const; - virtual void accept(const ElementVisitor& v) const {v.visit(this);} - - virtual StraightElement* clone() const {return new StraightElement(getEntryPosition(), getExitPosition(), getSectionRadius());} + virtual StraightElement* clone() const; }; diff --git a/src/main/Vector3D.cc b/src/main/Vector3D.cc index 82a75cf..b733e2e 100644 --- a/src/main/Vector3D.cc +++ b/src/main/Vector3D.cc @@ -12,6 +12,62 @@ using namespace std; namespace vhc { +Vector3D::Vector3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z), normCache(-1) {}; + +inline double Vector3D::getX() const {return x;}; + +inline double Vector3D::getY() const {return y;}; + +inline double Vector3D::getZ() const {return z;}; + +inline bool Vector3D::operator== (const Vector3D& v) const {return x == v.x && y == v.y && z == v.z;}; + +inline bool Vector3D::operator!= (const Vector3D& v) const {return !((*this) == (v));}; + +inline Vector3D Vector3D::operator+ (const Vector3D& v) const {return Vector3D(x + v.x, y + v.y, z + v.z);}; + +inline Vector3D Vector3D::operator* (double n) const {return Vector3D(x * n, y * n, z * n);}; + +inline Vector3D Vector3D::operator- () const {return (*this) * (-1.0);}; + +inline Vector3D Vector3D::operator- (const Vector3D& v) const {return (*this) + -v;}; + +inline Vector3D Vector3D::operator/ (double n) const {return (*this) * (1.0 / n) ;}; + +inline double Vector3D::dot(const Vector3D& v) const {return x * v.x + y * v.y + z * v.z;}; + +inline Vector3D Vector3D::cross(const Vector3D& v) const {return Vector3D(y * v.z - v.y * z, v.x * z - x * v.z, x * v.y - v.x * y);}; + +inline Vector3D Vector3D::operator~ () const { + if (norm() != 0.0) return (*this) / norm(); + else throw UnsupportedOperationException("Zero vector does not have a unit vector."); +}; + +inline Vector3D Vector3D::unit() const {return ~(*this);} + +inline double Vector3D::norm() const { + if (normCache == -1) normCache = sqrt(dot(*this)); + return normCache; +} + +inline double Vector3D::normSquare() const {return dot(*this);} + +std::string Vector3D::toString() const { + std::stringstream s; + s << "(" << x << ", " << y << ", " << z << ")"; + return s.str(); +}; + +inline double Vector3D::angle(const Vector3D& v) const {return acos(dot(v) / norm() / v.norm());} + +inline double Vector3D::tripleProduct(const Vector3D& v, const Vector3D& w) const { return dot(v.cross(w)); } + +inline Vector3D Vector3D::rotate(const Vector3D& axis, double t) const { + const Vector3D& x = *this; + const Vector3D& a = ~axis; + return x * cos(t) + a * x.dot(a) * (1-cos(t)) + a.cross(x) * sin(t); +} + //c.f. header Vector3D const Vector3D::Null = Vector3D(0.0, 0.0, 0.0); diff --git a/src/main/Vector3D.h b/src/main/Vector3D.h index a7764df..c4935e2 100644 --- a/src/main/Vector3D.h +++ b/src/main/Vector3D.h @@ -10,7 +10,7 @@ #include <sstream> #include <math.h> -#include "exception.h" +#include "exceptions.h" #include "Printable.h" namespace vhc { @@ -48,87 +48,71 @@ public: * @param _y 2e composante * @param _z 3e composante */ - Vector3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z), normCache(-1) {}; + Vector3D(double _x, double _y, double _z); /** Retourne la composante x de ce vecteur. */ - double getX() const {return x;}; + double getX() const; /** Retourne la composante y de ce vecteur. */ - double getY() const {return y;}; + double getY() const; /** Retourne la composante z de ce vecteur. */ - double getZ() const {return z;}; + double getZ() const; /** Vérifie si ce vecteur et le vecteur <code>v</code> sont égaux, i.e. qu'ils ont les mêmes composantes. */ - bool operator== (const Vector3D& v) const {return x == v.x && y == v.y && z == v.z;}; + bool operator== (const Vector3D& v) const; /** Vérifie si ce vecteur et le vecteur <code>v</code> sont différents, i.e. qu'ils ont des composantes différentes. */ - bool operator!= (const Vector3D& v) const {return !((*this) == (v));}; + bool operator!= (const Vector3D& v) const; /** Addition de vecteurs. Retourne un nouveau vecteur résultant de l'addition de ce vecteur avec <code>v</code>. */ - Vector3D operator+ (const Vector3D& v) const {return Vector3D(x + v.x, y + v.y, z + v.z);}; + Vector3D operator+ (const Vector3D& v) const; /** Multiplication scalaire. Retourne un nouveau vecteur résultant de la multiplication de ce vecteur par <code>n</code>. */ - Vector3D operator* (double n) const {return Vector3D(x * n, y * n, z * n);}; + Vector3D operator* (double n) const; /** Retourne l'opposé de ce vecteur. */ - Vector3D operator-() const {return (*this) * (-1.0);}; + Vector3D operator-() const; /** Soustraction de vecteurs. Retourne un nouveau vecteur résultant de la soustraction de ce vecteur avec <code>v</code>. */ - Vector3D operator- (const Vector3D& v) const {return (*this) + -v;}; + Vector3D operator- (const Vector3D& v) const; /** Division scalaire. Retourne un nouveau vecteur résultant de la division de ce vecteur par <code>n</code>. */ - Vector3D operator/ (double n) const {return (*this) * (1.0 / n) ;}; + Vector3D operator/ (double n) const; /** Produit scalaire. Retourne le produit scalaire de ce vecteur avec le vecteur <code>v</code>. */ - double dot(const Vector3D& v) const {return x * v.x + y * v.y + z * v.z;}; + double dot(const Vector3D& v) const; /** Produit vectoriel. Retourne le produit vectoriel direct (main droite) de ce vecteur avec le vecteur <code>v</code>. * Nous avons decidé de ne pas utiliser l'operateur `^' pour représenter le produit vectoriel car sa précédence est plus * basse que toutes autres opérations binaires sur les vecteurs. */ - Vector3D cross(const Vector3D& v) const {return Vector3D(y * v.z - v.y * z, v.x * z - x * v.z, x * v.y - v.x * y);}; + Vector3D cross(const Vector3D& v) const; /** Vecteur unitaire de ce vecteur. */ - Vector3D operator~() const { - if (norm() != 0.0) return (*this) / norm(); - else throw UnsupportedOperationException("Zero vector does not have a unit vector."); - }; + Vector3D operator~() const; + /** Retourne le vecteur unitaire */ - Vector3D unit() const {return ~(*this);} + Vector3D unit() const; /** Retourne la norme du vecteur. */ - double norm() const { - if (normCache == -1) normCache = sqrt(dot(*this)); - return normCache; - } + double norm() const; /** Retourne la norme du vecteur au carre. */ - double normSquare() const {return dot(*this);} + double normSquare() const; /** Retourne une représentation en chaîne de caractères de ce vecteur. */ - virtual std::string toString() const { - std::stringstream s; - s << "(" << x << ", " << y << ", " << z << ")"; - return s.str(); - }; + virtual std::string toString() const; - double angle(const Vector3D& v) const {return acos(dot(v) / norm() / v.norm());} + double angle(const Vector3D& v) const; /** Produit mixte de 3 vecteurs. Retourne le produit scalaire de ce vecteur * avec le produit vectoriel de deux vecteurs <code>v</code> et <code>w</code>). */ - double tripleProduct(const Vector3D& v, const Vector3D& w) const { return dot(v.cross(w)); } + double tripleProduct(const Vector3D& v, const Vector3D& w) const; /** Rotation vectorielle. Retourne le vecteur courant, évalué dans la formule en <code>a</code>, * le vecteur de l'axe, et en <code>t</code>, l'angle de rotation. */ - Vector3D rotate(const Vector3D& axis, double t) const { - const Vector3D& x = *this; - const Vector3D& a = ~axis; - - //cos(t) x + ( 1-cos(t) ) (x*a) a + sin(t) a ^ x - - return x * cos(t) + a * x.dot(a) * (1-cos(t)) + a.cross(x) * sin(t); - } + Vector3D rotate(const Vector3D& axis, double t) const; /** Vecteur nul. (0,0,0) */ static const Vector3D Null; diff --git a/src/main/constants.h b/src/main/constants.h index df2afe6..25353a7 100644 --- a/src/main/constants.h +++ b/src/main/constants.h @@ -14,17 +14,22 @@ namespace vhc { namespace constants { /** Vitesse de la lumière dans le vide [m/s]. */ -const double c = 299792458; +const double C = 299792458; /** Vitesse de la lumière dans le vide au carré [m/s]. */ -const double c2 = c * c; +const double C2 = C * C; /** Charge élémentaire [C]. */ -const double e = 1.60217653E-19; +const double E = 1.60217653E-19; -} +/** Masse d'un proton [kg]. */ +const double PROTON_MASS = 1.672623E-27; + +/** Masse d'un électron [kg]. */ +const double ELECTRON_MASS = 9.109383E-31; } +} #endif /* CONSTANTS_H_ */ diff --git a/src/main/doxygen.h b/src/main/doxygen.h new file mode 100644 index 0000000..1fbbd68 --- /dev/null +++ b/src/main/doxygen.h @@ -0,0 +1,21 @@ +/* + * doxygen.h + * + * Created on: Apr 17, 2011 + * Author: jakob + */ + +#ifndef DOXYGEN_H_ + +/**@mainpage + * Page principale. + * + */ + + + + +#define DOXYGEN_H_ + + +#endif /* DOXYGEN_H_ */ diff --git a/src/main/exceptions.cc b/src/main/exceptions.cc new file mode 100644 index 0000000..577a079 --- /dev/null +++ b/src/main/exceptions.cc @@ -0,0 +1,43 @@ +/* + * exceptions.cc + * + * Created on: Apr 17, 2011 + * Author: jakob + */ + +#include <sstream> +#include "exceptions.h" + +namespace vhc { + +Exception::Exception(): message("") {}; + +Exception::Exception(std::string message): message(message) {}; + +Exception::~Exception() {}; + +std::string Exception::getExceptionType() const {return "Exception";} + +std::string Exception::getMessage() const {return message;} + +std::string Exception::toString() const { + std::stringstream s; + s << getExceptionType() << ": " << getMessage(); + return s.str(); +} + + +IllegalArgumentException::IllegalArgumentException(): Exception() {}; +IllegalArgumentException::IllegalArgumentException(std::string message): Exception(message) {}; + +std::string IllegalArgumentException::getExceptionType() const {return "IllegalArgumentException";} + + + +UnsupportedOperationException::UnsupportedOperationException(): Exception() {}; +UnsupportedOperationException::UnsupportedOperationException(std::string message): Exception(message) {}; + +std::string UnsupportedOperationException::getExceptionType() const {return "UnsupportedOperationException";} + +} + diff --git a/src/main/exception.h b/src/main/exceptions.h index 03c2fb8..2bf40f0 100644 --- a/src/main/exception.h +++ b/src/main/exceptions.h @@ -1,14 +1,13 @@ /* - * exception.h + * exceptions.h * * Created on: Mar 24, 2011 * Author: jakob */ -#ifndef EXCEPTION_H_ -#define EXCEPTION_H_ +#ifndef EXCEPTIONS_H_ +#define EXCEPTIONS_H_ -#include <sstream> #include <string> #include "Printable.h" @@ -26,28 +25,24 @@ private: public: /** Constructeur par defaut. */ - Exception(): message("") {}; + Exception(); /** Instancie une nouvelle exception avec le message d'erreur donne. * @param message message d'erreur*/ - Exception(std::string message): message(message) {}; + Exception(std::string message); /** Destructeur virtuel. */ - virtual ~Exception() {}; + virtual ~Exception(); /** Retourne le type de cette exception, c'est-a-dire le nom de la classe. */ - virtual std::string getExceptionType() const {return "Exception";} + virtual std::string getExceptionType() const; /** Retourne le message d'erreur de cette exception. */ - virtual std::string getMessage() const {return message;} + virtual std::string getMessage() const; /** Retourne une representation en chaine de cette exception. Cette methode est a appeller pour * si on veut connaitre les details de cette exception.*/ - virtual std::string toString() const { - std::stringstream s; - s << getExceptionType() << ": " << getMessage(); - return s.str(); - } + virtual std::string toString() const; }; @@ -55,24 +50,24 @@ public: * Exemple: si on voudrait instancier un polygone avec moins de 3 faces. */ class IllegalArgumentException: public Exception { public: - IllegalArgumentException(): Exception() {}; - IllegalArgumentException(std::string message): Exception(message) {}; + IllegalArgumentException(); + IllegalArgumentException(std::string message); - virtual std::string getExceptionType() const {return "IllegalArgumentException";} + virtual std::string getExceptionType() const; }; /** Represente une exception due a l'appelle d'une operation non supportee par une instance de classe. * Exemple: calculer le vecteur unitaire du vecteur nul. */ class UnsupportedOperationException: public Exception { public: - UnsupportedOperationException(): Exception() {}; - UnsupportedOperationException(std::string message): Exception(message) {}; + UnsupportedOperationException(); + UnsupportedOperationException(std::string message); - virtual std::string getExceptionType() const {return "UnsupportedOperationException";} + virtual std::string getExceptionType() const; }; } -#endif /* EXCEPTION_H_ */ +#endif /* EXCEPTIONS_H_ */ diff --git a/src/test/ParticleTest.cc b/src/test/ParticleTest.cc index b1e3788..14458dd 100644 --- a/src/test/ParticleTest.cc +++ b/src/test/ParticleTest.cc @@ -25,7 +25,7 @@ Particle* particle = NULL; void step(double h); double toKg(double mGeV) { - return constants::e / constants::c2 * 1E9 * mGeV; + return constants::E / constants::C2 * 1E9 * mGeV; } int main() { @@ -36,8 +36,8 @@ int main() { Vector3D direction = entry.cross(Vector3D::k); double mass = 9.11E-31; - double charge = constants::e; - double energy = 1 * 1E9 * constants::e; + double charge = constants::E; + double energy = 1 * 1E9 * constants::E; particle = new Particle(entry, mass, charge, energy, direction); diff --git a/src/test/Vector3DTest.cc b/src/test/Vector3DTest.cc index d71f0d1..d090682 100644 --- a/src/test/Vector3DTest.cc +++ b/src/test/Vector3DTest.cc @@ -9,7 +9,7 @@ #include <assert.h> #include <iomanip> #include <limits> -#include "exception.h" +#include "exceptions.h" #include "Vector3D.h" using namespace std; |