diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-19 15:49:14 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-19 15:49:14 +0000 |
commit | 8f85e6c82e573402c2d34f709e868c4ae55510a7 (patch) | |
tree | cf32de50c6f41c1c62e3882889aa460836868451 | |
parent | 12a5fafab92e4a6803c56af5a934ba21f84ee762 (diff) | |
download | vhc-8f85e6c82e573402c2d34f709e868c4ae55510a7.tar.gz vhc-8f85e6c82e573402c2d34f709e868c4ae55510a7.tar.bz2 vhc-8f85e6c82e573402c2d34f709e868c4ae55510a7.zip |
Resolution de quelques bugs mineures.
-rw-r--r-- | src/gui/ElementRenderer.cc | 2 | ||||
-rw-r--r-- | src/gui/Main.cc | 10 | ||||
-rw-r--r-- | src/main/Accelerator.h | 8 | ||||
-rw-r--r-- | src/main/CompositeElement.cc | 2 | ||||
-rw-r--r-- | src/main/CompositeElement.h | 6 | ||||
-rw-r--r-- | src/main/CurvedElement.cc | 14 | ||||
-rw-r--r-- | src/main/CurvedElement.h | 12 | ||||
-rw-r--r-- | src/main/Dipole.cc | 2 | ||||
-rw-r--r-- | src/main/FODO.cc | 2 | ||||
-rw-r--r-- | src/main/FODO.h | 10 | ||||
-rw-r--r-- | src/main/Quadrupole.cc | 14 | ||||
-rw-r--r-- | src/main/Quadrupole.h | 3 |
12 files changed, 54 insertions, 31 deletions
diff --git a/src/gui/ElementRenderer.cc b/src/gui/ElementRenderer.cc index f4012ea..5f99491 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->getFocalizingCoefficient() > 1) + if (quadrupole->getFocalizingCoefficient() > 0) glColor4d(0.4, 0, 0, 0.9); else glColor4d(0.4, 0.2, 0.2, 0.9); diff --git a/src/gui/Main.cc b/src/gui/Main.cc index cfef31e..6b60310 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -66,10 +66,10 @@ Accelerator* standardAccelerator() { } Accelerator* linear() { - FODO element = FODO(Vector3D(0, 0, 0), Vector3D(4, 0, 0), 0.2, 1.0, 5E9); + FODO element = FODO(Vector3D(0, 0, 0), Vector3D(4, 0, 0), 0.2, 1.2, 0.1); Accelerator* acc = new Accelerator(); Element* celement = acc->add(element); - Particle e(Vector3D(0, 0.05, 0.01), constants::ELECTRON_MASS, constants::E, 14E9 * constants::E, Vector3D::i); + 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); @@ -85,12 +85,12 @@ Accelerator* singleDipole() { double mass = constants::ELECTRON_MASS; double charge = constants::E; - double energy = 14 * 1E9 * constants::E; + double energy = 1 * 1E9 * constants::E; Particle particle = Particle(entry, mass, charge, energy, direction); double Bz = particle.getGamma() * particle.getMass() * curvature * particle.getVelocity().norm() / particle.getCharge(); - std::cout << Bz << std::endl; + std::cout << "|B:|" << Bz << std::endl; Dipole element = Dipole(entry, exit, sectionRadius, curvature, Vector3D::k * Bz); Accelerator* acc = new Accelerator(); @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); vhc::Stage window; - Accelerator* acc = singleDipole(); + Accelerator* acc = linear(); window.accelerator = acc; window.showFullScreen(); diff --git a/src/main/Accelerator.h b/src/main/Accelerator.h index 89f87b3..60e8ed9 100644 --- a/src/main/Accelerator.h +++ b/src/main/Accelerator.h @@ -98,8 +98,16 @@ public: for (int i = 0; i < particleCollec.size(); ++i) { Particle* particle = particleCollec[i]; + std::cout << "element: " << (particle->getElement()->toString()) << "\n"; + + std::cout << "B field at particle position: " << (particle->getElement()->magneticFieldAt(particle->getPosition())) << "\n"; + std::cout << "B field at entry position: " << (particle->getElement()->magneticFieldAt(particle->getElement()->getEntryPosition())) << "\n"; + + std::cout << "real stuff\n"; particle->applyMagneticForce(particle->getElement()->magneticFieldAt(particle->getPosition()), dt); + std::cout.flush(); + Vector3D a = particle->getForce() / (particle->getGamma() * particle->getMass()); particle->setVelocity(particle->getVelocity() + a * dt); } diff --git a/src/main/CompositeElement.cc b/src/main/CompositeElement.cc index 3b1a709..4c4170e 100644 --- a/src/main/CompositeElement.cc +++ b/src/main/CompositeElement.cc @@ -49,6 +49,8 @@ void CompositeElement::accept(const ElementVisitor& v) const { } } +std::string CompositeElement::getType() const {return "CompositeElement";} + std::string CompositeElement::toString() const { std::stringstream s; for (int i(0); i < elements.size(); ++i) { diff --git a/src/main/CompositeElement.h b/src/main/CompositeElement.h index 42786e2..4cf55a8 100644 --- a/src/main/CompositeElement.h +++ b/src/main/CompositeElement.h @@ -38,16 +38,14 @@ public: /** Determine si une particule a passe cet element, donc passe le dernier element composant. */ virtual bool isPast(const Particle& particle) const; - /** Retourne le vecteur résultant du champ magnétique de tous les éléments, à une certaine position donnée.*/ virtual Vector3D magneticFieldAt(const Vector3D& position) const; - /** Retourne le vecteur résultant du champ électrique de tous les éléments, à une certaine position donnée.*/ virtual Vector3D electricFieldAt(const Vector3D& position) const; - // TODO une explication simple.....lol virtual void accept(const ElementVisitor& v) const; - /** Retourne cet élément composé sous forme de chaîne de caractères.*/ + virtual std::string getType() const; + virtual std::string toString() const; }; diff --git a/src/main/CurvedElement.cc b/src/main/CurvedElement.cc index 1afae38..ca1a4bd 100644 --- a/src/main/CurvedElement.cc +++ b/src/main/CurvedElement.cc @@ -24,7 +24,11 @@ CurvedElement::CurvedElement(const Vector3D& entry, const Vector3D& exit, double //pas possible que le rayon de courbure soit plus petit la moitie //de la distance entre les points d'entree et de sortie - if (fabs(1.0 / k) < (exit - entry).norm() / 2) throw IllegalArgumentException("Invalid curvature radius."); + if (fabs(1.0 / k) < (exit - entry).norm() / 2) throw IllegalArgumentException("Invalid curvature radius: too small."); + + Vector3D outDirection = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(exitPosition - curvatureCenter); + if ((entryPosition - exitPosition).dot(outDirection) > 0) throw IllegalArgumentException("A curved element cannot be more than half a turn."); + Vector3D midpoint = (getEntryPosition() + getExitPosition())/ 2; curvatureCenter = midpoint + 1 / k * sqrt(1.0 - (k * k) / 4 * getDiagonal().normSquare()) * (getDiagonal().unit().cross(Vector3D::k)); @@ -41,13 +45,13 @@ double CurvedElement::getAngle() const { } 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; + Vector3D X(particle.getPosition() - curvatureCenter); + Vector3D u = (X - particle.getPosition().getZ() * Vector3D::k).unit(); + return (X - fabs(1.0 / curvature) * u).norm() > sectionRadius; } bool CurvedElement::isPast(const Particle& particle) const { - Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(entryPosition - curvatureCenter); + Vector3D out = (entryPosition - curvatureCenter).cross(exitPosition - curvatureCenter).cross(exitPosition - curvatureCenter); return (particle.getPosition() - exitPosition).dot(out) > 0; } diff --git a/src/main/CurvedElement.h b/src/main/CurvedElement.h index f0aeae6..f7cc902 100644 --- a/src/main/CurvedElement.h +++ b/src/main/CurvedElement.h @@ -17,10 +17,14 @@ namespace vhc { -/** Represente un element courbe. En plus de posseder les proprietes generales d'un element, - * un element courbe a de plus une courbure et un centre de courbure. - * ==> TODO ajouter explication de la courbure - * Le centre de courbure est calcule avec la courbure et les positions des faces d'entree et de sortie d'un element. */ +/** Classe de base pour elements courbes. En plus de posseder les proprietes generales d'un element, + * un element courbe une courbure et un centre de courbure. + * La courbure est donnee par l'inverse du rayon de courbure dont le signe indique le sens de courbure par + * rapport à l’orientation donnée par l’opposé de l’axe vertical (Vector3D::k); + * + * Le centre de courbure est calcule avec la courbure et les positions des faces d'entree et de sortie d'un element. + * + * <b>ATTENTION:</b> un element courbe ne peut faire plus d'un demi tour! */ class CurvedElement: public Element { protected: diff --git a/src/main/Dipole.cc b/src/main/Dipole.cc index a313d12..fc811d4 100644 --- a/src/main/Dipole.cc +++ b/src/main/Dipole.cc @@ -29,7 +29,7 @@ std::string Dipole::getType() const {return "Dipole";} std::string Dipole::toString() const { std::stringstream s; s << CurvedElement::toString() << "\n"; - s << "\tB: " << getMagneticField(); + s << "\tB: " << getMagneticField() << "\n"; s << "\t|B|: " << getMagneticField().norm(); return s.str(); } diff --git a/src/main/FODO.cc b/src/main/FODO.cc index 59eb91b..b1fbf2e 100644 --- a/src/main/FODO.cc +++ b/src/main/FODO.cc @@ -52,6 +52,8 @@ FODO::~FODO() { elements.clear(); } +std::string FODO::getType() const {return "FODO";} + FODO* FODO::clone() const { return new FODO(getEntryPosition(), getExitPosition(), getSectionRadius(), straightLength, focalizingCoefficient); } diff --git a/src/main/FODO.h b/src/main/FODO.h index a3f19f2..4d61ad3 100644 --- a/src/main/FODO.h +++ b/src/main/FODO.h @@ -8,16 +8,13 @@ #ifndef FODO_H_ #define FODO_H_ +#include <string> #include "Quadrupole.h" #include "CompositeElement.h" #include "Vector3D.h" namespace vhc { -/** Représente une maille FODO, qui est un composé d'éléments constitué - * -d'un quadrupole focalisant; - * -de deux éléments droits; - * -à la sortie, d'un quadrupole défocalisant. */ class FODO: public CompositeElement { private: @@ -29,13 +26,12 @@ private: StraightElement* straightElement2; public: - /** Constructeur d'une maille FODO.*/ FODO(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double straightLength, double focalizingCoefficient, Element* next = NULL); - /** Destructeur virtuel.*/ virtual ~FODO(); - // TODO expl. + virtual std::string getType() const; + virtual FODO* clone() const; }; diff --git a/src/main/Quadrupole.cc b/src/main/Quadrupole.cc index 2d73fbb..9b1c3e9 100644 --- a/src/main/Quadrupole.cc +++ b/src/main/Quadrupole.cc @@ -5,18 +5,20 @@ * Author: jakob */ +#include <iostream> +#include <sstream> #include "Quadrupole.h" namespace vhc { -Quadrupole::Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focusingCoefficient, Element* next): +Quadrupole::Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focalizingCoefficient, Element* next): StraightElement(entry, exit, sectionRadius, next), - focalizingCoefficient(focusingCoefficient) + focalizingCoefficient(focalizingCoefficient) {}; Quadrupole::~Quadrupole() {}; -Vector3D Quadrupole::magneticFieldAt(const Vector3D& position) { +Vector3D Quadrupole::magneticFieldAt(const Vector3D& position) const { Vector3D x = position - getEntryPosition(); Vector3D d = getDiagonal().unit(); Vector3D y = x - x.dot(d) * d; @@ -33,6 +35,12 @@ void Quadrupole::setFocalizingCoefficient(double value) { } std::string Quadrupole::getType() const {return "Quadrupole";} +std::string Quadrupole::toString() const { + std::stringstream s; + s << Element::toString() << "\n"; + s << "\tfocalizing coefficient: " << focalizingCoefficient; + return s.str(); +} void Quadrupole::accept(const ElementVisitor& v) const {v.visit(this);} diff --git a/src/main/Quadrupole.h b/src/main/Quadrupole.h index 0f28537..06cca9a 100644 --- a/src/main/Quadrupole.h +++ b/src/main/Quadrupole.h @@ -25,13 +25,14 @@ public: virtual ~Quadrupole(); - virtual Vector3D magneticFieldAt(const Vector3D& position); + virtual Vector3D magneticFieldAt(const Vector3D& position) const; double getFocalizingCoefficient() const; void setFocalizingCoefficient(double value); virtual std::string getType() const; + virtual std::string toString() const; virtual void accept(const ElementVisitor& v) const; |