当前位置: 首页>>代码示例>>Python>>正文


Python LinSystem.get_matrix方法代码示例

本文整理汇总了Python中hermes2d.LinSystem.get_matrix方法的典型用法代码示例。如果您正苦于以下问题:Python LinSystem.get_matrix方法的具体用法?Python LinSystem.get_matrix怎么用?Python LinSystem.get_matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hermes2d.LinSystem的用法示例。


在下文中一共展示了LinSystem.get_matrix方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_matrix

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
def test_matrix():
    set_verbose(False)

    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(5)
    space.assign_dofs()

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)

    # assemble the stiffness matrix and solve the system
    sln = Solution()
    sys.assemble()
    A = sys.get_matrix()
开发者ID:Zhonghua,项目名称:hermes2d,代码行数:29,代码来源:test_basics.py

示例2: test_ScalarView_mpl_unknown

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
def test_ScalarView_mpl_unknown():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(5)
    space.assign_dofs()

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    A = sys.get_matrix()
    b = sys.get_rhs()
    from scipy.sparse.linalg import cg

    x, res = cg(A, b)
    sln = Solution()
    sln.set_fe_solution(space, pss, x)

    view = ScalarView("Solution")
开发者ID:hpfem,项目名称:hermes2d,代码行数:34,代码来源:test_plots.py

示例3: test_matrix

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
def test_matrix():
    set_verbose(False)

    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)

    # create an H1 space with default shapeset
    space = H1Space(mesh, 1)

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    sys = LinSystem(wf)
    sys.set_spaces(space)

    # assemble the stiffness matrix and solve the system
    sln = Solution()
    sys.assemble()
    A = sys.get_matrix()
开发者ID:FranzGrenvicht,项目名称:hermes,代码行数:23,代码来源:test_basics.py

示例4: poisson_solver

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
def poisson_solver(mesh_tuple):
    """
    Poisson solver.

    mesh_tuple ... a tuple of (nodes, elements, boundary, nurbs)
    """
    set_verbose(False)
    mesh = Mesh()
    mesh.create(*mesh_tuple)
    mesh.refine_element(0)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(5)
    space.assign_dofs()

    # initialize the discrete problem
    wf = WeakForm(1)
    set_forms(wf)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    A = sys.get_matrix()
    b = sys.get_rhs()
    from scipy.sparse.linalg import cg
    x, res = cg(A, b)
    sln = Solution()
    sln.set_fe_solution(space, pss, x)
    return sln
开发者ID:adam-urbanczyk,项目名称:hermes-gui,代码行数:38,代码来源:handle_hermes.py

示例5: ScalarView

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
view = ScalarView("Solution")
mview = MeshView("Mesh")
graph = []
iter = 0
print "Calculating..."

while 1:
    space.assign_dofs()

    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)
    sys.assemble()
    sys.solve_system(sln)
    dofs = sys.get_matrix().shape[0]
    if interactive_plotting:
        view.show(sln, lib="mayavi", filename="a%02d.png" % iter)
        if show_mesh:
            mview.show(mesh, lib="mpl", method="orders", filename="b%02d.png" % iter)

    rsys = RefSystem(sys)
    rsys.assemble()

    rsys.solve_system(rsln)

    hp = H1OrthoHP(space)
    error_est = hp.calc_error(sln, rsln) * 100
    print "iter=%02d, error_est=%5.2f%%, DOFS=%d" % (iter, error_est, dofs)
    graph.append([dofs, error_est])
    if error_est < error_tol:
开发者ID:solin,项目名称:hermes2d,代码行数:32,代码来源:22.py

示例6: H1Space

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
# create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(5)
space.assign_dofs()

# initialize the discrete problem
wf = WeakForm(1)
set_forms(wf)

solver = DummySolver()
sys = LinSystem(wf, solver)
sys.set_spaces(space)
sys.set_pss(pss)

# assemble the stiffness matrix and solve the system
sys.assemble()
A = sys.get_matrix()
b = sys.get_rhs()
from scipy.sparse.linalg import cg
x, res = cg(A, b)
sln = Solution()
sln.set_fe_solution(space, pss, x)

view = ScalarView("Solution")
view.show(sln, lib="mayavi")
# view.wait()

mview = MeshView("Hello world!", 100, 100, 500, 500)
mview.show(mesh, lib="mpl", method="orders", notebook=False)
mview.wait()
开发者ID:davidquantum,项目名称:hermes2dold,代码行数:32,代码来源:03.py

示例7: schroedinger_solver

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]

