# Multipole Decomposition 2¶

01/2021: updated to pyGDM v1.1+

Here we analyze the contributions of the electric and magnetic dipole modes to the extinction spectra of a silicon nano-disc and study the impact of a hole in the nanodisc.

The example is based on the multipole decomposition described in reference [1].

[1] Evlyukhin, A. B., Reinhardt, C. and Chichkov, B. N. Multipole light scattering by nonspherical nanoparticles in the discrete dipole approximation. Phys. Rev. B 84, 235429 (2011)

[1]:

from __future__ import print_function, division

## --- load the modules
import numpy as np
import matplotlib.pyplot as plt

from pyGDM2 import structures
from pyGDM2 import materials
from pyGDM2 import fields
from pyGDM2 import core
from pyGDM2 import propagators
from pyGDM2 import visu
from pyGDM2 import tools
from pyGDM2 import linear


## Config and run simulation¶

Si nanocube of 160 nm side-length in vacuum, plane wave illumination.

We discretize with 10 nm to achieve a relatively fast inversion for this demonstration.

[2]:

## --- simulation initialization ---

## --- geometry
mesh = 'hex'
step = 10         # in nm
radius = 60       # in nm
height = 120      # in nm
hole_radius = 25  # in nm

## --- Full nanodisc
geometry_0 = structures.nanodisc(step, R=radius/step,
H=height//step, mesh=mesh)
## --- Holed nanodisc
## We copy the full nanodisc meshpoints except where the hole is
X_h, _, Z_h = geometry_0.T
X_h = X_h - np.mean(X_h) + radius / 2.   # hole center = radius/2
Z_h = Z_h - np.mean(Z_h)
geometry_1 = geometry_0.copy()[X_h**2 + Z_h**2 > hole_radius**2]

material = materials.silicon()
struct_0 = structures.struct(step, geometry_0, material)
struct_1 = structures.struct(step, geometry_1, material)

## --- incident field: lin. pol plane wave
field_generator = fields.plane_wave
wavelengths = np.arange(400, 700, 5)
kwargs = dict(theta=0.0, inc_angle=180)   ## normal incidence from top
efield = fields.efield(field_generator,
wavelengths=wavelengths, kwargs=kwargs)

## --- environment

## --- create simulation instance
sim_0 = core.simulation(struct_0, efield, dyads)
sim_1 = core.simulation(struct_1, efield, dyads)

visu.structure(sim_0, projection = 'XZ')
print("full:   N dp={}".format(len(geometry_0)))
visu.structure(sim_1, projection = 'XZ')
print("hole:   N dp={}".format(len(geometry_0)))

## --- run the main simulation ---
sim_0.scatter()
sim_1.scatter()


structure initialization - automatic mesh detection: hex
structure initialization - consistency check: 1960/1960 dipoles valid
structure initialization - automatic mesh detection: hex
structure initialization - consistency check: 1681/1681 dipoles valid

full:   N dp=1960

hole:   N dp=1960
timing for wl=400.00nm - setup: EE 1824.9ms, inv.: 872.5ms, repropa.: 643.0ms (1 field configs), tot: 3347.0ms
timing for wl=405.00nm - setup: EE 159.8ms, inv.: 361.2ms, repropa.: 45.3ms (1 field configs), tot: 573.0ms
timing for wl=410.00nm - setup: EE 184.0ms, inv.: 366.3ms, repropa.: 45.6ms (1 field configs), tot: 602.8ms
timing for wl=415.00nm - setup: EE 159.9ms, inv.: 355.2ms, repropa.: 47.7ms (1 field configs), tot: 569.5ms
timing for wl=420.00nm - setup: EE 157.3ms, inv.: 360.8ms, repropa.: 45.7ms (1 field configs), tot: 570.4ms
timing for wl=425.00nm - setup: EE 163.6ms, inv.: 365.8ms, repropa.: 46.0ms (1 field configs), tot: 582.1ms
timing for wl=430.00nm - setup: EE 160.2ms, inv.: 352.5ms, repropa.: 45.2ms (1 field configs), tot: 564.6ms
timing for wl=435.00nm - setup: EE 157.3ms, inv.: 354.3ms, repropa.: 48.3ms (1 field configs), tot: 566.6ms
timing for wl=440.00nm - setup: EE 156.7ms, inv.: 366.4ms, repropa.: 46.0ms (1 field configs), tot: 575.9ms
timing for wl=445.00nm - setup: EE 159.9ms, inv.: 361.5ms, repropa.: 46.3ms (1 field configs), tot: 574.5ms
timing for wl=450.00nm - setup: EE 160.3ms, inv.: 358.7ms, repropa.: 45.7ms (1 field configs), tot: 571.2ms
timing for wl=455.00nm - setup: EE 162.3ms, inv.: 363.6ms, repropa.: 54.7ms (1 field configs), tot: 587.4ms
timing for wl=460.00nm - setup: EE 163.9ms, inv.: 351.0ms, repropa.: 47.4ms (1 field configs), tot: 568.9ms
timing for wl=465.00nm - setup: EE 156.1ms, inv.: 362.7ms, repropa.: 46.0ms (1 field configs), tot: 571.5ms
timing for wl=470.00nm - setup: EE 157.2ms, inv.: 351.0ms, repropa.: 46.5ms (1 field configs), tot: 562.1ms
timing for wl=475.00nm - setup: EE 199.9ms, inv.: 371.1ms, repropa.: 50.2ms (1 field configs), tot: 628.1ms
timing for wl=480.00nm - setup: EE 160.1ms, inv.: 354.2ms, repropa.: 45.8ms (1 field configs), tot: 566.8ms
timing for wl=485.00nm - setup: EE 160.2ms, inv.: 358.6ms, repropa.: 46.5ms (1 field configs), tot: 571.8ms
timing for wl=490.00nm - setup: EE 188.9ms, inv.: 358.0ms, repropa.: 45.9ms (1 field configs), tot: 599.6ms
timing for wl=495.00nm - setup: EE 160.9ms, inv.: 379.4ms, repropa.: 45.8ms (1 field configs), tot: 592.6ms
timing for wl=500.00nm - setup: EE 204.2ms, inv.: 372.3ms, repropa.: 46.1ms (1 field configs), tot: 629.7ms
timing for wl=505.00nm - setup: EE 161.0ms, inv.: 356.5ms, repropa.: 46.6ms (1 field configs), tot: 570.8ms
timing for wl=510.00nm - setup: EE 170.2ms, inv.: 354.2ms, repropa.: 46.2ms (1 field configs), tot: 577.3ms
timing for wl=515.00nm - setup: EE 161.7ms, inv.: 371.8ms, repropa.: 46.3ms (1 field configs), tot: 586.5ms
timing for wl=520.00nm - setup: EE 159.5ms, inv.: 359.0ms, repropa.: 46.7ms (1 field configs), tot: 571.8ms
timing for wl=525.00nm - setup: EE 166.1ms, inv.: 374.8ms, repropa.: 45.9ms (1 field configs), tot: 593.7ms
timing for wl=530.00nm - setup: EE 155.4ms, inv.: 370.4ms, repropa.: 46.9ms (1 field configs), tot: 579.6ms
timing for wl=535.00nm - setup: EE 173.4ms, inv.: 368.5ms, repropa.: 52.1ms (1 field configs), tot: 601.0ms
timing for wl=540.00nm - setup: EE 164.8ms, inv.: 368.8ms, repropa.: 48.5ms (1 field configs), tot: 588.9ms
timing for wl=545.00nm - setup: EE 159.0ms, inv.: 373.7ms, repropa.: 45.9ms (1 field configs), tot: 585.2ms
timing for wl=550.00nm - setup: EE 160.0ms, inv.: 354.3ms, repropa.: 45.8ms (1 field configs), tot: 566.9ms
timing for wl=555.00nm - setup: EE 159.9ms, inv.: 356.9ms, repropa.: 45.8ms (1 field configs), tot: 569.2ms
timing for wl=560.00nm - setup: EE 157.4ms, inv.: 359.3ms, repropa.: 45.4ms (1 field configs), tot: 568.7ms
timing for wl=565.00nm - setup: EE 156.7ms, inv.: 368.4ms, repropa.: 48.1ms (1 field configs), tot: 580.1ms
timing for wl=570.00nm - setup: EE 167.9ms, inv.: 369.5ms, repropa.: 45.8ms (1 field configs), tot: 590.1ms
timing for wl=575.00nm - setup: EE 160.6ms, inv.: 360.7ms, repropa.: 45.7ms (1 field configs), tot: 573.7ms
timing for wl=580.00nm - setup: EE 174.7ms, inv.: 353.9ms, repropa.: 45.4ms (1 field configs), tot: 581.0ms
timing for wl=585.00nm - setup: EE 158.7ms, inv.: 359.5ms, repropa.: 45.1ms (1 field configs), tot: 570.6ms
timing for wl=590.00nm - setup: EE 166.5ms, inv.: 364.6ms, repropa.: 45.8ms (1 field configs), tot: 583.8ms
timing for wl=595.00nm - setup: EE 155.4ms, inv.: 372.6ms, repropa.: 45.3ms (1 field configs), tot: 580.2ms
timing for wl=600.00nm - setup: EE 154.9ms, inv.: 347.4ms, repropa.: 52.9ms (1 field configs), tot: 561.8ms
timing for wl=605.00nm - setup: EE 194.4ms, inv.: 378.8ms, repropa.: 44.7ms (1 field configs), tot: 624.8ms
timing for wl=610.00nm - setup: EE 159.6ms, inv.: 353.1ms, repropa.: 46.1ms (1 field configs), tot: 565.6ms
timing for wl=615.00nm - setup: EE 160.8ms, inv.: 380.4ms, repropa.: 45.6ms (1 field configs), tot: 593.5ms
timing for wl=620.00nm - setup: EE 155.6ms, inv.: 356.6ms, repropa.: 45.2ms (1 field configs), tot: 563.9ms
timing for wl=625.00nm - setup: EE 163.8ms, inv.: 360.8ms, repropa.: 45.8ms (1 field configs), tot: 577.2ms
timing for wl=630.00nm - setup: EE 164.2ms, inv.: 364.6ms, repropa.: 46.0ms (1 field configs), tot: 582.2ms
timing for wl=635.00nm - setup: EE 160.2ms, inv.: 368.4ms, repropa.: 45.8ms (1 field configs), tot: 581.2ms
timing for wl=640.00nm - setup: EE 158.6ms, inv.: 356.2ms, repropa.: 47.2ms (1 field configs), tot: 568.5ms
timing for wl=645.00nm - setup: EE 156.9ms, inv.: 373.1ms, repropa.: 46.3ms (1 field configs), tot: 583.1ms
timing for wl=650.00nm - setup: EE 167.2ms, inv.: 370.9ms, repropa.: 45.5ms (1 field configs), tot: 590.4ms
timing for wl=655.00nm - setup: EE 158.4ms, inv.: 368.4ms, repropa.: 45.9ms (1 field configs), tot: 579.8ms
timing for wl=660.00nm - setup: EE 173.4ms, inv.: 366.5ms, repropa.: 45.4ms (1 field configs), tot: 592.0ms
timing for wl=665.00nm - setup: EE 161.1ms, inv.: 375.5ms, repropa.: 47.1ms (1 field configs), tot: 590.7ms
timing for wl=670.00nm - setup: EE 174.6ms, inv.: 382.3ms, repropa.: 45.9ms (1 field configs), tot: 609.7ms
timing for wl=675.00nm - setup: EE 187.1ms, inv.: 361.9ms, repropa.: 45.2ms (1 field configs), tot: 600.7ms
timing for wl=680.00nm - setup: EE 158.3ms, inv.: 373.4ms, repropa.: 45.6ms (1 field configs), tot: 584.0ms
timing for wl=685.00nm - setup: EE 158.6ms, inv.: 374.5ms, repropa.: 45.0ms (1 field configs), tot: 584.8ms
timing for wl=690.00nm - setup: EE 155.3ms, inv.: 354.7ms, repropa.: 45.3ms (1 field configs), tot: 562.3ms
timing for wl=695.00nm - setup: EE 158.4ms, inv.: 357.3ms, repropa.: 45.8ms (1 field configs), tot: 568.4ms
timing for wl=400.00nm - setup: EE 137.0ms, inv.: 298.9ms, repropa.: 39.1ms (1 field configs), tot: 479.9ms
timing for wl=405.00nm - setup: EE 127.2ms, inv.: 238.4ms, repropa.: 39.1ms (1 field configs), tot: 409.5ms
timing for wl=410.00nm - setup: EE 127.8ms, inv.: 244.1ms, repropa.: 39.0ms (1 field configs), tot: 415.9ms
timing for wl=415.00nm - setup: EE 140.4ms, inv.: 248.4ms, repropa.: 39.7ms (1 field configs), tot: 433.4ms
timing for wl=420.00nm - setup: EE 124.2ms, inv.: 248.9ms, repropa.: 40.3ms (1 field configs), tot: 418.2ms
timing for wl=425.00nm - setup: EE 124.9ms, inv.: 239.8ms, repropa.: 41.3ms (1 field configs), tot: 410.8ms
timing for wl=430.00nm - setup: EE 133.7ms, inv.: 239.7ms, repropa.: 39.2ms (1 field configs), tot: 417.4ms
timing for wl=435.00nm - setup: EE 126.2ms, inv.: 247.9ms, repropa.: 39.6ms (1 field configs), tot: 418.7ms
timing for wl=440.00nm - setup: EE 124.9ms, inv.: 237.4ms, repropa.: 39.4ms (1 field configs), tot: 406.6ms
timing for wl=445.00nm - setup: EE 124.6ms, inv.: 259.7ms, repropa.: 39.6ms (1 field configs), tot: 428.8ms
timing for wl=450.00nm - setup: EE 127.2ms, inv.: 233.8ms, repropa.: 39.5ms (1 field configs), tot: 405.3ms
timing for wl=455.00nm - setup: EE 128.8ms, inv.: 242.3ms, repropa.: 39.8ms (1 field configs), tot: 415.8ms
timing for wl=460.00nm - setup: EE 124.8ms, inv.: 238.4ms, repropa.: 39.7ms (1 field configs), tot: 407.9ms
timing for wl=465.00nm - setup: EE 124.8ms, inv.: 239.7ms, repropa.: 39.5ms (1 field configs), tot: 409.0ms
timing for wl=470.00nm - setup: EE 126.9ms, inv.: 231.2ms, repropa.: 39.9ms (1 field configs), tot: 402.9ms
timing for wl=475.00nm - setup: EE 123.6ms, inv.: 251.0ms, repropa.: 39.8ms (1 field configs), tot: 419.4ms
timing for wl=480.00nm - setup: EE 125.3ms, inv.: 243.6ms, repropa.: 42.1ms (1 field configs), tot: 416.0ms
timing for wl=485.00nm - setup: EE 129.0ms, inv.: 245.5ms, repropa.: 41.5ms (1 field configs), tot: 420.9ms
timing for wl=490.00nm - setup: EE 126.6ms, inv.: 248.1ms, repropa.: 40.8ms (1 field configs), tot: 420.3ms
timing for wl=495.00nm - setup: EE 126.5ms, inv.: 241.2ms, repropa.: 41.8ms (1 field configs), tot: 414.3ms
timing for wl=500.00nm - setup: EE 129.7ms, inv.: 230.9ms, repropa.: 41.8ms (1 field configs), tot: 407.4ms
timing for wl=505.00nm - setup: EE 140.8ms, inv.: 240.3ms, repropa.: 39.8ms (1 field configs), tot: 425.8ms
timing for wl=510.00nm - setup: EE 135.3ms, inv.: 258.8ms, repropa.: 39.1ms (1 field configs), tot: 438.0ms
timing for wl=515.00nm - setup: EE 129.4ms, inv.: 259.6ms, repropa.: 40.0ms (1 field configs), tot: 434.0ms
timing for wl=520.00nm - setup: EE 125.3ms, inv.: 247.3ms, repropa.: 40.1ms (1 field configs), tot: 417.5ms
timing for wl=525.00nm - setup: EE 136.6ms, inv.: 259.0ms, repropa.: 40.2ms (1 field configs), tot: 440.8ms
timing for wl=530.00nm - setup: EE 132.9ms, inv.: 249.6ms, repropa.: 41.8ms (1 field configs), tot: 429.3ms
timing for wl=535.00nm - setup: EE 129.4ms, inv.: 257.4ms, repropa.: 39.9ms (1 field configs), tot: 432.3ms
timing for wl=540.00nm - setup: EE 134.6ms, inv.: 244.9ms, repropa.: 39.8ms (1 field configs), tot: 424.2ms
timing for wl=545.00nm - setup: EE 122.9ms, inv.: 249.0ms, repropa.: 40.2ms (1 field configs), tot: 416.9ms
timing for wl=550.00nm - setup: EE 124.8ms, inv.: 253.3ms, repropa.: 41.0ms (1 field configs), tot: 424.2ms
timing for wl=555.00nm - setup: EE 122.7ms, inv.: 237.1ms, repropa.: 40.0ms (1 field configs), tot: 405.6ms
timing for wl=560.00nm - setup: EE 123.9ms, inv.: 235.8ms, repropa.: 40.0ms (1 field configs), tot: 405.4ms
timing for wl=565.00nm - setup: EE 129.3ms, inv.: 242.8ms, repropa.: 40.3ms (1 field configs), tot: 417.9ms
timing for wl=570.00nm - setup: EE 129.0ms, inv.: 232.7ms, repropa.: 40.0ms (1 field configs), tot: 407.5ms
timing for wl=575.00nm - setup: EE 138.9ms, inv.: 266.2ms, repropa.: 40.4ms (1 field configs), tot: 452.1ms
timing for wl=580.00nm - setup: EE 129.4ms, inv.: 242.2ms, repropa.: 40.1ms (1 field configs), tot: 417.5ms
timing for wl=585.00nm - setup: EE 125.7ms, inv.: 244.3ms, repropa.: 40.9ms (1 field configs), tot: 416.8ms
timing for wl=590.00nm - setup: EE 156.4ms, inv.: 245.6ms, repropa.: 39.6ms (1 field configs), tot: 447.4ms
timing for wl=595.00nm - setup: EE 131.0ms, inv.: 247.6ms, repropa.: 39.9ms (1 field configs), tot: 424.0ms
timing for wl=600.00nm - setup: EE 125.7ms, inv.: 242.9ms, repropa.: 42.0ms (1 field configs), tot: 416.4ms
timing for wl=605.00nm - setup: EE 142.8ms, inv.: 236.9ms, repropa.: 44.8ms (1 field configs), tot: 430.2ms
timing for wl=610.00nm - setup: EE 125.2ms, inv.: 247.2ms, repropa.: 39.7ms (1 field configs), tot: 417.8ms
timing for wl=615.00nm - setup: EE 136.4ms, inv.: 242.9ms, repropa.: 40.7ms (1 field configs), tot: 425.8ms
timing for wl=620.00nm - setup: EE 138.3ms, inv.: 255.5ms, repropa.: 41.0ms (1 field configs), tot: 440.5ms
timing for wl=625.00nm - setup: EE 131.3ms, inv.: 233.2ms, repropa.: 39.5ms (1 field configs), tot: 409.2ms
timing for wl=630.00nm - setup: EE 126.1ms, inv.: 239.5ms, repropa.: 40.0ms (1 field configs), tot: 410.7ms
timing for wl=635.00nm - setup: EE 135.4ms, inv.: 231.3ms, repropa.: 40.3ms (1 field configs), tot: 412.1ms
timing for wl=640.00nm - setup: EE 140.7ms, inv.: 261.6ms, repropa.: 42.2ms (1 field configs), tot: 449.8ms
timing for wl=645.00nm - setup: EE 148.8ms, inv.: 246.6ms, repropa.: 45.8ms (1 field configs), tot: 451.2ms
timing for wl=650.00nm - setup: EE 147.0ms, inv.: 249.9ms, repropa.: 40.0ms (1 field configs), tot: 442.7ms
timing for wl=655.00nm - setup: EE 137.8ms, inv.: 236.6ms, repropa.: 40.3ms (1 field configs), tot: 419.7ms
timing for wl=660.00nm - setup: EE 123.2ms, inv.: 228.7ms, repropa.: 39.7ms (1 field configs), tot: 397.0ms
timing for wl=665.00nm - setup: EE 122.0ms, inv.: 232.5ms, repropa.: 40.6ms (1 field configs), tot: 400.4ms
timing for wl=670.00nm - setup: EE 124.2ms, inv.: 243.4ms, repropa.: 39.2ms (1 field configs), tot: 412.0ms
timing for wl=675.00nm - setup: EE 120.8ms, inv.: 233.7ms, repropa.: 48.1ms (1 field configs), tot: 407.7ms
timing for wl=680.00nm - setup: EE 123.6ms, inv.: 239.1ms, repropa.: 39.9ms (1 field configs), tot: 407.7ms
timing for wl=685.00nm - setup: EE 120.0ms, inv.: 233.5ms, repropa.: 39.5ms (1 field configs), tot: 397.9ms
timing for wl=690.00nm - setup: EE 137.1ms, inv.: 233.0ms, repropa.: 39.4ms (1 field configs), tot: 414.6ms
timing for wl=695.00nm - setup: EE 139.5ms, inv.: 244.1ms, repropa.: 39.9ms (1 field configs), tot: 428.8ms

[2]:

1


## Extinction spectra¶

[3]:

## -- spectra of extinction sections per multipole moment
wl, spec1 = tools.calculate_spectrum(sim_0, 0, linear.extinct)
ex_0, sc_0, ab_0 = spec1.T
wl, spec2 = tools.calculate_spectrum(sim_0, 0, linear.multipole_decomp_extinct, quadrupoles=False)
ex_p_0, ex_m_0 = spec2.T

plt.figure()
plt.title("full disc")
plt.plot(wl, ex_0, label='extinct')
plt.plot(wl, ex_p_0, label='p')
plt.plot(wl, ex_m_0, label='m')
plt.plot(wl, ex_p_0 + ex_m_0, label='multipole sum', dashes=[2,2])

plt.legend()
plt.xlabel("wavelength (nm)")
plt.ylabel("extinction cross section (nm^2)")
plt.show()

## -- spectra of extinction sections per multipole moment
wl, spec1 = tools.calculate_spectrum(sim_1, 0, linear.extinct)
ex_1, sc_1, ab_1 = spec1.T
wl, spec2 = tools.calculate_spectrum(sim_1, 0, linear.multipole_decomp_extinct, quadrupoles=False)
ex_p_1, ex_m_1 = spec2.T

plt.figure()
plt.title("disc with hole")
plt.plot(wl, ex_1, label='extinct')
plt.plot(wl, ex_p_1, label='p')
plt.plot(wl, ex_m_1, label='m')
plt.plot(wl, ex_p_1 + ex_m_1, label='multipole sum', dashes=[2,2])

plt.legend()
plt.xlabel("wavelength (nm)")
plt.ylabel("extinction cross section (nm^2)")
plt.show()

/home/hans/.local/lib/python3.8/site-packages/pyGDM2/linear.py:226: UserWarning: Multipole decomposition is a new functionality still under testing. Please use with caution.
warnings.warn("Multipole decomposition is a new functionality still under testing. " +

/home/hans/.local/lib/python3.8/site-packages/pyGDM2/linear.py:226: UserWarning: Multipole decomposition is a new functionality still under testing. Please use with caution.
warnings.warn("Multipole decomposition is a new functionality still under testing. " +


## nearfield intensity across discs¶

[7]:

## -- nearfield intensity map: full disc
wl_0 = 540  # MD resonance
delta_wl = np.abs(wl - wl_0)
i_0 = np.argmin(delta_wl)
plt.figure()
MAP = tools.generate_NF_map_XZ(-150,150,51, -100,200,51, Y0 = 0)
Etot_0 = linear.nearfield(sim_0, field_index=i_0, r_probe=MAP, which_fields=['Et'])[0]
visu.vectorfield_color(Etot_0, cmap='jet', projection="XZ",
fieldComp='I', clim=(0,30), tit='full disc',
interpolation='bicubic', show=True)

## -- nearfield intensity map: with hole
wl_1 = 476  # MD resonance
delta_wl = np.abs(wl - wl_1)
i_1 = np.argmin(delta_wl)
plt.figure()
MAP = tools.generate_NF_map_XZ(-150,150,51, -100,200,51, Y0 = 0)
Etot_1 = linear.nearfield(sim_1, field_index=i_1, r_probe=MAP, which_fields=['Et'])[0]
visu.vectorfield_color(Etot_1, cmap='jet', projection="XZ",
fieldComp='I', clim=(0,30), tit='with hole',
interpolation='bicubic', show=True)