def laplaceeigs(k,N,n): import scipy.linalg as sl tag = "B1" elements = H1Elements(k) quadrule = pyramidquadrature(k+1) system = SymmetricSystem(elements, quadrule, lambda m: buildcubemesh(N, m, tag), [tag]) SM = system.systemMatrix(True) S, SIBs, Gs = system.processBoundary(SM, {tag:lambda p: numpy.zeros((len(p),1))}) print S.shape MM = system.systemMatrix(False) M, _, _ = system.processBoundary(MM, {tag:lambda p: numpy.zeros((len(p),1))}) MLU = ssl.splu(M) L = A = ssl.LinearOperator( M.shape, matvec=lambda x: MLU.solve(S* x), dtype=float) return ssl.eigen(L, k=n, which='SM', return_eigenvectors=False)
def testSymmetry(self): tag = "B1" for k in range(1,3): quadrule = pyramidquadrature(k+1) for N in range(1,3): for elements in [H1Elements(k), HcurlElements(k), HdivElements(k)]: system = SymmetricSystem(elements, quadrule, lambda m: buildcubemesh(N, m, tag), [tag]) for deriv in [False, True]: SM = system.systemMatrix(deriv) g = lambda x: np.zeros((len(x),1)) S, SIBs, Gs = system.processBoundary(SM, {tag:g}) np.testing.assert_array_almost_equal(SM.todense(), SM.transpose().todense()) np.testing.assert_array_almost_equal(S.todense(), S.transpose().todense())
def laplacedirichlet(k, N, g, points): tag = "B1" elements = H1Elements(k) quadrule = pyramidquadrature(k+1) system = SymmetricSystem(elements, quadrule, lambda m: buildcubemesh(N, m, tag), [tag]) SM = system.systemMatrix(True) S, SIBs, Gs = system.processBoundary(SM, {tag:g}) SG = SIBs[tag] * Gs[tag] print S.shape U = spsolve(S, -SG)[:,numpy.newaxis] return system.evaluate(points, U, Gs, False)
def poissondirichlet(k,N,g,f, points): tag = "B1" elements = H1Elements(k) quadrule = pyramidquadrature(k+1) system = SymmetricSystem(elements, quadrule, lambda m: buildcubemesh(N, m, tag), [tag]) SM = system.systemMatrix(True) S, SIBs, Gs = system.processBoundary(SM, {tag:g}) SG = SIBs[tag] * Gs[tag] if f: F = system.loadVector(f) else: F = 0 print SM.shape, S.shape, SIBs[tag].shape, Gs[tag].shape, F.shape, SG.shape t = Timer().start() U = spsolve(S, -F-SG)[:,numpy.newaxis] t.split("spsolve").show() return system.evaluate(points, U, Gs, False)