Tutorial: Split Simulations

This tutorial demonstrates how to use the split_simulation tool to investigate near-field coupling effects.

Dimer nano-structure

[1]:
import numpy as np
import matplotlib.pyplot as plt

from pyGDM2 import core
from pyGDM2 import propagators
from pyGDM2 import fields
from pyGDM2 import materials
from pyGDM2 import linear

from pyGDM2 import structures
from pyGDM2 import tools
from pyGDM2 import visu



# =============================================================================
# some global parameters
# =============================================================================
solver_method = 'lu'


## simulation environment
n3 = 1.0   # cladding layer
n2 = 1.0   # environment
n1 = 1.0   # substrate

dyads = propagators.DyadsQuasistatic123(n1, n2, n3)


# =============================================================================
# set up dielectric dimer geometry
# =============================================================================
## size of blocks
mesh = 'cube'
step = 20     # in nm

## generate two different size cuboids
geo1 = structures.rect_wire(step, L=8, H=8, W=5, mesh=mesh)
geo2 = structures.rect_wire(step, L=6,  H=8, W=3, mesh=mesh)

## move relative to each other
delta_X = 60
delta_Y = 100
geo1 = structures.shift(geo1, [-delta_X/2, -delta_Y/2, 0])
geo2 = structures.shift(geo2, [delta_X/2, delta_Y/2, 0])

## combine also the two geometries
geo_combined = structures.combine_geometries([geo1, geo2], step=step)

## instantiate structure objects: isolated block and combined blocks
material = materials.silicon()
struct_single = structures.struct(step, geo1, material)
struct_combined = structures.struct(step, geo_combined, material)


print('N dipoles full geo = {}'.format(len(geo_combined)))


# =============================================================================
# illumination: spectrum
# =============================================================================
field_generator = fields.plane_wave
wavelengths = np.linspace(500,900,31)   # nm

## ---------- Generate positions for raster-scan, aligned with structure mesh
field_kwargs = dict(inc_angle=180, E_s=1)  # 180 (deg): incident angle along -z (0deg: +z)

efield = fields.efield(field_generator, wavelengths=wavelengths, kwargs=field_kwargs)


# =============================================================================
# simulation objects
# =============================================================================
## one block isolated
sim_single = core.simulation(struct=struct_single, efield=efield, dyads=dyads)

## both blocks
sim_combined = core.simulation(struct=struct_combined, efield=efield, dyads=dyads)

structure initialization - automatic mesh detection: cube
structure initialization - consistency check: 320/320 dipoles valid
structure initialization - automatic mesh detection: cube
structure initialization - consistency check: 464/464 dipoles valid
N dipoles full geo = 464

Run simulations and split combined sim

We now first run both simulations (isolated block and combined structure). Then we split the combined structure to extract the cuboid corresponding to the isolated simulation. The simulated fields are copied into the splitted simulation, so we can analyze the result further and compare to the actual isolated simulation.

[2]:
## run the single and combined simulations
sim_single.scatter(method=solver_method, calc_H=0)
sim_combined.scatter(method=solver_method, calc_H=0)

## remove part of geometry from combined simulation. This conserves the simulated fields
## --> the split simulation can be further evaluated to analyze the impact of near-field effects
sim_split, sim_remain = tools.split_simulation(sim_combined, geo1)


## plot the internal fields at a selected wavelength
fidx = tools.get_closest_field_index(sim_single, dict(wavelength=620))

plt.figure(figsize=(10,4))
plt.subplot(131)
plt.title(r"full simulation ($\lambda=620${}nm)")
visu.vectorfield_by_fieldindex(sim_combined, field_index=fidx, show=0, projection='XY')
visu.structure_contour(sim_combined, color='k', dashes=[2,2], show=0)

plt.subplot(132)
plt.title("splitted sub-geometry")
visu.vectorfield_by_fieldindex(sim_split, field_index=fidx, show=0, projection='XY')
visu.structure_contour(sim_combined, color='k', dashes=[2,2], show=0)

