nearfield.cpp
2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
#include "nearfield.h"
nearfieldStruct::nearfieldStruct()
{
scalarSim = true;
planeWave = false;
nWaves = 0;
}
void nearfieldStruct::init()
{
//set the field parameters
U.scalarField = scalarSim;
Uf.scalarField = scalarSim;
//initialize dynamic memory
U.init_gpu();
Uf.init_gpu();
}
void nearfieldStruct::destroy()
{
U.kill_gpu();
Uf.kill_gpu();
}
void nearfieldStruct::setPos(bsPoint pMin, bsPoint pMax, bsVector normal)
{
pos = rts::rtsQuad<ptype, 3>(pMin, pMax, normal);
}
void nearfieldStruct::setRes(int x_res, int y_res)
{
U.R[0] = Uf.R[0] = x_res;
U.R[1] = Uf.R[1] = y_res;
}
std::string nearfieldStruct::toStr()
{
std::stringstream ss;
ss<<"------Field Parameters-------"<<std::endl;
ss<<"Wavelength: "<<lambda<<"um"<<std::endl;
ss<<"K Vector (r, theta, phi): "<<k.cart2sph()<<std::endl;
ss<<"Condenser NA: "<<condenser[0]<<" to "<<condenser[1]<<std::endl;
ss<<"Focal Point: "<<focus[0]<<", "<<focus[1]<<", "<<focus[2]<<std::endl;
ss<<"Field Slice: "<<std::endl;
ss<<pos<<std::endl;
ss<<std::endl<<"---------Materials-----------"<<std::endl;
ss<<"Number of Materials: "<<mVector.size()<<std::endl;
ss<<"Refractive Indices at lambda = "<<lambda<<"um"<<std::endl;
//output each material
for(unsigned int m=0; m<mVector.size(); m++)
ss<<" "<<m<<": "<<mVector[m](lambda)<<std::endl;
ss<<"---------Spheres-------------"<<std::endl;
ss<<"Number of Spheres: "<<sVector.size()<<std::endl;
//output each sphere
for(unsigned int s=0; s<sVector.size(); s++)
ss<<sVector[s].toStr()<<std::endl;
return ss.str();
}
//generate monte-carlo waves
void nearfieldStruct::calcWaves()
{
inWaves.resize(nWaves);
//re-seed the random number generator
//srand(seed);
//calculate the monte-carlo samples
mcSampleNA(&inWaves[0], nWaves, k, condenser[0], condenser[1]);
}
void nearfieldStruct::calcSpheres()
{
//calculate all of the constants necessary to evaluate the scattered field
//estimate the order required to represent the scattered field for each sphere
//for each sphere
for(int i=0; i<sVector.size(); i++)
{
//a = sVector[i].a;
//calculate the required order
sVector[i].calcNl(lambda);
//std::cout<<sVector[i].Nl<<std::endl;
//set the refractive index for the sphere
int imat = sVector[i].iMaterial;
rts::rtsComplex<ptype> n = mVector[imat](lambda);
//std::cout<<"Sphere refractive index: "<<n<<std::endl;
//calculate the scattering coefficients
sVector[i].calcCoeff(lambda, n);
//save the refractive index
sVector[i].n = n;
}
}
void nearfieldStruct::Simulate()
{
//compute a set of plane waves for Monte-Carlo simulation
calcWaves();
//the near field has to be simulated no matter what the output rtsPoint is
scalarUf();
calcSpheres();
scalarUs();
sumUf();
}