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)
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)