def callback_clone_shape(self): tab = self.notebook.currentWidget() s = self.epi.find_shape_by_file_name(tab.file_name) name = s.name + "_new" new_sim_name = dlg_get_text("Clone the shape:", name, "clone.png") new_sim_name = new_sim_name.ret if new_sim_name != None: old_name = os.path.join(get_sim_path(), tab.file_name) new_name = get_epi().new_electrical_file("shape") my_shape = shape() my_shape.load(old_name) my_shape.name = new_sim_name my_shape.x0 = my_shape.x0 - my_shape.dx my_shape.shape_electrical = get_epi().gen_new_electrical_file( "electrical") my_shape.file_name = new_name my_shape.save() get_epi().layers[self.layer_index].shapes.append(my_shape) get_epi().save() my_tab = tab_class(my_shape.file_name + ".inp") self.notebook.addTab(my_tab, my_shape.name) my_tab.changed.connect(self.callback_edit) global_object_run("gl_force_redraw")
def interlock(img, birds_eye, thresholds, lines): ''' runs the actual vision interlock; the parameters are the components that create the `certificate` :param img: image from the controller :param birds_eye: bird's eye transformation object from the controller :param thresholds: thresholds used for vision filters :param lines: proposed lane lines :return: the result of each vision interlock test ''' wb = get_wb(img, birds_eye, thresholds) plt.imshow(wb) plt.show() shape_result = shape(lines[0], lines[1], img.shape[0]) left_result = convolve(True, lines[0], wb) right_result = convolve(False, lines[1], wb) result = birds_eye.project(img, wb, lines[0], lines[1]) plt.title("Approach 1: " + ("pass" if shape_result else "fail") + "\nApproach 2L: " + (left_result if left_result else "fail") + ", Approach 2R: " + (right_result if right_result else "fail")) plt.imshow(result) plt.show() return shape_result, left_result, right_result
def produce_impl(self): # Creates the patterns # Convert parameters from [um] to [dbu] or database units d = self.specDiameter[self.diameter] / self.layout.dbu * 1000 pFlat = self.specPrimaryFlat[self.diameter] / self.layout.dbu * 1000 sFlat = self.specSecondaryFlat[self.diameter] / self.layout.dbu * 1000 aFlat = self.specSecondaryFlatAngle[self.secondaryFlatAngle] b = self.border / self.layout.dbu * 1000 dIn = self.dIn / self.layout.dbu * 1000 dOut = self.dOut / self.layout.dbu * 1000 # Create the wafer shape s = shape() region = s.siWafer(d, pFlat, sFlat, aFlat, 128) if (self.doubleFlat): regionTmp = region.dup() regionTmp.transform(pya.ICplxTrans(1, 180, False, 0, 0)) region = region & regionTmp if (self.ring): scaleIn = (d - dIn) / d scaleOut = (d + dOut) / d regionOut = region.dup() regionOut.transform(pya.ICplxTrans(scaleOut, 0, False, 0, 0)) regionIn = region.dup() regionIn.transform(pya.ICplxTrans(scaleIn, 0, False, 0, 0)) region = regionOut - regionIn if (self.invert): region = s.invert(region, b) self.cell.shapes(self.layer_layer).insert(region)
def layer_add(self): obj=self.gl_objects_get_first_selected() if obj!=None: epi=get_epi() s=epi.find_shape_by_id(obj.id[0]) if type(s)==epi_layer or type(s)==shape: layer_index=epi.find_layer_by_id(obj.id[0]) new_filename=epi.new_electrical_file("shape")+".inp" orig_filename=os.path.join(get_default_material_path(),"shape.inp") inp_copy_file(os.path.join(get_sim_path(),new_filename),os.path.join(get_sim_path(),orig_filename)) mesh=get_mesh() my_shape=shape() my_shape.load(new_filename) my_shape.dy=epi.layers[layer_index].dy my_shape.dx=mesh.get_xlen() my_shape.dz=mesh.get_zlen() my_shape.shape_electrical=epi.gen_new_electrical_file("electrical") my_shape.shape_nx=1 my_shape.shape_ny=1 my_shape.shape_nz=1 my_shape.name="New shape" my_shape.save() epi.layers[layer_index].shapes.append(my_shape) epi.save() self.force_redraw()
def cclock(self, brd): self.bloc.remove(brd) self.nbloc = shape(self.bloc) self.nbloc.shape = self.nbloc.twist_cclock(brd) self.nbloc.update_hw() if self.nbloc.can_insert(brd): self.bloc = self.nbloc else: pass self.bloc.insert(brd)
def produce_impl(self): # Creates the patterns # Convert parameters from [um] to [dbu] or database units d = self.diameter / self.layout.dbu b = self.border / self.layout.dbu # Create the cross s = shape() region = s.circle(d, self.vertices) if (self.invert): region = s.invert(region, b) self.cell.shapes(self.layer_layer).insert(region)
def produce_impl(self): # Creates the patterns # Convert parameters from [um] to [dbu] or database units w = self.width / self.layout.dbu b = self.border / self.layout.dbu # Create the cross s = shape() region = s.checkerboard(w, self.num) if (self.invert): region = s.invert(region, b) self.cell.shapes(self.layer_layer).insert(region)
def draw_light_profile(self): self.gl_objects_remove_regex("light_profile") name = inp_get_token_value(os.path.join(get_sim_path(), "light.inp"), "#light_profile") if name != "box": epi = get_epi() s = shape() s.type = name s.load_triangles() s.triangles.data = triangles_remove_below(s.triangles.data, 0.1) a = gl_base_object() a.id = ["light_profile"] a.type = "open_triangles" a.x = gl_scale.project_m2screen_x(0) a.y = gl_scale.project_m2screen_y(0) a.z = gl_scale.project_m2screen_z(0) a.dx = 1.0 a.dy = scale_get_ymul() * 1.0 a.dz = 1.0 a.r = 0.0 a.g = 1.0 a.b = 0.0 a.alpha = 1.0 my_vec = vec() my_vec.x = get_mesh().get_xlen() my_vec.y = epi.ylen() * 1.0 my_vec.z = get_mesh().get_zlen() t = triangles_mul_vec(s.triangles.data, my_vec) my_vec = vec() my_vec.x = 0.0 my_vec.y = -epi.ylen() * 3.0 my_vec.z = 0.0 t = triangles_add_vec(t, my_vec) a.triangles = scale_trianges_m2screen(t) #triangles_mul_vec(triangles_flip_in_box(s.triangles.data),my_vec) #print("bing!",gl_scale.project_m2screen_x(0)) self.gl_objects_add(a)
def main(): print(list(set([11, 22, 33, 44, 11, 22]))) defaultshape = sp.shape() if (isinstance(defaultshape, sp.shape)): print('default area is {}'.format(defaultshape.area())) squareshape = sp.square(5) if (isinstance(squareshape, sp.shape)): print('Square area is {}'.format(squareshape.area())) c1 = cn.ComplexNumber(4, 2) c2 = cn.ComplexNumber(5, 3) c3 = c1.add(c2) #print("Complex Number {}+i{}".format(c3.real, c3.complex)) print('Sum is {}'.format(c3))
def produce_impl(self): # Creates the patterns # Convert parameters from [um] to [dbu] or database units do = self.outerDiameter / self.layout.dbu di = self.innerDiameter / self.layout.dbu b = self.border / self.layout.dbu # Create the cross s = shape() region = s.ring(do, di, self.vertices, self.fracture) if (self.invert): region = s.invert(region, b) self.cell.shapes(self.layer_layer).insert(region)
def produce_impl(self): # Creates the patterns # Convert parameters from [um] to [dbu] or database units d = self.specDiameter[self.diameter] / self.layout.dbu * 1000 pFlat = self.specPrimaryFlat[self.diameter] / self.layout.dbu * 1000 sFlat = self.specSecondaryFlat[self.diameter] / self.layout.dbu * 1000 aFlat = self.specSecondaryFlatAngle[self.secondaryFlatAngle] b = self.border / self.layout.dbu * 1000 # Create the cross s = shape() region = s.siWafer(d, pFlat, sFlat, aFlat, 128) if (self.invert): region = s.invert(region, b) self.cell.shapes(self.layer_layer).insert(region)
def new_shape_file(self,layer): new_filename=self.gen_new_electrical_file("shape") mesh=get_mesh() my_shape=shape() my_shape.load(os.path.join(get_sim_path(),new_filename)+".inp") if layer!=None: my_shape.dy=layer.dy my_shape.dx=mesh.get_xlen() my_shape.dz=mesh.get_zlen() my_shape.shape_electrical=self.gen_new_electrical_file("electrical") my_shape.shape_nx=1 my_shape.shape_ny=1 my_shape.shape_nz=1 my_shape.name="New shape" my_shape.optical_material="blends/p3htpcbm" my_shape.save() return my_shape
def plot(space,sol): T = lambda x: x**2#np.sin(x) plt.figure(1) xplot = np.linspace(space.bounds[0],space.bounds[1],space.nels*10+1) plt.plot(xplot,T(xplot), linewidth = 2, color = 'blue') nw,xw,w = QuadParams.QP(space.maxord) ## set mesh parameters to spatial grid nels = space.nels order = space.order nod = space.nod xnod = space.xnod for el in range(0,nels): xL = xnod[nod[el,0]] # left endpoint on element xR = xnod[nod[el,order[el]-1]] # right endpoint on element dx = (xR-xL)/2. # Jacobian of transformation xpp = np.linspace(xL,xR,10); # set up 10 points in the true element for plotting xww =(xpp-xL)/dx-1; # xww runs in reference element ypp = 0*xpp; # initializes a zero array of len(xpp) for j in range(0,len(xpp)): psi,dpsi = shape.shape(xww[j],order[el]) uhval = 0 for k in range(0,order[el]): mynum = nod[el,k] # (nod=global numbering of nodes). mynum = node,k, of element,el uhval = uhval + sol[mynum]*psi[k] ypp[j]=uhval plt.plot(xpp,ypp,linewidth = 2, color = 'red') plt.title('Exact solution (blue) and BVP FEM solution (red)') plt.xlabel('Space') plt.grid(True) plt.show()
def Error(space,sol,T,Tp): nw,xw,w = QuadParams.QP(space.maxord) ## set mesh parameters to spatial grid nels = space.nels order = space.order nod = space.nod xnod = space.xnod l2Err = 0.0; h1Err=0.0 for el in range(0,nels): # for each element in all elements tL = xnod[nod[el,0]] # left endpoint on element tR = xnod[nod[el,order[el]-1]] # right endpoint on element dt = (tR-tL)/2. # Jacobian of transformation for l in range(0,nw): t = tL + (1 + xw[l])*dt # x runs in true element, xw runs in reference element psi,dpsi = shape.shape(xw[l],order[el]) # calculations on ref.element uval = T(t) duval = Tp(t) uhval = 0.0; duhval = 0.0 #reset uh and duh evaluations over each element for k in range(0,order[el]): mynum = nod[el,k] # (nod=global numbering of nodes). mynum = node,k, of element,el uhval = uhval + sol[mynum]*psi[k] duhval = duhval + sol[mynum]*dpsi[k]/dt #complete integration over element l2Err = l2Err + (uval-uhval)**2 *w[l]*dt h1Err = h1Err + (duval-duhval)**2 *w[l]*dt l2Err = math.sqrt(l2Err) h1Err = math.sqrt(l2Err+h1Err) return(l2Err,h1Err)
def __init__(self): self.bloc = shape(False)
def produce_impl(self): # Cross parameters cWidth = 10 cLength = 100 cGap = 0 cBorder = 10 cPos = pya.Point(0, 0) # Vernier parameters vWidth = 4 vLength = 40 vPitch = 8 vGap = 0 vPosL = pya.Point(-120000, cPos.y) vPosB = pya.Point(cPos.x, -120000) # Mask number parameters mLineWidth = 4 mPosL = pya.Point(-40000, 90000) mPosR = pya.Point(40000, 90000) # Border border = 10 # Create references to the active cell cv = pya.CellView().active() layout = cv.layout() dbu = self.layout.dbu s = shape() #Creates a cross if (self.cross == 0): #Solid Cross if (self.type == 0): #Wafer Type #Creates an inverted cross cross = s.cross((cWidth + 2 * cGap) / dbu, (cLength + 2 * cGap) / dbu) cross = s.invert(cross, cBorder / dbu) cross.transform(pya.Trans(cPos)) else: cross = s.cross(cWidth / dbu, cLength / dbu) cross.transform(pya.Trans(cPos)) else: #Dashed Cross if (self.type == 0): #Wafer Type cross = s.cross(cWidth / dbu, cLength / dbu, 1) cross = s.invert(cross, cBorder / dbu) cross.transform(pya.Trans(cPos)) else: cross = s.cross(cWidth / dbu, cLength / dbu, 2) cross.transform(pya.Trans(cPos)) if (self.type == 0): #Wafer Type #Create Vernier Left 1 vLeft = s.vernier(vWidth / dbu, vLength / dbu, vPitch / dbu) vLeft.transform(pya.Trans(vPosL)) #Create Vernier Bottom 1 vBot = s.vernier(vWidth / dbu, vLength / dbu, vPitch / dbu) vBot.transform(pya.Trans(1, False, vPosB.x, vPosB.y)) #Create Mask Number tt = pya.CplxTrans(mLineWidth, 0, False, mPosL.x, mPosL.y) mNum = s.text(self.num).transform(tt) else: #Create Vernier Left 2 vLeft = s.vernier(vWidth / dbu, vLength / dbu, vPitch / dbu + self.res / dbu) vLeft.transform( pya.Trans(2, False, vPosL.x - vLength / dbu - vGap / dbu, vPosL.y)) #Create Vernier Bottom 2 vBot = s.vernier(vWidth / dbu, vLength / dbu, vPitch / dbu + self.res / dbu) vBot.transform( pya.Trans(3, False, vPosB.x, vPosB.y - vLength / dbu - vGap / dbu)) #Create Mask Number tt = pya.CplxTrans(mLineWidth, 0, False, mPosR.x, mPosR.y) mNum = s.text(self.num).transform(tt) #Creates the Wafer Alignment Mark region = pya.Region() region.insert(cross) region.insert(vLeft) region.insert(vBot) region.insert(mNum) if (self.type == 1) and (self.mask == 0): region = s.invert(region, border / dbu) self.cell.shapes(self.layer_layer).insert(region)
def produce_impl(self): # Cross parameters cWidth = 10 cLength = 100 cGap = 0 cBorder = 10 cPos = pya.Point(0,0) # Vernier parameters vWidth = 4 vLength = 40 vPitch = 8 vGap = 0 vPosL = pya.Point(-120000,cPos.y) vPosB = pya.Point(cPos.x,-120000) # Mask number parameters mLineWidth = 4 mPos = pya.Point(140000,140000) # Border border = 10 # Create references to the active cell cv = pya.CellView().active() layout = cv.layout() dbu = self.layout.dbu # Position of the Alignment Marks posLeftMark = pya.Point(-self.pos*1000/dbu,0) posRightMark = pya.Point(self.pos*1000/dbu,0) s = shape() #Creates a cross if (self.cross == 0): #Solid Cross if (self.type == 0): #Wafer Type #Creates an inverted cross cross = s.cross((cWidth+2*cGap)/dbu, (cLength + 2*cGap)/dbu) cross = s.invert(cross, cBorder/dbu) cross.transform(pya.Trans(cPos)) else: cross = s.cross(cWidth/dbu, cLength/dbu) cross.transform(pya.Trans(cPos)) else: #Dashed Cross if (self.type == 0): #Wafer Type cross = s.cross(cWidth/dbu, cLength/dbu,1) cross = s.invert(cross, cBorder/dbu) cross.transform(pya.Trans(cPos)) else: cross = s.cross(cWidth/dbu, cLength/dbu,2) cross.transform(pya.Trans(cPos)) if (self.type == 0): #Wafer Type #Create Vernier Patterns vLeft = s.vernier(vWidth/dbu, vLength/dbu, vPitch/dbu) vLeft.transform(pya.Trans(vPosL)) vBot = vLeft.dup() vBot.transform(pya.Trans(1,0,0,0)) vRight = vLeft.dup() vRight.transform(pya.Trans(2,0,0,0)) vTop = vLeft.dup() vTop.transform(pya.Trans(3,0,0,0)) #Create Mask Number tt = pya.CplxTrans(mLineWidth, 0, False, -mPos.x, mPos.y) mNumLeft = s.text(self.num).transform(tt) mNumRight = mNumLeft.dup() mNumRight.transform(pya.Trans(2,True,0,0)) else: #Create Vernier Left 2 vLeft = s.vernier(vWidth/dbu, vLength/dbu, vPitch/dbu+self.res/dbu) vLeft.transform(pya.Trans(2, False, vPosL.x-vLength/dbu-vGap/dbu, vPosL.y)) vBot = vLeft.dup() vBot.transform(pya.Trans(1,0,0,0)) vRight = vLeft.dup() vRight.transform(pya.Trans(2,0,0,0)) vTop = vLeft.dup() vTop.transform(pya.Trans(3,0,0,0)) #Create Mask Number tt = pya.CplxTrans(mLineWidth, 0, False, -mPos.x, -mPos.y) mNumLeft = s.text(self.num).transform(tt) mNumRight = mNumLeft.dup() mNumRight.transform(pya.Trans(2,True,0,0)) #Create Shapes for Left Mark and Right Mark leftMarkCross = cross.dup() leftMarkCross.transform(pya.Trans(posLeftMark)) leftMarkVernierLeft = vLeft.dup() leftMarkVernierLeft.transform(pya.Trans(posLeftMark)) leftMarkVernierBot = vBot.dup() leftMarkVernierBot.transform(pya.Trans(posLeftMark)) leftMarkVernierRight = vRight.dup() leftMarkVernierRight.transform(pya.Trans(posLeftMark)) leftMarkVernierTop = vTop.dup() leftMarkVernierTop.transform(pya.Trans(posLeftMark)) leftMarkMNumLeft = mNumLeft.dup() leftMarkMNumLeft.transform(pya.Trans(posLeftMark)) leftMarkMNumRight = mNumRight.dup() leftMarkMNumRight.transform(pya.Trans(posLeftMark)) rightMarkCross = cross.dup() rightMarkCross.transform(pya.Trans(posRightMark)) rightMarkVernierLeft = vLeft.dup() rightMarkVernierLeft.transform(pya.Trans(posRightMark)) rightMarkVernierBot = vBot.dup() rightMarkVernierBot.transform(pya.Trans(posRightMark)) rightMarkVernierRight = vRight.dup() rightMarkVernierRight.transform(pya.Trans(posRightMark)) rightMarkVernierTop = vTop.dup() rightMarkVernierTop.transform(pya.Trans(posRightMark)) rightMarkMNumLeft = mNumLeft.dup() rightMarkMNumLeft.transform(pya.Trans(posRightMark)) rightMarkMNumRight = mNumRight.dup() rightMarkMNumRight.transform(pya.Trans(posRightMark)) #Creates the Wafer Alignment MarkCross regionLeft = pya.Region() regionLeft.insert(leftMarkCross) regionLeft.insert(leftMarkVernierLeft) regionLeft.insert(leftMarkVernierBot) regionLeft.insert(leftMarkVernierRight) regionLeft.insert(leftMarkVernierTop) regionLeft.insert(leftMarkMNumLeft) regionLeft.insert(leftMarkMNumRight) regionRight = pya.Region() regionRight.insert(rightMarkCross) regionRight.insert(rightMarkVernierLeft) regionRight.insert(rightMarkVernierBot) regionRight.insert(rightMarkVernierRight) regionRight.insert(rightMarkVernierTop) regionRight.insert(rightMarkMNumLeft) regionRight.insert(rightMarkMNumRight) if (self.type == 1) and (self.mask == 0): regionLeft = s.invert(regionLeft,border/dbu) regionRight = s.invert(regionRight,border/dbu) self.cell.shapes(self.layer_layer).insert(regionLeft) self.cell.shapes(self.layer_layer).insert(regionRight)
#Constants for certain RGB colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) GREEN = (0, 255, 0) pygame.display.set_caption(("A* Shortest Pathfinder")) icon = pygame.image.load("maze.png") pygame.display.set_icon(icon) pygame.init() #List of different shape objects shapes = [ shape((29, 12), (31, 15), (31, 18), (29, 19), (25, 18), (25, 15)), shape((5, 15), (5, 19), (17, 19), (17, 15)), shape((7, 3), (10, 8), (8, 13), (4, 12), (3, 8)), shape((23, 3), (23, 11), (28, 11), (28, 3)), shape((31, 3), (33, 5), (32, 13), (29, 5)), shape((18, 3), (19, 5), (16, 8), (16, 4)), shape((11, 12), (13, 6), (15, 12)), shape((18, 13), (20, 18), (23, 16)) ] #Fixed starting and ending locations start_fixed = ((2 * scalex, 18 * scaley)) end_fixed = ((34 * scalex, 3 * scaley)) startrand = random.randint(1, 19) endrand = random.randint(1, 19)
def DFEM_BVP_1D(space,T,source,cond): ''' This function solves a two-point BVP using discontinuous Galerkin finite elements. INPUT: nw, xw, w: number of integration points, nodes, and weights nels: number of elements ord: lost of polynomial order for corresponsing elements xnod, nod, nnodes: list of node coordinates, global numbering of nodes, and total number of nodes OUTPUT: sol: is the numerical solution of the corresponding FEM coefficients A. Alberti 07/2017 ''' nw,xw,w = QuadParams.QP(space.maxord) ## set mesh parameters to spatial grid nels = space.nels order = space.order nod = space.nod xnod = space.xnod edge = space.edge xedge = space.xedge nnodes = space.nnodes ## set up matrix and rhs of linear system stiff = np.zeros((nnodes,nnodes)); rhsf = np.zeros(nnodes)#rhsf = np.zeros((nnodes,1)); # impose dirichlet boudnary conditions on solution sol = np.zeros(nnodes) sol[0] = T(space.bounds[0]) # space.bounds[0] BC sol[-1] = T(space.bounds[1]) #space.bounds[1] # BC for el in range(0,nels): # for each element... xL = xnod[nod[el,0]] # ...leftmost node xR = xnod[nod[el,order[el]-1]] # ...rightmost node dx = (xR-xL)/2. # Jacobian of transformation for nodes xEdgeL = xedge[edge[el,0]] # ...leftmost edge xEdgeR = xedge[edge[el,1]] # ...rightmost edge dxEdge = (xEdgeR-xEdgeL)/2. # Jacobian of transformation for edges # compute element stiffness matrix and load vector k = np.zeros((order[el],order[el])) # element stiffness matrix f = np.zeros(order[el]) # element load vector lmbda = 1 for l in range(0,nw): x = xL + (1 + xw[l])*dx # t runs in true element, xw runs in reference element xEdge = xEdgeL + (1 + xw[l])*dxEdge psi,dpsi = shape.shape(xw[l],order[el]) # calculations on ref.element kval = cond(x) fval = source(x) f = f + fval * psi *w[l]*dxEdge k = k + kval*np.outer(dpsi, dpsi)/dx/dx * w[l]*dx if el == 0: # first element f[0] = f[0] - T(space.bounds[0]) k[order[el]-1,order[el]-1] = k[order[el]-1,order[el]-1] - 1.0 elif el==nels-1: # last element f[1] = f[1] + T(space.bounds[1]) else: k[order[el]-1,order[el]-1] = k[order[el]-1,order[el]-1] - 1.0 # print(Cyan+'k');print(mat) # print(Cyan+'RHS');print(f) # add the computed element stiffness matrix and load vector to the global matrix and vector for idx in range(0,order[el]): rhsf[nod[el,idx]] = rhsf[nod[el,idx]] + f[idx] for idy in range(0,order[el]): stiff[nod[el,idx],nod[el,idy]] = stiff[nod[el,idx],nod[el,idy]] + k[idx][idy] if el!=nels-1: stiff[nod[el,idx]+1,nod[el,idy]] = 1.0 # # uncomment to see the global stiffness matrix and load vector # print(Cyan+'s stiffness mat');print(stiff) # print(Cyan+'RHS');print(rhsf) # sys.exit() rhsf = np.subtract(rhsf , np.dot(stiff,sol)) sol[1:-1] = np.linalg.solve(stiff[1:-1,1:-1],rhsf[1:-1]) return(sol)
def CFEM_BVP_1D(space,T,source,cond): ''' This function solves a two-point BVP using continuous Galerkin finite elements. - either first or second order FE - Numerical integration is used in computation of stiffness matrix and rhs INPUT: nw, xw, w: number of integration points, nodes, and weights nels: number of elements ord: lost of polynomial order for corresponsing elements xnod, nod, nnodes: list of node coordinates, global numbering of nodes, and total number of nodes OUTPUT: sol: is the numerical solution of the corresponding FEM coefficients A. Alberti 06/2017 Referenced from M. Peszynska MTH659 FEM Course ''' nw,xw,w = QuadParams.QP(space.maxord) ## set mesh parameters to spatial grid nels = space.nels order = space.order nod = space.nod xnod = space.xnod nnodes = space.nnodes ## set up matrix and rhs of linear system stiff = np.zeros((nnodes,nnodes)); rhsf = np.zeros(nnodes)#rhsf = np.zeros((nnodes,1)); for el in range(0,nels): # for each element in all elements xL = xnod[nod[el,0]] # left endpoint on element xR = xnod[nod[el,order[el]-1]] # right endpoint on element dx = (xR-xL)/2. # Jacobian of transformation # compute element stiffness matrix and load vector k = np.zeros((order[el],order[el])) # element stiffness matrix f = np.zeros(order[el]) # element load vector for l in range(0,nw): x = xL + (1 + xw[l])*dx # x runs in true element, xw runs in reference element # print('x -> '+str(x)) psi,dpsi = shape.shape(xw[l],order[el]) # calculations on ref.element kval = cond(x) fval = source(x) f = f + fval * psi *w[l]*dx k = k + kval*np.outer(dpsi, dpsi)/dx/dx * w[l]*dx # # uncomment to see the local (stiffness+mass) matrix and local load vector # print(k) # print(f) # sys.exit() # add the computed element stiffness matrix and load vector to the global matrix and vector for idx in range(0,order[el]): rhsf[nod[el,idx]] = rhsf[nod[el,idx]] + f[idx] for idy in range(0,order[el]): stiff[nod[el,idx],nod[el,idy]] = stiff[nod[el,idx],nod[el,idy]] + k[idx][idy] # impose Dirichlet boundary conditions eliminate known values from the system sol = np.zeros(nnodes) sol[0] = T(space.bounds[0]) #space.bounds[0] # BC sol[-1] = T(space.bounds[1]) #space.bounds[1] # BC mat = stiff # rhsf = np.subtract(rhsf , np.dot(mat,sol)) # SOLVE! (for coefficients of finite elements, still not the \emph{actual} solution) sol[1:-1] = np.linalg.solve(mat[1:-1,1:-1],rhsf[1:-1]) return(sol)
def run(d, *, squash=False): print("") print(d) print(shape(d, squash=squash))
def load(self,path): self.layers=[] f=inp() y_pos=0.0 if f.load(os.path.join(path,"epitaxy.inp"))!=False: number_of_layers=int(f.get_next_val()) f.to_sections(start="#layer_type") for s in f.sections: a=epi_layer() a.layer_type=s.layer_type a.dos_file=s.layer_dos_file if a.dos_file.startswith("dos")==True: a.layer_type="active" a.pl_file=s.layer_pl_file a.file_name=s.layer_base_shape if a.file_name!="none": a.load(os.path.join(get_sim_path(),a.file_name)) else: a.name=s.layer_name a.cal_rgb() #shape temp=s.layer_shape #value if temp=="none": a.shapes=[] else: files=temp.split(",") for sh in files: my_shape=shape() my_shape.load(sh) a.shapes.append(my_shape) #lumo a.lumo_file=s.layer_lumo #lumo a.homo_file=s.layer_homo #interface_file a.interface_file=s.layer_interface a.solve_optical_problem=s.solve_optical_problem a.solve_thermal_problem=s.solve_thermal_problem a.start=y_pos y_pos=y_pos+a.dy a.end=y_pos self.layers.append(a) self.contacts.load() self.loaded=True #self.dump_tree() changed=False for l in self.layers: if l.interface_file=="none": l.interface_file=self.gen_new_electrical_file("interface") changed=True if changed==True: self.save()
def run(d, *, squash=False): print("") print(d) print(shape(d, squash=squash))
COLOR_AVG = colorAverage() end = time.time() duration = end - start DURATION_SUM += duration DURATION_AVG = DURATION_SUM / 10 find_color = rgb2colorname.color_detect(red, green, blue) co_width, co_height = color_img.shape[:2] center_x = int(co_height / 2.0) center_y = int(co_width / 2.0) font = cv2.FONT_ITALIC (text_width, text_height), baseline = cv2.getTextSize(find_color, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 1) location = (center_x - 30, center_y + int(text_height / 2)) cv2.putText(color_img, find_color, location, cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 0), 1, 8) cv2.imwrite('images/color_result2.png', color_img) img = cv2.imread("images/result.jpg") tmp = img rs_width, rs_height = img.shape[:2] shadow.grabcut(5, 10, rs_height - 10, rs_width - 5) find_shape = shape.shape() find_print = imprint.detect_text('images/result.jpg') if find_print == None: find_print = '' print(find_color + "," + find_shape + "," + find_print)
def run_tetris(): board = tetris_board() level = 1 lost = False holding_shape = None shapes_to_fall = get_next_shape([]) falling_shape = shape(shapes_to_fall.pop(0)) next_shape = shape(shapes_to_fall.pop(0)) has_swapped = False last_action_time = 0 while not lost: composite_display(board, board.score, level, falling_shape, holding_shape, next_shape) fall_time = calculate_next_frame(level) while time.time() < fall_time: # look for input action = get_next_action(fall_time - time.time()) if action != NO_INPUT: last_action_time = time.time() if action == KILL_ME: exit(0) elif action == ROTATE_RIGHT: falling_shape = board.rotate_shape_right(falling_shape) elif action == ROTATE_LEFT: falling_shape = board.rotate_shape_left(falling_shape) elif action == MOVE_RIGHT: falling_shape = board.move_shape_right(falling_shape) elif action == MOVE_LEFT: falling_shape = board.move_shape_left(falling_shape) elif action == DROP_SHAPE: falling_shape = board.drop_shape(falling_shape) elif action == MOVE_DOWN: falling_shape = board.fall_shape(falling_shape, True) elif action == SWAP: if holding_shape is None: holding_shape = falling_shape holding_shape.reset_position() shapes_to_fall = get_next_shape(shapes_to_fall) falling_shape = shape(shapes_to_fall.pop(0)) has_swapped = True if holding_shape is not None and not has_swapped: has_swapped = True tmp = falling_shape falling_shape = holding_shape holding_shape = tmp holding_shape.reset_position() if falling_shape is None: falling_shape = next_shape shapes_to_fall = get_next_shape(shapes_to_fall) next_shape = shape(shapes_to_fall.pop(0)) has_swapped = False composite_display(board, board.score, level, falling_shape, holding_shape, next_shape) if board.score / 25 > level: level += 1 falling_shape = board.fall_shape(falling_shape, not (time.time() - last_action_time) > 1) if falling_shape is None: falling_shape = next_shape shapes_to_fall = get_next_shape(shapes_to_fall) next_shape = shape(shapes_to_fall.pop(0)) has_swapped = False if board.has_intersection(falling_shape): lost = True