def __constrInputMatrix(self): B = None; k = self.__class__.k for row,obj in zip(self.excPointMatrix,self.objs): E = lil_matrix((obj.Nm*2,self.excPointMatrix.shape[1])) for ep,i in zip(row,xrange(0,len(row))): if ep > 0.0: E[:obj.Nm,i] = spdistr2D(k**2/((1. + obj.b1*k)*obj.h**2),ep[0],ep[1],obj.Nx - 1,obj.Ny - 1,flatten=True)\ if isinstance(obj,Resonator2D) else spdistr1D(k**2/((1. + obj.b1*k)*obj.h),ep,obj.Nm,'lin') B = E if B is None else vstack((B,E)) return B.tocsc()
def __constrInputMatrix(self): B = None; k = self.__class__.k for row,obj in zip(self.excPointMatrix,self.objs): E = lil_matrix((obj.Nm*2,len(self.excPointMatrix[0]))) for ep,i in zip(row,xrange(0,len(row))): if ep > 0.0: E[:obj.Nm,i] = spdistr2D(k**2/((1. + obj.b1*k)*obj.h**2),ep[0],ep[1],obj.Nx - 1,obj.Ny - 1,flatten=True)\ if isinstance(obj,Resonator2D) else spdistr1D(k**2/((1. + obj.b1*k)*obj.h),ep,obj.Nm,'lin') B = E if B is None else vstack((B,E)) return B.tocsc()
def __constrOutputMatrix(self): S = None; k = self.__class__.k for col in self.readoutPointMatrix.T: E = None for rp,obj in zip(col,self.objs): if rp > 0.0: e = spdistr2D(1./k,rp[0],rp[1],obj.Nx - 1,obj.Ny - 1,flatten=True).T\ if isinstance(obj,Resonator2D) else spdistr1D(1./k,rp,obj.Nm,'lin').T E = hstack((e,-e)) if E is None else hstack((E,e,-e)) else: e = lil_matrix((1,obj.Nm*2)) E = e if E is None else hstack((E,e)) S = E if S is None else vstack((S,E)) return S.tocsc()
def __constrOutputMatrix(self): S = None; k = self.__class__.k for col in [list(x) for x in zip(*self.readoutPointMatrix)]: # transpose self.readoutPointMatrix E = None for rp,obj in zip(col,self.objs): if rp > 0.0: e = spdistr2D(1./k,rp[0],rp[1],obj.Nx - 1,obj.Ny - 1,flatten=True).T\ if isinstance(obj,Resonator2D) else spdistr1D(1./k,rp,obj.Nm,'lin').T E = hstack((e,-e)) if E is None else hstack((E,e,-e)) else: e = lil_matrix((1,obj.Nm*2)) E = e if E is None else hstack((E,e)) S = E if S is None else vstack((S,E)) return S.tocsc()
def __constrOutputMatrix(self): S = None k = self.__class__.k for col in [list(x) for x in zip(*self.readoutPointMatrix)]: # transpose self.readoutPointMatrix E = None for rp, obj in zip(col, self.objs): if rp > 0.0: e = ( spdistr2D(1.0 / k, rp[0], rp[1], obj.Nx - 1, obj.Ny - 1, flatten=True).T if isinstance(obj, Resonator2D) else spdistr1D(1.0 / k, rp, obj.Nm, "lin").T ) E = hstack((e, -e)) if E is None else hstack((E, e, -e)) else: e = lil_matrix((1, obj.Nm * 2)) E = e if E is None else hstack((E, e)) S = E if S is None else vstack((S, E)) return S.tocsc()
def __constrStateTransitionMatrix(self): k = self.__class__.k A = None # state transtion block matrix # loop over all rows (i.e. individual objs) and find all connections with other objs for row, i, obj in zip(self.massMatrix, xrange(len(self.objs)), self.objs): fac = 1.0 / (1.0 + obj.b1 * k) fac /= obj.h ** 2 if isinstance(obj, Resonator2D) else obj.h C1_total = csc_matrix((obj.Nm, obj.Nm)) C2_total = csc_matrix((obj.Nm, obj.Nm)) C3_total = {} C4_total = {} A_row = None colInds = np.nonzero(row)[0] # for every connection between obj q and r other objects, construct inter-connection matrices for j in colInds: cpoint_q = self.connPointMatrix[i][j] e_q = ( spdistr2D(1.0, cpoint_q[0], cpoint_q[1], obj.Nx - 1, obj.Ny - 1, flatten=True) if isinstance(obj, Resonator2D) else spdistr1D(1.0, cpoint_q, obj.Nm, "lin") ) # return the row indices of the nonzero entrees in the current col we are looking in row_r = [ ind for ind, item in enumerate([self.massMatrix[q][j] for q in xrange(len(self.massMatrix))]) if item > 0 ] # remove row index of current object and since list must now be of size 1, simply return row index row_r.remove(i) row_r = row_r[0] M = float(self.massMatrix[i][j]) / self.massMatrix[row_r][j] # mass ratio: Mq/Mr cpoint_r = self.connPointMatrix[row_r][j] e_r = ( spdistr2D( 1.0, cpoint_r[0], cpoint_r[1], self.objs[row_r].Nx - 1, self.objs[row_r].Ny - 1, flatten=True ) if isinstance(self.objs[row_r], Resonator2D) else spdistr1D(1.0, cpoint_r, self.objs[row_r].B.shape[0], "lin") ) c1 = fac / (e_q.T.dot(e_q)[0, 0] + M * e_r.T.dot(e_r)[0, 0]) e_qCre_q = e_q * e_q.T e_qCre_r = e_q * e_r.T C1_total = C1_total + c1 * e_qCre_q * obj.C1 C2_total = C2_total + c1 * e_qCre_q * obj.C2 if row_r in C3_total: # save to assert that when C3[row_r] is empty, C4[row_r] is empty also C3_total[row_r] = C3_total[row_r] - c1 * e_qCre_r * self.objs[row_r].C1 C4_total[row_r] = C4_total[row_r] - c1 * e_qCre_r * self.objs[row_r].C2 else: C3_total[row_r] = -c1 * e_qCre_r * self.objs[row_r].C1 C4_total[row_r] = -c1 * e_qCre_r * self.objs[row_r].C2 # construct row of A for u[n] for j in xrange(0, len(self.objs)): if i == j: # we're on the diagonal A_row = ( hstack((obj.B + C1_total, obj.C + C2_total), format="lil") if A_row == None else hstack((A_row, obj.B + C1_total, obj.C + C2_total), format="lil") ) elif j in C3_total: A_row = ( hstack((C3_total[j], C4_total[j]), format="lil") if A_row == None else hstack((A_row, C3_total[j], C4_total[j]), format="lil") ) else: Nm2 = self.objs[j].Nm * 2 A_row = lil_matrix((obj.Nm, Nm2)) if A_row is None else hstack((A_row, lil_matrix((obj.Nm, Nm2)))) # construct row of A for u[n - 1] if i == 0: # first object, so identity matrix is first in row I = hstack((identity(obj.Nm, format="lil"), lil_matrix((obj.Nm, A_row.shape[1] - obj.Nm)))) elif i == len(self.objs) - 1: # last object, so identity matrix is penultimate to last col I = hstack( ( lil_matrix((obj.Nm, A_row.shape[1] - 2 * self.objs[-1].Nm)), identity(obj.Nm, format="lil"), lil_matrix((obj.Nm, obj.Nm)), ) ) else: # if any other object, calc pos of identity matrix based on grid size N of each obj I = hstack( ( lil_matrix((obj.Nm, 2 * np.sum(self.Nt[:i]))), identity(obj.Nm), lil_matrix((obj.Nm, obj.Nm + 2 * np.sum(self.Nt[-(len(self.Nt) - 1 - i) :]))), ) ) # append row to block state transition matrix A A = vstack((A_row, I)) if A is None else vstack((A, A_row, I)) return A.tocsc()
def __constrStateTransitionMatrix(self): k = self.__class__.k A = None # state transtion block matrix # loop over all rows (i.e. individual objs) and find all connections with other objs for row,i,obj in zip(self.massMatrix,xrange(len(self.objs)),self.objs): fac = 1./(1. + obj.b1*k) fac /= obj.h**2 if isinstance(obj,Resonator2D) else obj.h C1_total = csc_matrix((obj.Nm,obj.Nm)); C2_total = csc_matrix((obj.Nm,obj.Nm)) C3_total = {}; C4_total = {}; A_row = None colInds = np.nonzero(row)[0] # for every connection between obj q and r other objects, construct inter-connection matrices for j in colInds: cpoint_q = self.connPointMatrix[i][j] e_q = spdistr2D(1.,cpoint_q[0],cpoint_q[1],obj.Nx - 1,obj.Ny - 1,flatten=True)\ if isinstance(obj,Resonator2D) else spdistr1D(1.,cpoint_q,obj.Nm,'lin') # return the row indices of the nonzero entrees in the current col we are looking in row_r = [ind for ind,item in enumerate([self.massMatrix[q][j] for q in xrange(len(self.massMatrix))]) if item > 0] # remove row index of current object and since list must now be of size 1, simply return row index row_r.remove(i); row_r = row_r[0] M = float(self.massMatrix[i][j])/self.massMatrix[row_r][j] # mass ratio: Mq/Mr cpoint_r = self.connPointMatrix[row_r][j] e_r = spdistr2D(1.,cpoint_r[0],cpoint_r[1],self.objs[row_r].Nx - 1,self.objs[row_r].Ny - 1,flatten=True) \ if isinstance(self.objs[row_r],Resonator2D) \ else spdistr1D(1.,cpoint_r,self.objs[row_r].B.shape[0],'lin') c1 = fac/(e_q.T.dot(e_q)[0,0] + M*e_r.T.dot(e_r)[0,0]) e_qCre_q = e_q*e_q.T; e_qCre_r = e_q*e_r.T C1_total = C1_total + c1*e_qCre_q*obj.C1 C2_total = C2_total + c1*e_qCre_q*obj.C2 if row_r in C3_total: # save to assert that when C3[row_r] is empty, C4[row_r] is empty also C3_total[row_r] = C3_total[row_r] - c1*e_qCre_r*self.objs[row_r].C1 C4_total[row_r] = C4_total[row_r] - c1*e_qCre_r*self.objs[row_r].C2 else: C3_total[row_r] = -c1*e_qCre_r*self.objs[row_r].C1 C4_total[row_r] = -c1*e_qCre_r*self.objs[row_r].C2 # construct row of A for u[n] for j in xrange(0,len(self.objs)): if i == j: # we're on the diagonal A_row = hstack((obj.B + C1_total,obj.C + C2_total),format="lil") if A_row == None else \ hstack((A_row,obj.B + C1_total,obj.C + C2_total),format="lil") elif j in C3_total: A_row = hstack((C3_total[j],C4_total[j]),format="lil") if A_row == None else \ hstack((A_row,C3_total[j],C4_total[j]),format="lil") else: Nm2 = self.objs[j].Nm*2 A_row = lil_matrix((obj.Nm,Nm2)) if A_row is None else \ hstack((A_row,lil_matrix((obj.Nm,Nm2)))) # construct row of A for u[n - 1] if i == 0: # first object, so identity matrix is first in row I = hstack((identity(obj.Nm,format="lil"),lil_matrix((obj.Nm,A_row.shape[1] - obj.Nm)))) elif i == len(self.objs) - 1: # last object, so identity matrix is penultimate to last col I = hstack((lil_matrix((obj.Nm,A_row.shape[1] - 2*self.objs[-1].Nm)),\ identity(obj.Nm,format="lil"),lil_matrix((obj.Nm,obj.Nm)))) else: # if any other object, calc pos of identity matrix based on grid size N of each obj I = hstack((lil_matrix((obj.Nm,2*np.sum(self.Nt[:i]))),identity(obj.Nm),\ lil_matrix((obj.Nm,obj.Nm + 2*np.sum(self.Nt[-(len(self.Nt) - 1 - i):]))))) # append row to block state transition matrix A A = vstack((A_row,I)) if A is None else vstack((A,A_row,I)) return A.tocsc()