edmundsj / rcwa

Rigorous Coupled Wave Analysis for the calculation of Photonic Crystal R/T spectra
MIT License
93 stars 29 forks source link

Failed to load TiO2 and PDMS material #65

Open 99rbbt opened 7 months ago

99rbbt commented 7 months ago

I tried testing my optical thin film structure and ran into errors when using TiO2 and PDMS. I'd like to simulate their emissivity, transmittance, and reflectivity in the 250-1800nm and 3μm-20μm regions. I believe the TiO2 error may be due to the data type. Formula 3 and 4 type data are contained in the TiO2 nk folder. I attempted to resolve this by editing the library.yml file, but I was unsuccessful...

My code:

from rcwa import Material, Layer, LayerStack, Source, Solver, Plotter
import numpy as np
from matplotlib import pyplot as plt

def solve_system():
    startWavelength = 0.3
    stopWavelength = 1.8
    stepWavelength = 0.001

    siO2 = Material(name = 'SiO2')
    tiO2 = Material(name = 'TiO2') #error
    PDMS = Material('polydimethylsiloxane') #error

    reflectionLayer = Layer(n=1)
    transmissionLayer = Layer(material= siO2)
    layer_E = Layer(thickness=25, material = PDMS)
    layer0 = Layer(thickness=0.05, material = tiO2)
    layer1 = Layer(thickness=0.05, material = siO2)
    layer2 = Layer(thickness=0.05, material = tiO2)
    layer3 = Layer(thickness=0.05, material = siO2)
    layer4 = Layer(thickness=0.05, material = tiO2)

    stack = LayerStack(layer_E, layer0, layer1, layer2, layer3, layer4, 
                       incident_layer=reflectionLayer, transmission_layer=transmissionLayer)
    source = Source(wavelength=startWavelength)

    print("Solving system...")
    TMMSolver = Solver(stack, source, 1)
    wavelengths = np.arange(startWavelength, stopWavelength + stepWavelength,
            stepWavelength)

    results = TMMSolver.solve(wavelength=wavelengths)
    return results

if __name__ == '__main__':
    results = solve_system()
    fig, ax = results.plot(x='wavelength', y=['RTot', 'TTot', 'conservation'])
    plt.show()

Error message:

for TiO2)

Traceback (most recent call last): File "c:\Users\jaehyeonshin\Desktop\EMCL\EMCL\PSC radiative cooler\radiative\RCWA\rcwa\rcwa\examples\5_layer.py", line 45, in results = solve_system() ^^^^^^^^^^^^^^ File "c:\Users\jaehyeonshin\Desktop\EMCL\EMCL\PSC radiative cooler\radiative\RCWA\rcwa\rcwa\examples\5_layer.py", line 19, in solve_system tiO2 = Material(name = 'TiO2') ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\material.py", line 41, in init self._load_from_database(name, filename=database_path) File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\material.py", line 100, in _load_from_database data_dict = self.database.load(file_to_load) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\utils\nk_loaders.py", line 83, in load data = self.load_nk_formula_data(material_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\utils\nk_loaders.py", line 93, in load_nk_formula_data raise ValueError(f'Formula type {data_dict["type"]} not supported. Please submit a bug report with this message and the specific material you are trying to use') ValueError: Formula type formula 4 not supported. Please submit a bug report with this message and the specific material you are trying to use

for PDMS)

Traceback (most recent call last): File "c:\Users\jaehyeonshin\Desktop\EMCL\EMCL\PSC radiative cooler\radiative\RCWA\rcwa\rcwa\examples\5_layer.py", line 45, in results = solve_system() ^^^^^^^^^^^^^^ File "c:\Users\jaehyeonshin\Desktop\EMCL\EMCL\PSC radiative cooler\radiative\RCWA\rcwa\rcwa\examples\5_layer.py", line 20, in solve_system PDMS = Material('polydimethylsiloxane') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\material.py", line 41, in init self._load_from_database(name, filename=database_path) File "C:\Users\jaehyeonshin\AppData\Local\Programs\Python\Python312\Lib\site-packages\rcwa\material.py", line 100, in _load_from_database data_dict = self.database.load(file_to_load) ^^^^^^^^^^^^ UnboundLocalError: cannot access local variable 'file_to_load' where it is not associated with a value