8e4f8364
David Mayerich
started a new opt...
|
1
2
|
#ifndef STIM_PLANEWAVE_H
#define STIM_PLANEWAVE_H
|
a9275be5
David Mayerich
added vector fiel...
|
3
4
5
|
#include <string>
#include <sstream>
|
8e4f8364
David Mayerich
started a new opt...
|
6
|
#include <cmath>
|
a9275be5
David Mayerich
added vector fiel...
|
7
|
|
14634fca
David Mayerich
edits to update s...
|
8
|
#include "../math/vec3.h"
|
8d4f0940
David Mayerich
ERROR in plane wa...
|
9
10
|
#include "../math/quaternion.h"
#include "../math/constants.h"
|
559d0fcb
David Mayerich
wave interactions...
|
11
|
#include "../math/plane.h"
|
14634fca
David Mayerich
edits to update s...
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <complex>
/// Calculate whether or not a vector v intersects the front (1) or back (-1) of a plane.
/// This function returns -1 if the vector lies within the plane (is orthogonal to the surface normal)
/*template <typename T>
int plane_face(stim::vec3<T> v, stim::vec3<T> plane_normal) {
T dotprod = v.dot(plane_normal); //calculate the dot product
if (dotprod < 0) return 1;
if (dotprod > 0) return -1;
return 0;
}
/// Calculate the component of a vector v that is perpendicular to a plane defined by a normal.
template <typename T>
stim::vec3<T> plane_perpendicular(stim::vec3<T> v, stim::vec3<T> plane_normal) {
return plane_normal * v.dot(plane_normal);
}
template <typename T>
stim::vec3<T> plane_parallel(stim::vec3<T> v, stim::vec3<T> plane_normal) {
return v - plane_perpendicular(v, plane_normal);
}*/
|
a9275be5
David Mayerich
added vector fiel...
|
35
|
|
8a86bd56
David Mayerich
changed rts names...
|
36
|
namespace stim{
|
8e4f8364
David Mayerich
started a new opt...
|
37
38
|
namespace optics{
|
14634fca
David Mayerich
edits to update s...
|
39
|
|
8e4f8364
David Mayerich
started a new opt...
|
40
41
42
43
44
45
46
47
48
49
|
/// evaluate the scalar field produced by a plane wave at a point (x, y, z)
/// @param x is the x-coordinate of the point
/// @param y is the y-coordinate of the point
/// @param z is the z-coordinate of the point
/// @param A is the amplitude of the plane wave, specifically the field at (0, 0, 0)
/// @param kx is the k-vector component in the x direction
/// @param ky is the k-vector component in the y direction
/// @param kz is the k-vector component in the z direction
template<typename T>
|
14634fca
David Mayerich
edits to update s...
|
50
|
std::complex<T> planewave_scalar(T x, T y, T z, std::complex<T> A, T kx, T ky, T kz){
|
8e4f8364
David Mayerich
started a new opt...
|
51
|
T d = x * kx + y * ky + z * kz; //calculate the dot product between k and p = (x, y, z) to find the distance p is along the propagation direction
|
14634fca
David Mayerich
edits to update s...
|
52
|
std::complex<T> di = std::complex<T>(0, d); //calculate the phase shift that will have to be applied to propagate the wave distance d
|
8e4f8364
David Mayerich
started a new opt...
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
return A * exp(di); //multiply the phase term by the amplitude at (0, 0, 0) to propagate the wave to p
}
/// evaluate the scalar field produced by a plane wave at several positions
/// @param field is a pre-allocated block of memory that will store the complex field at all points
/// @param N is the number of field values to be evaluated
/// @param x is a set of x coordinates defining positions within the field (NULL implies that all values are zero)
/// @param y is a set of y coordinates defining positions within the field (NULL implies that all values are zero)
/// @param z is a set of z coordinates defining positions within the field (NULL implies that all values are zero)
/// @param A is the amplitude of the plane wave, specifically the field at (0, 0, 0)
/// @param kx is the k-vector component in the x direction
/// @param ky is the k-vector component in the y direction
/// @param kz is the k-vector component in the z direction
template<typename T>
|
14634fca
David Mayerich
edits to update s...
|
68
|
void cpu_planewave_scalar(std::complex<T>* field, size_t N, T* x, T* y = NULL, T* z = NULL, std::complex<T> A = 1.0, T kx = 0.0, T ky = 0.0, T kz = 0.0){
|
8e4f8364
David Mayerich
started a new opt...
|
69
70
71
72
73
74
75
76
77
|
T px, py, pz;
for(size_t i = 0; i < N; i++){ // for each element in the array
(x == NULL) ? px = 0 : px = x[i]; // test for NULL values
(y == NULL) ? py = 0 : py = y[i];
(z == NULL) ? pz = 0 : pz = z[i];
field[i] = planewave_scalar(px, py, pz, A, kx, ky, kz); // call the single-value plane wave function
}
}
|
a9275be5
David Mayerich
added vector fiel...
|
78
|
|
14634fca
David Mayerich
edits to update s...
|
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/*template<typename T>
class cvec3 {
public:
std::complex<T> x;
std::complex<T> y;
std::complex<T> z;
cvec3(std::complex<T> _x, std::complex<T> _y, std::complex<T> _z) {
x = _x;
y = _y;
z = _z;
}
};*/
/*template<typename T>
class cvec3 {
public:
std::complex<T> m_v[3];
cvec3(std::complex<T> x, std::complex<T> y, std::complex<T> z) {
m_v[0] = x;
m_v[1] = y;
m_v[2] = z;
}
cvec3() : cvec3(0, 0, 0) {}
void operator()(std::complex<T> x, std::complex<T> y, std::complex<T> z) {
m_v[0] = x;
m_v[1] = y;
m_v[2] = z;
}
std::complex<T> operator[](int i) const { return m_v[i]; }
std::complex<T>& operator[](int i) { return m_v[i]; }
/// Calculate the 2-norm of the complex vector
T norm2() {
T xx = std::real(m_v[0] * std::conj(m_v[0]));
T yy = std::real(m_v[1] * std::conj(m_v[1]));
T zz = std::real(m_v[2] * std::conj(m_v[2]));
return std::sqrt(xx + yy + zz);
}
/// Returns the normalized direction vector
cvec3 direction() {
cvec3 result;
std::complex<T> length = norm2();
result[0] = m_v[0] / length;
result[1] = m_v[1] / length;
result[2] = m_v[2] / length;
return result;
}
std::string str() {
std::stringstream ss;
ss << m_v[0] << ", " << m_v[1] << ", " << m_v[2];
return ss.str();
}
//copy constructor
cvec3(const cvec3 &other) {
m_v[0] = other.m_v[0];
m_v[1] = other.m_v[1];
m_v[2] = other.m_v[2];
}
/// Assignment operator
cvec3& operator=(const cvec3 &rhs) {
m_v[0] = rhs.m_v[0];
m_v[1] = rhs.m_v[1];
m_v[2] = rhs.m_v[2];
return *this;
}
/// Calculate and return the cross product between this vector and another
cvec3 cross(cvec3 rhs) {
cvec3 result;
//compute the cross product (only valid for 3D vectors)
result[0] = (m_v[1] * rhs[2] - m_v[2] * rhs[1]);
result[1] = (m_v[2] * rhs[0] - m_v[0] * rhs[2]);
result[2] = (m_v[1] * rhs[1] - m_v[1] * rhs[0]);
return result;
}
/// Calculate and return the dot product between this vector and another
std::complex<T> dot(cvec3 rhs) {
return m_v[0] * rhs[0] + m_v[1] * rhs[1] + m_v[2] * rhs[2];
}
/// Arithmetic multiplication: returns the vector scaled by a constant value
template<typename R>
cvec3 operator*(R rhs) const
{
cvec3 result;
result[0] = m_v[0] * rhs;
result[1] = m_v[1] * rhs;
result[2] = m_v[2] * rhs;
return result;
}
};
template <typename T>
std::ostream& operator<<(std::ostream& os, stim::optics::cvec3<T> p) {
os << p.str();
return os;
}
*/
|
559d0fcb
David Mayerich
wave interactions...
|
195
|
template<typename T>
|
a9275be5
David Mayerich
added vector fiel...
|
196
197
|
class planewave{
|
559d0fcb
David Mayerich
wave interactions...
|
198
199
|
protected:
|
14634fca
David Mayerich
edits to update s...
|
200
201
|
cvec3<T> m_k; //k-vector, pointed in propagation direction with magnitude |k| = tau / lambda = 2pi / lambda
cvec3<T> m_E; //amplitude (for a scalar plane wave, only E0[0] is used)
|
559d0fcb
David Mayerich
wave interactions...
|
202
|
|
8e4f8364
David Mayerich
started a new opt...
|
203
|
/// Bend a plane wave via refraction, given that the new propagation direction is known
|
14634fca
David Mayerich
edits to update s...
|
204
|
CUDA_CALLABLE planewave<T> bend(stim::vec3<T> v) const {
|
559d0fcb
David Mayerich
wave interactions...
|
205
|
|
14634fca
David Mayerich
edits to update s...
|
206
207
208
209
|
stim::vec3<T> k_real(m_k.get(0).real(), m_k.get(1).real(), m_k.get(2).real()); //force the vector to be real (can only refract real directions)
stim::vec3<T> kn_hat = v.direction(); //normalize the new k
stim::vec3<T> k_hat = k_real.direction(); //normalize the current k
|
559d0fcb
David Mayerich
wave interactions...
|
210
|
|
8e4f8364
David Mayerich
started a new opt...
|
211
|
planewave<T> new_p; //create a new plane wave
|
559d0fcb
David Mayerich
wave interactions...
|
212
|
|
8e4f8364
David Mayerich
started a new opt...
|
213
|
T k_dot_kn = k_hat.dot(kn_hat); //if kn is equal to k or -k, handle the degenerate case
|
559d0fcb
David Mayerich
wave interactions...
|
214
215
|
//if k . n < 0, then the bend is a reflection
|
8e4f8364
David Mayerich
started a new opt...
|
216
|
if(k_dot_kn < 0) k_hat = -k_hat; //flip k_hat
|
559d0fcb
David Mayerich
wave interactions...
|
217
|
|
559d0fcb
David Mayerich
wave interactions...
|
218
|
if(k_dot_kn == -1){
|
14634fca
David Mayerich
edits to update s...
|
219
220
|
new_p.m_k = -m_k;
new_p.m_E = m_E;
|
559d0fcb
David Mayerich
wave interactions...
|
221
222
223
|
return new_p;
}
else if(k_dot_kn == 1){
|
14634fca
David Mayerich
edits to update s...
|
224
225
|
new_p.m_k = m_k;
new_p.m_E = m_E;
|
559d0fcb
David Mayerich
wave interactions...
|
226
227
228
|
return new_p;
}
|
14634fca
David Mayerich
edits to update s...
|
229
|
vec3<T> r = k_hat.cross(kn_hat); //compute the rotation vector
|
8e4f8364
David Mayerich
started a new opt...
|
230
231
|
T theta = asin(r.len()); //compute the angle of the rotation about r
quaternion<T> q; //create a quaternion to capture the rotation
|
14634fca
David Mayerich
edits to update s...
|
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
q.CreateRotation(theta, r.direction());
stim::matrix_sq<T, 3> R = q.toMatrix3();
vec3< std::complex<T> > E(m_E.get(0), m_E.get(1), m_E.get(2));
vec3< std::complex<T> > E0n = R * E; //apply the rotation to E0
//new_p.m_k = kn_hat * kmag();
//new_p.m_E = E0n;
new_p.m_k[0] = kn_hat[0] * kmag();
new_p.m_k[1] = kn_hat[1] * kmag();
new_p.m_k[2] = kn_hat[2] * kmag();
new_p.m_E[0] = E0n[0];
new_p.m_E[1] = E0n[1];
new_p.m_E[2] = E0n[2];
|
559d0fcb
David Mayerich
wave interactions...
|
246
247
248
249
|
return new_p;
}
|
a9275be5
David Mayerich
added vector fiel...
|
250
|
public:
|
a9275be5
David Mayerich
added vector fiel...
|
251
|
|
14634fca
David Mayerich
edits to update s...
|
252
253
|
|
8e4f8364
David Mayerich
started a new opt...
|
254
|
///constructor: create a plane wave propagating along k
|
14634fca
David Mayerich
edits to update s...
|
255
256
257
258
259
260
261
262
263
|
//CUDA_CALLABLE planewave(vec<T> kvec = stim::vec<T>(0, 0, stim::TAU),
// vec< complex<T> > E = stim::vec<T>(1, 0, 0))
CUDA_CALLABLE planewave(std::complex<T> kx, std::complex<T> ky, std::complex<T> kz,
std::complex<T> Ex, std::complex<T> Ey, std::complex<T> Ez) {
m_k = cvec3<T>(kx, ky, kz);
m_E = cvec3<T>(Ex, Ey, Ez);
force_orthogonal();
}
|
ecfd14df
David Mayerich
implemented D fie...
|
264
|
|
14634fca
David Mayerich
edits to update s...
|
265
|
CUDA_CALLABLE planewave() : planewave(0, 0, 1, 1, 0, 0) {}
|
559d0fcb
David Mayerich
wave interactions...
|
266
|
|
14634fca
David Mayerich
edits to update s...
|
267
268
269
270
271
272
273
274
275
276
|
//copy constructor
CUDA_CALLABLE planewave(const planewave& other) {
m_k = other.m_k;
m_E = other.m_E;
}
/// Assignment operator
CUDA_CALLABLE planewave& operator=(const planewave& rhs) {
m_k = rhs.m_k;
m_E = rhs.m_E;
|
ecfd14df
David Mayerich
implemented D fie...
|
277
|
|
14634fca
David Mayerich
edits to update s...
|
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
return *this;
}
/// Forces the k and E vectors to be orthogonal
CUDA_CALLABLE void force_orthogonal() {
/*if (m_E.norm2() == 0) return;
cvec3<T> k_dir = m_k.direction(); //calculate the normalized direction vectors for k and E
cvec3<T> E_dir = m_E.direction();
cvec3<T> side = k_dir.cross(E_dir); //calculate a side vector for projection
cvec3<T> side_dir = side.direction(); //normalize the side vector
E_dir = side_dir.cross(k_dir); //calculate the new E vector direction
T E_norm = m_E.norm2();
m_E = E_dir * E_norm; //apply the new direction to the existing E vector
*/
}
CUDA_CALLABLE cvec3<T> k() {
return m_k;
}
CUDA_CALLABLE cvec3<T> E() {
return m_E;
}
CUDA_CALLABLE cvec3<T> evaluate(T x, T y, T z) {
std::complex<T> k_dot_r = m_k[0] * x + m_k[1] * y + m_k[2] * z;
std::complex<T> e_k_dot_r = std::exp(std::complex<T>(0, 1) * k_dot_r);
cvec3<T> result;
result[0] = m_E[0] * e_k_dot_r;
result[1] = m_E[1] * e_k_dot_r;
result[2] = m_E[2] * e_k_dot_r;
return result;
}
/*int scatter(vec3<T> surface_normal, vec3<T> surface_point, T ni, std::complex<T> nt,
planewave& Pi, planewave& Pr, planewave& Pt) {
return 0;
}*/
CUDA_CALLABLE T kmag() const {
return std::sqrt(std::real(m_k.get(0) * std::conj(m_k.get(0)) + m_k.get(1) * std::conj(m_k.get(1)) + m_k.get(2) * std::conj(m_k.get(2))));
}
CUDA_CALLABLE planewave<T> refract(stim::vec3<T> kn) const {
return bend(kn);
}
/// Return a plane wave with the origin translated by (x, y, z)
CUDA_CALLABLE planewave<T> translate(T x, T y, T z) const {
planewave<T> result;
cvec3<T> k = m_k;
result.m_k = k;
std::complex<T> k_dot_r = k[0] * (-x) + k[1] * (-y) + k[2] * (-z);
std::complex<T> exp_k_dot_r = std::exp(std::complex<T>(0.0, 1.0) * k_dot_r);
cvec3<T> E = m_E;
result.m_E[0] = E[0] * exp_k_dot_r;
result.m_E[1] = E[1] * exp_k_dot_r;
result.m_E[2] = E[2] * exp_k_dot_r;
return result;
|
a9275be5
David Mayerich
added vector fiel...
|
345
346
347
|
}
///multiplication operator: scale E0
|
14634fca
David Mayerich
edits to update s...
|
348
|
/*CUDA_CALLABLE planewave<T>& operator* (const T& rhs) {
|
a9275be5
David Mayerich
added vector fiel...
|
349
350
351
352
|
E0 = E0 * rhs;
return *this;
}
|
8e4f8364
David Mayerich
started a new opt...
|
353
354
|
CUDA_CALLABLE T lambda() const{
return stim::TAU / k.len();
|
8d4f0940
David Mayerich
ERROR in plane wa...
|
355
356
|
}
|
8e4f8364
David Mayerich
started a new opt...
|
357
|
CUDA_CALLABLE T kmag() const{
|
8d4f0940
David Mayerich
ERROR in plane wa...
|
358
359
360
|
return k.len();
}
|
ecfd14df
David Mayerich
implemented D fie...
|
361
|
CUDA_CALLABLE vec< complex<T> > E(){
|
559d0fcb
David Mayerich
wave interactions...
|
362
363
364
365
366
367
368
|
return E0;
}
CUDA_CALLABLE vec<T> kvec(){
return k;
}
|
8e4f8364
David Mayerich
started a new opt...
|
369
370
371
|
/// calculate the value of the field produced by the plane wave given a three-dimensional position
CUDA_CALLABLE vec< complex<T> > pos(T x, T y, T z){
return pos( stim::vec<T>(x, y, z) );
|
559d0fcb
David Mayerich
wave interactions...
|
372
373
|
}
|
559d0fcb
David Mayerich
wave interactions...
|
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
CUDA_CALLABLE vec< complex<T> > pos(vec<T> p = vec<T>(0, 0, 0)){
vec< complex<T> > result;
T kdp = k.dot(p);
complex<T> x = complex<T>(0, kdp);
complex<T> expx = exp(x);
result[0] = E0[0] * expx;
result[1] = E0[1] * expx;
result[2] = E0[2] * expx;
return result;
}
//scales k based on a transition from material ni to material nt
CUDA_CALLABLE planewave<T> n(T ni, T nt){
return planewave<T>(k * (nt / ni), E0);
}
|
a9275be5
David Mayerich
added vector fiel...
|
392
|
|
8e4f8364
David Mayerich
started a new opt...
|
393
|
CUDA_CALLABLE planewave<T> refract(stim::vec<T> kn) const{
|
559d0fcb
David Mayerich
wave interactions...
|
394
395
|
return bend(kn);
}
|
d609550e
David Mayerich
fixed bug in plan...
|
396
|
|
8e4f8364
David Mayerich
started a new opt...
|
397
398
399
400
401
402
403
404
405
|
/// Calculate the result of a plane wave hitting an interface between two refractive indices
/// @param P is a plane representing the position and orientation of the surface
/// @param n0 is the refractive index outside of the surface (in the direction of the normal)
/// @param n1 is the refractive index inside the surface (in the direction away from the normal)
/// @param r is the reflected component of the plane wave
/// @param t is the transmitted component of the plane wave
void scatter(stim::plane<T> P, T n0, T n1, planewave<T> &r, planewave<T> &t){
scatter(P, n1/n0, r, t);
|
14634fca
David Mayerich
edits to update s...
|
406
|
}*/
|
8e4f8364
David Mayerich
started a new opt...
|
407
408
409
410
411
412
413
414
|
/// Calculate the scattering result when nr = n1/n0
/// @param P is a plane representing the position and orientation of the surface
/// @param r is the ration n1/n0
/// @param n1 is the refractive index inside the surface (in the direction away from the normal)
/// @param r is the reflected component of the plane wave
/// @param t is the transmitted component of the plane wave
|
14634fca
David Mayerich
edits to update s...
|
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/*void scatter(vec3<T> plane_normal, vec3<T> plane_position, std::complex<T> nr, planewave<T>& r, planewave<T>& t) {
//TODO: Generate a real vector from the current K vector - this will not address complex k-vectors
vec3< std::complex<T> > k(3);
k[0] = m_k[0];
k[1] = m_k[1];
k[2] = m_k[2];
vec3< std::complex<T> > E(3);
E[0] = m_E[0];// std::complex<T>(m_E[0].real(), m_E[0].imag());
E[1] = m_E[1];// std::complex<T>(m_E[1].real(), m_E[1].imag());
E[2] = m_E[2];// std::complex<T>(m_E[2].real(), m_E[2].imag());
std::complex<T> cOne(1, 0);
std::complex<T> cTwo(2, 0);
T kmag = m_k.norm2();
|
d609550e
David Mayerich
fixed bug in plan...
|
433
|
|
14634fca
David Mayerich
edits to update s...
|
434
|
int facing = plane_face(k, plane_normal); //determine which direction the plane wave is coming in
|
d609550e
David Mayerich
fixed bug in plan...
|
435
|
|
14634fca
David Mayerich
edits to update s...
|
436
437
438
|
if(facing == -1){ //if the wave hits the back of the plane, invert the plane and nr
plane_normal = -plane_normal; //flip the plane
nr = cOne / nr; //invert the refractive index (now nr = n0/n1)
|
559d0fcb
David Mayerich
wave interactions...
|
439
|
}
|
d609550e
David Mayerich
fixed bug in plan...
|
440
|
|
559d0fcb
David Mayerich
wave interactions...
|
441
|
//use Snell's Law to calculate the transmitted angle
|
14634fca
David Mayerich
edits to update s...
|
442
443
|
//vec3<T> plane_normal = -P.n();
T cos_theta_i = k.norm().dot(-plane_normal); //compute the cosine of theta_i
|
559d0fcb
David Mayerich
wave interactions...
|
444
|
T theta_i = acos(cos_theta_i); //compute theta_i
|
14634fca
David Mayerich
edits to update s...
|
445
446
|
std::complex<T> sin_theta_t = (cOne / nr) * sin(theta_i); //compute the sine of theta_t using Snell's law
std::complex<T> theta_t = asin(sin_theta_t); //compute the cosine of theta_t
|
559d0fcb
David Mayerich
wave interactions...
|
447
|
|
14634fca
David Mayerich
edits to update s...
|
448
449
450
451
452
|
//bool tir = false; //flag for total internal reflection
//if(theta_t != theta_t){
// tir = true;
// theta_t = stim::PI / (T)2;
//}
|
d609550e
David Mayerich
fixed bug in plan...
|
453
|
|
559d0fcb
David Mayerich
wave interactions...
|
454
455
|
//handle the degenerate case where theta_i is 0 (the plane wave hits head-on)
if(theta_i == 0){
|
14634fca
David Mayerich
edits to update s...
|
456
457
458
459
460
461
462
463
|
std::complex<T> rp = (cOne - nr) / (cOne + nr); //compute the Fresnel coefficients
std::complex<T> tp = (cOne * cTwo) / (cOne + nr);
vec3<T> kr = -k;
vec3<T> kt = k * nr; //set the k vectors for theta_i = 0
vec3< std::complex<T> > Er = E * rp; //compute the E vectors
vec3< std::complex<T> > Et = E * tp;
T phase_t = plane_position.dot(k - kt); //compute the phase offset
T phase_r = plane_position.dot(k - kr);
|
559d0fcb
David Mayerich
wave interactions...
|
464
465
|
//create the plane waves
|
14634fca
David Mayerich
edits to update s...
|
466
467
468
469
470
471
|
//r = planewave<T>(kr, Er, phase_r);
//t = planewave<T>(kt, Et, phase_t);
r = planewave(kr[0], kr[1], kr[2], Er[0], Er[1], Er[2]);
t = planewave(kt[0], kt[1], kt[2], Et[0], Et[1], Et[2]);
|
559d0fcb
David Mayerich
wave interactions...
|
472
473
|
return;
}
|
d609550e
David Mayerich
fixed bug in plan...
|
474
|
|
d609550e
David Mayerich
fixed bug in plan...
|
475
|
|
559d0fcb
David Mayerich
wave interactions...
|
476
477
478
479
480
|
//compute the Fresnel coefficients
T rp, rs, tp, ts;
rp = tan(theta_t - theta_i) / tan(theta_t + theta_i);
rs = sin(theta_t - theta_i) / sin(theta_t + theta_i);
|
14634fca
David Mayerich
edits to update s...
|
481
482
483
484
485
|
//if (tir) {
// tp = ts = 0;
//}
//else
{
|
559d0fcb
David Mayerich
wave interactions...
|
486
487
488
|
tp = ( 2 * sin(theta_t) * cos(theta_i) ) / ( sin(theta_t + theta_i) * cos(theta_t - theta_i) );
ts = ( 2 * sin(theta_t) * cos(theta_i) ) / sin(theta_t + theta_i);
}
|
d609550e
David Mayerich
fixed bug in plan...
|
489
|
|
559d0fcb
David Mayerich
wave interactions...
|
490
|
//compute the coordinate space for the plane of incidence
|
14634fca
David Mayerich
edits to update s...
|
491
492
493
|
vec3<T> z_hat = -plane_normal;
vec3<T> y_hat = plane_parallel(k, plane_normal).norm();
vec3<T> x_hat = y_hat.cross(z_hat).norm();
|
559d0fcb
David Mayerich
wave interactions...
|
494
495
|
//compute the k vectors for r and t
|
14634fca
David Mayerich
edits to update s...
|
496
497
498
|
vec3<T> kr, kt;
kr = ( y_hat * sin(theta_i) - z_hat * cos(theta_i) ) * kmag;
kt = ( y_hat * sin(theta_t) + z_hat * cos(theta_t) ) * kmag * nr;
|
559d0fcb
David Mayerich
wave interactions...
|
499
500
|
//compute the magnitude of the p- and s-polarized components of the incident E vector
|
14634fca
David Mayerich
edits to update s...
|
501
502
503
504
|
std::complex<T> Ei_s = E.dot(x_hat);
//int sign = sgn(E0.dot(y_hat));
vec3< std::complex<T> > cx_hat = x_hat;
std::complex<T> Ei_p = (E - cx_hat * Ei_s).len();// *(T)sign;
|
559d0fcb
David Mayerich
wave interactions...
|
505
|
//compute the magnitude of the p- and s-polarized components of the reflected E vector
|
14634fca
David Mayerich
edits to update s...
|
506
507
|
std::complex<T> Er_s = Ei_s * rs;
std::complex<T> Er_p = Ei_p * rp;
|
559d0fcb
David Mayerich
wave interactions...
|
508
|
//compute the magnitude of the p- and s-polarized components of the transmitted E vector
|
14634fca
David Mayerich
edits to update s...
|
509
510
|
std::complex<T> Et_s = Ei_s * ts;
std::complex<T> Et_p = Ei_p * tp;
|
559d0fcb
David Mayerich
wave interactions...
|
511
|
|
559d0fcb
David Mayerich
wave interactions...
|
512
|
//compute the reflected E vector
|
14634fca
David Mayerich
edits to update s...
|
513
|
vec3< std::complex<T> > Er = vec3< std::complex<T> >(y_hat * cos(theta_i) + z_hat * sin(theta_i)) * Er_p + cx_hat * Er_s;
|
559d0fcb
David Mayerich
wave interactions...
|
514
|
//compute the transmitted E vector
|
14634fca
David Mayerich
edits to update s...
|
515
|
vec3< std::complex<T> > Et = vec3< std::complex<T> >(y_hat * cos(theta_t) - z_hat * sin(theta_t)) * Et_p + cx_hat * Et_s;
|
559d0fcb
David Mayerich
wave interactions...
|
516
|
|
14634fca
David Mayerich
edits to update s...
|
517
518
|
T phase_t = plane_position.dot(k - kt);
T phase_r = plane_position.dot(k - kr);
|
559d0fcb
David Mayerich
wave interactions...
|
519
|
|
559d0fcb
David Mayerich
wave interactions...
|
520
|
//create the plane waves
|
14634fca
David Mayerich
edits to update s...
|
521
522
|
//r.m_k = kr;
//r.m_E = Er * exp( complex<T>(0, phase_r) );
|
559d0fcb
David Mayerich
wave interactions...
|
523
|
|
14634fca
David Mayerich
edits to update s...
|
524
525
526
527
528
529
|
//t.m_k = kt;
//t.m_E = Et * exp( complex<T>(0, phase_t) );
r = planewave(kr[0], kr[1], kr[2], Er[0], Er[1], Er[2]);
t = planewave(kt[0], kt[1], kt[2], Et[0], Et[1], Et[2]);
}*/
|
a9275be5
David Mayerich
added vector fiel...
|
530
531
532
533
|
std::string str()
{
std::stringstream ss;
|
14634fca
David Mayerich
edits to update s...
|
534
535
|
ss << "k: " << m_k << std::endl;
ss << "E: " << m_E << std::endl;
|
a9275be5
David Mayerich
added vector fiel...
|
536
537
|
return ss.str();
}
|
8e4f8364
David Mayerich
started a new opt...
|
538
539
540
|
}; //end planewave class
} //end namespace optics
} //end namespace stim
|
a9275be5
David Mayerich
added vector fiel...
|
541
|
|
559d0fcb
David Mayerich
wave interactions...
|
542
|
template <typename T>
|
8e4f8364
David Mayerich
started a new opt...
|
543
|
std::ostream& operator<<(std::ostream& os, stim::optics::planewave<T> p)
|
559d0fcb
David Mayerich
wave interactions...
|
544
545
546
547
548
|
{
os<<p.str();
return os;
}
|
8e4f8364
David Mayerich
started a new opt...
|
549
|
#endif
|