GOAT (Geometrical optics application tool) 0.1
Loading...
Searching...
No Matches
lightsrc.h
Go to the documentation of this file.
1#ifndef Lightsrc_H
2#define Lightsrc_H
3
4#include "raybase.h"
5#include "vector.h"
6#include "tubedray.h"
7#include "iray.h"
8#include "objectshape.h"
9#include "ray_pow.h"
10#include <vector>
11
12namespace GOAT
13{
14 namespace raytracing
15 {
16#define LIGHTSRC_RAYTYPE_RAY 1
17#define LIGHTSRC_RAYTYPE_IRAY 2
18#define LIGHTSRC_RAYTYPE_PRAY 3
19constexpr int LIGHTSRC_SRCTYPE_PLANE=1;
20constexpr int LIGHTSRC_SRCTYPE_GAUSS=2;
21constexpr int LIGHTSRC_SRCTYPE_RING = 3;
22constexpr int LIGHTSRC_SRCTYPE_TOPHAT=4;
23constexpr int LIGHTSRC_SRCTYPE_LINE = 5;
24constexpr int LIGHTSRC_SRCTYPE_POINT = 6;
25
26constexpr int LIGHTSRC_SRCTYPE_PLANE_MC = 11;
27constexpr int LIGHTSRC_SRCTYPE_GAUSS_MC = 12;
28constexpr int LIGHTSRC_SRCTYPE_RING_MC = 13;
29constexpr int LIGHTSRC_SRCTYPE_LINE_MC = 14;
30constexpr int LIGHTSRC_SRCTYPE_POINT_MC = 15;
31
32
33
34#define LIGHTSRC_NOT_LAST_RAY 0
35#define LIGHTSRC_IS_LAST_RAY 1
36#define LIGHTSRC_ERROR -1
37#define Z0 376.730313461
38
39#define LIGHTSRC_POL_X 0
40#define LIGHTSRC_POL_Y 1
41#define LIGHTSRC_POL_Z 2
42#define LIGHTSRC_POL_USER_DEFINED 0
43
44
45
46
67
68 {
69 public:
70 void reset();
71 ~LightSrc(void);
74 void clearObjects();
77 void ObjectList(int Anz, std::vector<ObjectShape*> Obj);
79
86 virtual int next(RayBase* ray) = 0; // gives back next ray
87 virtual int next(Ray_pow& ray) = 0; // gives back next ray
88 virtual int next(IRay& ray) = 0; // gives back next ray
89 virtual int next(tubedRay& ray) = 0; // gives back next ray
90 virtual double area() { return 1.0; }
92 void binRead(std::ifstream& is);
93 void binWrite(std::ofstream& os);
94 virtual void binWriteItem(std::ofstream& os) = 0;
95 virtual void binReadItem(std::ifstream& os) = 0;
96 int getNumObjs() { return numObjs; }
97 ObjectShape* getObject(int i) { if ((i < 0) || (i > numObjs)) return NULL; return Obj[i]; }
98 void setObject(ObjectShape* O, int i = -1);
99 int rayType() { return raytype; }
100 void setR0(double r0);
101 double getDensity() { return density; }
103 void setD(double D)
104 {
105 this->density = D / ((double)N);
106 this->D = D;
107 D1 = D;
108 D2 = D;
109 reset();
110 }
111
112 void setD(double D1, double D2)
113 {
114 if (D1<D2) density= D1 / ((double)N);
115 else density = D2 / ((double)N);
116 this->D1 = D1;
117 this->D2 = D2;
118 reset();
119 }
120
122 {
123 this->numRaysRT=numRaysRT;
124 }
125
126 int getNumRaysRT () {return numRaysRT; }
127
128
129
132 int getNumRays() { return N; }
133 void setNumRays(int N)
134 {
135 this->N = N;
136 density = D / ((double)N);
137 reset();
138 }
139 void setWavelength(double wvl) { this->wvl = wvl; k0 = 2.0 * M_PI / wvl; }
140 double getWavelength() { return wvl; }
141 void setWavenumber(double k0) { this->k0 = k0; wvl = 2.0 * M_PI / k0; }
142 double getWavenumber() { return k0; }
143
144 void setPol(maths::Vector<std::complex<double> > pol);
147 void setN0(std::complex<double> n0) { this->n0 = n0; }
148 std::vector<ObjectShape*> Obj;
149 // protected :
151 int type;
152 double P0=1.0;
153 double density;
155 int N=10000;
156 int i1;
157 int i2;
160 double r0=1.0;
161
163 std::complex<double> n0;
164
165 double D;
166 double D1, D2;
171 double Pall;
172 friend class LightSrcPlane;
173 friend class LightSrcGauss;
174 friend std::ostream& operator << (std::ostream& os, LightSrc* ls);
178 double getIsum1() { return Isum1; }
179 double getIsum2() { return Isum2; }
180
181 protected:
182 double wvl=1;
183 double k0;
185 double Isum1, Isum2;
186 int numRaysRT=20;
187
188 };
189
190
191
192
196 class LightSrcPlane : public LightSrc
197 {
198 public:
208 LightSrcPlane(maths::Vector<double> Pos, int N, double wvl, double D = 100.0, maths::Vector<std::complex<double> > Pol = maths::Vector<std::complex<double> >(0.0, 1.0, 0.0), int raytype = LIGHTSRC_RAYTYPE_IRAY, double r0 = 100.0);
210 ~LightSrcPlane(void) {};
212 int next(IRay& S);
213 int next(tubedRay& S);
214 int next(Ray_pow& S);
215 void binWriteItem(std::ofstream& os) { /* to be implemented !!! */ }
216 void binReadItem(std::ifstream& os) { /* to be implemented !!! */ }
217 double area() { return D * D; }
218
219 // void turnSrc // to be done !!!
220 };
221
224 class LightSrcLine : public LightSrc
225 {
226 public:
236 int next(RayBase* ray);
237 int next(IRay& S);
238 int next(Ray_pow& S);
239 int next(tubedRay& S);
240 void binWriteItem(std::ofstream& os) { /* to be implemented !!! */ }
241 void binReadItem(std::ifstream& os) { /* to be implemented !!! */ }
243 double size;
244 };
245
246
247
252 class LightSrcRing : public LightSrc
253 {
254 public:
256 LightSrcRing(maths::Vector<double> Pos, int N, double wvl, double rmin=0.0, double rmax=100.0, maths::Vector<std::complex<double> > Pol = maths::Vector<std::complex<double> >(0.0, 1.0, 0.0), int raytype = LIGHTSRC_RAYTYPE_IRAY, double r0 = 100.0);
257 int next(RayBase* ray);
258 int next(IRay& S);
259 int next(Ray_pow& S);
260 int next(tubedRay& S);
261 void binWriteItem(std::ofstream& os) { /* to be implemented !!! */ }
262 void binReadItem(std::ifstream& os) { /* to be implemented !!! */ }
263 double getRmin() {return rmin; }
264 double getRmax() {return rmax; }
265 void setRmin(double rmin);
266 void setRmax(double rmax);
267 double area() { return M_PI * (rmax * rmax - rmin * rmin); }
268 private:
269 double rmin = 0.0;
270 double rmax = 100.0;
271 };
272
282 class LightSrcGauss : public LightSrc
283 {
284 public:
285 void binWriteItem(std::ofstream& os);
286 void binReadItem(std::ifstream& is);
288 int next(Ray_pow& S);
289 int next(IRay& S);
290 int next(tubedRay& S);
291 // void initElectricFieldGauss(GOAT::maths::Vector<double> &P, GOAT::maths::Vector<double> &k, GOAT::maths::Vector<std::complex<double> > &E); ///< Initialisierung eines Teilstrahls
307 LightSrcGauss(maths::Vector<double> Pos, int N, double wvl, double w0, maths::Vector<double> focuspos, double D = 1.0, maths::Vector<std::complex<double> > Pol = maths::Vector<std::complex<double> >(0.0, 1.0, 0.0), int raytype = LIGHTSRC_RAYTYPE_IRAY, double r0 = 1.0);
308 double area() { return D * D; }
309 void setW0(double w0) { this->w0 = w0; calcz0(); reset(); }
312 void setPos(maths::Vector<double> pos) { Pos = pos; f = abs(Pos - focuspos); reset(); }
313
314 void setNA(double na);
315 void setWvl(double wvl);
317 double calcz0() { z0 = M_PI * w0 * w0 / wvl; return z0; }
318 std::complex<double> calcStartPhase(maths::Vector<double> P);
319 void reset()
320 {
321 polType = LIGHTSRC_POL_Y; // ???
322 k = focuspos - Pos;
323 k = k / abs(k);
324 e1 = k % maths::ez;
325 if (abs(e1) < 1E-10) e1 = maths::ex;
326 e2 = k % e1;
327 e1 = e1 / abs(e1);
328 e2 = e2 / abs(e2);
329
330 i1 = 0;
331 i2 = 0;
332 f = (Pos - focuspos)*k;
333 z0 = M_PI * w0 * w0 / wvl;
334 numObjs = 0;
335 n0 = 1.0;
336 double d = abs(Pos - focuspos);
337 calcz0();
338 calcw(d);
339 double theta = atan(wvl / (M_PI * w0));
340 NA = real(n0) * sin(theta);
341 calcNormfak();
342 zeta = atan(f / z0);
343 R = f * (1 + z0 * z0 / (f * f));
344 k0 = 2.0 * M_PI / wvl;
345 std::cout << "Gauss: k=" << k << std::endl;
346 }
347
348 double calcw(double z)
349 {
350 w = w0 * sqrt(1.0 + z * z / (z0 * z0));
351 return w;
352 }
353
354
355
357 {
358 double l = abs(Pos - focuspos);
359 calcz0();
360 calcw(l);
361 Normfak = Z0 * sqrt(2.0 / M_PI) / (n0 * l * M_PI) * w / w0 / w0 * exp(-2.0 * l * l / w / w);
362 Normfak = Normfak / ((double)N * N) * l * l;
363 }
364 //protected :
365 double w0;
366 double f;
367 double getNA() { return NA; }
368
369 std::complex<double> Normfak;
371 double z0;
372// maths::Vector<double> k; ///< direction of the gaussian beam
373 double w;
374 double NA;
375 double zeta;
376 double R;
377 };
378
379
386 void binWriteLSList(std::ofstream& os, int nLS, LightSrc** ls);
393 void binReadLSList(std::ifstream& is, int nLS, LightSrc**& ls);
400 void copyLightSrcList(LightSrc**& d, LightSrc** s, int nLS);
401 }
402}
403#endif
Template class for threedimensional vectors.
Definition vector.h:57
This class represents a single ray.
Definition iray.h:33
void binWriteItem(std::ofstream &os)
writes content of LightSrc in a binary file, represented by is (has to be specified by the derived cl...
int next(GOAT::raytracing::RayBase *ray)
std::complex< double > calcStartPhase(maths::Vector< double > P)
maths::Vector< double > getFocuspos()
returns the position of the focus
Definition lightsrc.h:310
void setWvl(double wvl)
sets the vacuum wavelength
LightSrcGauss(const LightSrcGauss &)
maths::Vector< double > focuspos
focal position
Definition lightsrc.h:370
void setk(maths::Vector< double > k)
sets the main direction of light source
double area()
area A of the light source
Definition lightsrc.h:308
double getNA()
returns numerical aperture
Definition lightsrc.h:367
double calcz0()
recalculates Rayleigh-length z0
Definition lightsrc.h:317
std::complex< double > Normfak
Definition lightsrc.h:369
void setW0(double w0)
sets the beam's waist
Definition lightsrc.h:309
void setFocuspos(maths::Vector< double > fp)
sets the focus position to fp
Definition lightsrc.h:311
void setNA(double na)
sets the numerical aperture NA and recalculates the width D, the focal beam waist w0 and the Rayleigh...
double z0
Rayleigh length (for internal use only)
Definition lightsrc.h:371
void binReadItem(std::ifstream &is)
reads content of LightSrc from a binary file, represented by os (has to be specified by the derived c...
double f
distance between light source area and the focal point
Definition lightsrc.h:366
double w
radius of the beam (for internal use only)
Definition lightsrc.h:373
double w0
Waist diameter (fictitious !), only used for the correct calculation of the electric field distributi...
Definition lightsrc.h:365
void setPos(maths::Vector< double > pos)
sets the position of the light source to pos
Definition lightsrc.h:312
double NA
numerical aperture (normalized by the intermediate refractive index)
Definition lightsrc.h:374
LightSrcGauss(maths::Vector< double > Pos, int N, double wvl, double w0, maths::Vector< double > focuspos, double D=1.0, maths::Vector< std::complex< double > > Pol=maths::Vector< std::complex< double > >(0.0, 1.0, 0.0), int raytype=LIGHTSRC_RAYTYPE_IRAY, double r0=1.0)
Main constructor for gaussian beam light source The direction of the beam is given by the starting po...
This abstract class is the basic class for all light sources used in this raytracing library....
Definition lightsrc.h:68
void setObject(ObjectShape *O, int i=-1)
exchanges i-th object in the object list
virtual void binReadItem(std::ifstream &os)=0
reads content of LightSrc from a binary file, represented by os (has to be specified by the derived c...
maths::Vector< std::complex< double > > initPol
Polarisation, if the k-Vector points in z-direction.
Definition lightsrc.h:170
int N
number of rays (per direction)
Definition lightsrc.h:155
int numObjs
number of objects
Definition lightsrc.h:162
maths::Vector< double > k
main direction of the light source
Definition lightsrc.h:154
double r0
radius of the calculation sphere
Definition lightsrc.h:160
void binWrite(std::ofstream &os)
reads content of LightSrc from a binary file, represented by os
void setR0(double r0)
sets the radius of the calculation sphere
void addObject(ObjectShape *obj)
add single object to the object list
maths::Vector< double > Pos
position of the light source (center of the square area of the light source)
Definition lightsrc.h:150
virtual void binWriteItem(std::ofstream &os)=0
writes content of LightSrc in a binary file, represented by is (has to be specified by the derived cl...
void setNumRaysRT(int numRaysRT)
Definition lightsrc.h:121
virtual int next(RayBase *ray)=0
double Pall
overall Power
Definition lightsrc.h:171
virtual int next(IRay &ray)=0
void setD(double D1, double D2)
Definition lightsrc.h:112
LightSrc(const LightSrc &)
Copy constructor.
void setPol(maths::Vector< std::complex< double > > pol)
sets the polarisation
void ObjectList(int Anz, std::vector< ObjectShape * > Obj)
void setWavelength(double wvl)
Definition lightsrc.h:139
void setD(double D)
sets the width of the light source (this resets also the ray counter)
Definition lightsrc.h:103
void setN0(std::complex< double > n0)
sets the complex valued refractive index of the intermediate medium
Definition lightsrc.h:147
friend class LightSrcGauss
Definition lightsrc.h:173
void clearObjects()
clear object list
int raytype
Strahltyp : ray oder ISTRAHL (=RAY oder IRAY)
Definition lightsrc.h:168
virtual int next(Ray_pow &ray)=0
friend class LightSrcPlane
Definition lightsrc.h:172
void binRead(std::ifstream &is)
writes content of LightSrc in a binary file, represented by is
ObjectShape * getObject(int i)
returns i-th item in the object list
Definition lightsrc.h:97
double D2
width in the e1- and the e2-direction (used only for _mc versions of LightSrc)
Definition lightsrc.h:166
int rayType()
returns the current ray type
Definition lightsrc.h:99
void removeObject(ObjectShape *obj)
remove object from the object list
int getNumRays()
returns the number of rays (per direction in space)
Definition lightsrc.h:132
std::complex< double > n0
refractive index of the intermediate medium
Definition lightsrc.h:163
double k0
wavenumber (i.e.
Definition lightsrc.h:183
maths::Vector< std::complex< double > > Pol2
second polarisation (used by IRay)
Definition lightsrc.h:159
double density
ray density, i.e. distance between two neighboring rays
Definition lightsrc.h:153
int getNumObjs()
returns the number of Objects (only needed, when used seperately outside scene)
Definition lightsrc.h:96
bool suppress_phase_progress
if set true, the phase won't be changed when calling a next method (needed for USP-calculations)
Definition lightsrc.h:175
void reset()
Reset everything (counting starts from the beginning)
void setWavenumber(double k0)
Definition lightsrc.h:141
maths::Vector< std::complex< double > > getInitPol()
Definition lightsrc.h:102
maths::Vector< double > e2
unit vectors that span the light source area
Definition lightsrc.h:167
double D
width of the square light source area
Definition lightsrc.h:165
int i1
first index of the ray inside the starting area (for internal use, -1 if the calculation has not yet ...
Definition lightsrc.h:156
int polType
Polarisationsrichtung (s.o.)
Definition lightsrc.h:169
double wvl
wavelength
Definition lightsrc.h:182
std::vector< ObjectShape * > Obj
list of all objects
Definition lightsrc.h:148
int numRaysRT
used in GOATvis to determine number of rays for ray representation
Definition lightsrc.h:186
maths::Vector< std::complex< double > > Pol
polarisation (default: (0.0, 1.0, 0.0)
Definition lightsrc.h:158
void setPos(maths::Vector< double > P)
sets the position of the light source. This is the center of the square area of the light source
maths::Vector< double > rotVec
Vector which holds the spherical coordinates , and of the direction vector k.
Definition lightsrc.h:184
void setk(const maths::Vector< double > &k)
sets the main direction of the light source
virtual int next(tubedRay &ray)=0
int type
type of the light source
Definition lightsrc.h:151
double getDensity()
returns the ray density, i.e. the number of rays per unit length (=D/N)
Definition lightsrc.h:101
maths::Vector< double > e1
Definition lightsrc.h:167
maths::Vector< double > getk()
returns the main direction of the light source
Definition lightsrc.h:131
virtual double area()
Definition lightsrc.h:90
int i2
second index of the ray inside the starting area (for internal use, -1 if the calculation has not yet...
Definition lightsrc.h:157
maths::Vector< double > getPos()
returns the position of the light source. This is the center of the square area of the light source
Definition lightsrc.h:146
friend std::ostream & operator<<(std::ostream &os, LightSrc *ls)
void binReadItem(std::ifstream &os)
reads content of LightSrc from a binary file, represented by os (has to be specified by the derived c...
Definition lightsrc.h:241
void binWriteItem(std::ofstream &os)
writes content of LightSrc in a binary file, represented by is (has to be specified by the derived cl...
Definition lightsrc.h:240
maths::Vector< double > direction
Definition lightsrc.h:242
LightSrcLine(maths::Vector< double > Pos, int N, double wvl, double size, maths::Vector< double > k=maths::ez, maths::Vector< double > direction=maths::ey)
constructor
double area()
area A of the light source,
Definition lightsrc.h:217
LightSrcPlane(const LightSrcPlane &)
copy Constructor
int next(tubedRay &S)
gives the next ray for the following calculations
int next(Ray_pow &S)
gives the next ray for the following calculations
int next(GOAT::raytracing::RayBase *ray)
Destructor, not needed.
LightSrcPlane(maths::Vector< double > Pos, int N, double wvl, double D=100.0, maths::Vector< std::complex< double > > Pol=maths::Vector< std::complex< double > >(0.0, 1.0, 0.0), int raytype=LIGHTSRC_RAYTYPE_IRAY, double r0=100.0)
constructor with the following parameters : Pos: position of the light source, k : main direction of ...
void binWriteItem(std::ofstream &os)
writes content of LightSrc in a binary file, represented by is (has to be specified by the derived cl...
Definition lightsrc.h:215
void binReadItem(std::ifstream &os)
reads content of LightSrc from a binary file, represented by os (has to be specified by the derived c...
Definition lightsrc.h:216
int next(IRay &S)
gives the next ray for the following calculations
LightSrcRing(maths::Vector< double > Pos, int N, double wvl, double rmin=0.0, double rmax=100.0, maths::Vector< std::complex< double > > Pol=maths::Vector< std::complex< double > >(0.0, 1.0, 0.0), int raytype=LIGHTSRC_RAYTYPE_IRAY, double r0=100.0)
void binReadItem(std::ifstream &os)
reads content of LightSrc from a binary file, represented by os (has to be specified by the derived c...
Definition lightsrc.h:262
double getRmax()
returns the outer radius of the light source
Definition lightsrc.h:264
void setRmax(double rmax)
set the outer radius of the light source
void binWriteItem(std::ofstream &os)
writes content of LightSrc in a binary file, represented by is (has to be specified by the derived cl...
Definition lightsrc.h:261
double getRmin()
returns the inner radius of the light source
Definition lightsrc.h:263
void setRmin(double rmin)
set the inner radius of the light source
Abstract base class for all volume objects This abstract class provides a template for all volume obj...
Definition objectshape.h:60
This class provides a ray which carries a special power.
Definition ray_pow.h:12
Abstract base class for all rays used for the raytracing process. This abstract base class for all ra...
Definition raybase.h:16
This class represents a ray with a finite cross section. class tubedRay: This class represents a ray ...
Definition tubedray.h:88
#define Z0
impedance of the free space in Ohms
Definition constants.h:11
#define LIGHTSRC_RAYTYPE_IRAY
Ray class : IRay.
Definition lightsrc.h:17
#define LIGHTSRC_POL_Y
Light source is polarized in y-direction.
Definition lightsrc.h:40
Raytracer used for ultrashort pulse calculation with raytracing only.
Definition asphericLens.h:6
constexpr int LIGHTSRC_SRCTYPE_GAUSS
Light source is a gaussian wave.
Definition lightsrc.h:20
void copyLightSrcList(LightSrc **&d, LightSrc **s, int nLS)
Copy the given light source list.
void binWriteLSList(std::ofstream &os, int nLS, LightSrc **ls)
Writes a list of light sources into a binary file.
void binReadLSList(std::ifstream &is, int nLS, LightSrc **&ls)
Reads list of light sources from a binary file and allocates the memory for the light source list.
constexpr int LIGHTSRC_SRCTYPE_TOPHAT
Light source is a top hat.
Definition lightsrc.h:22
constexpr int LIGHTSRC_SRCTYPE_PLANE_MC
Light source is a plane wave (random distribution)
Definition lightsrc.h:26
constexpr int LIGHTSRC_SRCTYPE_RING
Light source is a ring shaped wave.
Definition lightsrc.h:21
constexpr int LIGHTSRC_SRCTYPE_PLANE
Light source is a plane wave.
Definition lightsrc.h:19
constexpr int LIGHTSRC_SRCTYPE_RING_MC
Light source is a ring (random distribution)
Definition lightsrc.h:28
constexpr int LIGHTSRC_SRCTYPE_LINE
Light source along a straight line.
Definition lightsrc.h:23
constexpr int LIGHTSRC_SRCTYPE_GAUSS_MC
Light source is a gaussian wave (random distribution)
Definition lightsrc.h:27
constexpr int LIGHTSRC_SRCTYPE_POINT_MC
Point light source (random distribution)
Definition lightsrc.h:30
constexpr int LIGHTSRC_SRCTYPE_LINE_MC
Light source along a straight line (random distribution)
Definition lightsrc.h:29
constexpr int LIGHTSRC_SRCTYPE_POINT
Point light source.
Definition lightsrc.h:24
This class is used for the iray class. This class is intended for internal use only....
Definition fresnel.h:7
This file contains the Vector template class and some useful functions around this class.