def modalSolver(self, nev = 3, ncv = -1, tol = -1, mxiter = -1): if SOLVER == 'default': if ncv < 0: ncv = 4*nev ncv = ncv + nev if tol < 0.: tol = 1e-2 if mxiter < 0: mxiter = 1000. return solver.arpack(self.GK, self.GM, nev, ncv, tol, mxiter) elif SOLVER == 'pysparse': # copy matrixes GK = self.GK A = spmatrix.ll_mat_sym(self.dofcount, len(GK)) # TODO change to scipy for row, col in GK: A[row,col] = GK[row,col] GM = self.GM M = spmatrix.ll_mat_sym(self.dofcount, len(GM)) # TODO change to scipy for row, col in GM: M[row,col] = GM[row,col] # Atau = A + tau*M tau = -1.0 Atau = A.copy() Atau.shift(tau, M) K = precon.jacobi(Atau) # convert to skyline A = A.to_sss() M = M.to_sss() # solve k_conv, lmbd, Q, it, it_innser = \ jdsym.jdsym(A, M, K, nev, tau, 1e-6, 1000, itsolvers.qmrs, jmin=5, jmax=10, clvl=0, strategy=1) # eigen values return lmbd else: raise FEError('unknown solver')
def poisson2d_sym_blk(n): n2 = n*n L = spmatrix.ll_mat_sym(n2, 3*n2-2*n) I = spmatrix.ll_mat_sym(n, n) for i in range(n): I[i,i] = -1 P = spmatrix.ll_mat_sym(n, 2*n-1) for i in range(n): P[i,i] = 4 if i > 0: P[i,i-1] = -1 for i in range(0, n*n, n): L[i:i+n,i:i+n] = P if i > 0: L[i:i+n,i-n:i] = I return L
def poisson1d_sym(n): L = spmatrix.ll_mat_sym(n, 2*n-1) for i in range(n): L[i,i] = 2 if i > 0: L[i,i-1] = -1 return L
def modalSolver(self, nev=3, ncv=-1, tol=-1, mxiter=-1): if SOLVER == 'default': if ncv < 0: ncv = 4 * nev ncv = ncv + nev if tol < 0.: tol = 1e-2 if mxiter < 0: mxiter = 1000. return solver.arpack(self.GK, self.GM, nev, ncv, tol, mxiter) elif SOLVER == 'pysparse': # copy matrixes GK = self.GK A = spmatrix.ll_mat_sym(self.dofcount, len(GK)) for row, col in GK: A[row, col] = GK[row, col] GM = self.GM M = spmatrix.ll_mat_sym(self.dofcount, len(GM)) for row, col in GM: M[row, col] = GM[row, col] # Atau = A + tau*M tau = -1.0 Atau = A.copy() Atau.shift(tau, M) K = precon.jacobi(Atau) # convert to skyline A = A.to_sss() M = M.to_sss() # solve k_conv, lmbd, Q, it, it_innser = \ jdsym.jdsym(A, M, K, nev, tau, 1e-6, 1000, itsolvers.qmrs, jmin=5, jmax=10, clvl=0, strategy=1) # eigen values return lmbd else: raise FEError('unknown solver')
def convert_to_py_sparse_format(a): # check symmetric import spmatrix assert (a - a.T).nnz == 0 l_mat = spmatrix.ll_mat_sym(a.shape[0], a.nnz) a_coo = scipy.sparse.triu(a).tocoo() l_mat.put(a_coo.data, a_coo.row.astype(int), a_coo.col.astype(int)) return l_mat
def poisson2d_sym(n): n2 = n*n L = spmatrix.ll_mat_sym(n2, 3*n2-2*n) for i in range(n): for j in range(n): k = i + n*j L[k,k] = 4 if i > 0: L[k,k-1] = -1 if j > 0: L[k,k-n] = -1 return L
def assembleElementM(self): ''' Assembly: Evaluate element mass matrix and fill GM. ''' # Evaluate ESM's and assemble them to GSM if SOLVER == 'default': self.GM = spmatrix.LLd((self.dofcount, self.dofcount), isSym=True) elif SOLVER == 'pysparse': self.GM = spmatrix.ll_mat_sym(self.dofcount, self.dofcount) else: raise FEError('unknown solver') for element in self.elements: element.assembleElementM(self.GM)
def assembleElementM(self): ''' Assembly: Evaluate element mass matrix and fill GM. ''' # Evaluate ESM's and assemble them to GSM if SOLVER == 'default': self.GM = spmatrix.LLd((self.dofcount,self.dofcount), isSym=True) elif SOLVER == 'pysparse': self.GM = spmatrix.ll_mat_sym(self.dofcount, self.dofcount) else: raise FEError('unknown solver') for element in self.elements: element.assembleElementM(self.GM)
def assembleElementM(self, solver_arg): ''' Assembly: Evaluate element mass matrix and fill GM. ''' # Evaluate ESM's and assemble them to GSM if solver_arg == 'default': self.GM = spmatrix.LLd((self.dofcount,self.dofcount), isSym=True) elif solver_arg == 'pysparse': self.GM = spmatrix.ll_mat_sym(self.dofcount, self.dofcount) elif solver_arg == 'sparse': self.GM = sparse.lil_matrix((self.dofcount, self.dofcount)) else: raise FEError('unknown solver') for i, element in enumerate(self.elements): element.assembleElementM(self.GM) if solver_arg == 'sparse': pass self.GM = sparse.csc_matrix(symmetrise(self.GM))