def computeFaceDimensions(self): geometry = self.geometry bse = geometry._bse nsurf = bse._num['surf'] nedge = bse._num['edge'] ngroup = bse._num['group'] surf_edge = self.computeSurfEdge() edge_group = bse._topo['edge_group'] groupLengths = numpy.zeros(ngroup) groupCount = numpy.zeros(ngroup, int) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices groupLengths[:], groupCount[:] = PSMlib.addgrouplengths( ni, nj, nsurf, nedge, ngroup, surf_indices + 1, surf_edge, edge_group, self.surfEdgeLengths, groupLengths, groupCount) groupLengths = groupLengths / groupCount faceDims = OrderedDict() for comp in geometry.comps.values(): faceDimsComp = OrderedDict() for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices idims, jdims = PSMlib.computefacedimensions( ni, nj, nsurf, nedge, ngroup, surf_indices + 1, surf_edge, edge_group, groupLengths) faceDimsComp[face._name] = [idims, jdims] faceDims[comp._name] = faceDimsComp self.faceDims = faceDims
def computeFaceDimensions(self): geometry = self.geometry oml0 = geometry.oml0 groupLengths = numpy.zeros(oml0.ngroup) groupCount = numpy.zeros(oml0.ngroup, int) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face.num_surf groupLengths[:], groupCount[:] = PSMlib.addgrouplengths( ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, face.surf_indices + 1, oml0.surf_edge, oml0.edge_group, self.surfEdgeLengths, groupLengths, groupCount) groupLengths = groupLengths / groupCount faceDims = OrderedDict() for comp in geometry.comps.values(): faceDimsComp = OrderedDict() for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = PSMlib.computefacedimensions( ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, face.surf_indices + 1, oml0.surf_edge, oml0.edge_group, groupLengths) faceDimsComp[face.name] = [idims, jdims] faceDims[comp.name] = faceDimsComp self.faceDims = faceDims
def computeFaces(self): geometry = self.geometry quad = self.quad ngroup = self.ngroupS + self.ngroupM premeshFaces = self.premeshFaces groupIntPtr = self.groupIntPtr groupInts = self.groupInts groupSplitPtr = self.groupSplitPtr groupSplits = self.groupSplits nint = groupIntPtr[-1, -1] nsplit = groupSplitPtr[-1, -1] iList = 0 for comp in geometry.comps.values(): for face in comp.faces.values(): verts, edges, edge_group, edgeLengths = premeshFaces[iList] nvert = PSMlib.countintersectionverts(edges.shape[0], ngroup, edge_group, groupIntPtr, groupSplitPtr) verts = PSMlib.computeintersectionverts( verts.shape[0], edges.shape[0], ngroup, nint, nsplit, nvert + verts.shape[0], verts, edges, edge_group, groupIntPtr, groupInts, groupSplitPtr, groupSplits) quad.importVertsNEdges(verts, edges) quad.removeDuplicateVerts() quad.splitEdges() quad.removeDuplicateEdges() premeshFaces[iList][0] = quad.verts premeshFaces[iList][1] = quad.edges iList += 1
def importMembers(self): self.nmem = len(self.members) geometry = self.geometry nmem = self.nmem for imem in range(nmem): if len(self.members[imem]) is 2: self.members[imem].extend([[[-1, -1, -1] for j in range(5)] for i in range(2)]) members = numpy.array(self.members, order='F') membersInt, membersFlt = PSMlib.importmembers(nmem, members) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices idims, jdims = self.faceDims[comp._name][face._name] PSMlib.computepreviewmembercoords(comp._num + 1, face._num + 1, ni, nj, nmem, surf_indices + 1, idims, jdims, membersInt, membersFlt) self.membersInt = membersInt self.membersFlt = membersFlt
def computeFaces(self): geometry = self.geometry quad = self.quad ngroup = self.ngroupS + self.ngroupM premeshFaces = self.premeshFaces groupIntPtr = self.groupIntPtr groupInts = self.groupInts groupSplitPtr = self.groupSplitPtr groupSplits = self.groupSplits nint = groupIntPtr[-1,-1] nsplit = groupSplitPtr[-1,-1] iList = 0 for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): verts,edges,edge_group,edgeLengths = premeshFaces[iList] nvert = PSMlib.countintersectionverts(edges.shape[0], ngroup, edge_group, groupIntPtr, groupSplitPtr) verts = PSMlib.computeintersectionverts(verts.shape[0], edges.shape[0], ngroup, nint, nsplit, nvert + verts.shape[0], verts, edges, edge_group, groupIntPtr, groupInts, groupSplitPtr, groupSplits) quad.importVertsNEdges(verts, edges) quad.removeDuplicateVerts() quad.splitEdges() quad.removeDuplicateEdges() premeshFaces[iList][0] = quad.verts premeshFaces[iList][1] = quad.edges iList += 1
def computeFaceDimensions(self): geometry = self.geometry oml0 = self.geometry.oml0 groupLengths = numpy.zeros(oml0.ngroup) groupCount = numpy.zeros(oml0.ngroup,int) for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape groupLengths, groupCount = PSMlib.addgrouplengths(ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, comp.Ks[f]+1, oml0.surf_edge, oml0.edge_group, self.surfEdgeLengths, groupLengths, groupCount) groupLengths = groupLengths / groupCount faceDims = [] for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] faceDimsComp = [] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape idims, jdims = PSMlib.computefacedimensions(ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, comp.Ks[f]+1, oml0.surf_edge, oml0.edge_group, groupLengths) faceDimsComp.append([idims,jdims]) faceDims.append(faceDimsComp) self.faceDims = faceDims
def computePreviewMembers(self): nmem = self.nmem oml0 = self.geometry.oml0 quads, Wa = PSMlib.computepreviewmemberweights(nmem, 4*nmem, self.membersFlt) linW = numpy.linspace(0,4*nmem-1,4*nmem) B0 = scipy.sparse.csr_matrix((4*nmem,oml0.C.shape[0])) for src in range(4): W = scipy.sparse.csr_matrix((Wa[:,src],(linW,linW))) for surf in range(oml0.nsurf): npts = PSMlib.countpreviewmembers(surf+1, src+1, nmem, self.membersFlt) if npts is not 0: inds, P, Q = PSMlib.computepreviewmemberproj(surf+1, src+1, nmem, npts, self.membersFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0,npts-1,npts) T = scipy.sparse.csr_matrix((Ta,(Ti,Tj)),shape=(4*nmem,npts)) mu, mv = oml0.edgeProperty(surf,1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] oml0.computePointsC() s,u,v = oml0.evaluateProjection(P, [surf], Q) B = oml0.evaluateBases(s, u, v) B0 = B0 + W.dot(T.dot(B)) oml0.computePoints() nodes = B0.dot(oml0.C) self.memEdgeLengths = PSMlib.computeedgelengths(nodes.shape[1],nmem,nodes,quads) self.preview.append(['members', nodes, quads])
def computeFaceDimensions(self): geometry = self.geometry bse = geometry._bse nsurf = bse._num['surf'] nedge = bse._num['edge'] ngroup = bse._num['group'] surf_edge = self.computeSurfEdge() edge_group = bse._topo['edge_group'] groupLengths = numpy.zeros(ngroup) groupCount = numpy.zeros(ngroup,int) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices groupLengths[:], groupCount[:] = PSMlib.addgrouplengths(ni, nj, nsurf, nedge, ngroup, surf_indices+1, surf_edge, edge_group, self.surfEdgeLengths, groupLengths, groupCount) groupLengths = groupLengths / groupCount faceDims = OrderedDict() for comp in geometry.comps.values(): faceDimsComp = OrderedDict() for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices idims, jdims = PSMlib.computefacedimensions(ni, nj, nsurf, nedge, ngroup, surf_indices+1, surf_edge, edge_group, groupLengths) faceDimsComp[face._name] = [idims,jdims] faceDims[comp._name] = faceDimsComp self.faceDims = faceDims
def computeAdjoiningEdges(self): nmem = self.nmem nadj = PSMlib.countadjoiningedges(nmem, self.membersFlt) adjoiningInt, adjoiningFlt = PSMlib.computeadjoiningedges(nmem, nadj, self.membersInt, self.membersFlt) self.adjoiningInt = adjoiningInt self.adjoiningFlt = adjoiningFlt
def computeSurfaces(self): geometry = self.geometry oml0 = geometry.oml0 quad = self.quad premeshFaces = self.premeshFaces self.surfaceNames = [] B0 = [] quads0 = [] nnode0 = [0] iList = 0 for comp in geometry.comps.values(): for face in comp.faces.values(): verts,edges,edge_group,edgeLengths = premeshFaces[iList] iList += 1 nvert = verts.shape[0] nedge = edges.shape[0] ni, nj = face.num_surf idims, jdims = self.faceDims[comp.name][face.name] print 'Computing skin elements:', comp.name, face.name for i in range(ni): for j in range(nj): surf = face.surf_indices[i,j] if surf >= 0:# and oml0.visible[surf]: nedge1 = PSMlib.countsurfaceedges(nvert, nedge, idims[i], idims[i+1], jdims[j], jdims[j+1], verts, edges) edges1 = PSMlib.computesurfaceedges(nvert, nedge, nedge1, idims[i], idims[i+1], jdims[j], jdims[j+1], verts, edges) print comp.name, face.name, i, j quad.importEdges(edges1) output = False if comp.name=='lw' and face.name=='upp' and i==0 and j==2: output = True nodes, quads = quad.mesh(self.maxL, self.surfEdgeLengths[surf,:,:], output, output) mu, mv = oml0.edgeProperty(surf,1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] oml0.computePointsC() P0, Q = PSMlib.computesurfaceprojections(nodes.shape[0], nodes) s,u,v = oml0.evaluateProjection(P0, [surf], Q) B = oml0.evaluateBases(s,u,v) name = comp.name + ':' + str(face.name) + ':' + str(i) + ':' + str(j) self.surfaceNames.append(name) B0.append(B) nnode0.append(nnode0[-1] + P0.shape[0]) quads0.append(quads) B0 = scipy.sparse.vstack(B0) self.meshS = [B0, quads0, nnode0]
def computeSurfaces(self): geometry = self.geometry oml0 = geometry.oml0 quad = self.quad premeshFaces = self.premeshFaces self.surfaceNames = [] B0 = [] quads0 = [] nnode0 = [0] iList = 0 for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): verts,edges,edge_group,edgeLengths = premeshFaces[iList] iList += 1 nvert = verts.shape[0] nedge = edges.shape[0] ni, nj = comp.Ks[f].shape idims, jdims = self.faceDims[k][f] print 'Computing skin elements:', geometry.keys[k], f for i in range(ni): for j in range(nj): surf = comp.Ks[f][i,j] if oml0.visible[surf]: nedge1 = PSMlib.countsurfaceedges(nvert, nedge, idims[i], idims[i+1], jdims[j], jdims[j+1], verts, edges) edges1 = PSMlib.computesurfaceedges(nvert, nedge, nedge1, idims[i], idims[i+1], jdims[j], jdims[j+1], verts, edges) print geometry.keys[k], f, i, j quad.importEdges(edges1) if geometry.keys[k]=='fu' and f==1 and i==0 and j==0: nodes, quads = quad.mesh(self.maxL, self.surfEdgeLengths[surf,:,:])#,True,True) else: nodes, quads = quad.mesh(self.maxL, self.surfEdgeLengths[surf,:,:]) mu, mv = oml0.edgeProperty(surf,1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] oml0.computePointsC() P0, Q = PSMlib.computesurfaceprojections(nodes.shape[0], nodes) s,u,v = oml0.evaluateProjection(P0, [surf], Q) B = oml0.evaluateBases(s,u,v) name = geometry.keys[k] + ':' + str(f) + '-' + str(i) + '-' + str(j) self.surfaceNames.append(name) B0.append(B) nnode0.append(nnode0[-1] + P0.shape[0]) quads0.append(quads) B0 = scipy.sparse.vstack(B0) self.meshS = [B0, quads0, nnode0]
def computePreviewSurfaces(self): oml0 = self.geometry.oml0 nsurf = oml0.nsurf quads,s,u,v = PSMlib.computepreviewsurfaces(4*nsurf,nsurf) B = oml0.evaluateBases(s,u,v) nodes = B.dot(oml0.C) self.surfEdgeLengths = PSMlib.computeedgelengths(nodes.shape[1],nsurf,nodes,quads) self.preview.append(['surfs', nodes, quads])
def computePreviewSurfaces(self): oml0 = self.geometry.oml0 nsurf = oml0.nsurf quads, s, u, v = PSMlib.computepreviewsurfaces(4 * nsurf, nsurf) B = oml0.evaluateBases(s, u, v) nodes = B.dot(oml0.C) self.surfEdgeLengths = PSMlib.computeedgelengths( nodes.shape[1], nsurf, nodes, quads) self.preview.append(['surfs', nodes, quads])
def computePreviewSurfaces(self): bse = self.geometry._bse nsurf = bse._num['surf'] quads,s,u,v = PSMlib.computepreviewsurfaces(4*nsurf,nsurf) bse.add_jacobian('temp', s, u, v, ndim=3) bse.apply_jacobian('temp', 'd(temp)/d(cp_str)', 'cp_str') nodes = bse.vec['temp'].array self.surfEdgeLengths = PSMlib.computeedgelengths(nodes.shape[1],nsurf,nodes,quads) self.preview.append(['surfs', nodes, quads])
def computePreviewMembers(self): nmem = self.nmem bse = self.geometry._bse nsurf = bse._num['surf'] ncp = bse._size['cp_str'] quads, Wa = PSMlib.computepreviewmemberweights(nmem, 4 * nmem, self.membersFlt) linW = numpy.linspace(0, 4 * nmem - 1, 4 * nmem, dtype='int') B0 = scipy.sparse.csr_matrix((4 * nmem, ncp)) for src in range(4): W = scipy.sparse.csr_matrix((Wa[:, src], (linW, linW))) for surf in range(nsurf): npts = PSMlib.countpreviewmembers(surf + 1, src + 1, nmem, self.membersFlt) if npts is not 0: inds, P, Q = PSMlib.computepreviewmemberproj( surf + 1, src + 1, nmem, npts, self.membersFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0, npts - 1, npts) T = scipy.sparse.csr_matrix((Ta, (Ti, Tj)), shape=(4 * nmem, npts)) mu = bse.get_bspline_option('num_cp', surf, 'u') mv = bse.get_bspline_option('num_cp', surf, 'v') nu = bse.get_bspline_option('num_pt', surf, 'u') nv = bse.get_bspline_option('num_pt', surf, 'v') for u in range(mu): for v in range(mv): bse.vec['cp_str'](surf)[u, v, :] = [ u / (mu - 1), v / (mv - 1), 0 ] for u in range(nu): for v in range(nv): bse.vec['pt_str'](surf)[u, v, :] = [ u / (nu - 1), v / (nv - 1), 0 ] bse.compute_projection('temp', P, [surf], ndim=3) B = bse.jac['d(temp)/d(cp_str)'] B0 = B0 + W * T * B bse.apply_jacobian('cp_str', 'd(cp_str)/d(cp)', 'cp') nodes = B0 * bse.vec['cp_str'].array self.memEdgeLengths = PSMlib.computeedgelengths( nodes.shape[1], nmem, nodes, quads) self.preview.append(['members', nodes, quads])
def computeTopology(self): nmem = self.nmem bse = self.geometry._bse nsurf = bse._num['surf'] Ps = numpy.zeros((nsurf,3,3,3),order='F') for s in range(nsurf): for i in range(3): for j in range(3): bse.add_jacobian('temp', [s], [i/2.0], [j/2.0], ndim=3) Ps[s,i,j] = bse.jac['d(temp)/d(cp_str)'] * bse.vec['cp_str'].array nvertS,ngroupS,surf_vert,surf_group = PSMlib.initializeconnectivities(nsurf,1e-13,1e-5,Ps) nvertM,ngroupM,mem_vert,mem_group = PSMlib.computemembertopology(nmem, self.membersInt, self.membersFlt) mem_group[:,:,:] += ngroupS self.surf_group = surf_group self.mem_group = mem_group self.ngroupS = ngroupS self.ngroupM = ngroupM
def __init__(self, maxL, lines, limits=None): if limits==None: self.limits = numpy.array([ [numpy.amin(lines[:,:,0]), numpy.amin(lines[:,:,1])], [numpy.amax(lines[:,:,0]), numpy.amax(lines[:,:,1])], ], order='F') else: self.limits = limits self.maxL = maxL self.verts, self.edges = PSMlib.importedges(2*lines.shape[0], lines.shape[0], lines)
def computePreviewMembers(self): nmem = self.nmem bse = self.geometry._bse nsurf = bse._num['surf'] ncp = bse._size['cp_str'] quads, Wa = PSMlib.computepreviewmemberweights(nmem, 4*nmem, self.membersFlt) linW = numpy.linspace(0,4*nmem-1,4*nmem) B0 = scipy.sparse.csr_matrix((4*nmem,ncp)) for src in range(4): W = scipy.sparse.csr_matrix((Wa[:,src],(linW,linW))) for surf in range(nsurf): npts = PSMlib.countpreviewmembers(surf+1, src+1, nmem, self.membersFlt) if npts is not 0: inds, P, Q = PSMlib.computepreviewmemberproj(surf+1, src+1, nmem, npts, self.membersFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0,npts-1,npts) T = scipy.sparse.csr_matrix((Ta,(Ti,Tj)),shape=(4*nmem,npts)) mu = bse.get_bspline_option('num_cp', surf, 'u') mv = bse.get_bspline_option('num_cp', surf, 'v') nu = bse.get_bspline_option('num_pt', surf, 'u') nv = bse.get_bspline_option('num_pt', surf, 'v') for u in range(mu): for v in range(mv): bse.vec['cp_str'](surf)[u, v, :] = [u/(mu-1), v/(mv-1), 0] for u in range(nu): for v in range(nv): bse.vec['pt_str'](surf)[u, v, :] = [u/(nu-1), v/(nv-1), 0] bse.compute_projection('temp', P, [surf], ndim=3) B = bse.jac['d(temp)/d(cp_str)'] B0 = B0 + W * T * B bse.apply_jacobian('cp_str', 'd(cp_str)/d(cp)', 'cp') nodes = B0 * bse.vec['cp_str'].array self.memEdgeLengths = PSMlib.computeedgelengths(nodes.shape[1],nmem,nodes,quads) self.preview.append(['members', nodes, quads])
def importMembers(self): self.nmem = len(self.members) geometry = self.geometry nmem = self.nmem for imem in range(nmem): if len(self.members[imem]) is 2: self.members[imem].extend([[[-1,-1,-1] for j in range(5)] for i in range(2)]) members = numpy.array(self.members, order='F') membersInt, membersFlt = PSMlib.importmembers(nmem, members) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = self.faceDims[comp.name][face.name] PSMlib.computepreviewmembercoords(comp.num+1,face.num+1,ni,nj,nmem,face.surf_indices+1,idims,jdims,membersInt,membersFlt) self.membersInt = membersInt self.membersFlt = membersFlt
def computePreviewMembers(self): nmem = self.nmem oml0 = self.geometry.oml0 quads, Wa = PSMlib.computepreviewmemberweights(nmem, 4 * nmem, self.membersFlt) linW = numpy.linspace(0, 4 * nmem - 1, 4 * nmem) B0 = scipy.sparse.csr_matrix((4 * nmem, oml0.C.shape[0])) for src in range(4): W = scipy.sparse.csr_matrix((Wa[:, src], (linW, linW))) for surf in range(oml0.nsurf): npts = PSMlib.countpreviewmembers(surf + 1, src + 1, nmem, self.membersFlt) if npts is not 0: inds, P, Q = PSMlib.computepreviewmemberproj( surf + 1, src + 1, nmem, npts, self.membersFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0, npts - 1, npts) T = scipy.sparse.csr_matrix((Ta, (Ti, Tj)), shape=(4 * nmem, npts)) mu, mv = oml0.edgeProperty(surf, 1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf, u, v, 1), :3] = [ u / (mu - 1), v / (mv - 1), 0 ] oml0.computePointsC() s, u, v = oml0.evaluateProjection(P, [surf], Q) B = oml0.evaluateBases(s, u, v) B0 = B0 + W.dot(T.dot(B)) oml0.computePoints() nodes = B0.dot(oml0.C) self.memEdgeLengths = PSMlib.computeedgelengths( nodes.shape[1], nmem, nodes, quads) self.preview.append(['members', nodes, quads])
def importMembers(self): self.nmem = len(self.members) geometry = self.geometry nmem = self.nmem for imem in range(nmem): if len(self.members[imem]) is 2: self.members[imem].extend([[[-1,-1,-1] for j in range(5)] for i in range(2)]) members = numpy.array(self.members, order='F') membersInt, membersFlt = PSMlib.importmembers(nmem, members) for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape idims, jdims = self.faceDims[k][f] PSMlib.computepreviewmembercoords(k+1,f+1,ni,nj,nmem,comp.Ks[f]+1,idims,jdims,membersInt,membersFlt) self.membersInt = membersInt self.membersFlt = membersFlt
def computeGroupIntersections(self): geometry = self.geometry quad = self.quad nsurf = geometry.oml0.nsurf nmem = self.nmem ngroup = self.ngroupS + self.ngroupM nadj = self.adjoiningInt.shape[0] premeshFaces = [] groupIntCount = numpy.zeros(ngroup,int) for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape idims, jdims = self.faceDims[k][f] nedge = PSMlib.countfaceedges(k+1, f+1, ni, nj, nadj, self.adjoiningInt) edge_group, edgeLengths, edges = PSMlib.computefaceedges(k+1, f+1, ni, nj, nsurf, nmem, nadj, nedge, idims, jdims, comp.Ks[f]+1, self.surf_group, self.mem_group, self.adjoiningInt, self.adjoiningFlt, self.surfEdgeLengths, self.memEdgeLengths) quad.importEdges(edges) quad.addIntersectionPts() quad.removeDuplicateVerts() verts, edges = quad.verts, quad.edges groupIntCount = PSMlib.countgroupintersections(verts.shape[0], edges.shape[0], ngroup, verts, edges, edge_group, groupIntCount) premeshFaces.append([verts,edges,edge_group,edgeLengths]) groupIntPtr = PSMlib.computegroupintptr(ngroup, groupIntCount) nint = groupIntPtr[-1,-1] iList = 0 groupInts = numpy.zeros(nint) for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): verts,edges,edge_group,edgeLengths = premeshFaces[iList] iList += 1 groupInts = PSMlib.computegroupintersections(verts.shape[0], edges.shape[0], ngroup, nint, verts, edges, edge_group, groupIntPtr, groupInts) groupSplitCount = PSMlib.countgroupsplits(nsurf, nmem, ngroup, nint, self.maxL, self.surf_group, self.mem_group, self.surfEdgeLengths, self.memEdgeLengths, groupIntPtr, groupInts) groupSplitPtr = PSMlib.computegroupintptr(ngroup, groupSplitCount) nsplit = groupSplitPtr[-1,-1] groupSplits = PSMlib.computegroupsplits(nsurf, nmem, ngroup, nint, nsplit, self.maxL, self.surf_group, self.mem_group, self.surfEdgeLengths, self.memEdgeLengths, groupIntPtr, groupInts, groupSplitPtr) self.premeshFaces = premeshFaces self.groupIntPtr = groupIntPtr self.groupInts = groupInts self.groupSplitPtr = groupSplitPtr self.groupSplits = groupSplits
def computeGroupIntersections(self): geometry = self.geometry quad = self.quad nsurf = geometry._bse._num['surf'] nmem = self.nmem ngroup = self.ngroupS + self.ngroupM nadj = self.adjoiningInt.shape[0] premeshFaces = [] groupIntCount = numpy.zeros(ngroup,int) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices idims, jdims = self.faceDims[comp._name][face._name] nedge = PSMlib.countfaceedges(comp._num+1, face._num+1, ni, nj, nadj, self.adjoiningInt) edge_group, edgeLengths, edges = PSMlib.computefaceedges(comp._num+1, face._num+1, ni, nj, nsurf, nmem, nadj, nedge, idims, jdims, surf_indices+1, self.surf_group, self.mem_group, self.adjoiningInt, self.adjoiningFlt, self.surfEdgeLengths, self.memEdgeLengths) quad.importEdges(edges) quad.addIntersectionPts() quad.removeDuplicateVerts() verts, edges = quad.verts, quad.edges groupIntCount = PSMlib.countgroupintersections(verts.shape[0], edges.shape[0], ngroup, verts, edges, edge_group, groupIntCount) premeshFaces.append([verts,edges,edge_group,edgeLengths]) groupIntPtr = PSMlib.computegroupintptr(ngroup, groupIntCount) nint = groupIntPtr[-1,-1] iList = 0 groupInts = numpy.zeros(nint) for comp in geometry.comps.values(): for face in comp.faces.values(): verts,edges,edge_group,edgeLengths = premeshFaces[iList] iList += 1 groupInts = PSMlib.computegroupintersections(verts.shape[0], edges.shape[0], ngroup, nint, verts, edges, edge_group, groupIntPtr, groupInts) groupSplitCount = PSMlib.countgroupsplits(nsurf, nmem, ngroup, nint, self.maxL, self.surf_group, self.mem_group, self.surfEdgeLengths, self.memEdgeLengths, groupIntPtr, groupInts) groupSplitPtr = PSMlib.computegroupintptr(ngroup, groupSplitCount) nsplit = groupSplitPtr[-1,-1] groupSplits = PSMlib.computegroupsplits(nsurf, nmem, ngroup, nint, nsplit, self.maxL, self.surf_group, self.mem_group, self.surfEdgeLengths, self.memEdgeLengths, groupIntPtr, groupInts, groupSplitPtr) self.premeshFaces = premeshFaces self.groupIntPtr = groupIntPtr self.groupInts = groupInts self.groupSplitPtr = groupSplitPtr self.groupSplits = groupSplits
def computeFaceDimensions(self): geometry = self.geometry oml0 = geometry.oml0 groupLengths = numpy.zeros(oml0.ngroup) groupCount = numpy.zeros(oml0.ngroup,int) for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face.num_surf groupLengths[:], groupCount[:] = PSMlib.addgrouplengths(ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, face.surf_indices+1, oml0.surf_edge, oml0.edge_group, self.surfEdgeLengths, groupLengths, groupCount) groupLengths = groupLengths / groupCount faceDims = OrderedDict() for comp in geometry.comps.values(): faceDimsComp = OrderedDict() for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = PSMlib.computefacedimensions(ni, nj, oml0.nsurf, oml0.nedge, oml0.ngroup, face.surf_indices+1, oml0.surf_edge, oml0.edge_group, groupLengths) faceDimsComp[face.name] = [idims,jdims] faceDims[comp.name] = faceDimsComp self.faceDims = faceDims
def computeTopology(self): nmem = self.nmem oml0 = self.geometry.oml0 Ps = numpy.zeros((oml0.nsurf,3,3,3),order='F') for s in range(oml0.nsurf): for i in range(3): for j in range(3): Ps[s,i,j] = oml0.evaluatePoint(s,i/2.0,j/2.0)[:3] nvertS,ngroupS,surf_vert,surf_group = PUBSlib.initializeconnectivities(oml0.nsurf,1e-13,1e-5,Ps) nvertM,ngroupM,mem_vert,mem_group = PSMlib.computemembertopology(nmem, self.membersInt, self.membersFlt) mem_group[:,:,:] += ngroupS self.surf_group = surf_group self.mem_group = mem_group self.ngroupS = ngroupS self.ngroupM = ngroupM
def computeFaceDimensions0(self): geometry = self.geometry nsurf = self.geometry.oml0.nsurf faceDims = {} for comp in geometry.comps.values(): faceDimsComp = [] jdim0 = numpy.zeros(comp.faces.values()[0].num_surf[1]+1) for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = PSMlib.computefacedimensions0(ni,nj,nsurf,face.surf_indices+1,self.surfEdgeLengths) jdim0 += jdims faceDimsComp[face.name] = [idims,jdims] jdim0 /= len(comp.faces) for face in comp.faces.values(): faceDimsComp[face.name][1][:] = jdim0[:] faceDims[comp.name] = faceDimsComp self.faceDims = faceDims
def computeTopology(self): nmem = self.nmem oml0 = self.geometry.oml0 Ps = numpy.zeros((oml0.nsurf, 3, 3, 3), order='F') for s in range(oml0.nsurf): for i in range(3): for j in range(3): Ps[s, i, j] = oml0.evaluatePoint(s, i / 2.0, j / 2.0)[:3] nvertS, ngroupS, surf_vert, surf_group = PUBSlib.initializeconnectivities( oml0.nsurf, 1e-13, 1e-5, Ps) nvertM, ngroupM, mem_vert, mem_group = PSMlib.computemembertopology( nmem, self.membersInt, self.membersFlt) mem_group[:, :, :] += ngroupS self.surf_group = surf_group self.mem_group = mem_group self.ngroupS = ngroupS self.ngroupM = ngroupM
def computeFaceDimensions0(self): geometry = self.geometry nsurf = self.geometry.oml0.nsurf faceDims = {} for comp in geometry.comps.values(): faceDimsComp = [] jdim0 = numpy.zeros(comp.faces.values()[0].num_surf[1] + 1) for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = PSMlib.computefacedimensions0( ni, nj, nsurf, face.surf_indices + 1, self.surfEdgeLengths) jdim0 += jdims faceDimsComp[face.name] = [idims, jdims] jdim0 /= len(comp.faces) for face in comp.faces.values(): faceDimsComp[face.name][1][:] = jdim0[:] faceDims[comp.name] = faceDimsComp self.faceDims = faceDims
def computeFaceDimensions0(self): geometry = self.geometry nsurf = self.geometry.oml0.nsurf faceDims = [] for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] faceDimsComp = [] jdim0 = numpy.zeros(comp.Ks[0].shape[1]+1) for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape idims, jdims = PSMlib.computefacedimensions(ni,nj,nsurf,comp.Ks[f]+1,self.surfEdgeLengths) jdim0 += jdims faceDimsComp.append([idims,jdims]) jdim0 /= len(comp.Ks) for f in range(len(comp.Ks)): faceDimsComp[f][1][:] = jdim0[:] faceDims.append(faceDimsComp) self.faceDims = faceDims
def computeMesh(self, filename): oml0 = self.geometry.oml0 oml0.computePoints() B1, quads1, nnode1 = self.meshS B2, quads2, nnode2 = self.meshM nodes1 = B1.dot(oml0.C) nodes2 = B2.dot(oml0.C) mesh = [] nodes = [] quads = [] quad_groups = [] group_names = [] nCount = 0 nGroup = 0 for i in range(len(self.surfaceNames)): mesh.append([ self.surfaceNames[i], nodes1[nnode1[i]:nnode1[i + 1]], quads1[i] ]) nodes.append(nodes1[nnode1[i]:nnode1[i + 1]]) quads.append(quads1[i] + nCount) nCount = nCount + nnode1[i + 1] - nnode1[i] quad_groups.append(nGroup * numpy.ones(quads1[i].shape[0], int)) group_names.append(self.surfaceNames[i]) nGroup += 1 for i in range(self.nmem): mesh.append([ self.memberNames[i], nodes2[nnode2[i]:nnode2[i + 1]], quads2[i] ]) nodes.append(nodes2[nnode2[i]:nnode2[i + 1]]) quads.append(quads2[i] + nCount) nCount = nCount + nnode2[i + 1] - nnode2[i] quad_groups.append(nGroup * numpy.ones(quads2[i].shape[0], int)) group_names.append(self.memberNames[i]) nGroup += 1 self.geometry.oml0.export.write2TecFEquads(filename, mesh, self.geometry.oml0.var) quad_groups = numpy.concatenate(quad_groups) nodes = numpy.array(numpy.concatenate(nodes, axis=0)[:, :3], order='F') quads = numpy.array(numpy.concatenate(quads, axis=0), order='F') nnode = nodes.shape[0] nquad = quads.shape[0] nid, ids = PSMlib.computeuniquenodes(nnode, nodes, 1e-7) nodes, quads = PSMlib.removeduplicatenodes(nnode, nid, nquad, ids, nodes, quads) nnode = nodes.shape[0] nquad = quads.shape[0] right = PSMlib.countrightquads(nnode, nquad, nodes, quads) quads = PSMlib.removerightquads(nquad, nquad - numpy.sum(right), quads, right) temp = numpy.zeros((nquad, 4), int) temp[:, 0] = quad_groups[:] temp = PSMlib.removerightquads(nquad, nquad - numpy.sum(right), temp, right) quad_groups = temp[:, 0] nnode = nodes.shape[0] symm = PSMlib.identifysymmnodes(nnode, nodes) self.geometry.oml0.export.write2TecFEquads('test.dat', [['test', nodes, quads]], self.geometry.oml0.var[:3]) import BDFwriter BDFwriter.writeBDF(filename + '.bdf', nodes, quads, symm, quad_groups, group_names)
def splitEdges(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] nsplit = PSMlib.countsplits(nvert, nedge, self.verts, self.edges) self.edges = PSMlib.splitedges(nvert, nedge, nedge+nsplit, self.verts, self.edges)
def deleteDuplicateEdges(self): nedge0 = self.edges.shape[0] nedge, ids = PSMlib.computeuniqueedgeids(nedge0, self.edges) self.edges = PSMlib.deleteduplicateedges(nedge0, nedge, ids, self.edges)
def computeDivisions(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] ndiv = PSMlib.countdivisions(nvert, nedge, self.maxL, self.verts, self.edges) self.verts = PSMlib.computedivisions(nvert, nedge, nvert+ndiv, self.maxL, self.verts, self.edges)
def deleteDuplicateTriangles(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] ntri = nedge - nvert + 1 self.triangles = PSMlib.deleteduplicatetriangles(6*ntri, ntri, self.triangles)
def computeMembers(self): nmem = self.nmem geometry = self.geometry oml0 = geometry.oml0 groupIntPtr = self.groupIntPtr groupInts = self.groupInts groupSplitPtr = self.groupSplitPtr groupSplits = self.groupSplits quad = self.quad ngroup = self.ngroupS + self.ngroupM nint = groupIntPtr[-1,-1] nsplit = groupSplitPtr[-1,-1] nodesInt0 = [] nodesFlt0 = [] quads0 = [] nnode0 = [0] for imem in range(nmem): print 'Computing internal members:', self.memberNames[imem] edges, edge_group = PSMlib.computememberedges(imem+1, nmem, self.mem_group) quad.importEdges(edges) verts, edges = quad.verts, quad.edges nvert = PSMlib.countintersectionverts(edges.shape[0], ngroup, edge_group, groupIntPtr, groupSplitPtr) verts = PSMlib.computeintersectionverts(verts.shape[0], edges.shape[0], ngroup, nint, nsplit, nvert + verts.shape[0], verts, edges, edge_group, groupIntPtr, groupInts, groupSplitPtr, groupSplits) quad.importVertsNEdges(verts, edges) nodes, quads = quad.mesh(self.maxL, self.memEdgeLengths[imem,:,:]) nodesInt, nodesFlt = PSMlib.computemembernodes(imem+1, nmem, nodes.shape[0], self.membersInt, self.membersFlt, nodes) nodesInt0.append(nodesInt) nodesFlt0.append(nodesFlt) quads0.append(quads) nnode0.append(nnode0[-1] + nodes.shape[0]) nodesInt = numpy.array(numpy.vstack(nodesInt0),order='F') nodesFlt = numpy.array(numpy.vstack(nodesFlt0),order='F') nnode = nodesInt.shape[0] for k in range(len(geometry.comps)): comp = geometry.comps[geometry.keys[k]] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape idims, jdims = self.faceDims[k][f] PSMlib.computememberlocalcoords(k+1, f+1, ni, nj, nnode, idims, jdims, comp.Ks[f]+1, nodesInt, nodesFlt) linW = numpy.linspace(0,nnode-1,nnode) B0 = scipy.sparse.csr_matrix((nnode,oml0.C.shape[0])) for src in range(4): W = scipy.sparse.csr_matrix((nodesFlt[:,src,0],(linW,linW))) for surf in range(oml0.nsurf): npts = PSMlib.countmembers(surf+1, src+1, nnode, nodesInt) if npts is not 0: inds, P, Q = PSMlib.computememberproj(surf+1, src+1, nnode, npts, nodesInt, nodesFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0,npts-1,npts) T = scipy.sparse.csr_matrix((Ta,(Ti,Tj)),shape=(nnode,npts)) mu, mv = oml0.edgeProperty(surf,1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] oml0.computePointsC() s,u,v = oml0.evaluateProjection(P, [surf], Q) B = oml0.evaluateBases(s, u, v) B0 = B0 + W.dot(T.dot(B)) self.meshM = [B0, quads0, nnode0]
def meshStructure(self, members, lengths): oml0 = self.oml0 nmem = len(members) faces = -numpy.ones((nmem,4,2),int,order='F') coords = numpy.zeros((nmem,4,2,2,3),order='F') for imem in range(nmem): key = members.keys()[imem] for icontr in range(len(members[key])): faces[imem,icontr,0] = self.inds[members[key][icontr][0]] faces[imem,icontr,1] = members[key][icontr][1] coords[imem,icontr,0,0,:] = members[key][icontr][2] coords[imem,icontr,1,0,:] = members[key][icontr][3] coords[imem,icontr,0,1,:] = members[key][icontr][4] coords[imem,icontr,1,1,:] = members[key][icontr][5] surfs = numpy.linspace(0,oml0.nsurf-1,oml0.nsurf) s = numpy.zeros(4*oml0.nsurf) s[0::4] = surfs s[1::4] = surfs s[2::4] = surfs s[3::4] = surfs u = numpy.zeros(4*oml0.nsurf) u[1::4] = 1. u[3::4] = 1. v = numpy.zeros(4*oml0.nsurf) v[2::4] = 1. v[3::4] = 1. quadsS = numpy.zeros((oml0.nsurf,4),order='F') quadsS[:,0] = 4*surfs + 0 quadsS[:,1] = 4*surfs + 1 quadsS[:,2] = 4*surfs + 3 quadsS[:,3] = 4*surfs + 2 B = oml0.evaluateBases(s,u,v) nodesS = B.dot(oml0.C[:,:3]) oml0.export.write2TecQuads('john.dat',nodesS,quadsS) #oml0.C[:,:] = -1.0 #for k in range(len(self.comps)): # c = self.keys[k] # comp = self.comps[c] # for f in range(len(comp.Ks)): # ni, nj = comp.Ks[f].shape # for i in range(ni): # for j in range(nj): # surf = comp.Ks[f][i,j] # mu, mv = oml0.edgeProperty(surf,1) # ugroup = oml0.edge_group[abs(oml0.surf_edge[surf,0,0])-1] # vgroup = oml0.edge_group[abs(oml0.surf_edge[surf,1,0])-1] # mu = oml0.group_m[ugroup-1] # mv = oml0.group_m[vgroup-1] # for u in range(mu): # for v in range(mv): # oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] oml0.C[:,:] = -1.0 for surf in range(oml0.nsurf): mu, mv = oml0.edgeProperty(surf,1) ugroup = oml0.edge_group[abs(oml0.surf_edge[surf,0,0])-1] vgroup = oml0.edge_group[abs(oml0.surf_edge[surf,1,0])-1] mu = oml0.group_m[ugroup-1] mv = oml0.group_m[vgroup-1] for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf,u,v,1),:3] = [u/(mu-1), v/(mv-1), 0] print u/(mu-1), v/(mv-1) oml0.computePointsC() #oml0.export.write2TecQuads('john2.dat',nodesM,quadsM) oml0.write2Tec('test2') oml0.write2TecC('test2') self.computePoints() print oml0.C[oml0.getIndex(147,-1, 0,1),:3] print oml0.C[oml0.getIndex(144,-1,-1,1),:3] print oml0.C[oml0.getIndex( 49, 0, 0,1),:3] s = numpy.zeros(4*nmem) P = numpy.zeros((4*nmem,3),order='F') Q = numpy.zeros((4*nmem,3),order='F') w = numpy.zeros((4*nmem,4),order='F') mems = numpy.linspace(0,nmem-1,nmem) Q[:,2] = 1. Bs = [] ws = [] for icontr in range(4): for imem in range(nmem): k = faces[imem,icontr,0] f = faces[imem,icontr,1] c = self.keys[k] comp = self.comps[c] ni, nj = comp.Ks[f].shape for i in range(2): for j in range(2): u, v = coords[imem,icontr,i,j,:2] ii = int(numpy.floor(u*ni)) jj = int(numpy.floor(v*nj)) s[4*imem+2*j+i] = comp.Ks[f][ii,jj] P[4*imem+2*j+i,0] = u*ni - ii P[4*imem+2*j+i,1] = v*nj - jj w[4*imem+2*j+i,icontr] = coords[imem,icontr,i,j,2] surf,u,v = oml0.evaluateProjection(P, Q=Q) Bs.append(oml0.evaluateBases(surf, u, v)) quadsM = numpy.zeros((nmem,4),order='F') quadsM[:,0] = 4*mems + 0 quadsM[:,1] = 4*mems + 1 quadsM[:,2] = 4*mems + 3 quadsM[:,3] = 4*mems + 2 nodesM = numpy.zeros((4*nmem,3),order='F') for icontr in range(4): for k in range(3): nodesM[:,k] += w[:,icontr] * Bs[icontr].dot(oml0.C[:,k]) oml0.export.write2TecQuads('john2.dat',nodesM,quadsM) exit() Ps = numpy.zeros((oml0.nsurf,3,3,3),order='F') for s in range(oml0.nsurf): for i in range(3): for j in range(3): Ps[s,i,j] = oml0.evaluatePoint(s,i/2.0,j/2.0)[:3] nvertS,ngroupS,surf_vert,surf_group = PUBSlib.initializeconnectivities(oml0.nsurf,1e-13,1e-5,Ps) nvertM,ngroupM,mem_vert,mem_group = PSMlib.computemembertopology(nmem, faces, coords) mem_group[:,:,:] += ngroupS ngroup = ngroupS + ngroupM nint = PSMlib.countfaceintersections(nmem, coords) intFaces, intCoords = PSMlib.computefaceintersections(nmem, nint, faces, coords) groupIntCount = numpy.zeros(ngroup,int) meshesS = [] for k in range(len(self.comps)): c = self.keys[k] comp = self.comps[c] meshes = [] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape nedge = PSMlib.countfaceedges(k, f, ni, nj, nint, intFaces) edges, edge_group = PSMlib.computefaceedges(k, f, ni, nj, oml0.nsurf, nint, nmem, nedge, comp.Ks[f], surf_group, mem_group, intFaces, intCoords) mesh = QuadMesh(0.2,edges) mesh.computeIntersections() mesh.computeDivisions() mesh.deleteDuplicateVerts() groupIntCount = PSMlib.countgroupintersections(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, mesh.verts, mesh.edges, edge_group, groupIntCount) meshes.append([mesh,edge_group]) meshesS.append(meshes) meshesM = [] for imem in range(nmem): edges, edge_group = PSMlib.computememberedges(imem+1, nmem, mem_group) mesh = QuadMesh(1e6,edges) meshesM.append([mesh,edge_group]) groupIntPtr = PSMlib.computegroupintptr(ngroup, groupIntCount) nint = groupIntPtr[-1,-1] groupInts = numpy.zeros(nint) for k in range(len(self.comps)): c = self.keys[k] comp = self.comps[c] for f in range(len(comp.Ks)): mesh, edge_group = meshesS[k][f] groupInts = PSMlib.computegroupintersections(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts) #print groupInts for k in range(len(self.comps)): c = self.keys[k] comp = self.comps[c] for f in range(len(comp.Ks)): mesh, edge_group = meshesS[k][f] nvert = PSMlib.countintersectionverts(mesh.edges.shape[0], ngroup, edge_group, groupIntPtr) mesh.verts = PSMlib.computeintersectionverts(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, nvert + mesh.verts.shape[0], mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts) print 'QM1', k, f mesh.mesh() #edges[:,:,0] *= lengths[k,0] #edges[:,:,1] *= lengths[k,1] if k==1 and f==0 and 0: import pylab mesh.plot(111,pt=False,pq=False) pylab.show() exit() for imem in range(nmem): mesh, edge_group = meshesM[imem] nvert = PSMlib.countintersectionverts(mesh.edges.shape[0], ngroup, edge_group, groupIntPtr) mesh.verts = PSMlib.computeintersectionverts(mesh.verts.shape[0], mesh.edges.shape[0], ngroup, nint, nvert + mesh.verts.shape[0], mesh.verts, mesh.edges, edge_group, groupIntPtr, groupInts) print 'QM2', imem mesh.mesh() if 0: import pylab mesh.plot(111,pt=False,pq=False) pylab.show() exit() meshesM.append([mesh,edge_group]) oml0.C[:,:] = -1.0 for k in range(len(self.comps)): c = self.keys[k] comp = self.comps[c] for f in range(len(comp.Ks)): ni, nj = comp.Ks[f].shape for i in range(ni): for j in range(nj): surf = comp.Ks[f][i,j] mu, mv = oml0.edgeProperty(surf,1) for u in range(mu): uu = u/(mu-1) for v in range(mv): vv = v/(mv-1) oml0.C[oml0.getIndex(surf,u,v,1),:3] = [(uu+i)/ni, (vv+j)/nj, 0] oml0.computePointsC() #oml0.write2Tec('test2') #oml0.write2TecC('test2') #exit() Bs = [] quads = [] nquad0 = 0 for k in range(len(self.comps)): c = self.keys[k] comp = self.comps[c] for f in range(len(comp.Ks)): mesh, edge_group = meshesS[k][f] ni, nj = comp.Ks[f].shape print mesh.verts.shape[0] P0, surfs, Q = PSMlib.computeprojtninputs(mesh.verts.shape[0], ni, nj, mesh.verts, comp.Ks[f]) surf,u,v = oml0.evaluateProjection(P0, comp.Ks[f].flatten(), Q) Bs.append(oml0.evaluateBases(surf,u,v)) quads.append(nquad0 + mesh.quads - 1) #quads.append(mesh.quads - 1) nquad0 += mesh.verts.shape[0] self.computePoints() #i = 0 #for k in range(len(self.comps)): # c = self.keys[k] # comp = self.comps[c] # for f in range(len(comp.Ks)): # P = Bs[i].dot(oml0.C[:,:3]) # oml0.export.write2TecQuads('data'+str(k)+'-'+str(f)+'.dat',P,quads[i]-1) # i += 1 import scipy.sparse B = scipy.sparse.vstack(Bs) P = B.dot(oml0.C[:,:3]) quads = numpy.vstack(quads) oml0.export.write2TecQuads('john.dat',P,quads)#mesh.quads-1)
def computeMembers(self): nmem = self.nmem geometry = self.geometry bse = geometry._bse groupIntPtr = self.groupIntPtr groupInts = self.groupInts groupSplitPtr = self.groupSplitPtr groupSplits = self.groupSplits quad = self.quad ngroup = self.ngroupS + self.ngroupM nint = groupIntPtr[-1, -1] nsplit = groupSplitPtr[-1, -1] nsurf = bse._num['surf'] ncp = bse._size['cp_str'] nodesInt0 = [] nodesFlt0 = [] quads0 = [] nnode0 = [0] mem0 = [] ucoord0 = [] vcoord0 = [] for imem in range(nmem): print 'Computing internal members:', self.memberNames[imem] edges, edge_group = PSMlib.computememberedges( imem + 1, nmem, self.mem_group) quad.importEdges(edges) verts, edges = quad.verts, quad.edges nvert = PSMlib.countintersectionverts(edges.shape[0], ngroup, edge_group, groupIntPtr, groupSplitPtr) verts = PSMlib.computeintersectionverts( verts.shape[0], edges.shape[0], ngroup, nint, nsplit, nvert + verts.shape[0], verts, edges, edge_group, groupIntPtr, groupInts, groupSplitPtr, groupSplits) quad.importVertsNEdges(verts, edges) nodes, quads = quad.mesh(self.maxL, self.memEdgeLengths[imem, :, :]) nodesInt, nodesFlt = PSMlib.computemembernodes( imem + 1, nmem, nodes.shape[0], self.membersInt, self.membersFlt, nodes) nodesInt0.append(nodesInt) nodesFlt0.append(nodesFlt) quads0.append(quads) nnode0.append(nnode0[-1] + nodes.shape[0]) P0, Q = PSMlib.computesurfaceprojections(nodes.shape[0], nodes) mem0.append(imem * numpy.ones(P0.shape[0])) ucoord0.append(P0[:, 0]) vcoord0.append(P0[:, 1]) nodesInt = numpy.array(numpy.vstack(nodesInt0), order='F') nodesFlt = numpy.array(numpy.vstack(nodesFlt0), order='F') nnode = nodesInt.shape[0] for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face._num_surf['u'], face._num_surf['v'] surf_indices = face._surf_indices idims, jdims = self.faceDims[comp._name][face._name] PSMlib.computememberlocalcoords(comp._num + 1, face._num + 1, ni, nj, nnode, idims, jdims, surf_indices + 1, nodesInt, nodesFlt) linW = numpy.linspace(0, nnode - 1, nnode, dtype='int') B0 = scipy.sparse.csr_matrix((nnode, ncp)) for src in range(4): W = scipy.sparse.csr_matrix((nodesFlt[:, src, 0], (linW, linW))) for surf in range(nsurf): npts = PSMlib.countmembers(surf + 1, src + 1, nnode, nodesInt) if npts is not 0: inds, P, Q = PSMlib.computememberproj( surf + 1, src + 1, nnode, npts, nodesInt, nodesFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0, npts - 1, npts) T = scipy.sparse.csr_matrix((Ta, (Ti, Tj)), shape=(nnode, npts)) mu = bse.get_bspline_option('num_cp', surf, 'u') mv = bse.get_bspline_option('num_cp', surf, 'v') nu = bse.get_bspline_option('num_pt', surf, 'u') nv = bse.get_bspline_option('num_pt', surf, 'v') for u in range(mu): for v in range(mv): bse.vec['cp_str'](surf)[u, v, :] = [ u / (mu - 1), v / (mv - 1), 0 ] for u in range(nu): for v in range(nv): bse.vec['pt_str'](surf)[u, v, :] = [ u / (nu - 1), v / (nv - 1), 0 ] bse.compute_projection('temp', P, [surf], ndim=3) B = bse.jac['d(temp)/d(cp_str)'] B0 = B0 + W * T * B bse.apply_jacobian('cp_str', 'd(cp_str)/d(cp)', 'cp') self.meshM = [B0, quads0, nnode0, mem0, ucoord0, vcoord0]
def computeSurfaces(self): geometry = self.geometry bse = geometry._bse quad = self.quad premeshFaces = self.premeshFaces self.surfaceNames = [] B0 = [] quads0 = [] nnode0 = [0] mem0 = [] ucoord0 = [] vcoord0 = [] iList = 0 imem = 0 for comp in geometry.comps.values(): for face in comp.faces.values(): verts, edges, edge_group, edgeLengths = premeshFaces[iList] iList += 1 nvert = verts.shape[0] nedge = edges.shape[0] ni, nj = face._num_surf['u'], face._num_surf['v'] idims, jdims = self.faceDims[comp._name][face._name] print 'Computing skin elements:', comp._name, face._name for i in range(ni): for j in range(nj): surf = face._surf_indices[i, j] if surf >= 0: nedge1 = PSMlib.countsurfaceedges( nvert, nedge, idims[i], idims[i + 1], jdims[j], jdims[j + 1], verts, edges) edges1 = PSMlib.computesurfaceedges( nvert, nedge, nedge1, idims[i], idims[i + 1], jdims[j], jdims[j + 1], verts, edges) print comp._name, face._name, i, j quad.importEdges(edges1) output = False if comp._name == 'lw' and face._name == 'upp' and i == 0 and j == 2: output = True nodes, quads = quad.mesh( self.maxL, self.surfEdgeLengths[surf, :, :], output, output) mu = bse.get_bspline_option('num_cp', surf, 'u') mv = bse.get_bspline_option('num_cp', surf, 'v') nu = bse.get_bspline_option('num_pt', surf, 'u') nv = bse.get_bspline_option('num_pt', surf, 'v') for u in range(mu): for v in range(mv): bse.vec['cp_str'](surf)[u, v, :] = [ u / (mu - 1), v / (mv - 1), 0 ] for u in range(nu): for v in range(nv): bse.vec['pt_str'](surf)[u, v, :] = [ u / (nu - 1), v / (nv - 1), 0 ] P0, Q = PSMlib.computesurfaceprojections( nodes.shape[0], nodes) bse.compute_projection('temp', P0, [surf], ndim=3) B = bse.jac['d(temp)/d(cp_str)'] name = '{}:{}:{:03d}:{:03d}'.format( comp._name, face._name, i, j) self.surfaceNames.append(name) B0.append(B) nnode0.append(nnode0[-1] + P0.shape[0]) quads0.append(quads) mem0.append(imem * numpy.ones(P0.shape[0])) imem += 1 ucoord0.append(P0[:, 0]) vcoord0.append(P0[:, 1]) bse.apply_jacobian('cp_str', 'd(cp_str)/d(cp)', 'cp') B0 = scipy.sparse.vstack(B0) self.meshS = [B0, quads0, nnode0, mem0, ucoord0, vcoord0]
def computeAdjMap(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] self.adjPtr, self.adjMap = PSMlib.computeadjmap(nvert, nedge, 2*nedge, self.edges)
def computeTriangles(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] nadj = self.adjMap.shape[0] ntri = nedge - nvert + 1 self.triangles = PSMlib.computetriangles(nvert, nadj, 6*ntri, self.adjPtr, self.adjMap)
def computeMembers(self): nmem = self.nmem geometry = self.geometry oml0 = geometry.oml0 groupIntPtr = self.groupIntPtr groupInts = self.groupInts groupSplitPtr = self.groupSplitPtr groupSplits = self.groupSplits quad = self.quad ngroup = self.ngroupS + self.ngroupM nint = groupIntPtr[-1, -1] nsplit = groupSplitPtr[-1, -1] nodesInt0 = [] nodesFlt0 = [] quads0 = [] nnode0 = [0] for imem in range(nmem): print 'Computing internal members:', self.memberNames[imem] edges, edge_group = PSMlib.computememberedges( imem + 1, nmem, self.mem_group) quad.importEdges(edges) verts, edges = quad.verts, quad.edges nvert = PSMlib.countintersectionverts(edges.shape[0], ngroup, edge_group, groupIntPtr, groupSplitPtr) verts = PSMlib.computeintersectionverts( verts.shape[0], edges.shape[0], ngroup, nint, nsplit, nvert + verts.shape[0], verts, edges, edge_group, groupIntPtr, groupInts, groupSplitPtr, groupSplits) quad.importVertsNEdges(verts, edges) nodes, quads = quad.mesh(self.maxL, self.memEdgeLengths[imem, :, :]) nodesInt, nodesFlt = PSMlib.computemembernodes( imem + 1, nmem, nodes.shape[0], self.membersInt, self.membersFlt, nodes) nodesInt0.append(nodesInt) nodesFlt0.append(nodesFlt) quads0.append(quads) nnode0.append(nnode0[-1] + nodes.shape[0]) nodesInt = numpy.array(numpy.vstack(nodesInt0), order='F') nodesFlt = numpy.array(numpy.vstack(nodesFlt0), order='F') nnode = nodesInt.shape[0] for comp in geometry.comps.values(): for face in comp.faces.values(): ni, nj = face.num_surf idims, jdims = self.faceDims[comp.name][face.name] PSMlib.computememberlocalcoords(comp.num + 1, face.num + 1, ni, nj, nnode, idims, jdims, face.surf_indices + 1, nodesInt, nodesFlt) linW = numpy.linspace(0, nnode - 1, nnode) B0 = scipy.sparse.csr_matrix((nnode, oml0.C.shape[0])) for src in range(4): W = scipy.sparse.csr_matrix((nodesFlt[:, src, 0], (linW, linW))) for surf in range(oml0.nsurf): npts = PSMlib.countmembers(surf + 1, src + 1, nnode, nodesInt) if npts is not 0: inds, P, Q = PSMlib.computememberproj( surf + 1, src + 1, nnode, npts, nodesInt, nodesFlt) Ta = numpy.ones(npts) Ti = inds - 1 Tj = numpy.linspace(0, npts - 1, npts) T = scipy.sparse.csr_matrix((Ta, (Ti, Tj)), shape=(nnode, npts)) mu, mv = oml0.edgeProperty(surf, 1) for u in range(mu): for v in range(mv): oml0.C[oml0.getIndex(surf, u, v, 1), :3] = [ u / (mu - 1), v / (mv - 1), 0 ] oml0.computePointsC() s, u, v = oml0.evaluateProjection(P, [surf], Q) B = oml0.evaluateBases(s, u, v) B0 = B0 + W.dot(T.dot(B)) self.meshM = [B0, quads0, nnode0]
def computeSurfaces(self): geometry = self.geometry oml0 = geometry.oml0 quad = self.quad premeshFaces = self.premeshFaces self.surfaceNames = [] B0 = [] quads0 = [] nnode0 = [0] iList = 0 for comp in geometry.comps.values(): for face in comp.faces.values(): verts, edges, edge_group, edgeLengths = premeshFaces[iList] iList += 1 nvert = verts.shape[0] nedge = edges.shape[0] ni, nj = face.num_surf idims, jdims = self.faceDims[comp.name][face.name] print 'Computing skin elements:', comp.name, face.name for i in range(ni): for j in range(nj): surf = face.surf_indices[i, j] if surf >= 0: # and oml0.visible[surf]: nedge1 = PSMlib.countsurfaceedges( nvert, nedge, idims[i], idims[i + 1], jdims[j], jdims[j + 1], verts, edges) edges1 = PSMlib.computesurfaceedges( nvert, nedge, nedge1, idims[i], idims[i + 1], jdims[j], jdims[j + 1], verts, edges) print comp.name, face.name, i, j quad.importEdges(edges1) output = False if comp.name == 'lw' and face.name == 'upp' and i == 0 and j == 2: output = True nodes, quads = quad.mesh( self.maxL, self.surfEdgeLengths[surf, :, :], output, output) mu, mv = oml0.edgeProperty(surf, 1) for u in range(mu): for v in range(mv): oml0.C[ oml0.getIndex(surf, u, v, 1), :3] = [ u / (mu - 1), v / (mv - 1), 0 ] oml0.computePointsC() P0, Q = PSMlib.computesurfaceprojections( nodes.shape[0], nodes) s, u, v = oml0.evaluateProjection(P0, [surf], Q) B = oml0.evaluateBases(s, u, v) name = comp.name + ':' + str( face.name) + ':' + str(i) + ':' + str(j) self.surfaceNames.append(name) B0.append(B) nnode0.append(nnode0[-1] + P0.shape[0]) quads0.append(quads) B0 = scipy.sparse.vstack(B0) self.meshS = [B0, quads0, nnode0]
def computeCDT(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] self.verts, self.edges = PSMlib.reordercollinear(nvert, nedge, self.verts, self.edges) ntri, triangles = CDTlib.computecdt(nvert, nedge, 2*nvert-5, self.verts, self.edges) self.edges = PSMlib.trianglestoedges(2*nvert-5, ntri, 3*ntri, triangles)
def computeGrid(self): nvert = self.verts.shape[0] nedge = self.edges.shape[0] ngp = PSMlib.countgridpoints(nvert, self.maxL, self.limits, self.verts) self.verts = PSMlib.computegridpoints(nvert, nvert+ngp, self.maxL, self.limits, self.verts)
def computeMesh(self, filename): bse = self.geometry._bse B1, quads1, nnode1, mem1, ucoord1, vcoord1 = self.meshS B2, quads2, nnode2, mem2, ucoord2, vcoord2 = self.meshM nodes1 = B1 * bse.vec['cp_str'].array nodes2 = B2 * bse.vec['cp_str'].array new_nodes = numpy.vstack([nodes1, nodes2]) new_ucoord = numpy.concatenate(ucoord1 + ucoord2) new_vcoord = numpy.concatenate(vcoord1 + vcoord2) mem1 = numpy.concatenate(mem1).astype(int) mem2 = numpy.concatenate(mem2).astype(int) mem2 += numpy.max(mem1) + 1 new_mem = numpy.concatenate([mem1, mem2]).astype(int) mesh = [] nodes = [] quads = [] quad_groups = [] group_names = [] nCount = 0 nGroup = 0 for i in range(len(self.surfaceNames)): mesh.append([ self.surfaceNames[i], nodes1[nnode1[i]:nnode1[i + 1]], quads1[i] ]) nodes.append(nodes1[nnode1[i]:nnode1[i + 1]]) quads.append(quads1[i] + nCount) nCount = nCount + nnode1[i + 1] - nnode1[i] quad_groups.append(nGroup * numpy.ones(quads1[i].shape[0], int)) group_names.append(self.surfaceNames[i]) nGroup += 1 for i in range(self.nmem): mesh.append([ self.memberNames[i], nodes2[nnode2[i]:nnode2[i + 1]], quads2[i] ]) nodes.append(nodes2[nnode2[i]:nnode2[i + 1]]) quads.append(quads2[i] + nCount) nCount = nCount + nnode2[i + 1] - nnode2[i] quad_groups.append(nGroup * numpy.ones(quads2[i].shape[0], int)) group_names.append(self.memberNames[i]) nGroup += 1 self.write2TecFEquads(filename, mesh) quad_groups = numpy.concatenate(quad_groups) nodes = numpy.array(numpy.concatenate(nodes, axis=0)[:, :3], order='F') quads = numpy.array(numpy.concatenate(quads, axis=0), order='F') nnode = nodes.shape[0] nquad = quads.shape[0] nid, ids = PSMlib.computeuniquenodes(nnode, nodes, 1e-7) nodes, quads = PSMlib.removeduplicatenodes(nnode, nid, nquad, ids, nodes, quads) nnode = nodes.shape[0] nquad = quads.shape[0] right = PSMlib.countrightquads(nnode, nquad, nodes, quads) quads = PSMlib.removerightquads(nquad, nquad - numpy.sum(right), quads, right) temp = numpy.zeros((nquad, 4), int) temp[:, 0] = quad_groups[:] temp = PSMlib.removerightquads(nquad, nquad - numpy.sum(right), temp, right) quad_groups = temp[:, 0] nnode = nodes.shape[0] symm = PSMlib.identifysymmnodes(nnode, nodes) self.write2TecFEquads('test.dat', [['test', nodes, quads]]) import BDFwriter BDFwriter.writeBDF(filename + '.bdf', nodes, quads, symm, quad_groups, group_names, new_mem, new_nodes, new_ucoord, new_vcoord)