Commit c2b9aa353d8f2f77ac0cd00663a8d6f633fcb7bd
1 parent
c0a2a7bb
Added scattering amplitude calculation.
Showing
4 changed files
with
104 additions
and
44 deletions
Show diff stats
msinput.inp
@@ -39,7 +39,7 @@ max_scattering_angle_deg | @@ -39,7 +39,7 @@ max_scattering_angle_deg | ||
39 | number_scattering_angles | 39 | number_scattering_angles |
40 | 181 | 40 | 181 |
41 | normalize_scattering_matrix | 41 | normalize_scattering_matrix |
42 | -1 | 42 | +0 |
43 | gaussian_beam_constant | 43 | gaussian_beam_constant |
44 | 0.0d0 | 44 | 0.0d0 |
45 | gaussian_beam_focal_point | 45 | gaussian_beam_focal_point |
mstm-gui.py
@@ -98,6 +98,7 @@ class GuiWindow(QtGui.QMainWindow): | @@ -98,6 +98,7 @@ class GuiWindow(QtGui.QMainWindow): | ||
98 | #plot results of interest | 98 | #plot results of interest |
99 | wl = self.results['lambda'] | 99 | wl = self.results['lambda'] |
100 | 100 | ||
101 | + #for a fixed orientation | ||
101 | if int(self.params['fixed_or_random_orientation']) == 0: | 102 | if int(self.params['fixed_or_random_orientation']) == 0: |
102 | unpol = self.results['extinction_unpolarized'] | 103 | unpol = self.results['extinction_unpolarized'] |
103 | para = self.results['extinction_parallel'] | 104 | para = self.results['extinction_parallel'] |
@@ -132,33 +133,19 @@ class GuiWindow(QtGui.QMainWindow): | @@ -132,33 +133,19 @@ class GuiWindow(QtGui.QMainWindow): | ||
132 | self.results = RunSimulation(False) | 133 | self.results = RunSimulation(False) |
133 | 134 | ||
134 | if self.params['calculate_near_field']: | 135 | if self.params['calculate_near_field']: |
135 | - #verts = self.params['near_field_plane_vertices'] | ||
136 | - #dx = (verts[2] - verts[0])/(self.params.nSteps) | ||
137 | - #x = arange(verts[0], verts[2], dx) | ||
138 | - #print(len(x)) | ||
139 | - #y = arange(verts[1], verts[3], dx) | ||
140 | - #X, Y = meshgrid(x, y) | 136 | + |
141 | E = array(self.results.gridNearField) | 137 | E = array(self.results.gridNearField) |
142 | - #pcolor(X, Y, E, cmap=cm.RdBu) | ||
143 | - #colorbar() | ||
144 | - #axis([verts[0], verts[2], verts[1], verts[3]]) | 138 | + |
145 | 139 | ||
146 | pcolor(E, cmap=cm.RdBu) | 140 | pcolor(E, cmap=cm.RdBu) |
147 | colorbar() | 141 | colorbar() |
142 | + | ||
143 | + #compute the maximum field magnitude in the plane | ||
148 | print("Maximum enhancement: " + str(abs(E).max())) | 144 | print("Maximum enhancement: " + str(abs(E).max())) |
145 | + | ||
146 | + #get the scattering amplitude matrix | ||
147 | + print(self.results.scatAmpMatrix[0]) | ||
149 | 148 | ||
150 | - # make these smaller to increase the resolution | ||
151 | - #dx, dy = 0.05, 0.05 | ||
152 | - | ||
153 | - #x = arange(-3.0, 3.0001, dx) | ||
154 | - #y = arange(-3.0, 3.0001, dy) | ||
155 | - #X,Y = meshgrid(x, y) | ||
156 | - | ||
157 | - #Z = self.func3(X, Y) | ||
158 | - #pcolor(X, Y, Z, cmap=cm.RdBu, vmax=abs(Z).max(), vmin=-abs(Z).max()) | ||
159 | - #colorbar() | ||
160 | - #axis([-3,3,-3,3]) | ||
161 | - | ||
162 | show() | 149 | show() |
163 | 150 | ||
164 | def saveresults(self): | 151 | def saveresults(self): |
@@ -184,12 +171,12 @@ class GuiWindow(QtGui.QMainWindow): | @@ -184,12 +171,12 @@ class GuiWindow(QtGui.QMainWindow): | ||
184 | a = self.ui.spinRadius.value() | 171 | a = self.ui.spinRadius.value() |
185 | 172 | ||
186 | self.ui.tblSpheres.setItem(0, 0, QtGui.QTableWidgetItem(str(a))) | 173 | self.ui.tblSpheres.setItem(0, 0, QtGui.QTableWidgetItem(str(a))) |
187 | - self.ui.tblSpheres.setItem(0, 1, QtGui.QTableWidgetItem(str(-(d + 2*a)/2))) | 174 | + self.ui.tblSpheres.setItem(0, 1, QtGui.QTableWidgetItem(str(-(d/2.0 + a)))) |
188 | self.ui.tblSpheres.setItem(0, 2, QtGui.QTableWidgetItem(str(0.0))) | 175 | self.ui.tblSpheres.setItem(0, 2, QtGui.QTableWidgetItem(str(0.0))) |
189 | self.ui.tblSpheres.setItem(0, 3, QtGui.QTableWidgetItem(str(0.0))) | 176 | self.ui.tblSpheres.setItem(0, 3, QtGui.QTableWidgetItem(str(0.0))) |
190 | 177 | ||
191 | self.ui.tblSpheres.setItem(1, 0, QtGui.QTableWidgetItem(str(a))) | 178 | self.ui.tblSpheres.setItem(1, 0, QtGui.QTableWidgetItem(str(a))) |
192 | - self.ui.tblSpheres.setItem(1, 1, QtGui.QTableWidgetItem(str((d + 2*a)/2))) | 179 | + self.ui.tblSpheres.setItem(1, 1, QtGui.QTableWidgetItem(str((d/2.0 + a)))) |
193 | self.ui.tblSpheres.setItem(1, 2, QtGui.QTableWidgetItem(str(0.0))) | 180 | self.ui.tblSpheres.setItem(1, 2, QtGui.QTableWidgetItem(str(0.0))) |
194 | self.ui.tblSpheres.setItem(1, 3, QtGui.QTableWidgetItem(str(0.0))) | 181 | self.ui.tblSpheres.setItem(1, 3, QtGui.QTableWidgetItem(str(0.0))) |
195 | 182 | ||
@@ -315,6 +302,9 @@ def RunSimulation(spectralSim = True): | @@ -315,6 +302,9 @@ def RunSimulation(spectralSim = True): | ||
315 | 302 | ||
316 | if parameters['calculate_near_field']: | 303 | if parameters['calculate_near_field']: |
317 | results.parseNearField('nf-temp.dat') | 304 | results.parseNearField('nf-temp.dat') |
305 | + | ||
306 | + #get the scattering amplitude matrix | ||
307 | + results.calcScatteringAmp() | ||
318 | 308 | ||
319 | 309 | ||
320 | #update the progress bar | 310 | #update the progress bar |
mstm-main-v2.2.f90
@@ -348,31 +348,61 @@ | @@ -348,31 +348,61 @@ | ||
348 | write(1,'('' perpendicular total ext, abs, scat efficiencies'')') | 348 | write(1,'('' perpendicular total ext, abs, scat efficiencies'')') |
349 | write(1,'(6e13.5)') qexttotper,qabstotper,qscatotper | 349 | write(1,'(6e13.5)') qexttotper,qabstotper,qscatotper |
350 | endif | 350 | endif |
351 | - | 351 | + |
352 | write(1,'('' scattering matrix elements'')') | 352 | write(1,'('' scattering matrix elements'')') |
353 | if(normalizesm.eq.0) then | 353 | if(normalizesm.eq.0) then |
354 | - write(1,'('' theta s11 s22 s33'',& | ||
355 | - &'' s44'',& | ||
356 | - &'' s21 s32 s43 s31'',& | ||
357 | - &'' s42 s41'')') | 354 | + write(1,'('' theta s11 s12 s13'',& |
355 | + &'' s14'',& | ||
356 | + &'' s21 s22 s23 s24'',& | ||
357 | + &'' s31 s32 s33 s34'',& | ||
358 | + &'' s41 s42 s43 s44'')') | ||
358 | do i=1,numtheta | 359 | do i=1,numtheta |
359 | thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) | 360 | thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) |
360 | - write(1,'(f8.2,10e12.4)') thetad,smt(1,1,i),smt(2,2,i),smt(3,3,i), & | ||
361 | - smt(4,4,i),smt(1,2,i),smt(2,3,i),smt(3,4,i),smt(1,3,i), & | ||
362 | - smt(2,4,i),smt(1,4,i) | 361 | + write(1,'(f8.2,16e12.4)') thetad,smt(1,1,i),smt(2,1,i),smt(3,1,i), & |
362 | + smt(4,1,i),smt(1,2,i),smt(2,2,i),smt(3,2,i),smt(4,2,i), & | ||
363 | + smt(1,3,i),smt(2,3,i),smt(3,3,i),smt(4,3,i),smt(1,4,i), & | ||
364 | + smt(2,4,i),smt(3,4,i),smt(4,4,i) | ||
365 | + | ||
366 | +! write(1,'('' scattering matrix elements'')') | ||
367 | +! if(normalizesm.eq.0) then | ||
368 | +! write(1,'('' theta s11 s22 s33'',& | ||
369 | +! &'' s44'',& | ||
370 | +! &'' s21 s32 s43 s31'',& | ||
371 | +! &'' s42 s41'')') | ||
372 | +! do i=1,numtheta | ||
373 | +! thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) | ||
374 | +! write(1,'(f8.2,10e12.4)') thetad,smt(1,1,i),smt(2,2,i),smt(3,3,i), & | ||
375 | +! smt(4,4,i),smt(1,2,i),smt(2,3,i),smt(3,4,i),smt(1,3,i), & | ||
376 | +! smt(2,4,i),smt(1,4,i) | ||
363 | enddo | 377 | enddo |
364 | else | 378 | else |
365 | - write(1,'('' theta s11 s22/s11 s33'',& | ||
366 | - &''/s11 s44'',& | ||
367 | - &''/s11 s21/s11 s32/s11 s43/s11 s31'',& | ||
368 | - &''/s11 s42/s11 s41/s11'')') | 379 | +!This code was changed by David Mayericha and Thomas van Dijk |
380 | + write(1,'('' theta s11 s12/s11 s13'',& | ||
381 | + &''/s11 s14'',& | ||
382 | + &''/s11 s21/s11 s22/s11 s23/s11 s24'',& | ||
383 | + &''/s11 s31/s11 s32/s11 s33/s11 s34'',& | ||
384 | + &''/s11 s41/s11 s42/s11 s43/s11 s44/s11'')') | ||
369 | do i=1,numtheta | 385 | do i=1,numtheta |
370 | thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) | 386 | thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) |
371 | s11=smt(1,1,i) | 387 | s11=smt(1,1,i) |
372 | - write(1,'(f8.2,10e12.4)') thetad,smt(1,1,i),smt(2,2,i)/s11,smt(3,3,i)/s11, & | ||
373 | - smt(4,4,i)/s11,smt(1,2,i)/s11,smt(2,3,i)/s11,smt(3,4,i)/s11,smt(1,3,i)/s11, & | ||
374 | - smt(2,4,i)/s11,smt(1,4,i)/s11 | 388 | + write(1,'(f8.2,16e12.4)') thetad,smt(1,1,i),smt(2,1,i)/s11,smt(3,1,i)/s11, & |
389 | + smt(4,1,i)/s11,smt(1,2,i)/s11,smt(2,2,i)/s11,smt(3,2,i)/s11,smt(4,2,i)/s11, & | ||
390 | + smt(1,3,i)/s11,smt(2,3,i)/s11,smt(3,3,i)/s11,smt(4,3,i)/s11,smt(1,4,i)/s11, & | ||
391 | + smt(2,4,i)/s11,smt(3,4,i)/s11,smt(4,4,i)/s11 | ||
375 | enddo | 392 | enddo |
393 | + | ||
394 | +!original code here | ||
395 | +! write(1,'('' theta s11 s22/s11 s33'',& | ||
396 | +! &''/s11 s44'',& | ||
397 | +! &''/s11 s21/s11 s32/s11 s43/s11 s31'',& | ||
398 | +! &''/s11 s42/s11 s41/s11'')') | ||
399 | +! do i=1,numtheta | ||
400 | +! thetad=theta1d+(theta2d-theta1d)*(i-1)/max(1.d0,dble(numtheta-1)) | ||
401 | +! s11=smt(1,1,i) | ||
402 | +! write(1,'(f8.2,10e12.4)') thetad,smt(1,1,i),smt(2,2,i)/s11,smt(3,3,i)/s11, & | ||
403 | +! smt(4,4,i)/s11,smt(1,2,i)/s11,smt(2,3,i)/s11,smt(3,4,i)/s11,smt(1,3,i)/s11, & | ||
404 | +! smt(2,4,i)/s11,smt(1,4,i)/s11 | ||
405 | +! enddo | ||
376 | endif | 406 | endif |
377 | if(fixedorrandom.eq.1) then | 407 | if(fixedorrandom.eq.1) then |
378 | write(1,'('' scattering matrix expansion coefficients'')') | 408 | write(1,'('' scattering matrix expansion coefficients'')') |
mstm_simparser.py
1 | +#this code parses the results of a simulation and stores them in a SimParserClass structure | ||
1 | from pylab import * | 2 | from pylab import * |
2 | 3 | ||
3 | class SimParserClass: | 4 | class SimParserClass: |
@@ -12,6 +13,10 @@ class SimParserClass: | @@ -12,6 +13,10 @@ class SimParserClass: | ||
12 | gridNearField = [] | 13 | gridNearField = [] |
13 | maxNearField = [] | 14 | maxNearField = [] |
14 | 15 | ||
16 | + #the stokes matrix is read from the output | ||
17 | + stokesMatrix = [] | ||
18 | + scatAmpMatrix = [] | ||
19 | + | ||
15 | 20 | ||
16 | def __init__(self, parameters): | 21 | def __init__(self, parameters): |
17 | 22 | ||
@@ -23,6 +28,7 @@ class SimParserClass: | @@ -23,6 +28,7 @@ class SimParserClass: | ||
23 | self.simResults['extinction_parallel'] = list() | 28 | self.simResults['extinction_parallel'] = list() |
24 | self.simResults['extinction_perpendicular'] = list() | 29 | self.simResults['extinction_perpendicular'] = list() |
25 | self.simResults['extinction_total'] = list() | 30 | self.simResults['extinction_total'] = list() |
31 | + self.simResults['detector_field'] = list() | ||
26 | 32 | ||
27 | self.gridNearField = [] | 33 | self.gridNearField = [] |
28 | self.maxNearField = [] | 34 | self.maxNearField = [] |
@@ -36,10 +42,17 @@ class SimParserClass: | @@ -36,10 +42,17 @@ class SimParserClass: | ||
36 | while True: | 42 | while True: |
37 | 43 | ||
38 | line = inFile.readline().strip() | 44 | line = inFile.readline().strip() |
39 | - | 45 | + |
46 | + #if the simulation is for a single plane wave | ||
40 | if int(self.params['fixed_or_random_orientation']) == 0: | 47 | if int(self.params['fixed_or_random_orientation']) == 0: |
41 | if line == 'scattering matrix elements': | 48 | if line == 'scattering matrix elements': |
42 | - break | 49 | + #empty the stokes matrix |
50 | + self.stokesMatrix = [] | ||
51 | + inFile.readline() | ||
52 | + for s in range(0, 181): | ||
53 | + values = map(float, inFile.readline().strip().split()) | ||
54 | + self.stokesMatrix.append(values) | ||
55 | + break; | ||
43 | elif line == 'unpolarized total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm': | 56 | elif line == 'unpolarized total ext, abs, scat efficiencies, w.r.t. xv, and asym. parm': |
44 | values = inFile.readline().strip().split(' ') | 57 | values = inFile.readline().strip().split(' ') |
45 | self.simResults['extinction_unpolarized'].append(values[0]) | 58 | self.simResults['extinction_unpolarized'].append(values[0]) |
@@ -49,7 +62,8 @@ class SimParserClass: | @@ -49,7 +62,8 @@ class SimParserClass: | ||
49 | elif line == 'perpendicular total ext, abs, scat efficiencies': | 62 | elif line == 'perpendicular total ext, abs, scat efficiencies': |
50 | values = inFile.readline().strip().split(' ') | 63 | values = inFile.readline().strip().split(' ') |
51 | self.simResults['extinction_perpendicular'].append(values[0]) | 64 | self.simResults['extinction_perpendicular'].append(values[0]) |
52 | - | 65 | + |
66 | + #if the simulation is for random orientations | ||
53 | else: | 67 | else: |
54 | if line == 'scattering matrix elements': | 68 | if line == 'scattering matrix elements': |
55 | break | 69 | break |
@@ -83,6 +97,31 @@ class SimParserClass: | @@ -83,6 +97,31 @@ class SimParserClass: | ||
83 | 97 | ||
84 | E = array(self.gridNearField) | 98 | E = array(self.gridNearField) |
85 | self.maxNearField.append(abs(E).max()) | 99 | self.maxNearField.append(abs(E).max()) |
100 | + | ||
101 | + #calculate and return the scattering amplitude matrix | ||
102 | + def calcScatteringAmp(self): | ||
103 | + #compute the number of entries in the stokes matrix | ||
104 | + nEntries = len(self.stokesMatrix) | ||
105 | + | ||
106 | + #initialize the scattering amplitude matrix to empty | ||
107 | + self.scatAmpMatrix = [] | ||
108 | + | ||
109 | + for s in range(0, nEntries): | ||
110 | + Z = self.stokesMatrix[s] | ||
111 | + | ||
112 | + scatEntry = [] | ||
113 | + s11 = complex(sqrt(0.5 * (Z[1] - Z[2] - Z[5] + Z[6])), 0.0) | ||
114 | + scatEntry.append(s11) | ||
115 | + scatEntry.append(complex(-0.5 * (Z[3] + Z[7]) / s11, 0.5 * (Z[4] + Z[8]) / s11)) | ||
116 | + scatEntry.append(complex(-0.5 * (Z[9] + Z[10]) / s11, -0.5 * (Z[13] + Z[14]) / s11)) | ||
117 | + scatEntry.append(complex(0.5 * (Z[11] + Z[12]) / s11, -0.5 * (Z[12] - Z[15]) / s11)) | ||
118 | + | ||
119 | + self.scatAmpMatrix.append(scatEntry) | ||
120 | + | ||
121 | + S = self.scatAmpMatrix[0] | ||
122 | + E = [S[0], S[2]] | ||
123 | + self.simResults['detector_field'].append(E) | ||
124 | + print(E) | ||
86 | 125 | ||
87 | 126 | ||
88 | def saveFile(self, fileName): | 127 | def saveFile(self, fileName): |
@@ -101,10 +140,11 @@ class SimParserClass: | @@ -101,10 +140,11 @@ class SimParserClass: | ||
101 | result += '\t' + str(self.simResults['extinction_unpolarized'][i]) | 140 | result += '\t' + str(self.simResults['extinction_unpolarized'][i]) |
102 | result += '\t' + str(self.simResults['extinction_parallel'][i]) | 141 | result += '\t' + str(self.simResults['extinction_parallel'][i]) |
103 | result += '\t' + str(self.simResults['extinction_perpendicular'][i]) | 142 | result += '\t' + str(self.simResults['extinction_perpendicular'][i]) |
143 | + result += '\t' + str(self.simResults['detector_field'][i][0]) + '\t' + str(self.simResults['detector_field'][i][1]) | ||
104 | 144 | ||
105 | #parse the near field if it is included in the simulation | 145 | #parse the near field if it is included in the simulation |
106 | - if int(parameters['calculate_near_field']) == 1: | ||
107 | - result += '\t' + str(maxNearField) | 146 | + #if int(parameters['calculate_near_field']) == 1: |
147 | + # result += '\t' + str(maxNearField) | ||
108 | 148 | ||
109 | result += '\n' | 149 | result += '\n' |
110 | return result | 150 | return result |