summaryrefslogtreecommitdiff
path: root/src/main/BruteForceInteractor.cc
blob: 6e19bd8143df411109df4b21e6fa4372e77d2298 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * BruteForceInteractor.cc
 *
 *  Created on: May 26, 2011
 *      Author: jakob
 */

#include <iostream>
#include "BruteForceInteractor.h"

using namespace std;

namespace vhc {

BruteForceInteractor::BruteForceInteractor(): particles(0) {}

BruteForceInteractor::~BruteForceInteractor() {}

void BruteForceInteractor::applyInteractions() {
	for (list< Particle* >::iterator i = particles.begin(); i != particles.end(); ++i) {
		for (list< Particle* >::iterator j = particles.begin(); j != particles.end(); ++j) if (i != j) {
			double r = ((**j).getPosition() - (**i).getPosition()).norm();
			if (r != 0) {
				Vector3D d = ((**j).getPosition() - (**i).getPosition()).unit();
				Vector3D force = d * (**i).getCharge() * (**i).getCharge() /
								(4 * M_PI * constants::EPSILON_ZERO * r * r * r * (**i).getGamma() * (**i).getGamma());
				(**i).applyForce(force);
				(**j).applyForce(-force);
			}
		}
	}
}

void BruteForceInteractor::react(const ParticleAddedEvent& event) {
	particles.push_back(event.getParticle());
}
void BruteForceInteractor::react(const ParticleRemovedEvent& event) {
	particles.remove(event.getParticle());
}

}