#.........这里部分代码省略.........
    viewse = [ScalarView("", i*w, 2*h, w, h) for i in range(4)]
    #for v in viewse:
    #    v.set_min_max_range(0, 10**-4)
    ord = OrderView("Polynomial Orders", 0, 2*h, w, h)

    rs = None

    precision = 30.0

    if verbose_level >= 1:
        print "Problem initialized. Starting calculation."

    for it in range(iter):
        if verbose_level >= 1:
            print "-"*80
            print "Starting iteration %d." % it
        if report:
            iteration["n"] = it

        #mesh.save("refined2.mesh")
        sys1 = LinSystem(wf1, solver)
        sys1.set_spaces(space)
        sys1.set_pss(pss)
        sys2 = LinSystem(wf2, solver)
        sys2.set_spaces(space)
        sys2.set_pss(pss)

        if verbose_level >= 1:
            print "Assembling the matrices A, B."
        sys1.assemble()
        sys2.assemble()
        if verbose_level == 2:
            print "converting matrices A, B"
        A = sys1.get_matrix()
        B = sys2.get_matrix()
        if verbose_level >= 1:
            n = A.shape[0]
            print "Solving the problem Ax=EBx  (%d x %d)." % (n, n)
        if report:
            n = A.shape[0]
            iteration["DOF"] = n
        if report:
            t = clock()
        eigs, sols = solve(A, B, n_eigs, verbose_level == 2)
        if report:
            t = clock() - t
            iteration["cpu_solve"] = t
            iteration["eigenvalues"] = array(eigs)
            #h5eigs.append(sols)
        if verbose_level >= 1:
            print "   \-Done."
            print_eigs(eigs, E_exact)
        s = []

        n = sols.shape[1]
        for i in range(n):
            sln = Solution()
            vec = sols[:, i]
            sln.set_fe_solution(space, pss, vec)
            s.append(sln)

        if verbose_level >= 1:
            print "Matching solutions."
        if rs is not None:
            def minus2(sols, i):
                sln = Solution()
开发者ID:certik,项目名称:schroedinger,代码行数:70,代码来源:schroedinger.py

示例8: calc

# 需要导入模块: from hermes2d import LinSystem [as 别名]
# 或者: from hermes2d.LinSystem import get_matrix [as 别名]
    def calc(
        threshold=0.3,
        strategy=0,
        h_only=False,
        error_tol=1,
        interactive_plotting=False,
        show_mesh=False,
        show_graph=True,
    ):
        mesh = Mesh()
        mesh.create(
            [[0, 0], [1, 0], [1, 1], [0, 1]], [[2, 3, 0, 1, 0]], [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]], []
        )

        mesh.refine_all_elements()

        shapeset = H1Shapeset()
        pss = PrecalcShapeset(shapeset)

        space = H1Space(mesh, shapeset)
        set_bc(space)
        space.set_uniform_order(1)

        wf = WeakForm(1)
        set_forms(wf)

        sln = Solution()
        rsln = Solution()
        solver = DummySolver()

        selector = H1ProjBasedSelector(CandList.HP_ANISO, 1.0, -1, shapeset)

        view = ScalarView("Solution")
        iter = 0
        graph = []
        while 1:
            space.assign_dofs()

            sys = LinSystem(wf, solver)
            sys.set_spaces(space)
            sys.set_pss(pss)
            sys.assemble()
            sys.solve_system(sln)
            dofs = sys.get_matrix().shape[0]
            if interactive_plotting:
                view.show(sln, lib=lib, notebook=True, filename="a%02d.png" % iter)

            rsys = RefSystem(sys)
            rsys.assemble()

            rsys.solve_system(rsln)

            hp = H1Adapt([space])
            hp.set_solutions([sln], [rsln])
            err_est = hp.calc_error() * 100

            err_est = hp.calc_error(sln, rsln) * 100
            print "iter=%02d, err_est=%5.2f%%, DOFS=%d" % (iter, err_est, dofs)
            graph.append([dofs, err_est])
            if err_est < error_tol:
                break
            hp.adapt(selector, threshold, strategy)
            iter += 1

        if not interactive_plotting:
            view.show(sln, lib=lib, notebook=True)

        if show_mesh:
            mview = MeshView("Mesh")
            mview.show(mesh, lib="mpl", notebook=True, filename="b.png")

        if show_graph:
            from numpy import array

            graph = array(graph)
            import pylab

            pylab.clf()
            pylab.plot(graph[:, 0], graph[:, 1], "ko", label="error estimate")
            pylab.plot(graph[:, 0], graph[:, 1], "k-")
            pylab.title("Error Convergence for the Inner Layer Problem")
            pylab.legend()
            pylab.xlabel("Degrees of Freedom")
            pylab.ylabel("Error [%]")
            pylab.yscale("log")
            pylab.grid()
            pylab.savefig("graph.png")
开发者ID:hpfem,项目名称:hermes2d,代码行数:89,代码来源:demos.py


注:本文中的hermes2d.LinSystem.get_matrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。