diff options
author | Jakob Odersky <jodersky@gmail.com> | 2011-05-19 08:33:16 +0000 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2011-05-19 08:33:16 +0000 |
commit | 2c8bb59d4ccca47c5342ee030f31e13c0cb2674b (patch) | |
tree | db127642457cd6bccf32f0d8a5dea3c83f8d67db /src/main/Beam.cc | |
parent | b88deff7c45593bb6ad0780b70ce929346056aae (diff) | |
download | vhc-2c8bb59d4ccca47c5342ee030f31e13c0cb2674b.tar.gz vhc-2c8bb59d4ccca47c5342ee030f31e13c0cb2674b.tar.bz2 vhc-2c8bb59d4ccca47c5342ee030f31e13c0cb2674b.zip |
Migration des particules vers les faisceau.
Il reste une subtilite a gerer: pour des raisons de compatibilite, un accelerateur contient toujours une methode getParticles(). Celle-ci renvoi une concatenation de tous les particules de tous les faisceaux de l'accelerateur.
Or il y a un probleme d'allocation de la memoire avec cette methode (temporairement repare dans cette revision mais degeu!). Je vois deux solutions:
1) changer tous les test qui appellent la methode getParticles()
2) essayer de reparer le probleme d'allocation (difficile et je ne sais pas si c'est possible)
Diffstat (limited to 'src/main/Beam.cc')
-rw-r--r-- | src/main/Beam.cc | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/src/main/Beam.cc b/src/main/Beam.cc index f01368e..97c2688 100644 --- a/src/main/Beam.cc +++ b/src/main/Beam.cc @@ -13,18 +13,27 @@ using namespace std; namespace vhc { -Beam::Beam(const Particle& referenceParticle, int quantity, int lambda): referenceParticle(referenceParticle), quantity(quantity), lambda(lambda) { - init(referenceParticle, quantity, lambda); -} +Beam::Beam(const Particle& referenceParticle, int quantity, int lambda): + referenceParticle(referenceParticle), + quantity(quantity), + lambda(lambda) {} Beam::~Beam() { - for (list<Particle*>::iterator i = particles.begin(); i != particles.end(); ++i) { + clear(); +} + +void Beam::clear() { + for (ParticleCollection::iterator i = particles.begin(); i != particles.end(); ++i) { delete *i; *i = NULL; } particles.clear(); } +int Beam::getQuantity() const { + return quantity; +} + int Beam::getSize() const { return particles.size(); } @@ -33,10 +42,55 @@ int Beam::getLambda() const { return lambda; } -const Particle& Beam::getReferenceParticle() const { +Particle& Beam::getReferenceParticle() { return referenceParticle; } +Beam::ParticleCollection& Beam::getParticles() {return particles;} + +void Beam::updateParticles() { + for (ParticleCollection::iterator i = particles.begin(); i != particles.end(); ++i) { + Particle& particle = **i; + if (particle.getElement()->isAfter(particle)) { + if (particle.getElement()->getNext() == NULL) { + delete *i; + i = particles.erase(i); + --i; + //cout << "Particle reached end of accelerator. Removed from simulation" << std::endl; + } else particle.setElement(particle.getElement()->getNext()); + } else if (particle.getElement()->isBefore(particle)) { + if (particle.getElement()->getPrevious() == NULL) { + delete *i; + i = particles.erase(i); + --i; + //cout << "Particle reached beginning of accelerator. Removed from simulation" << std::endl; + } else particle.setElement(particle.getElement()->getPrevious()); + } else if (particle.getElement()->isBeside(particle)) { + //std::cout << "Particle hit wall. Removed from simulation" << std::endl; + delete *i; + i = particles.erase(i); + --i; + } + } +} + +void Beam::step(double dt) { + for (ParticleCollection::iterator i = particles.begin(); i != particles.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(); +} + double Beam::getVR2() const { double z2 = 0; for (list<Particle*>::const_iterator i = particles.begin(); i != particles.end(); ++i) { |