def correct_TR(struct, incidence="top"): if not struct._TR_calculated: struct.calculate_TR() # Commented out because right now wl_A and struct.wl # have the same range and step ## T0 = calc.interpolate(struct.wl, struct.T, wl_A) ## R0 = calc.interpolate(struct.wl, struct.R, wl_A) T0 = struct.T R0 = struct.R _layers_list = struct._layers_list[:] _layers_list.reverse() struct_rev = ML(_layers_list, unit=struct.unit, label=struct.label+"_rev", min_wl=struct._min_wl, max_wl = struct._max_wl, wl_step=struct._wl_step, n0=struct.ns, ns=struct.n0) struct_rev.calculate_TR() ## Tr0 = calc.interpolate(struct_rev.wl, struct_rev.T, wl_A) ## Rr0 = calc.interpolate(struct_rev.wl, struct_rev.R, wl_A) Tr0 = struct_rev.T Rr0 = struct_rev.R if incidence == "top": T = (1 - A) * Tg * T0 / (1 - (1 - A)**2 * Rg * Rr0) R = R0 + (1 - A)**2 * Rg * T0 * Tr0 / (1 - (1 - A)**2 * Rg * Rr0) elif incidence == "bot": T = (1 - A) * Tg * Tr0 / (1 - (1 - A)**2 * Rg * Rr0) R = Rg + (1 - A)**2 * Rr0 * Tg * Tg / (1 - (1 - A)**2 * Rg * Rr0) return T, R
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first = Ag(arg[1]) second = DLC80WA(arg[2]) third = Ag(arg[3]) fourth = DLC80WA(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) #### Uncomment for 6-layer structure ## fifth = Ag(arg[5]) ## sixth = DLC80WA(arg[6]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) ## ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance return (priority, arg[1], arg[2], arg[3], arg[4])
def correct_TR(struct, incidence="top"): if not struct._TR_calculated: struct.calculate_TR() # Commented out because right now wl_A and struct.wl # have the same range and step T0 = calc.interpolate(struct.wl, struct.T, wl_A) R0 = calc.interpolate(struct.wl, struct.R, wl_A) ## T0 = struct.T ## R0 = struct.R _layers_list = struct._layers_list[:] _layers_list.reverse() struct_rev = ML(_layers_list, unit=struct.unit, label=struct.label+"_rev", min_wl=struct._min_wl, max_wl = struct._max_wl, wl_step=struct._wl_step, n0=struct.ns, ns=struct.n0) struct_rev.calculate_TR() Tr0 = calc.interpolate(struct_rev.wl, struct_rev.T, wl_A) Rr0 = calc.interpolate(struct_rev.wl, struct_rev.R, wl_A) ## Tr0 = struct_rev.T ## Rr0 = struct_rev.R if incidence == "top": T = (1 - A) * Tg * T0 / (1 - (1 - A)**2 * Rg * Rr0) R = R0 + (1 - A)**2 * Rg * T0 * Tr0 / (1 - (1 - A)**2 * Rg * Rr0) elif incidence == "bot": T = (1 - A) * Tg * Tr0 / (1 - (1 - A)**2 * Rg * Rr0) R = Rg + (1 - A)**2 * Rr0 * Tg * Tg / (1 - (1 - A)**2 * Rg * Rr0) return T, R
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = DLC80WA(arg[0]) second = Ag(arg[1]) third = DLC80WA(arg[2]) fourth = Ag(arg[3]) fifth = DLC80WA(arg[4]) sixth = Ag(arg[5]) seventh = DLC80WA(arg[6]) mystruct = ML([first, second, third, fourth, fifth, sixth, seventh]) print mystruct mystruct.calculate_color() TR(mystruct) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority_value = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance)) print 'Transmittance =%s' % float("{0:.4f}".format(Transmittance)) print 'T color:', mystruct.T_color print 'R color:', mystruct.R_color show()
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Al(arg[1]) second =Al2O3(arg[2]) third=Ag(arg[3]) fourth=Al2O3(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) #### Uncomment for 6-layer structure ## fifth = Ag(arg[5]) ## sixth = DLC80WA(arg[6]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) ## ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR #mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index if index_lower_middle ==0 and i>=myConst.middle_limit: index_lower_middle = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==800: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, arg[1], arg[2], arg[3], arg[4])
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = DLC80WA(arg[0]) second = Ag(arg[1]) third = DLC80WA(arg[2]) fourth = Ag(arg[3]) fifth = DLC80WA(arg[4]) sixth=Ag(arg[5]) seventh=DLC80WA(arg[6]) eighth=Ag(arg[7]) nineth=DLC80WA(arg[8]) mystruct = ML([first, second, third, fourth, fifth, sixth, seventh, eighth, nineth]) print mystruct mystruct.calculate_color() TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) R_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) Reflectance = sum(mystruct.R[upper_middle:index_upper]*R_array)/(sum(R_array)) priority_value = myConst.R_factor*Reflectance + myConst.T_factor*Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance)) print 'Transmittance =%s' % float("{0:.4f}".format(Transmittance)) print 'T color:', mystruct.T_color print 'R color:', mystruct.R_color show()
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Ag(arg[0]) second = DLC80WA(arg[1]) mystruct = ML([first, second]) print mystruct mystruct.calculate_color() TR(mystruct, min_wl=200, max_wl=2500, legend=False, show_solar=True) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(440, 0.70, "visible", fontsize=16) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) R_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) Reflectance = sum(mystruct.R[upper_middle:index_upper]*R_array)/(sum(R_array)) priority_value = myConst.R_factor*Reflectance + myConst.T_factor*Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance)) print 'Transmittance =%s' % float("{0:.4f}".format(Transmittance)) print 'T color:', mystruct.T_color print 'R color:', mystruct.R_color show()
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Al(arg[1]) second = Ag(arg[2]) third = ITO(arg[3]) mystruct = ML([first, second, third]) print mystruct mystruct.calculate_color() TR(mystruct, show_solar=True, max_wl=2500, min_wl=250, legend=True) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance/2)) print 'Transmittance =%s' % float("{0:.4f}".format(Transmittance)) print 'T color:', mystruct.T_color print 'R color:', mystruct.R_color show()
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L1_thickness = float("{0:.1f}".format(L1_thickness)) layer_one = DLC80WA(L1_thickness) L2_thickness = random.uniform(3.0, 20.0) L2_thickness = float("{0:.1f}".format(L2_thickness)) layer_two = Ag(L2_thickness) L3_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L3_thickness = float("{0:.1f}".format(L3_thickness)) layer_three = DLC80WA(L3_thickness) mystruct = ML([layer_one, layer_two, layer_three]) ML.calculate_TR(mystruct) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance return (priority, L1_thickness, L2_thickness, L3_thickness)
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(5.0, 20.0) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Al(L1_thickness) L2_thickness=random.uniform(5.0, 20.0) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=Ag(L2_thickness) L3_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=ITO(L3_thickness) mystruct = ML([layer_one, layer_two, layer_three]) ML.calculate_TR(mystruct) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index if index_lower_middle ==0 and i>=myConst.middle_limit: index_lower_middle = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, L1_thickness, L2_thickness, L3_thickness)
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(3., 30.) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Ag(L1_thickness) L2_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=Al2O3(L2_thickness) mystruct = ML([layer_one, layer_two]) ML.calculate_TR(mystruct) mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, L1_thickness, L2_thickness, Tvis, TSER)
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Ag(arg[1]) second =Al2O3(arg[2]) third=Ag(arg[3]) fourth=DLC80WA(arg[4]) fifth=Al2O3(arg[5]) mystruct = ML([first, second, third, fourth, fifth], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, arg[1], arg[2], arg[3], arg[4], arg[5], Tvis, TSER)
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first = DLC80WA(arg[1]) second = Ag(arg[2]) third = DLC80WA(arg[3]) fourth = Ag(arg[4]) fifth = DLC80WA(arg[5]) sixth = Ag(arg[6]) seventh = DLC80WA(arg[7]) mystruct = ML([first, second, third, fourth, fifth, sixth, seventh]) ML.calculate_TR(mystruct) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance return (priority, arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7])
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Ag(arg[1]) second =DLC80WA (arg[2]) third=Ag(arg[3]) fourth=DLC80WA(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, arg[1], arg[2], arg[3], arg[4], Tvis, TSER)
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=DLC80WA(arg[1]) second = Ag(arg[2]) third=DLC80WA(arg[3]) fourth=Ag(arg[4]) fifth=DLC80WA(arg[5]) sixth=Ag(arg[6]) seventh=DLC80WA(arg[7]) eighth=Ag(arg[8]) nineth=DLC80WA(arg[9]) mystruct = ML([first, second, third, fourth, fifth, sixth, seventh, eighth, nineth]) ML.calculate_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) R_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) Reflectance = sum(mystruct.R[upper_middle:index_upper]*R_array)/(sum(R_array)) priority = myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9])
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Al(arg[1]) second = Ag(arg[2]) third=ITO(arg[3]) mystruct = ML([first, second, third]) ML.calculate_TR(mystruct) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index if index_lower_middle ==0 and i>=myConst.middle_limit: index_lower_middle = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, arg[1], arg[2], arg[3])
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Ag(arg[1]) second=Al2O3(arg[2]) mystruct = ML([first, second]) ML.calculate_TR(mystruct) mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, arg[1], arg[2], Tvis, TSER)
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(11.1+3.5, 11.1+3.5) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Ag(L1_thickness) L2_thickness=random.uniform (43,43) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=AlNH(L2_thickness) mystruct = ML([layer_one, layer_two], min_wl=MIN_WL, max_wl=MAX_WL) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct = correct_TR(mystruct) index_lowerUV=0 index_lowervis=0 index_uppervis=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lowervis ==0 and i>=myConst.lower_limit: index_lowervis = index elif index_uppervis==0 and i>=myConst.upper_limit: index_uppervis=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_uppervis photopic_array = np.interp(mystruct.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) V_normalized_data = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0], V_data[:, 3]) / max(V_data[:, 3]) T_ideal_array = photopic_array/V_normalized_data perfect_T_array = [1] * (len(photopic_array)) sol_array = np.interp(mystruct.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3]) sol_array_UV = np.interp(mystruct.wl[index_lowerUV:index_lowervis],U_data[:, 0] , U_data[:, 3]) sol_array_vis = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0] , V_data[:, 3]) sol_array_IR = np.interp(mystruct.wl[index_uppervis:index_upper],I_data[:, 0] , I_data[:, 3]) Tvis = sum(mystruct.T[index_lowervis:index_uppervis]*photopic_array)/(sum(photopic_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*T_ideal_array)/(sum(T_ideal_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis*photopic_array)/(sum(sol_array_vis*photopic_array)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]*sol_array_vis/max(sol_array_vis)-photopic_array)**2)) Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-sol_array_vis/max(sol_array_vis))**2)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-perfect_T_array)**2)) TSER_UV = 1 - sum(mystruct.T[index_lowerUV:index_lowervis]*sol_array_UV)/(sum(sol_array_UV)) TSER_vis = 1 - sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis)/(sum(sol_array_vis)) TSER_IR = 1 - sum(mystruct.T[index_uppervis:index_upper]*sol_array_IR)/(sum(sol_array_IR)) # 0.0342 = % of AM1.5 energy in UV # 0.426 = % of AM1.5 energy in visible # 0.54 = % of AM1.5 energy in IR (700-2500) check_TSER = TSER_UV * 0.0342 + TSER_vis * 0.426 + TSER_IR * 0.54 - .04 TSER = 1 - sum(mystruct.T[index_lowerUV:index_upper]*sol_array)/(sum(sol_array)) - 0.04 #TSER_priority = TSER_UV * 0.0342 / (0.0342 + 0.54) + TSER_IR * 0.54 / (0.0342 + 0.54) TSER_priority = TSER_IR #priority = myConst.p1 * Tpriority + myConst.p2 * (TSER_IR - myConst.wanted_TSER) priority = myConst.p1 * Tpriority + myConst.p2 * TSER_priority #priority = myConst.p1 * Tpriority * Tvis + myConst.p2 * TSER_priority #priority = -1 / (Tvis - myConst.p1) - \ # abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, L1_thickness, L2_thickness, Tvis, TSER)
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' ## first = DLC80WA(arg[0]) ## second = Ag(arg[1]) ## third = DLC80WA(arg[2]) ## fourth = Ag(arg[3]) ## fifth = DLC80WA(arg[4]) first = Ag(arg[0]) second = DLC80WA(arg[1]) third = Ag(arg[2]) fourth = DLC80WA(arg[3]) fifth = AlN(arg[4]) mystruct = ML([first, second, third, fourth, fifth], min_wl=230, max_wl=2476) print mystruct mystruct.calculate_color() # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) TR(mystruct, show_solar=True, max_wl=2500) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority_value = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance)) print 'Transmitance =%s' % float("{0:.4f}".format(Transmittance)) print 'T_color:', mystruct.T_color print 'R_color:', mystruct.R_color show()
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L1_thickness = float("{0:.1f}".format(L1_thickness)) ## layer_one=DLC80WA(L1_thickness) layer_one = Ag(L1_thickness) L2_thickness = random.uniform(3.0, 20.0) L2_thickness = float("{0:.1f}".format(L2_thickness)) ## layer_two=Ag(L2_thickness) layer_two = DLC80WA(L2_thickness) L3_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L3_thickness = float("{0:.1f}".format(L3_thickness)) ## layer_three=DLC80WA(L3_thickness) layer_three = Ag(L3_thickness) L4_thickness = random.uniform(3.0, 20.0) L4_thickness = float("{0:.1f}".format(L4_thickness)) ## layer_four=Ag(L4_thickness) layer_four = DLC80WA(L4_thickness) L5_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L5_thickness = float("{0:.1f}".format(L5_thickness)) ## layer_five=DLC80WA(L5_thickness) layer_five = AlN(L5_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four, layer_five], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower = 0 index_middle = 0 upper_middle = 0 index_upper = 0 if mystruct.wl[len(mystruct.wl) - 1] < 3000: index_upper = len(mystruct.wl) - 1 for index, i in enumerate(mystruct.wl): if index_lower == 0 and i >= myConst.lower_limit: index_lower = index elif index_middle == 0 and i >= myConst.upper_limit: index_middle = index elif myConst.upper_limit != 700 and upper_middle == 0: if i >= 700: upper_middle = index elif index_upper == 0 and i >= 3000: index_upper = index break if myConst.upper_limit == 700: upper_middle = index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle], P_data[:, 0], P_data[:, 1]) R_array = np.interp(mystruct.wl[upper_middle:index_upper], S_data[:, 0], S_data[:, 3]) Transmittance = sum( mystruct.T[index_lower:index_middle] * T_array) / (sum(T_array)) Reflectance = sum( mystruct.R[upper_middle:index_upper] * R_array) / (sum(R_array)) priority = myConst.R_factor * Reflectance + myConst.T_factor * Transmittance return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness, L5_thickness)
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Ag(arg[1]) second = AlN(arg[2]) third=Ag(arg[3]) fourth=AlN(arg[4]) fifth=Ag(arg[5]) sixth=AlN(arg[6]) mystruct = ML([first, second, third, fourth, fifth, sixth]) ML.calculate_TR(mystruct) mystruct.T, mystruct.R = correct_TR(mystruct) index_lowerUV=0 index_lowervis=0 index_uppervis=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lowervis ==0 and i>=myConst.lower_limit: index_lowervis = index elif index_uppervis==0 and i>=myConst.upper_limit: index_uppervis =index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_uppervis photopic_array = np.interp(mystruct.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) V_normalized_data = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0], V_data[:, 3]) / max(V_data[:, 3]) T_ideal_array = photopic_array/V_normalized_data sol_array = np.interp(mystruct.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3]) sol_array_UV = np.interp(mystruct.wl[index_lowerUV:index_lowervis],U_data[:, 0] , U_data[:, 3]) sol_array_vis = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0] , V_data[:, 3]) sol_array_IR = np.interp(mystruct.wl[index_uppervis:index_upper],I_data[:, 0] , I_data[:, 3]) Tvis = sum(mystruct.T[index_lowervis:index_uppervis]*photopic_array)/(sum(photopic_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*T_ideal_array)/(sum(T_ideal_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis*photopic_array)/(sum(sol_array_vis*photopic_array)) Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]*sol_array_vis/max(V_data[:, 3])-photopic_array)**2)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-sol_array_vis)**2)) TSER_UV = 1 - sum(mystruct.T[index_lowerUV:index_lowervis]*sol_array_UV)/(sum(sol_array_UV)) TSER_vis = 1 - sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis)/(sum(sol_array_vis)) TSER_IR = 1 - sum(mystruct.T[index_uppervis:index_upper]*sol_array_IR)/(sum(sol_array_IR)) # 0.0342 = % of AM1.5 energy in UV # 0.426 = % of AM1.5 energy in visible # 0.54 = % of AM1.5 energy in IR (700-2500) #TSER = TSER_UV * 0.0342 + TSER_vis * 0.426 + TSER_IR * 0.54 - .04 TSER = 1 - sum(mystruct.T[index_lowerUV:index_upper]*sol_array)/(sum(sol_array)) - 0.04 #TSER_priority = TSER_UV * 0.0342 / (0.0342 + 0.54) + TSER_IR * 0.54 / (0.0342 + 0.54) TSER_priority = TSER_IR #priority = myConst.p1 * Tpriority + myConst.p2 * (TSER_IR - myConst.wanted_TSER) priority = myConst.p1 * Tpriority + myConst.p2 * TSER_priority #priority = myConst.p1 * Tpriority * Tvis + myConst.p2 * TSER_priority #priority = -1 / (Tvis - myConst.p1) - \ # abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], Tvis, TSER)
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(3.0, 20.0) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Al(L1_thickness) L2_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=Al2O3(L2_thickness) L3_thickness=random.uniform(3.0, 15.0) L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=Ag(L3_thickness) L4_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L4_thickness=float("{0:.1f}".format(L4_thickness)) layer_four=Al2O3(L4_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) #### Uncomment for 6-layer structure ## L1_thickness=random.uniform(3.0, 20.0) ## L1_thickness=float("{0:.1f}".format(L1_thickness)) ## layer_one=Ag(L1_thickness) ## ## L2_thickness=random.uniform(20.0, myConst.max_DLC_thickness) ## L2_thickness=float("{0:.1f}".format(L2_thickness)) ## layer_two=DLC80WA(L2_thickness) ## ## L3_thickness=random.uniform(3.0, 20.0) ## L3_thickness=float("{0:.1f}".format(L3_thickness)) ## layer_three=Ag(L3_thickness) ## ## L4_thickness=random.uniform(20.0, myConst.max_DLC_thickness) ## L4_thickness=float("{0:.1f}".format(L4_thickness)) ## layer_four=DLC80WA(L4_thickness) ## ## L5_thickness=random.uniform(3.0, 20.0) ## L5_thickness=float("{0:.1f}".format(L5_thickness)) ## layer_5=Ag(L5_thickness) ## ## L6_thickness=random.uniform(20.0, myConst.max_DLC_thickness) ## L6_thickness=float("{0:.1f}".format(L6_thickness)) ## layer_6=DLC80WA(L6_thickness) ## ## mystruct = ML([layer_one, layer_two, layer_three, layer_four, ## layer_5, layer_6, AlN(20)], ## min_wl=230, max_wl=2476) ## ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR # mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index if index_lower_middle ==0 and i>=myConst.middle_limit: index_lower_middle = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==800: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness)
def plot_structure(arg, text_only=False): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Al(arg[1]) second = DLC80WA(arg[2]) third = Ag(arg[3]) fourth = DLC80WA(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) #### Uncomment for 6-layer structure ## fifth = Ag(arg[4]) ## sixth = DLC80WA(arg[5]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) print mystruct ## mystruct.calculate_color() # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) print 'TSER = %s' % float("{0:.4f}".format(TSER)) print 'Tvis = %s' % float("{0:.4f}".format(Tvis)) ## print 'T_color:', mystruct.T_color ## print 'R_color:', mystruct.R_color if not text_only: TR(mystruct, show_solar=True, max_wl=2500, min_wl=200, legend=True) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) show() return mystruct
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Ag(arg[1]) second = Al2O3(arg[2]) mystruct = ML([first, second]) TR(mystruct) show() print mystruct mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) print 'TSER = %s' % float("{0:.4f}".format(TSER)) print 'Tvis = %s' % float("{0:.4f}".format(Tvis)) ## print 'T_color:', mystruct.T_color ## print 'R_color:', mystruct.R_color if not text_only: TR(mystruct, show_solar=True, max_wl=2500) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) show() return mystruct
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(15., 30.) # 3 to 20 used to be L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Ag(L1_thickness) L2_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=DLC80WA(L2_thickness) L3_thickness=random.uniform(15., 30.) # 3 to 20 used to be L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=Ag(L3_thickness) L4_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L4_thickness=float("{0:.1f}".format(L4_thickness)) layer_four=DLC80WA(L4_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness, Tvis, TSER)
def plot_structure(arg, text_only=False): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Ag(arg[1]) second = DLC80WA(arg[2]) third = Ag(arg[3]) fourth = DLC80WA(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) #### Uncomment for 6-layer structure ## fifth = Ag(arg[4]) ## sixth = DLC80WA(arg[5]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) print mystruct ## mystruct.calculate_color() # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) print 'TSER = %s' % float("{0:.4f}".format(TSER)) print 'Tvis = %s' % float("{0:.4f}".format(Tvis)) ## print 'T_color:', mystruct.T_color ## print 'R_color:', mystruct.R_color if not text_only: TR(mystruct, show_solar=True, max_wl=2500, min_wl=200, legend=False) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) show() return mystruct
def plot_structure(arg, text_only=False): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Ag(arg[1]) second = AlN(arg[2]) mystruct = ML([first, second], min_wl=MIN_WL, max_wl=MAX_WL) TR(mystruct) show() #### Uncomment for 6-layer structure ## fifth = Ag(arg[4]) ## sixth = DLC80WA(arg[5]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) print mystruct mystruct.calculate_color() # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct = correct_TR(mystruct) index_lowerUV=0 index_lowervis=0 index_uppervis=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lowervis ==0 and i>=myConst.lower_limit: index_lowervis = index elif index_uppervis==0 and i>=myConst.upper_limit: index_uppervis=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_uppervis photopic_array = np.interp(mystruct.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) V_normalized_data = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0], V_data[:, 3]) / max(V_data[:, 3]) T_ideal_array = photopic_array/V_normalized_data perfect_T_array = [1] * (len(photopic_array)) sol_array = np.interp(mystruct.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3]) sol_array_UV = np.interp(mystruct.wl[index_lowerUV:index_lowervis],U_data[:, 0] , U_data[:, 3]) sol_array_vis = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0] , V_data[:, 3]) sol_array_IR = np.interp(mystruct.wl[index_uppervis:index_upper],I_data[:, 0] , I_data[:, 3]) Tvis = sum(mystruct.T[index_lowervis:index_uppervis]*photopic_array)/(sum(photopic_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*T_ideal_array)/(sum(T_ideal_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis*photopic_array)/(sum(sol_array_vis*photopic_array)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]*sol_array_vis/max(sol_array_vis)-photopic_array)**2)) Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-sol_array_vis/max(sol_array_vis))**2)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-perfect_T_array)**2)) TSER_UV = 1 - sum(mystruct.T[index_lowerUV:index_lowervis]*sol_array_UV)/(sum(sol_array_UV)) TSER_vis = 1 - sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis)/(sum(sol_array_vis)) TSER_IR = 1 - sum(mystruct.T[index_uppervis:index_upper]*sol_array_IR)/(sum(sol_array_IR)) # 0.0342 = % of AM1.5 energy in UV # 0.426 = % of AM1.5 energy in visible # 0.54 = % of AM1.5 energy in IR (700-2500) check_TSER = TSER_UV * 0.0342 + TSER_vis * 0.426 + TSER_IR * 0.54 - .04 TSER = 1 - sum(mystruct.T[index_lowerUV:index_upper]*sol_array)/(sum(sol_array)) - 0.04 #TSER_priority = TSER_UV * 0.0342 / (0.0342 + 0.54) + TSER_IR * 0.54 / (0.0342 + 0.54) TSER_priority = TSER_IR #priority = myConst.p1 * Tpriority + myConst.p2 * (TSER_IR - myConst.wanted_TSER) priority = myConst.p1 * Tpriority + myConst.p2 * TSER_priority #priority = myConst.p1 * Tpriority * Tvis + myConst.p2 * TSER_priority #priority = -1 / (Tvis - myConst.p1) - \ # abs(myConst.p2 * (TSER - myConst.wanted_TSER)) print 'TSER = %s' % float("{0:.4f}".format(TSER)) print 'check_TSER = %s' % float("{0:.4f}".format(check_TSER)) print 'TSER in UV = %s' % float("{0:.4f}".format(TSER_UV)) print 'TSER in visible = %s' % float("{0:.4f}".format(TSER_vis)) print 'TSER in IR = %s' % float("{0:.4f}".format(TSER_IR)) print 'Tpriority = %s' % float("{0:.4f}".format(Tpriority)) print 'Tvis = %s' % float("{0:.4f}".format(Tvis)) print 'T_color:', mystruct.T_color print 'R_color:', mystruct.R_color for i in range(len(mystruct.wl)): print mystruct.wl[i]," ", mystruct.T[i]," ", mystruct.R[i] #print 'UV lower bound:', index_lowerUV #print 'Visible lower bound:', index_lowervis #print 'Visible upper bound:', index_uppervis #print 'IR upper bound:', index_upper #print mystruct.wl[:] if not text_only: TR(mystruct, show_solar=True, min_wl=200, max_wl=2500) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) show() return mystruct
def recalculate_priority(arg): ''' This function returns a tuple containing a list of layers with calculated priority. The structure is given as an argument ''' first=Ag(arg[1]) second=AlN(arg[2]) mystruct = ML([first, second], min_wl=MIN_WL, max_wl=MAX_WL) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct = correct_TR(mystruct) index_lowerUV=0 index_lowervis=0 index_uppervis=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lowervis ==0 and i>=myConst.lower_limit: index_lowervis = index elif index_uppervis==0 and i>=myConst.upper_limit: index_uppervis=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_uppervis photopic_array = np.interp(mystruct.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) V_normalized_data = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0], V_data[:, 3]) / max(V_data[:, 3]) T_ideal_array = photopic_array/V_normalized_data perfect_T_array = [1] * (len(photopic_array)) sol_array = np.interp(mystruct.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3]) sol_array_UV = np.interp(mystruct.wl[index_lowerUV:index_lowervis],U_data[:, 0] , U_data[:, 3]) sol_array_vis = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0] , V_data[:, 3]) sol_array_IR = np.interp(mystruct.wl[index_uppervis:index_upper],I_data[:, 0] , I_data[:, 3]) Tvis = sum(mystruct.T[index_lowervis:index_uppervis]*photopic_array)/(sum(photopic_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*T_ideal_array)/(sum(T_ideal_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis*photopic_array)/(sum(sol_array_vis*photopic_array)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]*sol_array_vis/max(sol_array_vis)-photopic_array)**2)) Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-sol_array_vis/max(sol_array_vis))**2)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-perfect_T_array)**2)) TSER_UV = 1 - sum(mystruct.T[index_lowerUV:index_lowervis]*sol_array_UV)/(sum(sol_array_UV)) TSER_vis = 1 - sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis)/(sum(sol_array_vis)) TSER_IR = 1 - sum(mystruct.T[index_uppervis:index_upper]*sol_array_IR)/(sum(sol_array_IR)) # 0.0342 = % of AM1.5 energy in UV # 0.426 = % of AM1.5 energy in visible # 0.54 = % of AM1.5 energy in IR (700-2500) check_TSER = TSER_UV * 0.0342 + TSER_vis * 0.426 + TSER_IR * 0.54 - .04 TSER = 1 - sum(mystruct.T[index_lowerUV:index_upper]*sol_array)/(sum(sol_array)) - 0.04 #TSER_priority = TSER_UV * 0.0342 / (0.0342 + 0.54) + TSER_IR * 0.54 / (0.0342 + 0.54) TSER_priority = TSER_IR #priority = myConst.p1 * Tpriority + myConst.p2 * (TSER_IR - myConst.wanted_TSER) priority = myConst.p1 * Tpriority + myConst.p2 * TSER_priority #priority = myConst.p1 * Tpriority * Tvis + myConst.p2 * TSER_priority #priority = -1 / (Tvis - myConst.p1) - \ # abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, arg[1], arg[2], Tvis, TSER)
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(11., 50.) # 3 to 20 used to be L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Al(L1_thickness) L2_thickness=random.uniform(10.0, myConst.max_DLC_thickness) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=DLC80WA(L2_thickness) L3_thickness=random.uniform(11., 50.) # 3 to 20 used to be L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=Ag(L3_thickness) L4_thickness=random.uniform(10.0, myConst.max_DLC_thickness) L4_thickness=float("{0:.1f}".format(L4_thickness)) layer_four=DLC80WA(L4_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four], min_wl=230, max_wl=2476) ML.calculate_TR(mystruct) # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR mystruct.T, mystruct.R = correct_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) sol_array= np.interp(mystruct.wl[index_lower:index_upper],S_data[:, 0] , S_data[:, 3]) Tvis = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) TSER = 1 - sum(mystruct.T[index_lower:index_upper]*sol_array)/(sum(sol_array)) - 0.04 priority = -1 / (Tvis - myConst.p1) - \ abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness, Tvis, TSER)
def plot_structure(arg): ''' Basically, this function plots the graph of reflectance and transmittance of a given three layer structure versus wavelength. The argument is given as a tuple or a list of 3 elements. In addition, it provides the values of reflectance, transmittance, R_color and T_color. ''' first = Al(arg[1]) second = Al2O3(arg[2]) third = Ag(arg[3]) fourth = Al2O3(arg[4]) mystruct = ML([first, second, third, fourth], min_wl=230, max_wl=2476) #### Uncomment for 6-layer structure ## fifth = Ag(arg[4]) ## sixth = DLC80WA(arg[5]) ## ## mystruct = ML([first, second, third, fourth, ## fifth, sixth, AlN(20)], ## min_wl=230, max_wl=2476) print mystruct mystruct.calculate_color() # Doing unchecked attribute mutation here...future person beware. This # only applies because of comment above in correct_TR TR(mystruct, show_solar=True, max_wl=1500, min_wl=250, legend=True) plot.plt.grid("on") plot.plt.plot([400,400], [0,1], "k--") plot.plt.plot([700,700], [0,1], "k--") plot.plt.text(425, 0.70, "visible", fontsize=16) index_lower=0 index_middle=0 index_lower_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index if index_lower_middle ==0 and i>=myConst.middle_limit: index_lower_middle = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==800: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower_middle:index_middle],P_data[:, 0] , P_data[:, 1]) R1_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) R2_array= np.interp(mystruct.wl[index_lower:index_lower_middle],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower_middle:index_middle]*T_array)/(sum(T_array)) Reflectance2 = sum(mystruct.R[index_lower:index_lower_middle]*R2_array)/(sum(R2_array)) Reflectance1 = sum(mystruct.R[upper_middle:index_upper]*R1_array)/(sum(R1_array)) Reflectance = Reflectance1 + Reflectance2 priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance print 'Reflectance=%s' % float("{0:.4f}".format(Reflectance/2)) print 'Transmitance =%s' % float("{0:.4f}".format(Transmittance)) #print 'Absorptance =%s' % float("{0:.4f}".format(priority_value)) print 'T_color:', mystruct.T_color print 'R_color:', mystruct.R_color show()
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(11, 30.0) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=Ag(L1_thickness) L2_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=AlN(L2_thickness) L3_thickness=random.uniform(11, 30.0) L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=Ag(L3_thickness) L4_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L4_thickness=float("{0:.1f}".format(L4_thickness)) layer_four=AlN(L4_thickness) L5_thickness=random.uniform(11, 30.0) L5_thickness=float("{0:.1f}".format(L5_thickness)) layer_five=Ag(L5_thickness) L6_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L6_thickness=float("{0:.1f}".format(L6_thickness)) layer_six = AlN(L6_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four, layer_five, layer_six]) ML.calculate_TR(mystruct) mystruct.T, mystruct.R = correct_TR(mystruct) index_lowerUV=0 index_lowervis=0 index_uppervis=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: #index_upper=len(mystruct.wl)-1 index_upper = 459 for index, i in enumerate(mystruct.wl): if index_lowervis ==0 and i>=myConst.lower_limit: index_lowervis = index elif index_uppervis==0 and i>=myConst.upper_limit: index_uppervis =index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: #index_upper=index index_upper = 459 break if myConst.upper_limit==700: upper_middle=index_uppervis print index_lowerUV print index_lowervis print index_uppervis print index_upper photopic_array = np.interp(mystruct.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) V_normalized_data = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0], V_data[:, 3]) / max(V_data[:, 3]) T_ideal_array = photopic_array/V_normalized_data sol_array = np.interp(mystruct.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3]) sol_array_UV = np.interp(mystruct.wl[index_lowerUV:index_lowervis],U_data[:, 0] , U_data[:, 3]) sol_array_vis = np.interp(mystruct.wl[index_lowervis:index_uppervis],V_data[:, 0] , V_data[:, 3]) sol_array_IR = np.interp(mystruct.wl[index_uppervis:index_upper],I_data[:, 0] , I_data[:, 3]) print len(sol_array_IR) print len(mystruct.T[index_uppervis:index_upper]) Tvis = sum(mystruct.T[index_lowervis:index_uppervis]*photopic_array)/(sum(photopic_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*T_ideal_array)/(sum(T_ideal_array)) #Tpriority = sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis*photopic_array)/(sum(sol_array_vis*photopic_array)) Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]*sol_array_vis/max(V_data[:, 3])-photopic_array)**2)) #Tpriority = 1/np.sqrt(sum((mystruct.T[index_lowervis:index_uppervis]-sol_array_vis)**2)) TSER_UV = 1 - sum(mystruct.T[index_lowerUV:index_lowervis]*sol_array_UV)/(sum(sol_array_UV)) TSER_vis = 1 - sum(mystruct.T[index_lowervis:index_uppervis]*sol_array_vis)/(sum(sol_array_vis)) TSER_IR = 1 - sum(mystruct.T[index_uppervis:index_upper]*sol_array_IR)/(sum(sol_array_IR)) # 0.0342 = % of AM1.5 energy in UV # 0.426 = % of AM1.5 energy in visible # 0.54 = % of AM1.5 energy in IR (700-2500) #TSER = TSER_UV * 0.0342 + TSER_vis * 0.426 + TSER_IR * 0.54 - .04 TSER = 1 - sum(mystruct.T[index_lowerUV:index_upper]*sol_array)/(sum(sol_array)) - 0.04 #TSER_priority = TSER_UV * 0.0342 / (0.0342 + 0.54) + TSER_IR * 0.54 / (0.0342 + 0.54) TSER_priority = TSER_IR #priority = myConst.p1 * Tpriority + myConst.p2 * (TSER_IR - myConst.wanted_TSER) priority = myConst.p1 * Tpriority + myConst.p2 * TSER_priority #priority = myConst.p1 * Tpriority * Tvis + myConst.p2 * TSER_priority #priority = -1 / (Tvis - myConst.p1) - \ # abs(myConst.p2 * (TSER - myConst.wanted_TSER)) return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness, L5_thickness, L6_thickness, Tvis, TSER)
AlNH_seed_thickness += 0.2 while Ag_thickness < 14: Ag_thickness += 0.2 AlNH_thickness = 40 while AlNH_thickness < 55: #Ag_thickness=random.uniform(13, 16) #AlN_thickness=random.uniform(20,55) AlNH_thickness += 0.2 GivenAgBot = nklib.Ag(Ag_thickness) GivenAlNHBot = nklib.AlNH(AlNH_thickness) GivenAlNHSeed = nklib.AlNH(AlNH_seed_thickness) #GivenAgTop = nklib.Ag(18.9+3.5) #GivenAlNTop = nklib.AlN(60) MyStack = ML([GivenAlNHSeed, GivenAgBot, GivenAlNHBot]) #MyStack = ML([GivenAgBot, GivenAlNBot, GivenAgTop, GivenAlNTop]) MyStack.calculate_TR() MyStack = bright.correct_TR(MyStack) MyStack.A = [1] * len(MyStack.T) - MyStack.T - MyStack.R L,a,b = GenerateColor.color_calc(MyStack.wl, MyStack.T, MyStack.R) index_lowerUV = 0 index_lowervis = 32 index_uppervis = 94 index_upper = 454 photopic_array = np.interp(MyStack.wl[index_lowervis:index_uppervis],P_data[:, 0] , P_data[:, 1]) sol_array = np.interp(MyStack.wl[index_lowerUV:index_upper],S_data[:, 0] , S_data[:, 3])
def create_structure(): ''' This function creates a structure composed of randomly generated thicknesses. It returns a tuple with a list of layer thicknesses and priority value. ''' L1_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L1_thickness=float("{0:.1f}".format(L1_thickness)) layer_one=DLC80WA(L1_thickness) L2_thickness=random.uniform(3.0, 20.0) L2_thickness=float("{0:.1f}".format(L2_thickness)) layer_two=Ag(L2_thickness) L3_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L3_thickness=float("{0:.1f}".format(L3_thickness)) layer_three=DLC80WA(L3_thickness) L4_thickness=random.uniform(3.0, 20.0) L4_thickness=float("{0:.1f}".format(L4_thickness)) layer_four=Ag(L4_thickness) L5_thickness=random.uniform(20.0, myConst.max_DLC_thickness) L5_thickness=float("{0:.1f}".format(L5_thickness)) layer_five=DLC80WA(L5_thickness) L6_thickness = random.uniform(3.0, 20.0) L6_thickness=float("{0:.1f}".format(L6_thickness)) layer_six = Ag(L6_thickness) L7_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L7_thickness=float("{0:.1f}".format(L7_thickness)) layer_seven = DLC80WA(L7_thickness) L8_thickness = random.uniform(3.0, 20.0) L8_thickness=float("{0:.1f}".format(L8_thickness)) layer_eight = Ag(L8_thickness) L9_thickness = random.uniform(20.0, myConst.max_DLC_thickness) L9_thickness=float("{0:.1f}".format(L9_thickness)) layer_nine = DLC80WA(L9_thickness) mystruct = ML([layer_one, layer_two, layer_three, layer_four, layer_five, layer_six, layer_seven, layer_eight, layer_nine]) ML.calculate_TR(mystruct) index_lower=0 index_middle=0 upper_middle=0 index_upper=0 if mystruct.wl[len(mystruct.wl)-1]<3000: index_upper=len(mystruct.wl)-1 for index, i in enumerate(mystruct.wl): if index_lower ==0 and i>=myConst.lower_limit: index_lower = index elif index_middle==0 and i>=myConst.upper_limit: index_middle=index elif myConst.upper_limit!= 700 and upper_middle==0: if i>=700: upper_middle=index elif index_upper==0 and i>=3000: index_upper=index break if myConst.upper_limit==700: upper_middle=index_middle T_array = np.interp(mystruct.wl[index_lower:index_middle],P_data[:, 0] , P_data[:, 1]) R_array= np.interp(mystruct.wl[upper_middle:index_upper],S_data[:, 0] , S_data[:, 3]) Transmittance = sum(mystruct.T[index_lower:index_middle]*T_array)/(sum(T_array)) Reflectance = sum(mystruct.R[upper_middle:index_upper]*R_array)/(sum(R_array)) priority= myConst.R_factor*Reflectance + myConst.T_factor*Transmittance return (priority, L1_thickness, L2_thickness, L3_thickness, L4_thickness, L5_thickness, L6_thickness, L7_thickness, L8_thickness, L9_thickness)