def compute(self, name): face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if name == 'cp_prim': #If we are at the cp_prim step... return super(PGMcone, self).compute(name) #Call the function that sets up the normal properties elif name == 'cp_bez': #If we are at the cp_bez step... rgt = self._comp.faces['rgt'] top = self._comp.faces['top'] lft = self._comp.faces['lft'] bot = self._comp.faces['bot'] if self._side == 'front': W = rgt.vec_inds['cp_prim'][::-1,:2,:] N = top.vec_inds['cp_prim'][:,:2,:] E = lft.vec_inds['cp_prim'][:,:2,:] S = bot.vec_inds['cp_prim'][::-1,:2,:] elif self._side == 'rear': E = rgt.vec_inds['cp_prim'][::-1,-1:-3:-1,:] N = top.vec_inds['cp_prim'][::-1,-1:-3:-1,:] W = lft.vec_inds['cp_prim'][:,-1:-3:-1,:] S = bot.vec_inds['cp_prim'][:,-1:-3:-1,:] nD = 0 nD += 3 * 2 * num_v + 3 * 2 * (num_u - 2) nD += 3 * 8 * (num_v - 3 + num_u - 3) nD += 3 * 8 Da, Di, Dj = PGMlib.computeconewireframe(nD, num_u, num_v, 1.0, self._weight, W, E, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = super(PGMcone, self).compute(name) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) return Das + [Da], Dis + [Di], Djs + [Dj] elif name == 'cp_coons': #If we are at the cp_coons step... nD = 3 * 8 * 4 * ((num_u-1)/2 -1) * ((num_v-1)/2 -1) Da, Di, Dj = PGMlib.computeconecoons(nD, num_u, num_v, face.vec_inds['cp_coons']) Das, Dis, Djs = super(PGMcone, self).compute(name) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) return Das + [Da], Dis + [Di], Djs + [Dj]
def updateQs(self): Qs = self.Qs Ns = self.Ns oml0 = self.oml0 for f in range(len(Ns)): PGMlib.updateqs(oml0.nQ, Ns[f].shape[0], Ns[f].shape[1], Ns[f], Qs[f], oml0.Q)
def setDerivatives(self, var, dV0): nf = len(self.Qs) nv = self.dQs_dv[0].shape[1] n = self.Qs[0].shape[1] dV = numpy.zeros(nv) if var=='scl': dV[:3*n] = dV0.T.flatten() for f in range(nf): ni, nj = self.Qs[f].shape[:2] self.Qs[f][:,:,:] += PGMlib.inflatevector(ni, nj, 3*ni*nj, self.dQs_dv[f].dot(dV)) elif var=='pos': dV[3*n:6*n] = dV0.T.flatten() for f in range(nf): ni, nj = self.Qs[f].shape[:2] for i in range(ni): self.Qs[f][i,:,:] += dV0 self.Qs[f][:,:,:] += PGMlib.inflatevector(ni, nj, 3*ni*nj, self.dQs_dv[f].dot(dV)) elif var=='rot': dV[6*n:9*n] = dV0.T.flatten() for f in range(nf): ni, nj = self.Qs[f].shape[:2] self.Qs[f][:,:,:] += PGMlib.inflatevector(ni, nj, 3*ni*nj, self.dQs_dv[f].dot(dV)*numpy.pi/180.0) else: self.variables[var] += dV0 self.computeQs() self.variables[var] -= dV0
def computeStructure(self, P): oml0 = self.oml0 Ms = self.Ms Js = self.Js layout = self.layout skinIndices = self.getSkinIndices() C = numpy.zeros((4,2),order='F') As = [] Jns = [] Jus = [] col = 0 for s in range(len(skinIndices)): n = max(self.quad_indices[:,s])*self.layout.n**2 Aa = numpy.ones(n) Ai = numpy.linspace(0, n-1, n) Aj = numpy.linspace(0, n-1, n) + col As.append(scipy.sparse.csr_matrix((Aa,(Ai,Aj)), shape=(n,P.shape[0]))) Jn = [] Ju = [] col += n for f in skinIndices[s]: for k in range(Js[f].shape[0]): C[0,:] = oml0.C[Ms[f][Js[f][k,0],Js[f][k,1]],:2] C[1,:] = oml0.C[Ms[f][Js[f][k,0],Js[f][k,3]],:2] C[2,:] = oml0.C[Ms[f][Js[f][k,2],Js[f][k,1]],:2] C[3,:] = oml0.C[Ms[f][Js[f][k,2],Js[f][k,3]],:2] nu1, nu2, nv1, nv2 = layout.countJunctionEdges(self.JQs[s], min(C[:,0]), max(C[:,0]), min(C[:,1]), max(C[:,1])) Jn.append([nu1, nu2, nv1, nv2]) Ju.append([min(C[:,0]), max(C[:,0]), min(C[:,1]), max(C[:,1])]) nP = layout.n*(nu1 + nu2 + nv1 + nv2) col += nP if Jn==[]: Jn.append([-1,-1,-1,-1]) Ju.append([-1,-1,-1,-1]) Jns.append(numpy.array(Jn, int, order='F')) Jus.append(numpy.array(Ju, order='F')) nM = len(self.keys) members = numpy.zeros((nM,34),order='F') for i in range(nM): member = self.members[self.keys[i]] members[i,:4] = [member.domain, member.shape, member.nmem, member.ndiv] members[i, 4:16] = member.A1 + member.B1 + member.C1 + member.D1 members[i,16:28] = member.A2 + member.B2 + member.C2 + member.D2 members[i,28:] = [member.tx, member.ty, member.rx, member.ry, member.n1, member.n2] nP, nS = PGMlib.countinternalnodes(self.layout.n, nM, members) P2, M, S = PGMlib.computeinternalnodes(nP, nS, self.layout.n, nM, members) nA = PGMlib.countannz(nP, layout.nvert, layout.nquad, layout.verts, layout.poly_vert, self.quad_indices, P2, M) if len(skinIndices)==1: Aa, Ai, Aj = PGMlib.assembleamtx(nA, self.layout.n, nP, Jns[0].shape[0], Jns[0].shape[0], self.layout.nvert, self.layout.nquad, Jns[0], Jns[0], Jus[0], Jus[0], self.quad_indices, self.layout.verts, self.layout.poly_vert, P2, M) else: Aa, Ai, Aj = PGMlib.assembleamtx(nA, self.layout.n, nP, Jns[0].shape[0], Jns[1].shape[0], self.layout.nvert, self.layout.nquad, Jns[0], Jns[1], Jus[0], Jus[1], self.quad_indices, self.layout.verts, self.layout.poly_vert, P2, M) As.append(scipy.sparse.csr_matrix((Aa,(Ai,Aj)), shape=(max(Ai)+1,P.shape[0]))) return As, S
def compute(self, name): if name == 'cp_prim': theta1 = { 'rgt': -1 / 4.0, 'top': 1 / 4.0, 'lft': 3 / 4.0, 'bot': 5 / 4.0, } theta2 = { 'rgt': 1 / 4.0, 'top': 3 / 4.0, 'lft': 5 / 4.0, 'bot': 7 / 4.0, } flt = self.props['flt'].vec_data['prop'] for fname in self.faces: face = self.faces[fname] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] self._shapes[fname][:,:,:] \ = PGMlib.computeshape(num_u, num_v, theta1[fname], theta2[fname], numpy.ones((num_v, 3), order='F'), flt, numpy.zeros((num_u, num_v), order='F')) return super(PGMbody, self).compute(name)
def compute(self, name): if name == 'cp_prim': #If we are at the cp_prim step... return super(PGMtip, self).compute(name) #Call the function that sets up the normal properties elif name == 'cp_bez': #If we are at the cp_bez step... upp = self._comp.faces['upp'] low = self._comp.faces['low'] face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] # print 'here: ', num_u, num_v if self._side == 'right': N = upp.vec_inds['cp_prim'][:,:2,:] S = low.vec_inds['cp_prim'][::-1,:2,:] elif self._side == 'left': N = upp.vec_inds['cp_prim'][::-1,-1:-3:-1,:] S = low.vec_inds['cp_prim'][:,-1:-3:-1,:] nD = 3 * 2 * num_v + 3 * 4 * (num_u-2) * num_v Da, Di, Dj = PGMlib.computetip(nD, num_u, num_v, self._weight, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = super(PGMtip, self).compute(name) return Das + [Da], Dis + [Di], Djs + [Dj] #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) elif name == 'cp_coons': #If we are at the cp_coons step... return super(PGMtip, self).compute(name) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py)
def compute(self, name): upp = self._comp.faces['upp'] low = self._comp.faces['low'] face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if self._side == 'right': N = upp.vec_inds['cp_prim'][:,:2,:] S = low.vec_inds['cp_prim'][::-1,:2,:] elif self._side == 'left': N = upp.vec_inds['cp_prim'][::-1,-1:-3:-1,:] S = low.vec_inds['cp_prim'][:,-1:-3:-1,:] nD = 3 * 2 * num_v + 3 * 4 * (num_u-2) * num_v Da, Di, Dj = PGMlib.computetip(nD, num_u, num_v, self._weight, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = [Da], [Di], [Dj] if name == 'cp_bez': return Das, Dis, Djs elif name == 'cp_coons': return Das, Dis, Djs elif name == 'cp_prim': return [], [], []
def compute(self, name): if name == 'cp_prim': #If we are at the cp_prim step... return super(PGMtip, self).compute(name) #Call the function that sets up the normal properties elif name == 'cp_bez': #If we are at the cp_bez step... upp = self._comp.faces['upp'] low = self._comp.faces['low'] face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if self._side == 'right': N = upp.vec_inds['cp_prim'][:,:2,:] S = low.vec_inds['cp_prim'][::-1,:2,:] elif self._side == 'left': N = upp.vec_inds['cp_prim'][::-1,-1:-3:-1,:] S = low.vec_inds['cp_prim'][:,-1:-3:-1,:] nD = 3 * 2 * num_v + 3 * 4 * (num_u-2) * num_v Da, Di, Dj = PGMlib.computetip(nD, num_u, num_v, self._weight, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = super(PGMtip, self).compute(name) return Das + [Da], Dis + [Di], Djs + [Dj] #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) elif name == 'cp_coons': #If we are at the cp_coons step... return super(PGMtip, self).compute(name) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py)
def compute(self, name): upp = self._comp.faces['upp'] low = self._comp.faces['low'] face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if self._side == 'right': N = upp.vec_inds['cp_prim'][:, :2, :] S = low.vec_inds['cp_prim'][::-1, :2, :] elif self._side == 'left': N = upp.vec_inds['cp_prim'][::-1, -1:-3:-1, :] S = low.vec_inds['cp_prim'][:, -1:-3:-1, :] nD = 3 * 2 * num_v + 3 * 4 * (num_u - 2) * num_v Da, Di, Dj = PGMlib.computetip(nD, num_u, num_v, self._weight, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = [Da], [Di], [Dj] if name == 'cp_bez': return Das, Dis, Djs elif name == 'cp_coons': return Das, Dis, Djs elif name == 'cp_prim': return [], [], []
def compute(self, name): if name == 'cp_prim': theta1 = {'rgt': -1/4.0, 'top': 1/4.0, 'lft': 3/4.0, 'bot': 5/4.0, } theta2 = {'rgt': 1/4.0, 'top': 3/4.0, 'lft': 5/4.0, 'bot': 7/4.0, } flt = self.props['flt'].vec_data['prop'] for fname in self.faces: face = self.faces[fname] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] self._shapes[fname][:,:,:] \ = PGMlib.computeshape(num_u, num_v, theta1[fname], theta2[fname], numpy.ones((num_v, 3), order='F'), flt) return super(PGMbody, self).compute(name)
def addFace(self, du, dv, d, ru=0.5, rv=0.5): """ Creates a set of rectangular surfaces, their IDs, and face dims. nu,nv: number of surfaces in the u and v directions du,dv: {1,2,3} maps to {x,y,z}; negative sign means reverse order d: position of the surfaces in the remaining coordinate axis ru,rv: surfaces span -ru to +ru in u dir. and -rv to +rv in v dir. Adds to self.Ps and self.Ks """ self.faces.append([du,dv]) nP = 10 ni = self.ms[abs(du)-1].shape[0] nj = self.ms[abs(dv)-1].shape[0] verts = numpy.zeros((2,2,3),order='F') verts[:,:,:] = d verts[0,:,abs(du)-1] = -ru*numpy.sign(du) verts[1,:,abs(du)-1] = ru*numpy.sign(du) verts[:,0,abs(dv)-1] = -rv*numpy.sign(dv) verts[:,1,abs(dv)-1] = rv*numpy.sign(dv) for j in range(nj): for i in range(ni): self.Ps.append(PGMlib.bilinearinterp(nP, ni, nj, i+1, j+1, verts)) if len(self.Ks) > 0: counter = numpy.max(self.Ks[-1]) + 1 else: counter = 0 K = numpy.zeros((ni,nj),int) for j in range(nj): for i in range(ni): K[i,j] = counter counter += 1 self.Ks.append(K) self.outers.append(numpy.ones((ni,nj),bool))
def computeQs(self): nx = self.Qs[0].shape[1] ny = self.Qs[0].shape[0] nz = self.Qs[1].shape[0] v = self.variables b = self.bottom==2 #v['pos'][0] = 2*v['pos'][1] - v['pos'][2] #v['pos'][-1] = 2*v['pos'][-2] - v['pos'][-3] shapes = range(4) shapes[0] = PGMlib.computeshape(ny, nx,-b/4.0, 1/4.0, v['flt'], v['shR']) shapes[1] = PGMlib.computeshape(nz, nx, 1/4.0, 3/4.0, v['flt'], v['shT']) shapes[2] = PGMlib.computeshape(ny, nx, 3/4.0, (4+b)/4.0, v['flt'], v['shL']) shapes[3] = PGMlib.computeshape(nz, nx, 5/4.0, 7/4.0, v['flt'], v['shB']) nQ = nx*(9+6*ny+6*nz) if self.bottom==2 else nx*(9+6*ny+3*nz) self.computeSections(nQ, shapes)
def compute(self, name): face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if name == 'cp_prim': #If we are at the cp_prim step... return super(PGMcone, self).compute( name) #Call the function that sets up the normal properties elif name == 'cp_bez': #If we are at the cp_bez step... rgt = self._comp.faces['rgt'] top = self._comp.faces['top'] lft = self._comp.faces['lft'] bot = self._comp.faces['bot'] if self._side == 'front': W = rgt.vec_inds['cp_prim'][::-1, :2, :] N = top.vec_inds['cp_prim'][:, :2, :] E = lft.vec_inds['cp_prim'][:, :2, :] S = bot.vec_inds['cp_prim'][::-1, :2, :] elif self._side == 'rear': E = rgt.vec_inds['cp_prim'][::-1, -1:-3:-1, :] N = top.vec_inds['cp_prim'][::-1, -1:-3:-1, :] W = lft.vec_inds['cp_prim'][:, -1:-3:-1, :] S = bot.vec_inds['cp_prim'][:, -1:-3:-1, :] nD = 0 nD += 3 * 2 * num_v + 3 * 2 * (num_u - 2) nD += 3 * 8 * (num_v - 3 + num_u - 3) nD += 3 * 8 Da, Di, Dj = PGMlib.computeconewireframe(nD, num_u, num_v, 1.0, self._weight, W, E, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = super(PGMcone, self).compute( name ) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) return Das + [Da], Dis + [Di], Djs + [Dj] elif name == 'cp_coons': #If we are at the cp_coons step... nD = 3 * 8 * 4 * ((num_u - 1) / 2 - 1) * ((num_v - 1) / 2 - 1) Da, Di, Dj = PGMlib.computeconecoons(nD, num_u, num_v, face.vec_inds['cp_coons']) Das, Dis, Djs = super(PGMcone, self).compute( name ) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) return Das + [Da], Dis + [Di], Djs + [Dj]
def compute(self, name): props = self.props if name == 'cp_prim': data = {} inds = {} for pname in ['pos', 'rot', 'nor', 'ogn', 'scl']: data[pname] = props[pname].vec_data['prop'] inds[pname] = props[pname].vec_inds['prop'] vals_list, rows_list, cols_list = [], [], [] for fname in self.faces: face = self.faces[fname] sh_data = {} sh_inds = {} pnames = ['shX', 'shY', 'shZ'] for ind in xrange(3): pname = pnames[ind] sh_data[pname] \ = props[pname, fname].vec_data['prop'] \ + self._shapes[fname][:, :, ind] sh_inds[pname] \ = props[pname, fname].vec_inds['prop'] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] cp_data = face.vec_data['cp_prim'] cp_inds = face.vec_inds['cp_prim'] nnz = num_u*num_v*3*3*6 cp_data[:, :, :], vals, rows, cols \ = PGMlib.computesections(self._ax1, self._ax2, num_u, num_v, nnz, data['ogn'], data['nor'], data['pos'], data['rot'], data['scl'], sh_data['shX'], sh_data['shY'], sh_data['shZ'], inds['ogn'], inds['nor'], inds['pos'], inds['rot'], inds['scl'], sh_inds['shX'], sh_inds['shY'], sh_inds['shZ'], cp_inds) vals_list.append(vals) rows_list.append(rows) cols_list.append(cols) return vals_list, rows_list, cols_list elif name == 'cp_bez' or name == 'cp_coons': vals_list, rows_list, cols_list = [], [], [] for face in self.faces.values(): num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] vals = numpy.ones(3 * num_u * num_v) inds = face.vec_inds['cp_prim'].flatten() vals_list.append(vals) rows_list.append(inds) cols_list.append(inds) return vals_list, rows_list, cols_list
def compute(self, name): if name == 'cp_prim': theta1 = { 'rt0': -1 / 4.0, 'tp0': 1 / 4.0, 'lt0': 3 / 4.0, 'bt0': 5 / 4.0, 'rt1': 1 / 4.0, 'tp1': 3 / 4.0, 'lt1': 5 / 4.0, 'bt1': 7 / 4.0, } theta2 = { 'rt0': 1 / 4.0, 'tp0': 3 / 4.0, 'lt0': 5 / 4.0, 'bt0': 7 / 4.0, 'rt1': -1 / 4.0, 'tp1': 1 / 4.0, 'lt1': 3 / 4.0, 'bt1': 5 / 4.0, } flt = self.props['flt'].vec_data['prop'] thk = self.props['thk'].vec_data['prop'] for fname in self.faces: face = self.faces[fname] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if fname[2] == '0': sgn = 1.0 elif fname[2] == '1': sgn = -1.0 self._shapes[fname][:,:,:] \ = PGMlib.computeshape(num_u, num_v, theta1[fname], theta2[fname], numpy.ones((num_v, 3), order='F') + sgn*thk/2.0, flt, numpy.zeros((num_u, num_v), order='F')) output = super(PGMshell, self).compute(name) for fname in ['rt', 'tp', 'lt', 'bt']: for ind in range(2): outer = self.faces[fname + '0'].vec_data['cp_prim'][:, -ind, :] inner = self.faces[fname + '1'].vec_data['cp_prim'][::-1, -ind, :] outer[:, :] = 0.5 * (outer + inner) inner[:, :] = outer[:, :] return output else: return super(PGMshell, self).compute(name)
def compute(self, name): props = self.props if name == 'cp_prim': data = {} inds = {} for pname in ['pos', 'rot', 'nor', 'ogn', 'scl']: data[pname] = props[pname].vec_data['prop'] inds[pname] = props[pname].vec_inds['prop'] vals_list, rows_list, cols_list = [], [], [] for fname in self.faces: face = self.faces[fname] sh_data = {} sh_inds = {} pnames = ['shX', 'shY', 'shZ'] for ind in xrange(3): pname = pnames[ind] sh_data[pname] \ = props[pname, fname].vec_data['prop'] \ + self._shapes[fname][:, :, ind] sh_inds[pname] \ = props[pname, fname].vec_inds['prop'] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] cp_data = face.vec_data['cp_prim'] cp_inds = face.vec_inds['cp_prim'] nnz = num_u * num_v * 3 * 3 * 6 cp_data[:, :, :], vals, rows, cols \ = PGMlib.computesections(self._ax1, self._ax2, num_u, num_v, nnz, data['ogn'], data['nor'], data['pos'], data['rot'], data['scl'], sh_data['shX'], sh_data['shY'], sh_data['shZ'], inds['ogn'], inds['nor'], inds['pos'], inds['rot'], inds['scl'], sh_inds['shX'], sh_inds['shY'], sh_inds['shZ'], cp_inds) vals_list.append(vals) rows_list.append(rows) cols_list.append(cols) return vals_list, rows_list, cols_list elif name == 'cp_bez' or name == 'cp_coons': vals_list, rows_list, cols_list = [], [], [] for face in self.faces.values(): num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] vals = numpy.ones(3 * num_u * num_v) inds = face.vec_inds['cp_prim'].flatten() vals_list.append(vals) rows_list.append(inds) cols_list.append(inds) return vals_list, rows_list, cols_list
def computeSections(self, nQ, shapes, radii=None): nf = len(self.Qs) n = self.Qs[0].shape[1] v = self.variables rot0, Da, Di, Dj = PGMlib.computerotations(self.ax1, self.ax2, n, 9*(n*3-2), v['pos'], v['nor']) rot = v['rot']*numpy.pi/180.0 + rot0 dv_dpos0 = scipy.sparse.csc_matrix((Da,(Di+6*n,Dj+3*n)),shape=(nQ,nQ)) self.dQs_dv = range(nf) counter = 0 for f in range(nf): if radii==None: scale = v['scl'] else: scale = radii[f] ni, nj = self.Qs[f].shape[:2] self.Qs[f][:,:,:], Da, Di, Dj = PGMlib.computesections(self.ax1, self.ax2, ni, nj, ni*nj*27, counter, v['ogn'], scale, v['pos'], rot, shapes[f]) self.dQs_dv[f] = scipy.sparse.csc_matrix((Da,(Di,Dj)),shape=(3*ni*nj,nQ)) self.dQs_dv[f] = self.dQs_dv[f] + self.dQs_dv[f].dot(dv_dpos0) counter += 3*ni*nj
def compute(self, name): rgt = self._comp.faces['rgt'] top = self._comp.faces['top'] lft = self._comp.faces['lft'] bot = self._comp.faces['bot'] face = self.faces[''] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if self._side == 'front': W = rgt.vec_inds['cp_prim'][::-1,:2,:] N = top.vec_inds['cp_prim'][:,:2,:] E = lft.vec_inds['cp_prim'][:,:2,:] S = bot.vec_inds['cp_prim'][::-1,:2,:] elif self._side == 'rear': E = rgt.vec_inds['cp_prim'][::-1,-1:-3:-1,:] N = top.vec_inds['cp_prim'][::-1,-1:-3:-1,:] W = lft.vec_inds['cp_prim'][:,-1:-3:-1,:] S = bot.vec_inds['cp_prim'][:,-1:-3:-1,:] nD = 0 nD += 3 * 2 * num_v + 3 * 2 * (num_u - 2) nD += 3 * 8 * (num_v - 3 + num_u - 3) nD += 3 * 8 Da, Di, Dj = PGMlib.computeconewireframe(nD, num_u, num_v, 1.0, self._weight, W, E, N, S, face.vec_inds['cp_bez']) Das, Dis, Djs = [Da], [Di], [Dj] if name == 'cp_bez': return Das, Dis, Djs elif name == 'cp_coons': nD = 3 * 8 * 4 * ((num_u-1)/2 -1) * ((num_v-1)/2 -1) Da, Di, Dj = PGMlib.computeconecoons(nD, num_u, num_v, face.vec_inds['cp_coons']) Das.append(Da) Dis.append(Di) Djs.append(Dj) return Das, Dis, Djs elif name == 'cp_prim': return [], [], []
def compute(self, name): if name == 'cp_prim': theta1 = {'rt0': -1/4.0, 'tp0': 1/4.0, 'lt0': 3/4.0, 'bt0': 5/4.0, 'rt1': 1/4.0, 'tp1': 3/4.0, 'lt1': 5/4.0, 'bt1': 7/4.0, } theta2 = {'rt0': 1/4.0, 'tp0': 3/4.0, 'lt0': 5/4.0, 'bt0': 7/4.0, 'rt1': -1/4.0, 'tp1': 1/4.0, 'lt1': 3/4.0, 'bt1': 5/4.0, } flt = self.props['flt'].vec_data['prop'] thk = self.props['thk'].vec_data['prop'] for fname in self.faces: face = self.faces[fname] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] if fname[2] == '0': sgn = 1.0 elif fname[2] == '1': sgn = -1.0 self._shapes[fname][:,:,:] \ = PGMlib.computeshape(num_u, num_v, theta1[fname], theta2[fname], numpy.ones((num_v, 3), order='F') + sgn*thk/2.0, flt, numpy.zeros((num_u, num_v), order='F')) output = super(PGMshell, self).compute(name) for fname in ['rt', 'tp', 'lt', 'bt']: for ind in range(2): outer = self.faces[fname+'0'].vec_data['cp_prim'][:, -ind, :] inner = self.faces[fname+'1'].vec_data['cp_prim'][::-1, -ind, :] outer[:, :] = 0.5 * (outer + inner) inner[:, :] = outer[:, :] return output else: return super(PGMshell, self).compute(name)
def compute(self, name): # print name if name == 'cp_prim': #x = 0.22 # 0.16 (small) <-> 0.25 (ini) x_top = 0.18 x_bot = 0.22 #0.1 # 0.0 <-> 0.5 theta1 = { 'rgt': -x_bot, #-1/6.0, # -0.5 + x, 'top': x_top, #1/6.0, # 1/3.0, 'lft': 1.0 - x_top, #5/6.0, # 2/3.0, 'bot': 1.0 + x_bot, #7/6.0, # 1.5 - x, } theta2 = { 'rgt': x_top, #1/6.0, # 1/3.0, 'top': 1.0 - x_top, #5/6.0, # 2/3.0, 'lft': 1.0 + x_bot, #7/6.0, # 1.5 - x, 'bot': 2.0 - x_bot, #11/6.0, # 1.5 + x, } # theta1 = {'rgt': -1/4.0, # 'top': 1/4.0, # 'lft': 3/4.0, # 'bot': 5/4.0, # } # theta2 = {'rgt': 1/4.0, # 'top': 3/4.0, # 'lft': 5/4.0, # 'bot': 7/4.0, # } flt = self.props['flt'].vec_data['prop'] for fname in self.faces: # print fname face = self.faces[fname] num_u = face._num_cp_total['u'] num_v = face._num_cp_total['v'] self._shapes[fname][:,:,:] \ = PGMlib.computeshape(num_u, num_v, theta1[fname], theta2[fname], numpy.ones((num_v, 3), order='F'), flt) return super(PGMbody, self).compute(name)
def compute(self, name): order = self._order num_cp = self._num_cp num_pt = self._num_pt pos = self._pos cp_indices = self.vec_inds['param'] pt_indices = self._prop.vec_inds['prop'] nnz = num_pt['u'] * num_pt['v'] * order['u'] * order['v'] vals, rows, cols \ = PGMlib.computebspline(nnz, order['u'], order['v'], num_cp['u'], num_cp['v'], num_pt['u'], num_pt['v'], cp_indices, pt_indices, pos['u'], pos['v']) return [vals], [rows], [cols]
def createSurfaces(self, Ks, nu, nv, du, dv, d): Ps = [] for j in range(len(nv)): for i in range(len(nu)): u1 = (sum(nu[:i])-i)/(sum(nu)-len(nu)) u2 = (sum(nu[:i+1])-i-1)/(sum(nu)-len(nu)) v1 = (sum(nv[:j])-j)/(sum(nv)-len(nv)) v2 = (sum(nv[:j+1])-j-1)/(sum(nv)-len(nv)) P = PGMlib.createsurfaces(nu[i],nv[j],du,dv,d,u1,u2,v1,v2) Ps.append(P) K = numpy.zeros((len(nu),len(nv)),int) counter = 0 if len(Ks) > 0: counter = numpy.max(Ks[-1]) + 1 for j in range(len(nv)): for i in range(len(nu)): K[i,j] = counter counter += 1 return Ps, K
def computeQs(self): nx = self.Qs[0].shape[1] ny = self.Qs[0].shape[0] nz = self.Qs[1].shape[0] v = self.variables b = self.bottom==2 r0 = v['scl'] + v['thk']/2.0 r1 = v['scl'] - v['thk']/2.0 shapes = range(8) shapes[0] = PGMlib.computeshape(ny, nx,-b/4.0, 1/4.0, v['flt'], v['sR0']) shapes[1] = PGMlib.computeshape(nz, nx, 1/4.0, 3/4.0, v['flt'], v['sT0']) shapes[2] = PGMlib.computeshape(ny, nx, 3/4.0, (4+b)/4.0, v['flt'], v['sL0']) shapes[6] = PGMlib.computeshape(nz, nx, 5/4.0, 7/4.0, v['flt'], v['sB0']) shapes[5] = PGMlib.computeshape(ny, nx, 1/4.0,-b/4.0, v['flt'], v['sR1']) shapes[4] = PGMlib.computeshape(nz, nx, 3/4.0, 1/4.0, v['flt'], v['sT1']) shapes[3] = PGMlib.computeshape(ny, nx, (4+b)/4.0, 3/4.0, v['flt'], v['sL1']) shapes[7] = PGMlib.computeshape(nz, nx, 7/4.0, 5/4.0, v['flt'], v['sB1']) nQ = nx*(9+12*ny+12*nz) if self.bottom==2 else nx*(9+12*ny+6*nz) radii = [r0,r0,r0,r1,r1,r1,r0,r1] self.computeSections(nQ, shapes, radii=radii)
def computeQs(self): fu = self.fComp.getms(self.fFace,0) fv = self.fComp.getms(self.fFace,1) fu,fv = self.flip(fu,fv) fu1 = sum(fu[:self.fNW[0]]) fu2 = sum(fu[:self.fNW[0]+self.si[3]]) fv1 = sum(fv[:self.fNW[1]]) fv2 = sum(fv[:self.fNW[1]+self.sj[3]]) fQ = self.rotate(self.fComp.Qs[self.fFace])[fu1:fu2+1,fv1:fv2+1,:] getEdge = self.getEdge if self.mSide==-1: W = getEdge(self.mComp.Qs[2], i=-1, d=1) E = getEdge(self.mComp.Qs[0], i=0, d=1) N = getEdge(self.mComp0.Qs[0], i=-1, d=-1) S = getEdge(self.mComp1.Qs[0], i=-1, d=1) elif self.mSide==0: W = numpy.zeros((1,2,3),order='F') E = numpy.zeros((1,2,3),order='F') N = getEdge(self.mComp.Qs[0], j=0, d=-1) S = getEdge(self.mComp.Qs[1], j=0, d=1) elif self.mSide==1: W = numpy.zeros((1,2,3),order='F') E = numpy.zeros((1,2,3),order='F') N = getEdge(self.mComp.Qs[0], j=-1, d=1) S = getEdge(self.mComp.Qs[1], j=-1, d=-1) mu = self.getms(0,0) mv = self.getms(0,1) nu = range(3) nv = range(3) for k in range(3): nu[k] = sum(mu[self.si[k]:self.si[k+1]]) + 1 nv[k] = sum(mv[self.sj[k]:self.sj[k+1]]) + 1 v = self.variables self.Qs[0] = PGMlib.computejunction(sum(nu)-2, sum(nv)-2, nu[0], nu[1], nu[2], nv[0], nv[1], nv[2], v['fC1'], v['mC1'], W, E, N, S, fQ, v['shp'])
def initializeSurfaces(self): def get(P, u, v, d): edge = P[u,:,:] if not u==None else P[:,v,:] return edge if d==1 else edge[::-1,:] getM = lambda f, i, j: self.mComp.Ps[self.mComp.Ks[f][i,j]] getI = lambda i, j: self.Ps[self.Ks[0][i,j]] getF = lambda i, j: self.rotate(self.fComp.Ps[self.fK[i,j]]) def copy(iI, jI, fM, iM, jM, uI=None, vI=None, uM=None, vM=None, d=1): edgeI = get(getI(iI, jI), uI, vI, 1) edgeM = get(getM(fM, iM, jM), uM, vM, d) edgeI[:,:] = edgeM[:,:] def copy2(i, j, u=None, v=None): edgeI = get(getI(i, j), u, v, 1) edgeF = get(getF(i, j), u, v, 1) edgeI[:,:] = edgeF[:,:] verts = self.initializeVerts() nP = self.nP ni = self.ni nj = self.nj si = self.si sj = self.sj self.Ps = [] self.Ks = [-numpy.ones((si[3],sj[3]),int)] counter = 0 for j in range(sj[3]): for i in range(si[3]): if i<si[1] or j<sj[1] or i>=si[2] or j>=sj[2]: self.Ps.append(numpy.zeros((nP,nP,3),order='F')) self.Ks[0][i,j] = counter counter += 1 for b in range(3): for a in range(3): for j in range(nj[b]): jj = sj[b] + j for i in range(ni[a]): ii = si[a] + i if not self.Ks[0][ii,jj]==-1: self.Ps[self.Ks[0][ii,jj]][:,:,:] = PGMlib.bilinearinterp(nP, ni[a], nj[b], i+1, j+1, verts[a:a+2,b:b+2,:]) for i in [0,-1]: for j in range(self.Ks[0].shape[1]): copy2(i, j, u=i) for j in [0,-1]: for i in range(self.Ks[0].shape[0]): copy2(i, j, v=j) if not self.mSide==-1: mComp = self.mComp ii = si[1] - 1 for j in range(nj[1]): jj = sj[1] + j if self.mSide==0: copy(ii, jj, 0, -1-j, 0, uI=-1, vM=0, d=-1) else: copy(ii, jj, 0, j, -1, uI=-1, vM=-1, d=1) ii = si[2] for j in range(nj[1]): jj = sj[1] + j if self.mSide==0: copy(ii, jj, 1, j, 0, uI=0, vM=0, d=1) else: copy(ii, jj, 1, -1-j, -1, uI=0, vM=-1, d=-1)
def compute(self, name): loc = self._loc fu = self._fcomp._num_cp_list['u'] fv = self._fcomp._num_cp_list['v'] fu, fv = self._flip(fu, fv) fu1 = sum(fu[:loc['u']]) fu2 = sum(fu[:loc['u'] + 2]) fv1 = sum(fv[:loc['v']]) fv2 = sum(fv[:loc['v'] + 2 + self._num_surf_wing]) fFace_inds = self._rotate(self._fcomp.vec_inds['cp_bez']) fFace_inds = fFace_inds[fu1:fu2 + 1, fv1:fv2 + 1] mcomp = self._mcomp if self._side == 'right': W = numpy.zeros((4, 2, 3), order='F') E = numpy.zeros((4, 2, 3), order='F') N = mcomp.faces['upp'].vec_inds['cp_prim'][::-1, :2, :] S = mcomp.faces['low'].vec_inds['cp_prim'][:, :2, :] elif self._side == 'left': W = numpy.zeros((4, 2, 3), order='F') E = numpy.zeros((4, 2, 3), order='F') N = mcomp.faces['upp'].vec_inds['cp_prim'][:, -1:-3:-1, :] S = mcomp.faces['low'].vec_inds['cp_prim'][::-1, -1:-3:-1, :] num_u = [fu[loc['u']] + 1, 4, fu[loc['u'] + 1] + 1] num_v = [ fv[loc['v']] + 1, sum(fv[loc['v'] + 1:loc['v'] + 1 + self._num_surf_wing]) + 1, fv[loc['v'] + 1 + self._num_surf_wing] + 1 ] nu0 = sum(num_u) - 2 nv0 = sum(num_v) - 2 fInds = -numpy.ones((nu0, nv0, 3), dtype=int, order='F') fInds[:num_u[0], :] = fFace_inds[:num_u[0], :] fInds[-num_u[2]:, :] = fFace_inds[-num_u[2]:, :] nD = 3 * 2 * nv0 + 3 * 2 * (nu0 - 2) nD += 3 * 2 if num_u[1] != 1: nD += 3 * 2 nD += 3 * 2 * (num_v[1] - 2) if num_u[1] != 1: nD += 3 * 2 * (num_u[1] - 2) nD += 3 * 4 * 2 * (num_u[0] - 2) nD += 3 * 4 * 2 * (num_u[2] - 2) nD += 3 * 4 * (num_v[0] - 2) nD += 3 * 4 * (num_v[2] - 2) if num_u[1] != 1: nD += 3 * 4 * (num_v[0] - 2) nD += 3 * 4 * (num_v[2] - 2) Da, Di, Dj = PGMlib.computejunctionwireframe( nD, nu0, nv0, num_u[0], num_u[1], num_u[2], num_v[0], num_v[1], num_v[2], self._fweight, self._mweight, W, E, N, S, fInds, self.faces[''].vec_inds['cp_bez']) Da = Da * (-1 != Dj) Dj = numpy.maximum(0, Dj) Das, Dis, Djs = [Da], [Di], [Dj] if name == 'cp_bez': return Das, Dis, Djs elif name == 'cp_coons': nD = 0 for i in range(3): for j in range(3): if (num_u[1] != 1) or (i != 1): nD += 3 * 8 * (num_u[i] - 2) * (num_v[j] - 2) Da, Di, Dj = PGMlib.computejunctioncoons( nD, nu0, nv0, num_u[0], num_u[1], num_u[2], num_v[0], num_v[1], num_v[2], self.faces[''].vec_inds['cp_coons']) Das.append(Da) Dis.append(Di) Djs.append(Dj) return Das, Dis, Djs elif name == 'cp_prim': return [], [], []
def compute(self): mu,mv = self.P.shape[:2] nu,nv = self.shp0 P = self.P Tu,Tv = self.T return PGMlib.computeparameter(mu, mv, nu, nv, P, Tu, Tv)
def createInterface(self, n, edge1, edge2, swap=False): P = PGMlib.createinterface(n, edge1.shape[0], edge1, edge2) if swap: P = numpy.swapaxes(P,0,1) return P
def compute(self, name): loc = self._loc fu = self._fcomp._num_cp_list['u'] ##################################################### if not self._fcomp_other is None: fu = numpy.concatenate((fu, self._fcomp_other._num_cp_list['u']), axis=0) ##################################################### fv = self._fcomp._num_cp_list['v'] fu, fv = self._flip(fu, fv) fu1 = sum(fu[:loc['u']]) fu2 = sum(fu[:loc['u'] + 2]) fv1 = sum(fv[:loc['v']]) fv2 = sum(fv[:loc['v'] + 2 + self._num_surf_wing]) fFace_inds = self._rotate(self._fcomp.vec_inds['cp_bez']) ##################################################### if not self._fcomp_other is None: fFace_inds = numpy.concatenate( (fFace_inds[0:-1], self._rotate(self._fcomp_other.vec_inds['cp_bez'])), axis=0) ##################################################### fFace_inds = fFace_inds[fu1:fu2 + 1, fv1:fv2 + 1] num_u = [fu[loc['u']] + 1, 4, fu[loc['u'] + 1] + 1] num_v = [ fv[loc['v']] + 1, sum(fv[loc['v'] + 1:loc['v'] + 1 + self._num_surf_wing]) + 1, fv[loc['v'] + 1 + self._num_surf_wing] + 1 ] nu0 = sum(num_u) - 2 nv0 = sum(num_v) - 2 if name == 'cp_prim': #If we are at the cp_prim step... return super(PGMjunction, self).compute( name) #Call the function that sets up the normal properties elif name == 'cp_bez': mcomp = self._mcomp if self._side == 'right': W = numpy.zeros((4, 2, 3), order='F') E = numpy.zeros((4, 2, 3), order='F') N = mcomp.faces['upp'].vec_inds['cp_prim'][::-1, :2, :] S = mcomp.faces['low'].vec_inds['cp_prim'][:, :2, :] elif self._side == 'left': W = numpy.zeros((4, 2, 3), order='F') E = numpy.zeros((4, 2, 3), order='F') N = mcomp.faces['upp'].vec_inds['cp_prim'][:, -1:-3:-1, :] S = mcomp.faces['low'].vec_inds['cp_prim'][::-1, -1:-3:-1, :] fInds = -numpy.ones((nu0, nv0, 3), dtype=int, order='F') fInds[:num_u[0], :] = fFace_inds[:num_u[0], :] fInds[-num_u[2]:, :] = fFace_inds[-num_u[2]:, :] nD = 3 * 2 * nv0 + 3 * 2 * (nu0 - 2) nD += 3 * 2 if num_u[1] != 1: nD += 3 * 2 nD += 3 * 2 * (num_v[1] - 2) if num_u[1] != 1: nD += 3 * 2 * (num_u[1] - 2) nD += 3 * 4 * 2 * (num_u[0] - 2) nD += 3 * 4 * 2 * (num_u[2] - 2) nD += 3 * 4 * (num_v[0] - 2) nD += 3 * 4 * (num_v[2] - 2) if num_u[1] != 1: nD += 3 * 4 * (num_v[0] - 2) nD += 3 * 4 * (num_v[2] - 2) Da, Di, Dj = PGMlib.computejunctionwireframe( nD, nu0, nv0, num_u[0], num_u[1], num_u[2], num_v[0], num_v[1], num_v[2], self._fweight, self._mweight, W, E, N, S, fInds, self.faces[''].vec_inds['cp_bez']) Da = Da * (-1 != Dj) Dj = numpy.maximum(0, Dj) Das, Dis, Djs = super(PGMjunction, self).compute( name ) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) return Das + [Da], Dis + [Di], Djs + [Dj] elif name == 'cp_coons': #If we are at the cp_coons step... nD = 0 for i in range(3): for j in range(3): if (num_u[1] != 1) or (i != 1): nD += 3 * 8 * (num_u[i] - 2) * (num_v[j] - 2) Das, Dis, Djs = super(PGMjunction, self).compute( name ) #We will recover identity matrices just to carry over the normal parameters (Check PGMinterpolant.py) Da, Di, Dj = PGMlib.computejunctioncoons( nD, nu0, nv0, num_u[0], num_u[1], num_u[2], num_v[0], num_v[1], num_v[2], self.faces[''].vec_inds['cp_coons']) return Das + [Da], Dis + [Di], Djs + [Dj]