def get_iJ(self): iJlu = self.xtf.get_iJlu() iJ0 = bem.BlockedDiscreteOperator(2, 2) iJ0[0, 0], iJ0[1, 1] = iJlu, iJlu iJ1 = bem.BlockedDiscreteOperator(2, 2) iJ1[0, 0], iJ1[1, 1] = iJlu, iJlu iJ = bem.BlockedDiscreteOperator(2, 2) iJ[0, 0], iJ[1, 1] = iJ0, iJ1 return iJ
def iJ_weak_form(self): self._collect() if self._iJ_assembled: return self.iJlu tinit = time() print('==Factorization LU: J') if self._J_is == 'Sp': self.iJlu = spla.splu(self.Jw) self.tassembiJ = time() - tinit self._iJ_assembled = True print('##time sparse J=LU: {}'.format(self.tassembiJ)) return self.iJlu Jw = self.opI.weak_form() N = len(self.domains) dtype = self.dtype iJlu = bem.BlockedDiscreteOperator(N, N) for ii in range(N): Jb = Jw[ii, ii] Jd, Jn = Jb[0, 0], Jb[1, 1] js = Jd.sparse_operator js = js.astype(dtype) js = spla.splu(js) iJd = Bridge(js.shape, dot=js.solve, dtype=dtype) js = Jn.sparse_operator js = js.astype(dtype) js = spla.splu(js) iJn = Bridge(js.shape, dot=js.solve, dtype=dtype) iJloc = bem.BlockedDiscreteOperator(2, 2) iJloc[0, 0], iJloc[1, 1] = iJd, iJn iJlu[ii, ii] = iJloc self.iJlu = iJlu self.tassembiJ = time() - tinit self._iJ_assembled = True print('##time blocked J=LU: {}'.format(self.tassembiJ)) return self.iJlu
def upper(self): print('==building Upper: E', flush=True) domains = self.domains dtype = self.dtype N = len(domains) if self._J_is == 'CSC': Jw = self.opI.weak_form() else: Jw = self.J_weak_form(self._J_is) # Xw = self.X_weak_form(self._X_is) Xw = self.opX.weak_form() ## not nice, because the type conversion is done 2 times ## need to fix with the Bridge tt = time() E = bem.BlockedDiscreteOperator(N, N) for dom in domains: ii = domains.getIndexDom(dom['name']) Jb = Jw[ii, ii] es = Bridge(Jb.shape, dot=lambda x: 0.0 * x, dtype=dtype) E[ii, ii] = es for d in domains.getNeighborOf(dom['name']): jj = domains.getIndexDom(d['name']) if jj > ii: Xij = Xw[ii, jj] Xd, Xn = Xij[0, 0], Xij[1, 1] ed = Xd.sparse_operator ed = ed.astype(dtype) en = Xn.sparse_operator en = en.astype(dtype) es = bem.BlockedDiscreteOperator(2, 2) es[0, 0], es[1, 1] = ed, en E[ii, jj] = es print('##time to build E: {}'.format(time() - tt), flush=True) E = spla.LinearOperator(self.shape, matvec=E.matvec, dtype=self.dtype) return E
def X_weak_form(self, X_is='Blocked'): self._collect() if self._X_assembled: return self.Xw tinit = time() domains = self.domains dtype = self.dtype print('==Coupling assembling: X', end=' ') Xw = self.opX.weak_form() self._check_shape(Xw.shape) if X_is == 'Blocked': self._X_is = 'Blocked' self.Xw = Xw self._X_assembled = True self.tassembX = time() - tinit print('Blocked time: {0}'.format(time() - tinit)) return self.Xw N = len(domains) for dom in domains: ii = domains.getIndexDom(dom['name']) for d in domains.getNeighborOf(dom['name']): jj = domains.getIndexDom(d['name']) Xb = Xw[ii, jj] Xd, Xn = Xb[0, 0], Xb[1, 1] xs = Xd.sparse_operator xs = xs.astype(dtype) Xd = Bridge(xs.shape, dot=xs.dot, dtype=dtype) xs = Xn.sparse_operator xs = xs.astype(dtype) Xn = Bridge(xs.shape, dot=xs.dot, dtype=dtype) Xloc = bem.BlockedDiscreteOperator(2, 2) Xloc[0, 0], Xloc[1, 1] = Xd, Xn Xw[ii, jj] = Xloc self.Xw = Xw self._X_assembled = True self._X_is = 'BlockedDiscrete' self.tassembX = time() - tinit print('BlockedDiscrete time: {0}'.format(time() - tinit)) return self.Xw
def get_Diag(spaces, get_op, k=None): if k is None: k = [None, None] D = bem.BlockedDiscreteOperator(2, 2) op0 = get_op(spaces, k[0], sign=1) op1 = get_op(spaces, k[1], sign=-1) for ii, op in enumerate([op0, op1]): try: Dw = op.weak_form() except: Dw = op D[ii, ii] = Dw return D
def get_iJi(spaces, k=None, sign=None): tt = time() iJ = bem.BlockedDiscreteOperator(2, 2) opJ = get_opJi(spaces) opId, opIn = opJ[0, 0], opJ[1, 1] for ii, opI in enumerate([opId, opIn]): Iw = opI.weak_form() II = Iw.sparse_operator II = II.astype(complex) iII = spla.splu(II) iIl = spla.LinearOperator(II.shape, matvec=iII.solve, dtype=complex) iJ[ii, ii] = iIl #print("compute iJ:", time()-tt) return iJ
def J_weak_form(self, J_is='Sp'): self._collect() if self._J_assembled: return self.Jw tinit = time() domains = self.domains dtype = self.dtype print('==Identity assembling: J') Jw = self.opI.weak_form() self._check_shape(Jw.shape) if J_is == 'Blocked': self._J_blocked = 'Blocked' self.Jw = Jw self.tassembJ = time() - tinit self._J_assembled = True return self.Jw if J_is == 'BlockedDiscrete': N = len(domains) for ii in range(N): Jb = Jw[ii, ii] Jd, Jn = Jb[0, 0], Jb[1, 1] js = Jd.sparse_operator js = js.astype(dtype) Jd = Bridge(js.shape, dot=js.dot, dtype=dtype) js = Jn.sparse_operator js = js.astype(dtype) Jn = Bridge(js.shape, dot=js.dot, dtype=dtype) Jloc = bem.BlockedDiscreteOperator(2, 2) Jloc[0, 0], Jloc[1, 1] = Jd, Jn Jw[ii, ii] = Jloc self.Jw = Jw self.tassembJ = time() - tinit self._J_assembled = True return self.Jw tt = time() Jsp = sp.lil_matrix(Jw.shape, dtype=np.float) row_start, col_start = 0, 0 row_end, col_end = 0, 0 for ii in range(len(domains)): Jb = Jw[ii, ii] Jd, Jn = Jb[0, 0], Jb[1, 1] #mat = bem.as_matrix(Jd) mat = Jd.sparse_operator.toarray() #mat = sp.lil_matrix(mat, dtype=dtype) r, c = mat.shape row_end += r col_end += c Jsp[row_start:row_end, col_start:col_end] = mat row_start, col_start = row_end, col_end #mat = bem.as_matrix(Jn) mat = Jn.sparse_operator.toarray() #mat = sp.lil_matrix(mat, dtype=dtype) r, c = mat.shape row_end += r col_end += c Jsp[row_start:row_end, col_start:col_end] = mat row_start, col_start = row_end, col_end Jsp = Jsp.astype(dtype) self.Jw = Jsp.tocsc() self._J_blocked = 'sparse' print('##time convert Identity to {0} CSC: {1}'.format( dtype, time() - tt)) self.tassembJ = time() - tinit self._J_assembled = True return self.Jw
I0 = II0.sparse_operator I1 = II1.sparse_operator opJ = bem.BlockedOperator(2, 2) opJ[0, 0], opJ[1, 1] = opI0, opI1 Jw = opJ.weak_form() iI0_lu = spla.splu(I0) iI1_lu = spla.splu(I1) iI0 = spla.LinearOperator(I0.shape, matvec=iI0_lu.solve) iI1 = spla.LinearOperator(I1.shape, matvec=iI1_lu.solve) iJb = bem.BlockedDiscreteOperator(2, 2) iJb[0, 0], iJb[1, 1] = iI0, iI1 opJt = bem.BlockedOperator(2, 2) opJt[0, 1], opJt[1, 0] = opI01, opI10 tJw = opJt.weak_form() print('\n==Projection by Pseudo-Inverse') II01 = opI01.weak_form() II10 = opI10.weak_form() I01 = II01.sparse_operator I10 = II10.sparse_operator tt = time()
def get_X(spaces): X = bem.BlockedDiscreteOperator(2, 2) opX = get_opXij(spaces) Xw = opX.weak_form() X[0, 1], X[1, 0] = Xw, Xw return X