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 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 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 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 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]) 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 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 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 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()