Example #1
0
def mixedpoissondual(k,N, g, f, points):
    tag = "B1"
    hdiveltsA = HdivElements(k)
    hdiveltsB = HdivElements(k)
    hdiveltsBt = HdivElements(k)
    l2eltsB = L2Elements(k)
    l2eltsBt = L2Elements(k)
    quadrule = pyramidquadrature(k+1)
    meshevents = lambda m: buildcubemesh(N,m,tag)
    
    Asystem = SymmetricSystem(hdiveltsA, quadrule, meshevents, [])
    Bsystem = AsymmetricSystem(l2eltsB, hdiveltsB, quadrule, meshevents, [],[])
    Btsystem = AsymmetricSystem(hdiveltsBt, l2eltsBt, quadrule, meshevents, [],[])
    
    A = Asystem.systemMatrix(False)
#    Bt = Btsystem.systemMatrix(True, False)
    B = Bsystem.systemMatrix(False, True)
    print A.shape, B.shape
    
    F = Bsystem.loadVector(f, False)
    gn = lambda x,n: g(x).reshape(-1,1,1) * n.reshape(-1,1,3)
    G = Btsystem.boundaryLoad({tag:gn}, squarequadrature(k+1), trianglequadrature(k+1), False)
    u,p = ps.directsolve(A, B, G[tag], F)    
    um,pm = ps.mixedcg(A, B, G[tag], F)
#    print numpy.hstack((UU[:len(u)], u))
    print math.sqrt(numpy.sum((u - um)**2)/len(u))
    print math.sqrt(numpy.sum((p - pm)**2)/len(p))
    
    return Btsystem.evaluate(points, p, {}, False)    
Example #2
0
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)
Example #3
0
def poissonneumann(k,N,g,f, points):
    tag = "B1"
    elements = H1Elements(k)
    quadrule = pyramidquadrature(k+1)
    system = SymmetricSystem(elements, quadrule, lambda m: buildcubemesh(N,m,tag), [])
    SM = system.systemMatrix(True)
    S = SM[1:,:][:,1:] # the first basis fn is guaranteed to be associated with an external degree, so is a linear comb of all the others 
    F = 0 if f is None else system.loadVector(f)
    G = 0 if g is None else system.boundaryLoad({tag:g}, squarequadrature(k+1), trianglequadrature(k+1), False)    
    U = numpy.concatenate((numpy.array([0]), spsolve(S, G[tag][1:]-F[1:])))[:,numpy.newaxis]
    return system.evaluate(points, U, {}, False)    
Example #4
0
 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())
Example #5
0
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)
Example #6
0
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)