Parameter Scan¶
With the parameterization of the test project in the previous section Keyword Substitution, it is straightforward to run a parameter scan within Python:
1import jcmwave
2import numpy as np
3import os
4
5# holds computed scattering cross sections
6scattering_cross_section_scan = []
7
8# loop over radius values
9radii = np.linspace(0.3, 0.5, 40)
10for radius in radii:
11 print ('Solving for radius %5.2e' %(radius,))
12
13 # set current parameter and solve the project
14 keys = {'radius': radius}
15 results = jcmwave.solve('mie2D.jcmp', keys=keys,
16 logfile=open(os.devnull, 'w'))
17
18 scs = results[1]['ElectromagneticFieldEnergyFlux'][0][0].real
19
20 # gather results
21 scattering_cross_section_scan.append(scs)
22
23
24# plot scattering cross section against rod radius
25from matplotlib.pyplot import *
26plot(radii, scattering_cross_section_scan, '-+', linewidth=2, markersize=14)
27xlabel('radius [$\mu$ m]', fontsize=14)
28ylabel('integral scattering cross section', fontsize=14)
29axis('tight')
30show()
In line 6 we initialize the vector scattering_cross_section_scan which later holds the computed data. In line 9 we define an equidistant parameter sampling for the rod radius. In line 10 we start a loop over the sampling. In each step the dictionary keys is updated with the current radius value (line 14), followed by a solver call (line 15). The optional parameter logfile redirects the solver console output to a file (using os.devnull disregards all console output). In line 21 we gather the relevant data. Line 25-30 serve the plotting of the results, see Figure “Scattering Cross Section”.
Scattering Cross Section¶
Computed scattering cross section versus rod radius.
The next section Python Code Snippets how to enrich the .jcmt input files with python scripts blocks.