plt.subplot(133)
plt.title("sim block alone")
visu.vectorfield_by_fieldindex(sim_single, field_index=fidx, show=0, projection='XY')
visu.structure_contour(sim_combined, color='k', dashes=[2,2], show=0)

plt.tight_layout()
plt.show()
/home/hans/.local/lib/python3.8/site-packages/numba/core/dispatcher.py:237: UserWarning: Numba extension module 'numba_scipy' failed to load due to 'ValueError(No function '__pyx_fuse_0pdtr' found in __pyx_capi__ of 'scipy.special.cython_special')'.
  entrypoints.init_all()
timing for wl=500.00nm - setup: EE 2817.7ms, inv.: 126.0ms, repropa.: 780.7ms (1 field configs), tot: 3724.6ms
timing for wl=513.33nm - setup: EE 34.3ms, inv.: 107.8ms, repropa.: 17.7ms (1 field configs), tot: 160.6ms
timing for wl=526.67nm - setup: EE 37.2ms, inv.: 146.8ms, repropa.: 23.3ms (1 field configs), tot: 208.0ms
timing for wl=540.00nm - setup: EE 36.6ms, inv.: 112.9ms, repropa.: 17.7ms (1 field configs), tot: 167.8ms
timing for wl=553.33nm - setup: EE 37.9ms, inv.: 158.9ms, repropa.: 17.8ms (1 field configs), tot: 215.0ms
timing for wl=566.67nm - setup: EE 36.1ms, inv.: 155.5ms, repropa.: 18.3ms (1 field configs), tot: 210.3ms
timing for wl=580.00nm - setup: EE 36.1ms, inv.: 131.8ms, repropa.: 18.4ms (1 field configs), tot: 186.6ms
timing for wl=593.33nm - setup: EE 50.7ms, inv.: 145.8ms, repropa.: 18.1ms (1 field configs), tot: 215.0ms
timing for wl=606.67nm - setup: EE 35.3ms, inv.: 131.0ms, repropa.: 18.7ms (1 field configs), tot: 185.2ms
timing for wl=620.00nm - setup: EE 33.1ms, inv.: 104.9ms, repropa.: 18.3ms (1 field configs), tot: 156.5ms
timing for wl=633.33nm - setup: EE 42.1ms, inv.: 155.7ms, repropa.: 18.4ms (1 field configs), tot: 216.4ms
timing for wl=646.67nm - setup: EE 39.9ms, inv.: 190.7ms, repropa.: 19.2ms (1 field configs), tot: 250.0ms
timing for wl=660.00nm - setup: EE 48.7ms, inv.: 280.9ms, repropa.: 18.0ms (1 field configs), tot: 347.7ms
timing for wl=673.33nm - setup: EE 44.3ms, inv.: 223.8ms, repropa.: 17.9ms (1 field configs), tot: 286.5ms
timing for wl=686.67nm - setup: EE 33.2ms, inv.: 114.6ms, repropa.: 18.5ms (1 field configs), tot: 166.7ms
timing for wl=700.00nm - setup: EE 41.3ms, inv.: 138.0ms, repropa.: 19.0ms (1 field configs), tot: 198.5ms
timing for wl=713.33nm - setup: EE 34.3ms, inv.: 201.4ms, repropa.: 17.1ms (1 field configs), tot: 253.3ms
timing for wl=726.67nm - setup: EE 35.5ms, inv.: 120.3ms, repropa.: 17.0ms (1 field configs), tot: 173.2ms
timing for wl=740.00nm - setup: EE 38.9ms, inv.: 146.5ms, repropa.: 18.4ms (1 field configs), tot: 204.0ms
timing for wl=753.33nm - setup: EE 34.1ms, inv.: 145.9ms, repropa.: 18.2ms (1 field configs), tot: 198.4ms
timing for wl=766.67nm - setup: EE 32.5ms, inv.: 107.8ms, repropa.: 18.5ms (1 field configs), tot: 159.0ms
timing for wl=780.00nm - setup: EE 34.5ms, inv.: 127.9ms, repropa.: 18.3ms (1 field configs), tot: 181.0ms
timing for wl=793.33nm - setup: EE 45.0ms, inv.: 150.4ms, repropa.: 18.2ms (1 field configs), tot: 214.1ms
timing for wl=806.67nm - setup: EE 35.3ms, inv.: 102.0ms, repropa.: 18.4ms (1 field configs), tot: 155.9ms
timing for wl=820.00nm - setup: EE 34.6ms, inv.: 146.1ms, repropa.: 18.3ms (1 field configs), tot: 199.3ms
timing for wl=833.33nm - setup: EE 32.6ms, inv.: 142.5ms, repropa.: 18.4ms (1 field configs), tot: 193.7ms
timing for wl=846.67nm - setup: EE 35.8ms, inv.: 102.1ms, repropa.: 18.0ms (1 field configs), tot: 156.5ms
timing for wl=860.00nm - setup: EE 35.2ms, inv.: 130.5ms, repropa.: 18.5ms (1 field configs), tot: 184.6ms
timing for wl=873.33nm - setup: EE 33.1ms, inv.: 149.0ms, repropa.: 18.3ms (1 field configs), tot: 200.8ms
timing for wl=886.67nm - setup: EE 34.5ms, inv.: 107.8ms, repropa.: 18.2ms (1 field configs), tot: 160.7ms
timing for wl=900.00nm - setup: EE 34.7ms, inv.: 142.0ms, repropa.: 17.5ms (1 field configs), tot: 194.6ms
timing for wl=500.00nm - setup: EE 58.7ms, inv.: 192.5ms, repropa.: 27.7ms (1 field configs), tot: 279.4ms
timing for wl=513.33nm - setup: EE 56.6ms, inv.: 202.0ms, repropa.: 25.9ms (1 field configs), tot: 285.0ms
timing for wl=526.67nm - setup: EE 57.8ms, inv.: 154.7ms, repropa.: 26.4ms (1 field configs), tot: 239.3ms
timing for wl=540.00nm - setup: EE 49.7ms, inv.: 151.4ms, repropa.: 26.8ms (1 field configs), tot: 228.1ms
timing for wl=553.33nm - setup: EE 51.3ms, inv.: 166.8ms, repropa.: 26.2ms (1 field configs), tot: 244.9ms
timing for wl=566.67nm - setup: EE 52.5ms, inv.: 150.6ms, repropa.: 26.0ms (1 field configs), tot: 229.5ms
timing for wl=580.00nm - setup: EE 54.0ms, inv.: 146.5ms, repropa.: 26.1ms (1 field configs), tot: 227.0ms
timing for wl=593.33nm - setup: EE 55.8ms, inv.: 153.6ms, repropa.: 25.6ms (1 field configs), tot: 235.3ms
timing for wl=606.67nm - setup: EE 56.7ms, inv.: 162.3ms, repropa.: 28.7ms (1 field configs), tot: 248.1ms
timing for wl=620.00nm - setup: EE 67.3ms, inv.: 179.2ms, repropa.: 25.0ms (1 field configs), tot: 272.1ms
timing for wl=633.33nm - setup: EE 57.9ms, inv.: 238.5ms, repropa.: 25.4ms (1 field configs), tot: 322.3ms
timing for wl=646.67nm - setup: EE 52.5ms, inv.: 148.3ms, repropa.: 27.0ms (1 field configs), tot: 228.2ms
timing for wl=660.00nm - setup: EE 62.9ms, inv.: 148.4ms, repropa.: 27.9ms (1 field configs), tot: 239.5ms
timing for wl=673.33nm - setup: EE 59.6ms, inv.: 152.3ms, repropa.: 27.3ms (1 field configs), tot: 239.5ms
timing for wl=686.67nm - setup: EE 50.0ms, inv.: 177.9ms, repropa.: 26.9ms (1 field configs), tot: 255.1ms
timing for wl=700.00nm - setup: EE 51.2ms, inv.: 153.4ms, repropa.: 26.3ms (1 field configs), tot: 231.2ms
timing for wl=713.33nm - setup: EE 53.9ms, inv.: 149.0ms, repropa.: 27.4ms (1 field configs), tot: 230.6ms
timing for wl=726.67nm - setup: EE 52.1ms, inv.: 161.1ms, repropa.: 26.1ms (1 field configs), tot: 239.7ms
timing for wl=740.00nm - setup: EE 52.1ms, inv.: 151.7ms, repropa.: 25.9ms (1 field configs), tot: 230.2ms
timing for wl=753.33nm - setup: EE 56.0ms, inv.: 151.1ms, repropa.: 27.0ms (1 field configs), tot: 234.6ms
timing for wl=766.67nm - setup: EE 52.6ms, inv.: 150.5ms, repropa.: 26.7ms (1 field configs), tot: 230.1ms
timing for wl=780.00nm - setup: EE 62.1ms, inv.: 155.0ms, repropa.: 26.0ms (1 field configs), tot: 243.5ms
timing for wl=793.33nm - setup: EE 65.6ms, inv.: 150.4ms, repropa.: 26.9ms (1 field configs), tot: 243.3ms
timing for wl=806.67nm - setup: EE 51.5ms, inv.: 183.4ms, repropa.: 26.4ms (1 field configs), tot: 261.5ms
timing for wl=820.00nm - setup: EE 56.7ms, inv.: 155.9ms, repropa.: 27.1ms (1 field configs), tot: 240.1ms
timing for wl=833.33nm - setup: EE 51.7ms, inv.: 251.5ms, repropa.: 25.6ms (1 field configs), tot: 329.4ms
timing for wl=846.67nm - setup: EE 52.5ms, inv.: 150.6ms, repropa.: 26.6ms (1 field configs), tot: 230.0ms
timing for wl=860.00nm - setup: EE 56.1ms, inv.: 180.2ms, repropa.: 31.9ms (1 field configs), tot: 268.6ms
timing for wl=873.33nm - setup: EE 60.9ms, inv.: 150.6ms, repropa.: 29.0ms (1 field configs), tot: 240.8ms
timing for wl=886.67nm - setup: EE 55.1ms, inv.: 151.3ms, repropa.: 26.0ms (1 field configs), tot: 232.8ms
timing for wl=900.00nm - setup: EE 53.4ms, inv.: 150.9ms, repropa.: 26.5ms (1 field configs), tot: 231.2ms
/home/hans/.local/lib/python3.8/site-packages/pyGDM2/visu.py:49: UserWarning: 3D data. Falling back to XY projection...
  warnings.warn("3D data. Falling back to XY projection...")
