def testSymmetry(self): tag = "B1" for k in range(1,3): quadrule = pyramidquadrature(k+1) for N in range(1,3): hdivelt1 = HdivElements(k) l2elt1 = L2Elements(k) hdivelt2 = HdivElements(k) l2elt2 = L2Elements(k) system = AsymmetricSystem(hdivelt1, l2elt1, quadrule, lambda m:buildcubemesh(N,m,tag), [], []) systemt = AsymmetricSystem(l2elt2, hdivelt2, quadrule, lambda m:buildcubemesh(N,m,tag), [], []) SM = system.systemMatrix(True, False) StM = system.transpose().systemMatrix(False, True) SMt = systemt.systemMatrix(False, True) np.testing.assert_array_almost_equal(SM.todense(), SMt.transpose().todense()) np.testing.assert_array_almost_equal(StM.todense(), SMt.todense())
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)