Spinor.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2016 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// epsic/src/util/Spinor.h
10
11#ifndef __Spinor_H
12#define __Spinor_H
13
14#include "Vector.h"
15#include "Jones.h"
16
17#include <iostream>
18
19/***************************************************************************
20 *
21 * Spinor class represents an instance of the electric field
22 *
23 ***************************************************************************/
24
25template<typename T>
26class Spinor
27{
28public:
29 Spinor (const std::complex<T>& _x, const std::complex<T>& _y) : x(_x), y(_y){}
30 Spinor () { }
31
32 std::complex<T> x;
33 std::complex<T> y;
34
35 template <typename U>
36 const Spinor& operator *= (U scale) { x *= scale; y *= scale; return *this; }
37 const Spinor& operator /= (T norm) { x /= norm; y /= norm; return *this; }
38 const Spinor& operator += (const Spinor& e) { x+=e.x; y+=e.y; return *this; }
39};
40
41template <typename T>
42std::ostream& operator << (std::ostream& os, const Spinor<T>& s)
43{
44 os << s.x << " " << s.y;
45 return os;
46}
47
48template <typename T>
49const Spinor<T> operator + (Spinor<T> s, const Spinor<T>& t)
50{
51 return s += t;
52}
53
55template<typename T>
56const Spinor<T> operator * (const Jones<T>& j, const Spinor<T>& in)
57{
58 return Spinor<T> ( j.j00 * in.x + j.j01 * in.y,
59 j.j10 * in.x + j.j11 * in.y );
60}
61
62template<typename T, typename U>
63const Spinor<T> operator * (U a, Spinor<T> in)
64{
65 return in *= a;
66}
67
68template<typename T, typename U>
69const Spinor<T> operator * (Spinor<T> in, U a)
70{
71 return in *= a;
72}
73
74
75template<typename T, typename U>
76void compute_stokes (Vector<4,T>& stokes, const Spinor<U>& e)
77{
78 double var_x = norm(e.x);
79 double var_y = norm(e.y);
80
81 std::complex<double> c_xy = conj(e.x) * e.y;
82
83 stokes[0] = var_x + var_y;
84 stokes[1] = var_x - var_y;
85 stokes[2] = 2.0*c_xy.real();
86 stokes[3] = 2.0*c_xy.imag();
87}
88
89#endif

Generated using doxygen 1.14.0