../_images/tutorials_09_split_simulations_3_3.png

Plot the spectra

We now compare the spectra of the isolated simulation and the block split from the combined simulation

[3]:
wl, specext = tools.calculate_spectrum(sim_single, 0, linear.multipole_decomp)
p, m = specext[:,0,:], specext[:,1,:]
wl, specext = tools.calculate_spectrum(sim_combined, 0, linear.multipole_decomp)
p_c, m_c = specext[:,0,:], specext[:,1,:]


plt.title("electric (ED) and magnetic (MD) dipole moments")
plt.plot(wl, np.linalg.norm(p, axis=1), color='C0', label='ED, isolated Si-block')
plt.plot(wl, np.linalg.norm(m, axis=1), color='C1', label='MD, isolated Si-block')

plt.plot(wl, np.linalg.norm(p_c, axis=1), color='C0', dashes=[2,2], label='ED, perturbed Si-block')
plt.plot(wl, np.linalg.norm(m_c, axis=1), color='C1', dashes=[2,2], label='MD, perturbed Si-block')

plt.legend()
plt.xlabel('wavelength (nm)')
plt.ylabel('dipole moment amplitude (a.u.)')

plt.show()
/home/hans/.local/lib/python3.8/site-packages/pyGDM2/linear.py:216: 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. " +
../_images/tutorials_09_split_simulations_5_1.png

We find that the neighbor structure has mainly a qualitative impact on the magnetic dipole response of the silicon block, while the electric dipole response remais qualitatively similar. Yet, the indiced electric dipole moment is stronger if the near-field coupling is included.