gaussian_beams.py 4.01 KB
 Daniel Brown committed Dec 05, 2013 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import pykat.exceptions as pkex import numpy import math class gauss_param(object): """ Gaussian beam complex parameter gauss_param is effectively a complex number with extra functionality to determine beam parameters. defaults to 1064e-9m for wavelength and refractive index 1 usage: q = gauss_param(w0=w0, z=z) q = gauss_param(z=z, zr=zr) q = gauss_param(wz=wz, rc=rc)  17  q = gauss_param(q=a) # where a is a complex number  Daniel Brown committed Dec 05, 2013 18 19 20 21 22 23 24 25 26 27 28 29 30  or change default wavelength and refractive index with: q = gauss_param(wavelength, nr, w0=w0, zr=zr) """ def __init__(self, wavelength=1064e-9, nr=1, *args, **kwargs): self.__q = None self.__lambda = wavelength self.__nr = nr if len(args) == 1: self.__q = args[0]  31 32 33 34 35  elif len(kwargs) == 1: if "q" in kwargs: self.__q = complex(kwargs["q"]) else:  Daniel Brown committed Dec 09, 2013 36  raise pkex.BasePyKatException("Must specify: z and w0 or z and zr or rc and wz or q, to define the beam parameter")  37   Daniel Brown committed Dec 05, 2013 38 39 40 41 42 43 44 45 46 47  elif len(kwargs) == 2: if "w0" in kwargs and "z" in kwargs: q = float(kwargs["z"]) + 1j *float(math.pi*kwargs["w0"]**2/(self.__lambda/self.__nr) ) elif "z" in kwargs and "zr" in kwargs: q = float(kwargs["z"]) + 1j *float(kwargs["zr"]) elif "rc" in kwargs and "wz" in kwargs: one_q = 1 / kwargs["rc"] - 1j * self.__lamda / (math.pi * self.__nr * kwargs["wz"]**2) q = 1/one_q else:  Daniel Brown committed Dec 09, 2013 48  raise pkex.BasePyKatException("Must specify: z and w0 or z and zr or rc and wz or q, to define the beam parameter")  Daniel Brown committed Dec 05, 2013 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134  self.__q = q else: raise pkex.BasePyKatException("Incorrect usage for gauss_param constructor") @property def wavelength(self): return self.__lambda @property def nr(self): return self.__nr @property def q(self): return self.__q @property def z(self): return self.__q.real @property def zr(self): return self.__q.imag @property def wz(self): return math.sqrt(self.__lambda /(self.__nr * math.pi) * abs(self.__q) / self.__q.imag) @property def w0(self): return math.sqrt(self.__q.imag * self.__lambda / (self.__nr * math.pi)) @property def Rc(self): if self.__q.real != 0: return abs(self.__q) / self.__q.real else: return float("inf") def conjugate(self): return gauss_param(self.__lambda, self.__nr, self.__q.conjugate()) def __complex__(self): return self.__q def __str__(self): return str(self.__q) def __mul__(self, a): return gauss_param(self.__lambda, self.__nr, self.__q * complex(a)) def __imul__(self, a): self.__q += complex(a) return self __rmul__ = __mul__ def __add__(self, a): return gauss_param(self.__lambda, self.__nr, self.__q + complex(a)) def __iadd__(self, a): self.__q += complex(a) return self __radd__ = __add__ def __sub__(self, a): return gauss_param(self.__lambda, self.__nr, self.__q - complex(a)) def __isub__(self, a): self.__q -= complex(a) return self __rsub__ = __sub__ def __div__(self, a): return gauss_param(self.__lambda, self.__nr, self.__q / complex(a)) def __idiv__(self, a): self.__q /= complex(a) return self def __pow__(self, q): return gauss_param(self.__lambda, self.__nr, self.__q**q) def __neg__(self, q): return gauss_param(self.__lambda, self.__nr, -self.__q) def __eq__(self, q): return complex(q) == self.__q