def create_model(self): self.tab.clear() self.tab.setColumnCount(6) if enable_betafeatures() == False: self.tab.setColumnHidden(5, True) self.tab.setColumnHidden(4, True) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([ _("Layer name"), _("Thicknes"), _("Optical material"), _("Layer type"), _("DoS Layer"), _("PL Layer") ]) self.tab.setColumnWidth(2, 250) self.tab.setRowCount(epitaxy_get_layers()) for i in range(0, epitaxy_get_layers()): thick = epitaxy_get_width(i) material = epitaxy_get_mat_file(i) dos_layer = epitaxy_get_electrical_layer(i) pl_file = epitaxy_get_pl_file(i) name = epitaxy_get_name(i) self.add_row(i, thick, material, dos_layer, pl_file, name) return
def recalculate(self): self.colors=[] lines=[] if dat_file_read(self.graph_data,self.graph_path)==True: #print(self.graph_path) self.graph_z_max,self.graph_z_min=dat_file_max_min(self.graph_data) #print(self.graph_z_max,self.graph_z_min) val=inp_get_token_value("light.inp", "#Psun") self.suns=float(val) l=epitaxy_get_layers()-1 for i in range(0,epitaxy_get_layers()): path=os.path.join(get_materials_path(),epitaxy_get_mat_file(l-i),"mat.inp") if inp_load_file(lines,path)==True: red=float(inp_search_token_value(lines, "#Red")) green=float(inp_search_token_value(lines, "#Green")) blue=float(inp_search_token_value(lines, "#Blue")) else: red=0.0 green=0.0 blue=0.0 self.colors.append(color(red,green,blue)) self.colors.reverse() self.update()
def draw(self): emission=False lines=[] for i in range(0,epitaxy_get_layers()): if epitaxy_get_pl_file(i)!="none": if inp_load_file(lines,epitaxy_get_pl_file(i)+".inp")==True: if str2bool(lines[1])==True: emission=True tot=0 for i in range(0,epitaxy_get_layers()): tot=tot+epitaxy_get_width(i) pos=0.0 l=epitaxy_get_layers()-1 lines=[] for i in range(0,epitaxy_get_layers()): thick=200.0*epitaxy_get_width(l-i)/tot pos=pos+thick path=os.path.join(get_materials_path(),epitaxy_get_mat_file(l-i),"mat.inp") if inp_load_file(lines,path)==True: red=float(inp_search_token_value(lines, "#Red")) green=float(inp_search_token_value(lines, "#Green")) blue=float(inp_search_token_value(lines, "#Blue")) else: print "Could not load",path red=0.0 green=0.0 blue=0.0 self.draw_box(200,450.0-pos,thick*0.9,red,green,blue,l-i) step=50.0 lines=[] if inp_load_file(lines,os.path.join(os.getcwd(),"light.inp"))==True: self.sun=float(inp_search_token_value(lines, "#Psun")) if self.sun<=0.01: step=200 elif self.sun<=0.1: step=100 elif self.sun<=1.0: step=50 elif self.sun<=10.0: step=10 else: step=5.0 if self.sun!=0: for x in range(0,200,step): self.draw_photon(270+x,50) if emission==True: for x in range(0,200,50): self.draw_photon_up(240+x,180) self.draw_mode(200,250,200)
def create_model(self): self.tab.blockSignals(True) self.tab.clear() self.tab.setColumnCount(11) #if enable_betafeatures()==False: # self.tab.setColumnHidden(4, True) # self.tab.setColumnHidden(5, True) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("Layer name"), _("Thicknes"), _("Optical material"), _("Layer type"), _("DoS\nfile"), _("PL\nfile"), _("LUMO\nfile"), _("H**O\nfile"), _("Solve optical\nproblem"), _("Solve thermal\nproblem"), _("ID")]) self.tab.setColumnWidth(2, 250) self.tab.setColumnWidth(4, 80) self.tab.setColumnWidth(5, 80) self.tab.setColumnWidth(6, 80) self.tab.setColumnWidth(7, 80) self.tab.setColumnWidth(10, 10) self.tab.horizontalHeader().setFixedHeight(40) self.tab.setRowCount(epitaxy_get_layers()) epi=get_epi() i=0 for l in epi.layers: self.add_row(i,l) i=i+1 self.tab.blockSignals(False)
def create_model(self): self.tab.blockSignals(True) self.tab.clear() self.tab.setColumnCount(2) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("Layer name"), _("Generation rate (m^{-3}s^{-1})")]) self.tab.setColumnWidth(1, 250) self.tab.setRowCount(epitaxy_get_layers()) data=inp() data.load(os.path.join(get_sim_path(),"light_gnp.inp")) data.to_sections(start="#layer_Gnp") epi=get_epi() i=0 for l in epi.layers: if i<len(data.sections): Gnp=float(data.sections[i].layer_Gnp) l.Gnp=data.sections[i].layer_Gnp else: Gnp=0 self.add_row(i,l.name,Gnp) i=i+1 self.tab.blockSignals(False)
def create_model(self): self.tab.clear() self.tab.setColumnCount(6) if enable_betafeatures()==False: self.tab.setColumnHidden(5, True) self.tab.setColumnHidden(4, True) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("Layer name"), _("Thicknes"), _("Optical material"), _("Layer type"), _("DoS Layer"),_("PL Layer")]) self.tab.setRowCount(epitaxy_get_layers()) for i in range(0,epitaxy_get_layers()): thick=epitaxy_get_width(i) material=epitaxy_get_mat_file(i) dos_layer=epitaxy_get_electrical_layer(i) pl_file=epitaxy_get_pl_file(i) name=epitaxy_get_name(i) self.add_row(i,thick,material,dos_layer,pl_file,name) return
def epitaxy_mesh_update(): mesh = get_mesh().y if len(mesh.layers) == 1: tot = 0.0 for i in range(0, epitaxy_get_layers()): width = float(epitaxy_get_dy(i)) dos_layer = epitaxy_get_dos_file(i) print(dos_layer, width) if dos_layer.startswith("dos") == True: tot = tot + width mesh.layers[0].thick = tot mesh.save()
def epitaxy_mesh_update(): if mesh_get_ylayers()==1: tot=0.0 for i in range(0,epitaxy_get_layers()): width=float(epitaxy_get_width(i)) dos_layer=epitaxy_get_electrical_layer(i) print(dos_layer,width) if dos_layer.startswith("dos")==True: tot=tot+width mesh_get_ymesh().layers[0].thick=tot mesh_save_y()
def update(self): self.notebook.clear() files = epitaxy_get_dos_files() for i in range(0, epitaxy_get_layers()): pl_file = epitaxy_get_pl_file(i) if pl_file.startswith("pl") == True: widget = QWidget() name = _("Luminescence of ") + epitaxy_get_name(i) widget = tab_class(pl_file + ".inp") self.notebook.addTab(widget, name)
def update(self): self.notebook.clear() files = epitaxy_get_dos_files() for i in range(0, epitaxy_get_layers()): dos_layer = epitaxy_get_electrical_layer(i) if dos_layer.startswith("dos") == True: #add_to_widget=True name = "DoS of " + epitaxy_get_name(i) widget = tab_class() widget.init(dos_layer + ".inp", name) self.notebook.addTab(widget, name)
def update(self): self.notebook.clear() files=epitaxy_get_dos_files() for i in range(0,epitaxy_get_layers()): pl_file=epitaxy_get_pl_file(i) if pl_file.startswith("pl")==True: widget = QWidget() name="Luminescence of "+epitaxy_get_name(i) print(pl_file,files) widget=tab_class() widget.init(pl_file+".inp",name) self.notebook.addTab(widget,name)
def random_device(self): self.view.render_grid=True self.view.render_photons=True self.view.render_text=False for i in range(0,100): r=random.randint(0,epitaxy_get_layers()-1) w=float(random.randint(20,100))*1e-9 e=epitaxy_get_epi() e[r].width=w levels = range(32,256,32) color=tuple(random.choice(levels) for _ in range(3)) if r!=2: e[r].r=color[0]/256.0 e[r].g=color[1]/256.0 e[r].b=color[2]/256.0 self.do_draw() self.grabFrameBuffer().save("./one/a"+str(i)+".png")
def update(self): self.tab.clear() self.tab.setColumnCount(5) self.tab.setRowCount(0) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("material"), _("Volume (m^-3)"), _("Mass (kg)"), _("Cost ($)"), _("Energy (J)")]) self.tab.setColumnWidth(1, 200) self.tab.setColumnWidth(2, 200) self.tab.setColumnWidth(3, 200) self.tab.setColumnWidth(4, 200) energy_tot=0.0 cost_tot=0.0 for i in range(0,epitaxy_get_layers()): volume=epitaxy_get_width(i)*1.0*1.0 name=epitaxy_get_mat_file(i) xls_file_name=os.path.join(get_materials_path(),epitaxy_get_mat_file(i),"cost.xlsx") wb = load_workbook(xls_file_name) ws= wb.get_sheet_by_name("results") density = float(ws['B2'].value) mass=density*volume cost_per_kg = float(ws['B3'].value) cost=mass*cost_per_kg energy_per_kg = float(ws['B4'].value) energy=energy_per_kg*mass tab_add(self.tab,[name,str(volume),str(mass),str(cost),str(energy)]) energy_tot=energy_tot+energy cost_tot=cost_tot+cost pce=inp_get_token_value("sim_info.dat", "#pce") payback_time=-1.0 if pce!=None: pce=float(pce) gen_energy=1366.0*pce/100.0 payback_time=energy_tot/gen_energy/60.0/60.0/24/365 tab_add(self.tab,["sum","","",str(cost_tot),str(energy_tot)]) tab_add(self.tab,["","","pay back time=",str(payback_time),"years"])
def load(self): self.tab.blockSignals(True) self.tab.clear() self.tab.setHorizontalHeaderLabels( [_("File Name"), _("Width"), _("Start"), _("Stop")]) layers = epitaxy_get_layers() for i in range(0, layers): dos_file = epitaxy_get_dos_file(i) width = epitaxy_get_width(i) if dos_file != "none": lines = [] print("loading", dos_file) file_name = os.path.join(get_sim_path(), dos_file + ".inp") lines = inp_load_file(file_name) if lines != False: doping_start = float( inp_search_token_value(lines, "#doping_start")) doping_stop = float( inp_search_token_value(lines, "#doping_stop")) print("add", dos_file) count = self.tab.rowCount() self.tab.insertRow(count) item1 = QTableWidgetItem(str(dos_file)) self.tab.setItem(count, 0, item1) item2 = QTableWidgetItem(str(width)) self.tab.setItem(count, 1, item2) item3 = QTableWidgetItem(str(doping_start)) self.tab.setItem(count, 2, item3) item3 = QTableWidgetItem(str(doping_stop)) self.tab.setItem(count, 3, item3) self.tab.blockSignals(False) return
def update(self): print "PL update" for child in self.notebook.get_children(): self.notebook.remove(child) files=epitaxy_get_dos_files() for i in range(0,epitaxy_get_layers()): pl_file=epitaxy_get_pl_file(i) if pl_file!="none": add_to_widget=True tab=tab_class() tab.show() tab.visible=True name="Luminescence of "+epitaxy_get_name(i) print pl_file,files tab.init(pl_file+".inp",name) tab.label_name=name self.notebook.append_page(tab, gtk.Label(name))
def update(self): print "DoS update" for child in self.notebook.get_children(): self.notebook.remove(child) files=epitaxy_get_dos_files() for i in range(0,epitaxy_get_layers()): dos_layer=epitaxy_get_electrical_layer(i) if dos_layer!="none": add_to_widget=True tab=tab_class() tab.show() tab.visible=True name="DoS of "+epitaxy_get_name(i) print dos_layer,files tab.init(dos_layer+".inp",name) tab.label_name=name self.notebook.append_page(tab, gtk.Label(name))
def __create_model(self): # create list store model = gtk.ListStore(str,str,str,str,str,str,str) # add items self.rebuild_mat_list() for i in range(0,epitaxy_get_layers()): thick=epitaxy_get_width(i) material=epitaxy_get_mat_file(i) dos_layer=epitaxy_get_electrical_layer(i) pl_file=epitaxy_get_pl_file(i) name=epitaxy_get_name(i) dos_file="" if dos_layer=="none": dos_file=_("no") else: dos_file=_("yes") scan_item_add("epitaxy.inp","#layer"+str(i),_("Material for ")+str(material),2) scan_item_add("epitaxy.inp","#layer"+str(i),_("Layer width ")+str(material),1) iter = model.append() model.set (iter, COLUMN_NAME, str(name), COLUMN_THICKNES, str(thick), COLUMN_MATERIAL, str(material), COLUMN_DEVICE, str(dos_file), COLUMN_DOS_LAYER, str(dos_layer), COLUMN_PL_FILE, str(pl_file) ) return model
def load(self): self.tab.blockSignals(True) self.tab.clear() self.tab.setHorizontalHeaderLabels([_("File Name"), _("Width"), _("Start"), _("Stop")]) layers=epitaxy_get_layers() for i in range(0,layers): dos_file=epitaxy_get_dos_file(i) width=epitaxy_get_width(i) if dos_file!="none": lines=[] print("loading",dos_file) if inp_load_file(lines,dos_file+".inp")==True: doping_start=float(inp_search_token_value(lines, "#doping_start")) doping_stop=float(inp_search_token_value(lines, "#doping_stop")) print("add",dos_file) count=self.tab.rowCount() self.tab.insertRow(count) item1 = QTableWidgetItem(str(dos_file)) self.tab.setItem(count,0,item1) item2 = QTableWidgetItem(str(width)) self.tab.setItem(count,1,item2) item3 = QTableWidgetItem(str(doping_start)) self.tab.setItem(count,2,item3) item3 = QTableWidgetItem(str(doping_stop)) self.tab.setItem(count,3,item3) self.tab.blockSignals(False) return
def drawWidget(self, qp): font = QFont("Sans", 11, QFont.Normal) qp.setFont(font) emission = False lines = [] for i in range(0, epitaxy_get_layers()): if epitaxy_get_pl_file(i) != "none": if inp_load_file(lines, epitaxy_get_pl_file(i) + ".inp") == True: if str2bool(lines[1]) == True: emission = True tot = 0 for i in range(0, epitaxy_get_layers()): tot = tot + epitaxy_get_width(i) pos = 0.0 l = epitaxy_get_layers() - 1 lines = [] for i in range(0, epitaxy_get_layers()): thick = 200.0 * epitaxy_get_width(l - i) / tot pos = pos + thick path = os.path.join(get_materials_path(), epitaxy_get_mat_file(l - i), "mat.inp") if inp_load_file(lines, path) == True: red = float(inp_search_token_value(lines, "#Red")) green = float(inp_search_token_value(lines, "#Green")) blue = float(inp_search_token_value(lines, "#Blue")) else: print("Could not load", path) red = 0.0 green = 0.0 blue = 0.0 self.draw_box(qp, 200, 450.0 - pos, thick * 0.9, red, green, blue, l - i) step = 50.0 lines = [] if inp_load_file(lines, os.path.join(os.getcwd(), "light.inp")) == True: self.sun = float(inp_search_token_value(lines, "#Psun")) if self.sun <= 0.01: step = 200 elif self.sun <= 0.1: step = 100 elif self.sun <= 1.0: step = 50 elif self.sun <= 10.0: step = 10 else: step = 5.0 if self.sun != 0: for x in range(0, 200, step): self.draw_photon(qp, 210 + x, 100, False) if emission == True: for x in range(0, 200, 50): self.draw_photon(qp, 240 + x, 140, True) self.draw_mode(qp, 200, 250) qp.drawText(40, 540 + 40, "No OpenGL support, using 2D fallback mode")
def draw_graph(self): self.layer_end=[] self.layer_name=[] n=0 self.my_figure.clf() ax1 = self.my_figure.add_subplot(111) ax2 = ax1.twinx() x_pos=0.0 layer=0 color =['r','g','b','y','o','r','g','b','y','o'] start=0.0 for i in range(0,epitaxy_get_layers()): if epitaxy_get_electrical_layer(i)=="none": start=start-epitaxy_get_width(i) else: break print "START=",start start=start*1e9 x_pos=start for i in range(0,epitaxy_get_layers()): label=epitaxy_get_mat_file(i) layer_ticknes=epitaxy_get_width(i) layer_material=epitaxy_get_mat_file(i) delta=float(layer_ticknes)*1e9 if epitaxy_get_electrical_layer(i)=="none": mat_file=os.path.join(os.getcwd(),'materials',layer_material,'mat.inp') myfile = open(mat_file) self.mat_file_lines = myfile.readlines() myfile.close() for ii in range(0, len(self.mat_file_lines)): self.mat_file_lines[ii]=self.mat_file_lines[ii].rstrip() lumo=-float(self.mat_file_lines[1]) Eg=float(self.mat_file_lines[3]) else: lines=[] if inp_load_file(lines,epitaxy_get_electrical_layer(i)+".inp")==True: lumo=-float(inp_search_token_value(lines, "#Xi")) Eg=float(inp_search_token_value(lines, "#Eg")) x = [x_pos,x_pos+delta,x_pos+delta,x_pos] lumo_delta=lumo-0.1 h**o=lumo-Eg homo_delta=h**o-0.1 if Eg==0.0: lumo_delta=-7.0 h**o=0.0 lumo_shape = [lumo,lumo,lumo_delta,lumo_delta] x_pos=x_pos+delta self.layer_end.append(x_pos) self.layer_name.append(layer_material) ax2.fill(x,lumo_shape, color[layer],alpha=0.4) ax2.text(x_pos-delta/1.5, lumo-0.4, epitaxy_get_name(i)) if h**o!=0.0: homo_shape = [h**o,h**o,homo_delta,homo_delta] ax2.fill(x,homo_shape, color[layer],alpha=0.4) layer=layer+1 n=n+1 state=plot_state() get_plot_file_info(state,self.optical_mode_file) #summary="<big><b>"+self.store[path[0]][0]+"</b></big>\n"+"\ntitle: "+state.title+"\nx axis: "+state.x_label+" ("+latex_to_pygtk_subscript(state.x_units)+")\ny axis: "++" ("+latex_to_pygtk_subscript(state.y_units)+")\n\n<big><b>Double click to open</b></big>" print "ROD!!!!",state.y_label,self.optical_mode_file ax1.set_ylabel(state.y_label) ax1.set_xlabel('Position (nm)') ax2.set_ylabel('Energy (eV)') ax2.set_xlim([start, x_pos]) #ax2.axis(max=)#autoscale(enable=True, axis='x', tight=None) loaded=False if os.path.isfile("light_dump.zip"): zf = zipfile.ZipFile("light_dump.zip", 'r') lines = zf.read(self.optical_mode_file).split("\n") zf.close() loaded=True elif os.path.isfile(self.optical_mode_file): print "I want to load",self.optical_mode_file f = open(self.optical_mode_file) lines = f.readlines() f.close() loaded=True if loaded==True: xx=[] yy=[] zz=[] lines_to_xyz(xx,yy,zz,lines) t = asarray(xx) s = asarray(yy) t=t*1e9 ax1.plot(t,s, 'black', linewidth=3 ,alpha=0.5) self.my_figure.tight_layout()
def render(self): #print("do draw") clear_color() glClearColor(self.view.bg_color[0], self.view.bg_color[1], self.view.bg_color[2], 0.5) gl_save_clear() dos_start=-1 dos_stop=-1 epi_y_len=epitaxy_get_y_len() if epi_y_len<=0: return self.x_mul=1e3 self.y_mul=self.gl_device_height/epi_y_len self.z_mul=1e3 x_len=mesh_get_xlen() max_gui_device_x=x_len*self.x_mul max_gui_device_y=1.0 max_gui_device_z=mesh_get_zlen()*self.z_mul l=epitaxy_get_layers()-1 xpoints=int(mesh_get_xpoints()) ypoints=int(mesh_get_ypoints()) zpoints=int(mesh_get_zpoints()) if ypoints>10: ypoints=10 if xpoints>10: xpoints=10 if ypoints>10: ypoints=10 self.emission=False self.ray_model=False lines=inp_load_file(os.path.join(get_sim_path(),"led.inp")) if lines!=False: self.ray_model=val=str2bool(inp_search_token_value(lines, "#led_on")) lines=[] for i in range(0,epitaxy_get_layers()): if epitaxy_get_pl_file(i)!="none": lines=inp_load_file(os.path.join(get_sim_path(),epitaxy_get_pl_file(i)+".inp")) if lines!=False: if str2bool(lines[1])==True: self.emission=True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(self.view.x_pos, self.view.y_pos, self.view.zoom) # Move Into The Screen glRotatef(self.view.xRot, 1.0, 0.0, 0.0) glRotatef(self.view.yRot, 0.0, 1.0, 0.0) glRotatef(self.view.zRot, 0.0, 0.0, 1.0) glColor3f( 1.0, 1.5, 0.0 ) glPolygonMode(GL_FRONT, GL_FILL); threed_files=glob.glob("*.3d") if len(threed_files)>0: gl_save_load() gl_save_draw() draw_grid() return #glClearColor(0.92, 0.92, 0.92, 0.5) # Clear to black. lines=[] pos=0.0 for i in range(0,epitaxy_get_layers()): thick=epitaxy_get_width(l-i)*self.y_mul obj=epitaxy_get_layer(l-i) red=obj.r green=obj.g blue=obj.b alpha=obj.alpha if i==l-self.selected_layer: box_lines(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z) if epitaxy_get_electrical_layer(l-i).startswith("dos")==True and ypoints!=0 and xpoints!=0 and zpoints!=0: dy=thick/float(ypoints) dx=max_gui_device_x/float(xpoints) dz=max_gui_device_z/float(zpoints) xshrink=0.8 zshrink=0.8 if dos_start==-1: dos_start=pos dos_stop=pos+thick if xpoints==1: xshrink=1.0 if zpoints==1: zshrink=1.0 if xpoints==1 and zpoints==1: box(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z,red,green,blue,alpha) else: for y in range(0,ypoints): for x in range(0,xpoints): for z in range(0,zpoints): box(dx*x,pos+y*(dy),z*dz,dx*xshrink,dy*0.8,dz*zshrink,red,green,blue,alpha) if self.tab_active_layers==True: tab(0.0,pos,max_gui_device_z,max_gui_device_x,thick,max_gui_device_z) elif epitaxy_get_electrical_layer(l-i).lower()=="contact" and (i==l or i==0): for c in contacts_get_array(): if (c.position=="top" and i==l) or (c.position=="bottom" and i==0): if xpoints==1 and zpoints==1: xstart=0.0 xwidth=max_gui_device_x else: xstart=max_gui_device_x*(c.start/x_len) xwidth=max_gui_device_x*(c.width/x_len) #print("contacts",xstart,xwidth,c.width,x_len) if (c.start+c.width)>x_len: xwidth=max_gui_device_x-xstart if c.depth>0.0: etch_depth=c.depth*self.y_mul if c.position=="top": box(xstart,pos-etch_depth-self.dy_layer_offset,0,xwidth,etch_depth,max_gui_device_z,0.0,0.0,1.0,1.0) else: box(xstart,pos+self.dy_layer_offset+thick,0,xwidth,etch_depth,max_gui_device_z,0.0,0.0,1.0,1.0) if c.active==True: box(xstart,pos,0,xwidth,thick,max_gui_device_z,0.0,1.0,0.0,alpha) else: box(xstart,pos,0,xwidth,thick,max_gui_device_z,red,green,blue,alpha) else: box(0.0,pos,0,max_gui_device_x,thick,max_gui_device_z,red,green,blue,alpha) if self.view.render_text==True: if epitaxy_get_electrical_layer(l-i).startswith("dos")==True: text=epitaxy_get_name(l-i)+" ("+_("active")+")" else: text=epitaxy_get_name(l-i) set_color(1.0,1.0,1.0,"text") font = QFont("Arial") font.setPointSize(18) if self.view.zoom>-20: self.renderText (max_gui_device_x+0.1,pos+thick/2,max_gui_device_z, text,font) pos=pos+thick+self.dy_layer_offset draw_mode(pos-self.dy_layer_offset,max_gui_device_z) draw_rays(self.ray_file,pos-self.dy_layer_offset,max_gui_device_x,self.y_mul,max_gui_device_z*1.05) #print(self.graph_path) if self.view.render_photons==True: #print(pos) self.draw_photons(max_gui_device_x,pos,max_gui_device_z) full_data_range=self.graph_z_max-self.graph_z_min graph(0.0,dos_start,max_gui_device_z+0.5,max_gui_device_x,dos_stop-dos_start,full_data_range,self.graph_data) if self.view.render_grid==True: draw_grid() if self.view.zoom<-60: draw_stars()
def gen_workbook(input_file_or_dir, output_file): if work_book_enabled == False: print("python3-openpyxl not found") return wb = Workbook() if os.path.isfile(input_file_or_dir): files = [input_file_or_dir] if os.path.isdir(input_file_or_dir): files = glob.glob(os.path.join(input_file_or_dir, "*.dat")) else: return ws = wb.active pos = 1 for i in range(0, epitaxy_get_layers()): dos_layer = epitaxy_get_dos_file(i) if dos_layer.startswith("dos") == True: pos = workbook_from_inp(ws, pos, dos_layer + ".inp", title=epitaxy_get_name(i)) for my_file in files: #print("about to save1",my_file) #print(my_file) data = dat_file() if data.load(my_file, guess=False) == True: x = [] y = [] z = [] if data.load(my_file) == True: #print("read",my_file) ws = wb.create_sheet( title=title_truncate(os.path.basename(my_file))) ws.cell(column=1, row=1, value=data.title) ws.cell(column=1, row=2, value=data.x_label + " (" + data.x_units + ") ") ws.cell(column=2, row=2, value=data.data_label + " (" + data.data_units + ") ") for i in range(0, data.y_len): ws.cell(column=1, row=i + 3, value=data.y_scale[i]) ws.cell(column=2, row=i + 3, value=data.data[0][0][i]) c1 = ScatterChart() c1.title = data.title c1.style = 13 c1.height = 20 c1.width = 20 c1.y_axis.title = data.data_label + " (" + data.data_units + ") " c1.x_axis.title = data.x_label + " (" + data.x_units + ") " xdata = Reference(ws, min_col=1, min_row=3, max_row=3 + data.y_len) ydata = Reference(ws, min_col=2, min_row=3, max_row=3 + data.y_len) series = Series(ydata, xdata, title_from_data=True) c1.series.append(series) ws.add_chart(c1, "G4") #print("about to save1") try: wb.save(filename=output_file) except: return False return True
def drawWidget(self, qp): font = QFont('Sans', 11, QFont.Normal) qp.setFont(font) emission = False lines = [] for i in range(0, epitaxy_get_layers()): if epitaxy_get_pl_file(i) != "none": lines = inp_load_file(epitaxy_get_pl_file(i) + ".inp") if lines != False: if str2bool(lines[1]) == True: emission = True tot = 0 for i in range(0, epitaxy_get_layers()): tot = tot + epitaxy_get_width(i) pos = 0.0 l = epitaxy_get_layers() - 1 lines = [] for i in range(0, epitaxy_get_layers()): red = 0.0 green = 0.0 blue = 0.0 thick = 200.0 * epitaxy_get_width(l - i) / tot pos = pos + thick path = os.path.join(get_materials_path(), epitaxy_get_mat_file(l - i), "mat.inp") lines = inp_load_file(path) if lines != False: ret = inp_search_token_array(lines, "#red_green_blue") if ret != False: red = float(ret[0]) green = float(ret[1]) blue = float(ret[2]) self.draw_box(qp, 200, 450.0 - pos, thick * 0.9, red, green, blue, l - i) step = 50.0 lines = inp_load_file(os.path.join(get_sim_path(), "light.inp")) if lines != False: self.sun = float(inp_search_token_value(lines, "#Psun")) if self.sun <= 0.01: step = 200 elif self.sun <= 0.1: step = 100 elif self.sun <= 1.0: step = 50 elif self.sun <= 10.0: step = 10 else: step = 5.0 if self.sun != 0: for x in range(0, 200, step): self.draw_photon(qp, 210 + x, 100, False) if emission == True: for x in range(0, 200, 50): self.draw_photon(qp, 240 + x, 140, True) self.draw_mode(qp, 200, 250) qp.drawText(40, 540 + 40, "No OpenGL support, using 2D fallback mode")
def update(self): self.tab.clear() self.tab.setColumnCount(5) self.tab.setRowCount(0) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([ _("material"), _("Volume") + " (m^-3)", _("Mass") + " (kg)", _("Cost") + " ($)", _("Energy") + " (J)" ]) self.tab.setColumnWidth(1, 200) self.tab.setColumnWidth(2, 200) self.tab.setColumnWidth(3, 200) self.tab.setColumnWidth(4, 200) if work_book_enabled == False: print(_("python3-openpyxl not found")) return energy_tot = 0.0 cost_tot = 0.0 for i in range(0, epitaxy_get_layers()): volume = epitaxy_get_width(i) * 1.0 * 1.0 name = epitaxy_get_mat_file(i) xls_file_name = os.path.join(get_materials_path(), epitaxy_get_mat_file(i), "cost.xlsx") if os.path.isfile(xls_file_name): wb = load_workbook(xls_file_name) ws = wb.get_sheet_by_name("results") density = float(ws['B2'].value) mass = density * volume cost_per_kg = float(ws['B3'].value) cost = mass * cost_per_kg energy_per_kg = float(ws['B4'].value) energy = energy_per_kg * mass tab_add(self.tab, [name, str(volume), str(mass), str(cost), str(energy)]) energy_tot = energy_tot + energy cost_tot = cost_tot + cost pce = inp_get_token_value("sim_info.dat", "#pce") payback_time = -1.0 if pce != None: pce = float(pce) gen_energy = 1366.0 * pce / 100.0 payback_time = energy_tot / gen_energy / 60.0 / 60.0 / 24 / 365 tab_add(self.tab, ["sum", "", "", str(cost_tot), str(energy_tot)]) tab_add(self.tab, ["", "", "pay back time=", str(payback_time), "years"])
def load(self): self.tab.blockSignals(True) self.tab.clear() self.tab.setHorizontalHeaderLabels([ _("Layer"), _("Width"), _("Doping Start (m-3)"), _("Doping Stop (m-3)"), _("Mobile ion density (m-3)"), _("Mobile ion mobility (m-3)") ]) layers = epitaxy_get_layers() row = 0 for i in range(0, layers): dos_file = epitaxy_get_dos_file(i) if dos_file.startswith("dos") == True: row = row + 1 self.tab.setRowCount(row) row = 0 for i in range(0, layers): dos_file = epitaxy_get_dos_file(i) e = epitaxy_get_layer(i) dy = e.dy if dos_file.startswith("dos") == True: lines = [] print("loading", dos_file) file_name = os.path.join(get_sim_path(), dos_file + ".inp") lines = inp_load_file(file_name) if lines != False: doping_start = float( inp_search_token_value(lines, "#doping_start")) doping_stop = float( inp_search_token_value(lines, "#doping_stop")) ion_density = float( inp_search_token_value(lines, "#ion_density")) ion_mobility = float( inp_search_token_value(lines, "#ion_mobility")) item = QTableWidgetItem(e.name) item.setFlags(item.flags() ^ Qt.ItemIsEnabled) self.tab.setItem(row, 0, item) item = QTableWidgetItem(str(dy)) item.setFlags(item.flags() ^ Qt.ItemIsEnabled) self.tab.setItem(row, 1, item) item = QTableWidgetItem(str(doping_start)) self.tab.setItem(row, 2, item) item = QTableWidgetItem(str(doping_stop)) self.tab.setItem(row, 3, item) item = QTableWidgetItem(str(ion_density)) self.tab.setItem(row, 4, item) item = QTableWidgetItem(str(ion_mobility)) self.tab.setItem(row, 5, item) row = row + 1 self.tab.blockSignals(False) return
def __init__(self): QWidgetSavePos.__init__(self, "doping") self.setMinimumSize(900, 600) self.setWindowIcon(icon_get("doping")) self.setWindowTitle( _("Doping/Mobilie ion profile editor") + " (https://www.gpvdm.com)") self.epi = get_epi() self.main_vbox = QVBoxLayout() toolbar = QToolBar() toolbar.setIconSize(QSize(48, 48)) self.save = QAction(icon_get("document-save-as"), _("Save"), self) self.save.triggered.connect(self.callback_save) toolbar.addAction(self.save) spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) toolbar.addWidget(spacer) self.help = QAction(icon_get("help"), _("Help"), self) self.help.triggered.connect(self.callback_help) toolbar.addAction(self.help) self.main_vbox.addWidget(toolbar) self.fig = Figure(figsize=(5, 4), dpi=100) self.ax1 = None self.show_key = True canvas = FigureCanvas(self.fig) #canvas.set_background('white') #canvas.set_facecolor('white') canvas.figure.patch.set_facecolor('white') canvas.show() self.main_vbox.addWidget(canvas) self.tab = gpvdm_tab() self.tab.resizeColumnsToContents() self.tab.verticalHeader().setVisible(False) self.tab.clear() self.tab.setColumnCount(6) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.load() self.build_mesh() self.tab.cellChanged.connect(self.tab_changed) self.tab.setColumnWidth(2, 150) self.tab.setColumnWidth(3, 150) self.tab.setColumnWidth(4, 180) self.tab.setColumnWidth(5, 180) self.main_vbox.addWidget(self.tab) self.draw_graph() self.setLayout(self.main_vbox) layers = epitaxy_get_layers() for i in range(0, layers): dos_file = epitaxy_get_dos_file(i) + ".inp" if dos_file.startswith("dos") == True: get_watch().add_call_back(dos_file, self.load) return
def draw_graph(self): self.layer_end=[] self.layer_name=[] self.optical_mode_file=os.path.join(get_sim_path(),"light_dump",self.data_file) self.my_figure.clf() ax1 = self.my_figure.add_subplot(111) ax2 = ax1.twinx() x_pos=0.0 layer=0 color =['r','g','b','y','o','r','g','b','y','o'] start=0.0 for i in range(0,epitaxy_get_layers()): if epitaxy_get_electrical_layer(i).startswith("dos")==False: start=start-epitaxy_get_width(i) else: break start=start*1e9 x_pos=start for i in range(0,epitaxy_get_layers()): # label=epitaxy_get_mat_file(i) layer_ticknes=epitaxy_get_width(i) layer_material=epitaxy_get_mat_file(i) lumo=0.0 h**o=0.0 delta=float(layer_ticknes)*1e9 #print(epitaxy_get_electrical_layer(i)) lines=[] material_type=inp_get_token_value(os.path.join(get_materials_path(),layer_material,'mat.inp'), "#material_type") if epitaxy_get_electrical_layer(i).startswith("dos")==False: dos_file=os.path.join(get_materials_path(),layer_material,'dos.inp') if os.path.isfile(dos_file)==False: dos_file=os.path.join(get_default_material_path(),"dos.inp") lines=inp_load_file(dos_file) if lines!=False: lumo=-float(inp_search_token_value(lines, "#Xi")) Eg=float(inp_search_token_value(lines, "#Eg")) else: lines=inp_load_file(os.path.join(get_sim_path(),epitaxy_get_electrical_layer(i)+".inp")) if lines!=False: lumo=-float(inp_search_token_value(lines, "#Xi")) Eg=float(inp_search_token_value(lines, "#Eg")) #print("b") x = [x_pos,x_pos+delta,x_pos+delta,x_pos] #print("lumo=",lumo) lumo_delta=lumo-0.1 h**o=lumo-Eg homo_delta=h**o-0.1 draw_homo=True y_name_pos=lumo-Eg/2 if Eg==0.0 or material_type=="metal": lumo_delta=-7.0 draw_homo=False y_name_pos=lumo-1.0 x_pos=x_pos+delta self.layer_end.append(x_pos) self.layer_name.append(layer_material) item=ax2.text(x_pos-delta/1.5, y_name_pos, epitaxy_get_name(i)) item.set_fontsize(15) lumo_shape = [lumo,lumo,lumo_delta,lumo_delta] ax2.fill(x,lumo_shape, color[layer],alpha=0.4) item=ax2.text(x_pos-delta/1.5, lumo+0.1, "%.2f eV" % lumo) item.set_fontsize(15) if draw_homo==True: homo_shape = [h**o,h**o,homo_delta,homo_delta] ax2.fill(x,homo_shape, color[layer],alpha=0.4) item=ax2.text(x_pos-delta/1.5, lumo-Eg-0.4, "%.2f eV" % h**o) item.set_fontsize(15) layer=layer+1 state=dat_file() if dat_file_read(state,self.optical_mode_file)==True: ax1.set_ylabel(state.data_label+" ("+state.data_units+")") ax1.set_xlabel(_("Position")+" (nm)") ax2.set_ylabel(_("Energy")+" (eV)") ax2.set_xlim([start, x_pos]) #ax2.axis(max=)#autoscale(enable=True, axis='x', tight=None) for i in range(0,len(state.y_scale)): state.y_scale[i]=state.y_scale[i]*1e9 ax1.plot(state.y_scale,state.data[0][0], 'black', linewidth=3 ,alpha=0.5) self.my_figure.tight_layout()
def paintGL(self): if self.failed==False: dos_start=-1 dos_stop=-1 self.x_mul=1e3 self.z_mul=1e3 width=mesh_get_xlen()*self.x_mul depth=mesh_get_zlen()*self.z_mul l=epitaxy_get_layers()-1 xpoints=int(mesh_get_xpoints()) ypoints=int(mesh_get_ypoints()) zpoints=int(mesh_get_zpoints()) x_len=mesh_get_xlen() self.emission=False self.ray_model=False lines=[] if inp_load_file(lines,"led.inp")==True: self.ray_model=val=str2bool(inp_search_token_value(lines, "#led_on")) lines=[] for i in range(0,epitaxy_get_layers()): if epitaxy_get_pl_file(i)!="none": if inp_load_file(lines,epitaxy_get_pl_file(i)+".inp")==True: if str2bool(lines[1])==True: self.emission=True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(self.x_pos, self.y_pos, self.zoom) # Move Into The Screen glRotatef(self.xRot, 1.0, 0.0, 0.0) glRotatef(self.yRot, 0.0, 1.0, 0.0) glRotatef(self.zRot, 0.0, 0.0, 1.0) glColor3f( 1.0, 1.5, 0.0 ) glPolygonMode(GL_FRONT, GL_FILL); #glClearColor(0.92, 0.92, 0.92, 0.5) # Clear to black. glClearColor(0.0, 0.0, 0.0, 0.5) lines=[] if self.suns!=0: if self.suns<=0.01: den=1.4 elif self.suns<=0.1: den=0.8 elif self.suns<=1.0: den=0.6 elif self.suns<=10.0: den=0.3 else: den=0.2 x=np.arange(0, width , den) z=np.arange(0, depth , den) for i in range(0,len(x)): for ii in range(0,len(z)): draw_photon(x[i],z[ii],False) if self.emission==True and self.ray_model==False: den=0.6 x=np.arange(0, width , den) y=np.arange(0, depth , den) for i in range(0,len(x)): for ii in range(0,len(y)): draw_photon(x[i]+0.1,y[ii]+0.1,True) tot=0 for i in range(0,epitaxy_get_layers()): tot=tot+epitaxy_get_width(i) pos=0.0 self.y_mul=0 if tot>0: self.y_mul=1.5/tot for i in range(0,epitaxy_get_layers()): thick=epitaxy_get_width(l-i)*self.y_mul red=self.colors[l-i].r green=self.colors[l-i].g blue=self.colors[l-i].b if i==l-self.selected_layer: box_lines(0.0,pos,0,width,thick,depth) if epitaxy_get_electrical_layer(l-i).startswith("dos")==True: dy=thick/float(ypoints) dx=width/float(xpoints) dz=depth/float(zpoints) xshrink=0.8 zshrink=0.8 if dos_start==-1: dos_start=pos dos_stop=pos+thick if xpoints==1: xshrink=1.0 if zpoints==1: zshrink=1.0 if xpoints==1 and zpoints==1: box(0.0,pos,0,width,thick,depth,red,green,blue) else: for y in range(0,ypoints): for x in range(0,xpoints): for z in range(0,zpoints): box(dx*x,pos+y*(dy),z*dz,dx*xshrink,dy*0.8,dz*zshrink,red,green,blue) tab(0.0,pos,depth,width,thick,depth) elif epitaxy_get_electrical_layer(l-i).lower()=="contact" and i==l: if xpoints==1 and zpoints==1: box(0.0,pos,0,width,thick,depth,red,green,blue) else: for c in contacts_get_array(): xstart=width*(c.start/x_len) xwidth=width*(c.width/x_len) #print("contacts",xstart,xwidth,c.width,x_len) if (c.start+c.width)>x_len: xwidth=width-xstart if c.active==True: box(xstart,pos,0,xwidth,thick,depth,0.0,1.0,0.0) else: box(xstart,pos,0,xwidth,thick,depth,red,green,blue) else: box(0.0,pos,0,width,thick,depth,red,green,blue) if epitaxy_get_electrical_layer(l-i).startswith("dos")==True: text=epitaxy_get_name(l-i)+" (active)" else: text=epitaxy_get_name(l-i) glColor3f(1.0,1.0,1.0) font = QFont("Arial") font.setPointSize(18) if self.zoom>-20: self.renderText (width+0.1,pos+thick/2,depth, text,font) pos=pos+thick+0.05 glRotatef(self.tet_rotate, tet_x_rate, tet_y_rate, tet_z_rate) draw_mode(pos-0.05,depth) draw_rays(self.ray_fast,pos-0.05,width,self.y_mul,depth*1.05) #print(self.graph_path) full_data_range=self.graph_z_max-self.graph_z_min graph(0.0,dos_start,depth+0.5,width,dos_stop-dos_start,full_data_range,self.graph_data) draw_grid() if self.zoom<-60: draw_stars()