diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 23:03:45 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-04-17 23:03:45 +0000 |
commit | 9d9da8b4ec09741c7482bea0da0ee8ac8c4366a4 (patch) | |
tree | 5b9850db16d9196a45c8a5fba47fc5a84e14f1e6 /src/gui/Main.cc | |
parent | 5c7b4e1372ec25a8df3af20afedb63349dddfdca (diff) | |
download | vhc-9d9da8b4ec09741c7482bea0da0ee8ac8c4366a4.tar.gz vhc-9d9da8b4ec09741c7482bea0da0ee8ac8c4366a4.tar.bz2 vhc-9d9da8b4ec09741c7482bea0da0ee8ac8c4366a4.zip |
Ajoute possibilite de simuler!
Diffstat (limited to 'src/gui/Main.cc')
-rw-r--r-- | src/gui/Main.cc | 103 |
1 files changed, 77 insertions, 26 deletions
diff --git a/src/gui/Main.cc b/src/gui/Main.cc index 012c6ef..cfef31e 100644 --- a/src/gui/Main.cc +++ b/src/gui/Main.cc @@ -8,6 +8,7 @@ #include <iostream> #include <QApplication> #include <QWidget> +#include <cmath> #include "Stage.h" #include "Accelerator.h" #include "StraightElement.h" @@ -15,29 +16,28 @@ #include "Particle.h" #include "FODO.h" #include "Vector3D.h" +#include "constants.h" #include <vector> using namespace vhc; -std::vector< Particle > createParticles(const Vector3D& position, int n) { +std::vector< Particle > createParticles(const Vector3D& position, int n, double mass = constants::ELECTRON_MASS, double charge = constants::E, double energy = 0, Vector3D direction = Vector3D::Null) { std::vector< Particle > v; + double r = 0.1; + for (int i = 0; i < n; ++i) { - double x = (rand() % 100) / 1000.0; - double y = (rand() % 100) / 1000.0; - double z = (rand() % 100) / 1000.0; - v.push_back(Particle(position + Vector3D(x, y, z), 1, 1)); + double x = (rand() % 1000) / 1000.0 * r; + double y = (rand() % 1000) / 1000.0 * sqrt(r * r - x * x); + double z = (rand() % 1000) / 1000.0 * sqrt(r * r - y * y - x * x);; + v.push_back(Particle(position + Vector3D(x, y, z), mass, charge, energy, direction)); } return v; } - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - +Accelerator* standardAccelerator() { FODO e1 = FODO(Vector3D(3, 2, 0), Vector3D(3, -2, 0), 0.2, 1.0, 5.0); Dipole e2 = Dipole(e1.getExitPosition(), Vector3D(2, -3, 0), 0.2, 1); FODO e3 = FODO(e2.getExitPosition(), Vector3D(-2, -3, 0), 0.2, 1, 5.0); @@ -46,29 +46,77 @@ int main(int argc, char *argv[]) Dipole e6 = Dipole(e5.getExitPosition(), Vector3D(-2, 3, 0), 0.2, 1); FODO e7 = FODO(e6.getExitPosition(), Vector3D(2, 3, 0), 0.2, 1.0, 5.0); Dipole e8 = Dipole(e7.getExitPosition(), e1.getEntryPosition(), 0.2, 1); - Accelerator acc; - acc.add(e1); - acc.add(e2); - acc.add(e3); - acc.add(e4); - acc.add(e5); - acc.add(e6); - acc.add(e7); - acc.add(e8); + Accelerator* acc = new Accelerator(); + acc->add(e1); + acc->add(e2); + acc->add(e3); + acc->add(e4); + acc->add(e5); + acc->add(e6); + acc->add(e7); + acc->add(e8); + + std::vector< Particle > ps = createParticles(e1.getEntryPosition(), 1000); + + for (int i = 0; i < ps.size(); ++i) { + acc->add(ps[i]); + } + + return acc; +} + +Accelerator* linear() { + FODO element = FODO(Vector3D(0, 0, 0), Vector3D(4, 0, 0), 0.2, 1.0, 5E9); + 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* ce = acc->add(e); + ce->setElement(celement); + + return acc; +} + +Accelerator* singleDipole() { + Vector3D entry = Vector3D(0, 2, 0); + Vector3D exit = Vector3D(2, 0, 0); + double sectionRadius = 0.2; + double curvature = 0.5; + Vector3D direction = entry.cross(Vector3D::k); + double mass = constants::ELECTRON_MASS; + double charge = constants::E; + double energy = 14 * 1E9 * constants::E; - vhc::Particle p(e1.getEntryPosition(), 1, 1); - acc.add(p); - std::vector< Particle > ps = createParticles(e1.getEntryPosition(), 1000); + 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; + Dipole element = Dipole(entry, exit, sectionRadius, curvature, Vector3D::k * Bz); - for (int i = 0; i < ps.size(); ++i) { - acc.add(ps[i]); - } + Accelerator* acc = new Accelerator(); + Element* celement = acc->add(element); + + std::vector< Particle > ps = createParticles(element.getEntryPosition(), 10, constants::ELECTRON_MASS, constants::E, energy, direction); + + for (int i = 0; i < ps.size(); ++i) { + Particle* cparticle = acc->add(ps[i]); + cparticle->setElement(celement); + } + + Particle* cparticle = acc->add(particle); + cparticle->setElement(celement); + return acc; +} + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); vhc::Stage window; - window.accelerator = &acc; + Accelerator* acc = singleDipole(); + window.accelerator = acc; window.showFullScreen(); //window.resize(QSize(500, 500)); @@ -76,4 +124,7 @@ int main(int argc, char *argv[]) window.show(); return app.exec(); + + delete acc; acc = NULL; + } |