In [5]:
import numpy as np
import matplotlib.pyplot as plt

from solcore import material, si
from solcore.structure import Layer, Structure
from solcore.absorption_calculator.rigorous_coupled_wave import calculate_rat_rcwa
In [8]:
T = 300
# define materials
Air = material("Air")(T=T)
TiO2 = material("TiO2", sopra=True)(T=T)  # for the nanoparticles
GaAs = material("GaAs")(T=T)

# define a flat layer and another with circular discs with the same thickness
Flat = Layer(si('50nm'), TiO2)
NP_layer = Layer(si('50nm'), Air, geometry=[{'type': 'circle', 'mat': TiO2, 'center': (200, 200), 'radius': 50}])

flat_struct = Structure([Flat])
np_struct = Structure([NP_layer])

# And the wavelength in which the solve the problem
wl = np.linspace(300, 1000, 150)
In [9]:
rat_flat = calculate_rat_rcwa(flat_struct, size=((400, 0), (0, 400)), orders=10, wavelength=wl,
                              substrate=GaAs, incidence=Air)
rat_np = calculate_rat_rcwa(np_struct, size=((400, 0), (0,  400)), orders=10, wavelength=wl,
                            substrate=GaAs, incidence=Air)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-a773b3b66008> in <module>
----> 1 rat_flat = calculate_rat_rcwa(flat_struct, size=((400, 0), (0, 400)), orders=10, wavelength=wl,
      2                               substrate=GaAs)
      3 rat_np = calculate_rat_rcwa(np_struct, size=((400, 0), (0,  400)), orders=10, wavelength=wl,
      4                             substrate=GaAs)

/usr/local/lib/python3.8/site-packages/solcore-5.6.0-py3.8-macosx-10.15-x86_64.egg/solcore/absorption_calculator/rigorous_coupled_wave.py in calculate_rat_rcwa(structure, size, orders, wavelength, theta, phi, pol, substrate)
     55         for i, wl in enumerate(wavelength):  # set the material values and indices in here
     56             S.SetFrequency(1 / wl)
---> 57             update_epsilon(S, stack_OS, shape_mats_OS, wl)
     58             S.SetExcitationPlanewave((theta, phi), 0, 1, 0)  # p-polarization
     59             out_p = rcwa_rat(S, len(stack_OS.get_widths()))

/usr/local/lib/python3.8/site-packages/solcore-5.6.0-py3.8-macosx-10.15-x86_64.egg/solcore/absorption_calculator/rigorous_coupled_wave.py in update_epsilon(S, stack_OS, shape_mats_OS, wl)
    144 def update_epsilon(S, stack_OS, shape_mats_OS, wl):
    145     for i1 in range(len(stack_OS.get_widths())):
--> 146         S.SetMaterial('layer_' + str(i1 + 1), stack_OS.get_indices(wl)[i1] ** 2)
    147     for i1 in range(len(shape_mats_OS.widths)):  # initialise the materials needed for all the shapes in S4
    148         S.SetMaterial('shape_mat_' + str(i1 + 1), shape_mats_OS.get_indices(wl)[i1 + 1] ** 2)

/usr/local/lib/python3.8/site-packages/solcore-5.6.0-py3.8-macosx-10.15-x86_64.egg/solcore/absorption_calculator/transfer_matrix.py in get_indices(self, wl)
    145 
    146         for i in range(self.num_layers):
--> 147             out.append(self.n_data[i](wl_m) + self.k_data[i](wl_m) * 1.0j)
    148 
    149         # substrate irrelevant if no_back_reflection = True

/usr/local/lib/python3.8/site-packages/solcore-5.6.0-py3.8-macosx-10.15-x86_64.egg/solcore/absorption_calculator/transfer_matrix.py in wrapper(array)
     32     @wraps(function)
     33     def wrapper(array):
---> 34         return cached_wrapper(tuple(array))
     35 
     36     # copy lru_cache attributes over too

TypeError: 'numpy.float64' object is not iterable
In [4]:
plt.plot(wl, rat_flat["R"], '-k', label="Flat (R)")
plt.plot(wl, rat_np["R"], '-b', label="Nanoparticles (R)")
plt.plot(wl, rat_flat["T"], '--k', label="Flat (T)")
plt.plot(wl, rat_np["T"], '--b', label="Nanoparticles (T)")
plt.legend()
plt.show()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-a460bacb78cc> in <module>
----> 1 plt.plot(wl, rat_flat["R"], '-k', label="Flat (R)")
      2 plt.plot(wl, rat_np["R"], '-b', label="Nanoparticles (R)")
      3 plt.plot(wl, rat_flat["T"], '--k', label="Flat (T)")
      4 plt.plot(wl, rat_np["T"], '--b', label="Nanoparticles (T)")
      5 plt.legend()

NameError: name 'rat_flat' is not defined
In [ ]: