コード例 #1
0
ファイル: test_ntree.py プロジェクト: 3Paulinchen/pyPUM
def test_ntree():
    bbox = Box(((0, 1), (0, 1)))
    tree = nTree(bbox)
    tree.refine(2)
    print "tree has", tree.totalsize, " nodes and", tree.size, " leafs:"
    
    # nodes and leafs
    for id in tree.nodes():
        print "\tnode id =", id
    for id in tree.leafs():
        print "\tleaf id =", id

    # neighbour tests
    c = 0;
    f = 0;
    for id in tree.leafs():
        c += 1
        n1 = tree.find_neighbours(id, 1.2)
        n2 = tree.find_neighbours_exhaustive(id)
        ndiff = set(n1).symmetric_difference(set(n2))
        if len(ndiff) > 0:
            f += 1
            print "neighbours for node ", id, " differ by ", ndiff, "    ( n1 =", n1, ")"
    print "neighbour test successful for", c - f, "out of", c, "nodes"


    # print neighbours for visual comparison
    for id in tree.leafs():
        nid = tree.find_neighbours(id, 1.2)
        print "neighbours of ", id, "are", nid

    tree.plot2d()
コード例 #2
0
ファイル: test_assembler.py プロジェクト: 3Paulinchen/pyPUM
def xtest_assembler2d():
    # setup discretisation
    # --------------------
    # setup PU
    bbox = Box([[0, 1], [0, 1]])
    tree = nTree(bbox=bbox)
#    tree.refine(refines)
    tree.refine(refines)
    pu = PU(tree, weighttype='bspline3', scaling=scaling)
    if plot_patches:
        pu.tree.plot2d()
    # setup monomial basis
    basis = MonomialBasis(maxdegree, 2)
    basisset = BasisSet(basis)
    # setup dof manager
    ids = [id for id in tree.leafs()]
    dof = DofManager(ids, basisset)
    # setup quadrature
    quad = TensorQuadrature()
    # setup assembler
    asm = Assembler(tree, pu, basisset, dof, quad)
    
    # assemble problem
    # ----------------
    N = dof.dim()
    logger.info("system has dimension " + str(N))
    print "PROBLEM SIZE %i" % N
    A = lil_matrix((N, N))
    b = np.zeros(N)
    PDE = ReactionDiffusion(basedegree=maxdegree, D=1, r=1)
    asm.assemble(A, b, lhs=PDE.lhs, rhs=PDE.rhs, symmetric=True)

    # solve system
    # ------------
    A = A.tocsr()
    x = spsolve(A, b)
#    x = bicg(A, b)

#    print A.todense()
#    print b
#    print x
#    print x.shape
    
    # plot solution
    if plot_solution:
        puf = PUFunction(x, tree, pu, basisset, dof)
        Plotter.plot(lambda x: puf(x, gradient=False), 2, [[0, 1], [0, 1]], resolution=1 / 3, vectorized=False)
コード例 #3
0
ファイル: test_pu.py プロジェクト: 3Paulinchen/pyPUM
def test_pu():
    print "\n" + "*"*50
    print "TEST PU"
    print "*"*50
    
    # 1d
    # ==================
    if False:
        print "======== 1d ========="
        bbox = Box([[0, 1]])
        tree = nTree(bbox=bbox)
        pu = PU(tree, weighttype='bspline3', scaling=1.8)
        pu.tree.refine(2)
        
        for id in pu.indices:
            print "\t", id, ":", pu.get_node(id)
    
        for id in pu.indices:        
            node = pu.get_node(id)
            cn = node.center
            print "\n", node
            neighbours = pu.get_neighbours(id)
            active_neighbours = pu.get_active_neighbours(id, cn)
            print "\tneighbours", neighbours
            print "\tactive neighbours", active_neighbours
            pu.prepare_neighbours(id)
            y = pu(cn, gradient=False)
            print "\tcenter f(", cn, ") =", y
            Dy = pu(cn, gradient=True)
            print "\tcenter Df(", cn, ") =", Dy
            if with_plot:
#                pu.prepare_neighbours(id, onlyself=True)
                Plotter.plot(lambda x:pu(x, gradient=False), 1, [-1 / 4, 5 / 4], resolution=1 / 50)
    
    # 2d
    # ==================
    if True:
        print "======== 2d ========="
        bbox = Box([[0, 1], [0, 1]])
        tree = nTree(bbox=bbox)
        pu = PU(tree, weighttype='bspline3', scaling=1.8)
        pu.tree.refine(2)
        
        for id in pu.indices:
            print "\t", id, ":", pu.get_node(id)
    
        if with_plot:
            pc = 0
        for id in pu.indices:        
            node = pu.get_node(id)
            cn = node.center
            print "\n", node
            neighbours = pu.get_neighbours(id)
            active_neighbours = pu.get_active_neighbours(id, cn)
            print "\tneighbours", neighbours
            print "\tactive neighbours", active_neighbours
            pu.prepare_neighbours(id)
            y = pu(cn, gradient=False)
            print "\tcenter f(", cn, ") =", y
            Dy = pu(cn, gradient=True)
            print "\tcenter Df(", cn, ") =", Dy
            if with_plot:
#                pu.prepare_neighbours(id, onlyself=True)
                if pc <= 5:     # don't plot too many functions...
                    pc += 1
                    Plotter.plot(lambda x:pu(x, gradient=False, only_weight=False), 2, [[-1 / 4, 5 / 4], [-1 / 4, 5 / 4]], resolution=1 / 50)