def readSmeshFacetsBlock(fil, nfacets, nbmark): """Read a tetgen .smesh facets bock. Returns a tuple of dictionaries with plexitudes as keys: - elems: for each plexitude a Connectivity array - nrs: for each plexitude a list of element numbers in corresponding elems """ elems = {} nrs = {} for i in range(nfacets): line = fil.readline() line = line.strip() if len(line) > 0: data = fromstring(line, sep=' ', dtype=int32) nplex = data[0] if nplex > 0: e = data[1:1 + nplex] # bmark currently not read addElem(elems, nrs, e, i, nplex) else: raise ValueError, "Invalid data line:\n%s" % line for np in elems: if np == 3: eltype = 'tri3' elif np == 4: eltype = 'quad4' else: eltype = None elems[np] = Connectivity(elems[np], eltype=eltype) nrs[np] = array(nrs[np]) return elems, nrs
def readElemsBlock(fil, nelems, nplex, nattr): """Read a tetgen elems block. Returns a tuple with: - elems: Connectivity of type 'tet4' or 'tet10' - nrs: the element numbers - attr: the element attributes The last can be None. """ ndata = 1 + nplex + nattr data = fromfile(fil, sep=' ', dtype=int32, count=ndata * nelems).reshape(nelems, ndata) nrs = data[:, 0] elems = data[:, 1:1 + nplex] if nattr > 0: attr = data[:, 1 + nplex:] else: attr = None if nplex == 4: eltype = 'tet4' elif nplex == 10: eltype = 'tet10' else: raise ValueError, "Unknown tetgen .ele plexitude %s" % nplex return Connectivity(elems, eltype=eltype), nrs, attr
def getEntities(self, level, reduce=False): """Return the type and connectivity table of some element entities. The full list of entities with increasing dimensionality 0,1,2,3 is:: ['points', 'edges', 'faces', 'cells' ] If level is negative, the dimensionality returned is relative to the highest dimensionality (.i.e., that of the element). If it is positive, it is taken absolute. Thus, for a 3D element type, getEntities(-1) returns the faces, while for a 2D element type, it returns the edges. For both types however, getLowerEntities(+1) returns the edges. The return value is a dict where the keys are element types and the values are connectivity tables. If reduce == False: there will be only one connectivity table and it may include degenerate elements. If reduce == True, an attempt is made to reduce the degenerate elements. The returned dict may then have multiple entries. If the requested entity level is outside the range 0..ndim, the return value is None. """ if level < 0: level = self.ndim + level if level < 0 or level > self.ndim: return Connectivity() if level == 0: return Connectivity(arange(self.nplex()).reshape((-1, 1)), eltype='point') elif level == self.ndim: return Connectivity(arange(self.nplex()).reshape((1, -1)), eltype=self) elif level == 1: return self.edges elif level == 2: return self.faces
def _sanitize(ent): # input is Connectivity or (eltype,table) # output is Connectivity if isinstance(ent, Connectivity): if hasattr(ent, 'eltype'): return ent else: raise ValueError, "Conectivity should have an element type" else: return Connectivity(ent[1], eltype=ent[0])
def readFacesBlock(fil, nelems, nbmark): """Read a tetgen faces block. Returns a a tuple with: - elems: Connectivity of type 'tri3' - nrs: face numbers - bmrk: face boundary marker The last can be None. """ ndata = 1 + 3 + nbmark data = fromfile(fil, sep=' ', dtype=int32, count=ndata * nelems).reshape(nelems, ndata) nrs = data[:, 0] elems = data[:, 1:4] if nbmark == 1: bmark = data[:, -1] else: bmark = None return Connectivity(elems, eltype='tri3'), nrs, bmark
import materials import cantilevers import matplotlib.pyplot as plt from scipy.interpolate import InterpolatedUnivariateSpline from gaussian import Gaussian from laminate_fem import LaminateFEM from connectivity import Connectivity import scipy.sparse as sparse """ """ material = materials.PiezoMumpsMaterial() cantilever = cantilevers.InitialCantileverFixedTip() la = laminate_analysis.LaminateAnalysis(cantilever, material, True) fem = LaminateFEM(cantilever, material, True, 0.01) connectivity = Connectivity(fem.mesh) gaussian = Gaussian(fem, fem.cantilever, 0.1) index = 100 # the index of the pseudo-density to vary. ps = np.arange(0.02, 1, 0.01) g3sums = np.empty_like(ps) netas = np.empty_like(ps) dg3sums = np.empty_like(ps) dnetas = np.empty_like(ps) print('Number of points: %d' % len(ps)) pnew = la.fem.density.copy() mdofmat = la.mdofmat tdofmat = la.tdofmat for i, p in enumerate(ps):
"""" D0 = GPIO16; D1 = GPIO5; D2 = GPIO4; D3 = GPIO0; D4 = GPIO2; D5 = GPIO14; D6 = GPIO12; D7 = GPIO13; D8 = GPIO15; D9 = GPIO3; D10 = GPIO1; LED_BUILTIN = GPIO16 """ from connectivity import Connectivity sv = Connectivity() if not sv.backup(): sv.server() sv.update() sv.wifi() gc.collect()
def GetHull(self): self.find_extreme_points() faces = self.find_simplex() connectivity = Connectivity(faces) dupPoints = set() vert_faces = [None] * len(self.mesh.verts) for i in range(len(self.mesh.verts)): for f in faces: if f.is_dup(i): dupPoints.add(i) break if i in dupPoints: continue for f in faces: if f.add_point(i): if vert_faces[i] == None: vert_faces[i] = set() vert_faces[i].add(f) finalFaces = FaceSet(self.mesh) donePoints = set() iter = -1 bw = None while len(faces): iter += 1 if self.dump_faces: bw = BinaryWriter(open(f"/tmp/quickhull-{iter:05d}.bin", "wb")) self.mesh.write(bw) faces.write(bw) finalFaces.write(bw) f = faces.pop() if not f.vispoints: finalFaces.add(f) iter -= 1 continue point = f.highest_point if f.dist(point) < 1e-12: #FIXME epsilon varies with data # the highest point is essentially on the face (possibly to # the side), so all points are on the face. Thus, this face # is done for p in f.vispoints: vert_faces[p].remove(f) f.vispoints.clear() finalFaces.add(f) iter -= 1 continue litFaces = connectivity.light_faces(f, point, vert_faces) vispoints = connectivity.remove(litFaces) #print(vispoints) for p in vispoints: vert_faces[p] -= litFaces.faces if bw: bw.write_int(point) litFaces.write(bw) horizonEdges = litFaces.find_outer_edges() newFaces = FaceSet(self.mesh) for e in horizonEdges: if e.touches_point(point): re = e.reverse t = connectivity[re] splitEdge = t.find_edge(re) if splitEdge >= 0: self.split_triangle(t, splitEdge, point, connectivity, vert_faces) else: tri = Triangle(self.mesh, e.a, e.b, point) newFaces.add(tri) connectivity.add(tri) donePoints.clear() for lf in litFaces: for p in lf.vispoints: if p in donePoints: continue donePoints.add(p) if vert_faces[p] == None: vert_faces[p] = set() for nf in newFaces: if nf.is_dup(p): dupPoints.add(p) p = -1 break if p < 0: continue for nf in newFaces: if nf.add_point(p): vert_faces[p].add(nf) for p, vf in enumerate(vert_faces): if not vf or p in donePoints: continue donePoints.add(p) for nf in newFaces: if nf.add_point(p): vert_faces[p].add(nf) if bw: newFaces.write(bw) for nf in set(newFaces.faces): if nf.vispoints: faces.add(nf) else: finalFaces.add(nf) if bw: bw.close() bw = None if connectivity.error: vis = set() for lf in litFaces: for vp in lf.vispoints: vis.add(vp) for lf in litFaces: dist1 = 1e38 dist2 = 1e38 for i in range(3): d = lf.edges[i].distance(point) if d < dist1: dist1 = d v = self.mesh.verts[point] v = sub(v, self.mesh.verts[lf.edges[i].a]) d = sqrt(dot(v, v)) if d < dist2: dist2 = d break if self.dump_faces and not connectivity.error: iter += 1 bw = BinaryWriter(open(f"/tmp/quickhull-{iter:05d}.bin", "wb")) self.mesh.write(bw) faces.write(bw) finalFaces.write(bw) bw.write_int(-1) bw.write_int(0) bw.write_int(0) bw.close() self.error = connectivity.error return finalFaces
def endPoints(parts): """Find the end points of all parts""" ep = Coords.concatenate([p.coords[[0, -1]] for p in parts]) endpoints, ind = ep.fuse() ind = Connectivity(ind.reshape(-1, 2)) return endpoints, ind
def main_menu(self, token): self.token = token main_answer = questionary.select( "What do you want to do?", choices=[ 'Connectivity', 'Device Setting', 'User Management', 'Current Status', 'Logout' ]).ask() # returns value of selection if(main_answer == 'Connectivity'): connectivity_answer = self.connectivity_menu() if(connectivity_answer == 'Connect'): connector = input("Enter Connector: ") adaptor = input("Enter Adaptor: ") date_time = input( "Enter Date and Time: (format: 2019-Aug-28 10:10:00)\n") a = Connectivity() a.connect(connector, adaptor, date_time, self.token) elif(connectivity_answer == 'Disconnect'): connector = input("Enter Connector: ") adaptor = input("Enter Adaptor: ") date_time = input( "Enter Date and Time: (format: 2019-Aug-28 10:10:00)\n") a = Connectivity() a.recovery(connector, adaptor, date_time, self.token) elif(connectivity_answer == 'Recovery'): connector = input("Enter Connector: ") adaptor = input("Enter Adaptor: ") date_time = input( "Enter Date and Time: (format: 2019-Aug-28 10:10:00)\n") a = Connectivity() a.disconnect(connector, adaptor, date_time, self.token) elif(connectivity_answer == 'Calibrate'): connector = input("Enter Connector: ") adaptor = input("Enter Adaptor: ") date_time = input( "Enter Date and Time: (format: 2019-Aug-28 10:10:00)\n") a = Connectivity() a.calibrate(connector, adaptor, date_time, self.token) elif(connectivity_answer == 'Queue Management'): a = Connectivity() a.queue_manage(self.token) elif(main_answer == 'Device Setting'): print('2') elif(main_answer == 'User Management'): print('3') elif(main_answer == 'Current Status'): print('4') elif(main_answer == 'Logout'): print('--Goodbye--') return -1 return 0