132 std::array<V, 3> nomChief = {0, 0, 1};
133 std::array<V, 3> zero = {0, 0, 0};
137 int nTot = 1 + rdict.nRing * 4 * rdict.nRays;
144 if (rdict.nRays > 0) {d_alpha = 2 * M_PI / (4 * rdict.nRays);}
148 std::array<V, 3> rotation;
149 std::array<V, 3> direction;
159 std::array<V, 3> pos;
161 for (
int i=1; i<nTot; i++)
163 fr->x[i] = rdict.x0 * cos(alpha) / rdict.nRing * n;
164 fr->y[i] = rdict.y0 * sin(alpha) / rdict.nRing * n;
167 rotation[0] = rdict.angy0 * sin(alpha) / rdict.nRing * n;
168 rotation[1] = rdict.angx0 * cos(alpha) / rdict.nRing * n;
169 rotation[2] = 2 * alpha;
171 ut.
matRot(rotation, nomChief, zero, direction);
173 fr->dx[i] = direction[0];
174 fr->dy[i] = direction[1];
175 fr->dz[i] = direction[2];
178 if (i ==
int(nTot / rdict.nRing) * n)
190 std::array<V, 3> nomChief = {0, 0, 1};
191 std::array<V, 3> zero = {0, 0, 0};
195 if (grdict.seed != -1) {
Random<V> rando(grdict.seed);}
197 fr->size = grdict.nRays;
199 std::array<V, 3> rotation;
200 std::array<V, 3> direction;
201 std::array<V, 3> pos;
204 std::vector<V> scales{grdict.x0, grdict.y0, grdict.angx0, grdict.angy0};
217 std::vector<V> xi(4, 0);
220 while (n_suc < grdict.nRays)
228 for (
int k = 0; k<4; k++) {xi[k] = xi[k] * thres * scales[k];}
232 rotation = {xi[3], xi[2], 0};
233 ut.
matRot(rotation, nomChief, zero, direction);
234 pos = {xi[0], xi[1], 0};
236 fr->x[n_suc] = pos[0];
237 fr->y[n_suc] = pos[1];
238 fr->z[n_suc] = pos[2];
240 fr->dx[n_suc] = direction[0];
241 fr->dy[n_suc] = direction[1];
242 fr->dz[n_suc] = direction[2];
258void initGauss(T gdict, U refldict, V *res_field, V *res_current)
260 int nTot = refldict.n_cells[0] * refldict.n_cells[1];
266 reflc.x =
new G[nTot];
267 reflc.y =
new G[nTot];
268 reflc.z =
new G[nTot];
270 reflc.nx =
new G[nTot];
271 reflc.ny =
new G[nTot];
272 reflc.nz =
new G[nTot];
274 reflc.area =
new G[nTot];
278 bool transform =
true;
282 G zRx = M_PI * gdict.w0x*gdict.w0x * gdict.n / gdict.lam;
283 G zRy = M_PI * gdict.w0y*gdict.w0y * gdict.n / gdict.lam;
284 G k = 2 * M_PI / gdict.lam;
293 std::complex<G> j(0, 1);
295 std::complex<G> field_atPoint;
296 std::array<std::complex<G>, 3> efield;
297 std::array<G, 3> n_source;
298 std::array<std::complex<G>, 3> m;
300 for (
int i=0; i<nTot; i++)
302 wzx = gdict.w0x * sqrt(1 + (reflc.z[i] / zRx)*(reflc.z[i] / zRx));
303 wzy = gdict.w0y * sqrt(1 + ((reflc.z[i] - gdict.dxyz) / zRy)*((reflc.z[i] - gdict.dxyz) / zRy));
304 Rzx_inv = reflc.z[i] / (reflc.z[i]*reflc.z[i] + zRx*zRx);
305 Rzy_inv = (reflc.z[i] - gdict.dxyz) / ((reflc.z[i] - gdict.dxyz)*(reflc.z[i] - gdict.dxyz) + zRy*zRy);
306 phizx = atan(reflc.z[i] / zRx);
307 phizy = atan((reflc.z[i] - gdict.dxyz) / zRy);
312 field_atPoint = gdict.E0 * exp(-(reflc.x[i]/wzx)*(reflc.x[i]/wzx) - (reflc.y[i]/wzy)*(reflc.y[i]/wzy) -
313 j*M_PI/gdict.lam * (reflc.x[i]*reflc.x[i]*Rzx_inv + reflc.y[i]*reflc.y[i]*Rzy_inv) - j*k*reflc.z[i] + j*(phizx - phizy)*0.5);
315 efield[0] = field_atPoint * gdict.pol[0];
316 efield[1] = field_atPoint * gdict.pol[1];
317 efield[2] = field_atPoint * gdict.pol[2];
319 n_source[0] = reflc.nx[i];
320 n_source[1] = reflc.ny[i];
321 n_source[2] = reflc.nz[i];
323 ut.
ext(n_source, efield, m);
325 res_field->r1x[i] = efield[0].real();
326 res_field->i1x[i] = efield[0].imag();
328 res_field->r1y[i] = efield[1].real();
329 res_field->i1y[i] = efield[1].imag();
331 res_field->r1z[i] = efield[2].real();
332 res_field->i1z[i] = efield[2].imag();
335 res_field->r2x[i] = 0;
336 res_field->i2x[i] = 0;
338 res_field->r2y[i] = 0;
339 res_field->i2y[i] = 0;
341 res_field->r2z[i] = 0;
342 res_field->i2z[i] = 0;
345 res_current->r1x[i] = 0;
346 res_current->i1x[i] = 0;
348 res_current->r1y[i] = 0;
349 res_current->i1y[i] = 0;
351 res_current->r1z[i] = 0;
352 res_current->i1z[i] = 0;
355 res_current->r2x[i] = -2*m[0].real();
356 res_current->i2x[i] = -2*m[0].imag();
358 res_current->r2y[i] = -2*m[1].real();
359 res_current->i2y[i] = -2*m[1].imag();
361 res_current->r2z[i] = -2*m[2].real();
362 res_current->i2z[i] = -2*m[2].imag();
379 int nTot = refldict.n_cells[0] * refldict.n_cells[1];
383 reflc.x =
new G[nTot];
384 reflc.y =
new G[nTot];
385 reflc.z =
new G[nTot];
387 reflc.nx =
new G[nTot];
388 reflc.ny =
new G[nTot];
389 reflc.nz =
new G[nTot];
391 reflc.area =
new G[nTot];
394 bool transform =
true;
397 G zRx = M_PI * sgdict.w0x*sgdict.w0x * sgdict.n / sgdict.lam;
398 G zRy = M_PI * sgdict.w0y*sgdict.w0y * sgdict.n / sgdict.lam;
399 G k = 2 * M_PI / sgdict.lam;
407 std::complex<G> j(0, 1);
409 std::complex<G> efield;
411 for (
int i=0; i<nTot; i++)
413 wzx = sgdict.w0x * sqrt(1 + (reflc.z[i] / zRx)*(reflc.z[i] / zRx));
414 wzy = sgdict.w0y * sqrt(1 + ((reflc.z[i] - sgdict.dxyz) / zRy)*((reflc.z[i] - sgdict.dxyz) / zRy));
415 Rzx_inv = reflc.z[i] / (reflc.z[i]*reflc.z[i] + zRx*zRx);
416 Rzy_inv = (reflc.z[i] - sgdict.dxyz) / ((reflc.z[i] - sgdict.dxyz)*(reflc.z[i] - sgdict.dxyz) + zRy*zRy);
417 phizx = atan(reflc.z[i] / zRx);
418 phizy = atan((reflc.z[i] - sgdict.dxyz) / zRy);
420 efield = sgdict.E0 * sqrt(2 / (M_PI * wzx * wzy)) * exp(-(reflc.x[i]/wzx)*(reflc.x[i]/wzx) - (reflc.y[i]/wzy)*(reflc.y[i]/wzy) -
421 j*M_PI/sgdict.lam * (reflc.x[i]*reflc.x[i]*Rzx_inv + reflc.y[i]*reflc.y[i]*Rzy_inv) - j*k*reflc.z[i] + j*(phizx - phizy)*0.5);
423 res_field->x[i] = efield.real();
424 res_field->y[i] = efield.imag();
439void calcJM(T *res_field, T *res_current, V refldict,
int mode)
442 int nTot = refldict.n_cells[0] * refldict.n_cells[1];
446 reflc.x =
new U[nTot];
447 reflc.y =
new U[nTot];
448 reflc.z =
new U[nTot];
450 reflc.nx =
new U[nTot];
451 reflc.ny =
new U[nTot];
452 reflc.nz =
new U[nTot];
454 reflc.area =
new U[nTot];
456 bool transform =
true;
461 std::array<std::complex<U>, 3> field;
462 std::array<U, 3> n_source;
464 std::array<std::complex<U>, 3> js;
465 std::array<std::complex<U>, 3> ms;
470 for (
int i=0; i<nTot; i++)
472 field[0] = {res_field->r1x[i], res_field->i1x[i]};
473 field[1] = {res_field->r1y[i], res_field->i1y[i]};
474 field[2] = {res_field->r1z[i], res_field->i1z[i]};
476 n_source[0] = reflc.nx[i];
477 n_source[1] = reflc.ny[i];
478 n_source[2] = reflc.nz[i];
480 ut.
ext(n_source, field, ms);
482 res_current->r2x[i] = -ms[0].real();
483 res_current->i2x[i] = -ms[0].imag();
485 res_current->r2y[i] = -ms[1].real();
486 res_current->i2y[i] = -ms[1].imag();
488 res_current->r2z[i] = -ms[2].real();
489 res_current->i2z[i] = -ms[2].imag();
491 field[0] = {res_field->r2x[i], res_field->i2x[i]};
492 field[1] = {res_field->r2y[i], res_field->i2y[i]};
493 field[2] = {res_field->r2z[i], res_field->i2z[i]};
495 ut.
ext(n_source, field, js);
497 res_current->r1x[i] = js[0].real();
498 res_current->i1x[i] = js[0].imag();
500 res_current->r1y[i] = js[1].real();
501 res_current->i1y[i] = js[1].imag();
503 res_current->r1z[i] = js[2].real();
504 res_current->i1z[i] = js[2].imag();
511 for (
int i=0; i<nTot; i++)
513 field[0] = {res_field->r1x[i], res_field->i1x[i]};
514 field[1] = {res_field->r1y[i], res_field->i1y[i]};
515 field[2] = {res_field->r1z[i], res_field->i1z[i]};
517 n_source[0] = reflc.nx[i];
518 n_source[1] = reflc.ny[i];
519 n_source[2] = reflc.nz[i];
521 ut.
ext(n_source, field, ms);
523 res_current->r2x[i] = -2*ms[0].real();
524 res_current->i2x[i] = -2*ms[0].imag();
526 res_current->r2y[i] = -2*ms[1].real();
527 res_current->i2y[i] = -2*ms[1].imag();
529 res_current->r2z[i] = -2*ms[2].real();
530 res_current->i2z[i] = -2*ms[2].imag();
532 res_current->r1x[i] = 0;
533 res_current->i1x[i] = 0;
535 res_current->r1y[i] = 0;
536 res_current->i1y[i] = 0;
538 res_current->r1z[i] = 0;
539 res_current->i1z[i] = 0;
546 for (
int i=0; i<nTot; i++)
548 field[0] = {res_field->r2x[i], res_field->i2x[i]};
549 field[1] = {res_field->r2y[i], res_field->i2y[i]};
550 field[2] = {res_field->r2z[i], res_field->i2z[i]};
552 n_source[0] = reflc.nx[i];
553 n_source[1] = reflc.ny[i];
554 n_source[2] = reflc.nz[i];
556 ut.
ext(n_source, field, js);
558 res_current->r1x[i] = 2*js[0].real();
559 res_current->i1x[i] = 2*js[0].imag();
561 res_current->r1y[i] = 2*js[1].real();
562 res_current->i1y[i] = 2*js[1].imag();
564 res_current->r1z[i] = 2*js[2].real();
565 res_current->i1z[i] = 2*js[2].imag();
567 res_current->r2x[i] = 0;
568 res_current->i2x[i] = 0;
570 res_current->r2y[i] = 0;
571 res_current->i2y[i] = 0;
573 res_current->r2z[i] = 0;
574 res_current->i2z[i] = 0;