summaryrefslogtreecommitdiff
path: root/src/main/Quadrupole.h
blob: 1f4903bf6d3c36bbd72ebfbe7ef2f72073cfcaed (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Quadrupole.h
 *
 *  Created on: Mar 29, 2011
 *      Author: jakob
 */

#ifndef QUADRUPOLE_H_
#define QUADRUPOLE_H_

#include <string>
#include "StraightElement.h"
#include "Vector3D.h"
#include "ElementVisitor.h"

namespace vhc {

class Quadrupole: public StraightElement {

private:
	double focusingCoefficient;

public:
	Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focusingCoefficient, Element* next = NULL):
		StraightElement(entry, exit, sectionRadius, next),
		focusingCoefficient(focusingCoefficient)
	{};

	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);
	}

	double getFocusingCoefficient() const {
		return focusingCoefficient;
	}

	void setFocusingCoefficient(double value) {
		focusingCoefficient = value;
	}

	virtual std::string getType() const {return "Quadrupole";}

	virtual void accept(ElementVisitor& v) {v.visit(this);}

	virtual Quadrupole* clone() const {return new Quadrupole(getEntryPosition(), getExitPosition(), getSectionRadius(), focusingCoefficient);}
};

}

#endif /* QUADRUPOLE_H_ */