Line data Source code
1 : #include "crpropa/magneticField/PolarizedSingleModeMagneticField.h"
2 :
3 : namespace crpropa {
4 :
5 1 : PolarizedSingleModeMagneticField::PolarizedSingleModeMagneticField( const double &B_0, const double &wavelength, const double &sigma, const Vector3d &r_0, const Vector3d &e_1, const Vector3d &e_2, std::string flagAmplitudeRms, std::string flagPolarizationHelicity, std::string flagMode ) {
6 1 : if (flagMode == "elliptical") {
7 1 : if (abs(sigma) > 1)
8 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: The value of the polarization parameter has to lie in the range [-1;+1].");
9 : }
10 0 : else if (flagMode == "circular") {
11 0 : if (abs(sigma) != 1)
12 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: For circular polarization the value of the polarization parameter has to be equal to -1 or +1.");
13 : }
14 0 : else if (flagMode == "linear") {
15 0 : if (abs(sigma) != 0)
16 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: For linear polarization the value of the polarization parameter has to be equal to 0.");
17 : }
18 : else
19 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: Wrong value for flagMode. Please choose \"elliptical\" or \"circular\" or \"linear\".");
20 :
21 1 : if (e_1.dot(e_2) != 0)
22 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: e_1 and e_2 have to be orthogonal to each other.");
23 :
24 1 : if (e_1.getR() == 0)
25 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: Vector e_1 cannot be zero.");
26 : unitVector_1 = e_1 / e_1.getR();
27 :
28 1 : if (e_2.getR() == 0)
29 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: Vector e_2 cannot be zero.");
30 : unitVector_2 = e_2 / e_2.getR();
31 :
32 : wavevector = e_2.cross(e_1);
33 :
34 : //This check is necessary if a polarization with non-orthogonal spanning vectors is desired. This is not implemented in this version, so any corresponding modifications should be made with caution.
35 : //if (wavevector.getR() == 0)
36 : // throw std::runtime_error("PolarizedSingleModeMagneticField: e_1 cannot be parallel to e_2.");
37 :
38 : wavevector = wavevector / wavevector.getR();
39 :
40 1 : if (wavelength == 0)
41 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: The correlation length cannot be zero.");
42 : wavevector = wavevector * 2 * M_PI / wavelength;
43 :
44 1 : if (!((flagPolarizationHelicity == "helicity") || (flagPolarizationHelicity == "polarization")))
45 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: Wrong value for flagPolarizationHelicity. Please choose \"polarization\" or \"helicity\".");
46 1 : if (flagPolarizationHelicity == "helicity" && abs(sigma) != 1)
47 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: In helicity mode only the maximum helicity case (sigma = +1 or sigma = -1) may be chosen.");
48 :
49 1 : if (flagAmplitudeRms == "amplitude")
50 1 : B_max = B_0;
51 0 : else if (flagAmplitudeRms == "rms")
52 0 : B_max = sqrt(2 / (1 + sigma * sigma)) * B_0;
53 : else
54 0 : throw std::runtime_error("PolarizedSingleModeMagneticField: Wrong value for flagAmplitudeRms. Please choose \"amplitude\" or \"rms\".");
55 :
56 : this->r_0 = r_0;
57 1 : this->sigma = sigma;
58 1 : }
59 :
60 1 : Vector3d PolarizedSingleModeMagneticField::getField(const Vector3d &position) const {
61 : Vector3d delta_r = position - r_0;
62 :
63 1 : return B_max * (unitVector_1 * cos(wavevector.dot(delta_r)) + unitVector_2 * sigma * sin(wavevector.dot(delta_r)));
64 : }
65 :
66 : } //end namespace crpropa
|