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


Python Mesh.refine_element方法代码示例

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


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

示例1: test_example_03

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
def test_example_03():
    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)
    from hermes2d.examples.c03 import set_bc

    set_bc(space)
    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()
    sys.solve_system(sln)
    assert abs(sln.l2_norm() - 0.25493) < 1e-4
    assert abs(sln.h1_norm() - 0.89534) < 1e-4
开发者ID:Zhonghua,项目名称:hermes2d,代码行数:34,代码来源:test_examples.py

示例2: test_matrix

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [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

示例3: test_ScalarView_mpl_unknown

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [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

示例4: test_plot_mesh2

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
def test_plot_mesh2():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element(0)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="simple", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements, plot_nodes=False)
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
开发者ID:hpfem,项目名称:hermes2d,代码行数:13,代码来源:test_plots.py

示例5: poisson_solver

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
def poisson_solver(rho, prec=0.1):
    """
    Solves the Poisson equation \Nabla^2\phi = \rho.

    prec ... the precision of the solution in percents

    Returns the solution.
    """
    mesh = Mesh()
    mesh.load("square.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_poisson(wf, rho)
    solver = DummySolver()

    # assemble the stiffness matrix and solve the system
    for i in range(10):
        sys = LinSystem(wf, solver)
        sys.set_spaces(space)
        sys.set_pss(pss)

        sln = Solution()
        print "poisson: assembly coarse"
        sys.assemble()
        print "poisson: done"
        sys.solve_system(sln)

        rp = RefSystem(sys)
        rsln = Solution()
        print "poisson: assembly reference"
        rp.assemble()
        print "poisson: done"
        rp.solve_system(rsln)

        hp = H1OrthoHP(space)
        error = hp.calc_error(sln, rsln) * 100
        print "iteration: %d, error: %f" % (i, error)
        if error < prec:
            print "Error less than %f%%, we are done." % prec
            break
        hp.adapt(0.3)
        space.assign_dofs()
    return sln
开发者ID:certik,项目名称:schroedinger,代码行数:54,代码来源:schroedinger.py

示例6: test_matrix

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [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

示例7: test_example_02

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
def test_example_02():
    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)
开发者ID:Zhonghua,项目名称:hermes2d,代码行数:24,代码来源:test_examples.py

示例8: poisson_solver

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [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

示例9: test_example_11

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
def test_example_11():
    from hermes2d.examples.c11 import set_bc, set_wf_forms, set_hp_forms

    # The following parameters can be changed: In particular, compare hp- and
    # h-adaptivity via the ADAPT_TYPE option, and compare the multi-mesh vs. single-mesh
    # using the MULTI parameter.
    P_INIT = 1  # Initial polynomial degree of all mesh elements.
    MULTI = True  # MULTI = true  ... use multi-mesh,
    # MULTI = false ... use single-mesh.
    # Note: In the single mesh option, the meshes are
    # forced to be geometrically the same but the
    # polynomial degrees can still vary.
    SAME_ORDERS = True  # SAME_ORDERS = true ... when single-mesh is used,
    # this forces the meshes for all components to be
    # identical, including the polynomial degrees of
    # corresponding elements. When multi-mesh is used,
    # this parameter is ignored.
    THRESHOLD = 0.3  # This is a quantitative parameter of the adapt(...) function and
    # it has different meanings for various adaptive strategies (see below).
    STRATEGY = 1  # Adaptive strategy:
    # STRATEGY = 0 ... refine elements until sqrt(THRESHOLD) times total
    #   error is processed. If more elements have similar errors, refine
    #   all to keep the mesh symmetric.
    # STRATEGY = 1 ... refine all elements whose error is larger
    #   than THRESHOLD times maximum element error.
    # STRATEGY = 2 ... refine all elements whose error is larger
    #   than THRESHOLD.
    # More adaptive strategies can be created in adapt_ortho_h1.cpp.
    ADAPT_TYPE = 0  # Type of automatic adaptivity:
    # ADAPT_TYPE = 0 ... adaptive hp-FEM (default),
    # ADAPT_TYPE = 1 ... adaptive h-FEM,
    # ADAPT_TYPE = 2 ... adaptive p-FEM.
    ISO_ONLY = False  # Isotropic refinement flag (concerns quadrilateral elements only).
    # ISO_ONLY = false ... anisotropic refinement of quad elements
    # is allowed (default),
    # ISO_ONLY = true ... only isotropic refinements of quad elements
    # are allowed.
    MESH_REGULARITY = -1  # Maximum allowed level of hanging nodes:
    # MESH_REGULARITY = -1 ... arbitrary level hangning nodes (default),
    # MESH_REGULARITY = 1 ... at most one-level hanging nodes,
    # MESH_REGULARITY = 2 ... at most two-level hanging nodes, etc.
    # Note that regular meshes are not supported, this is due to
    # their notoriously bad performance.
    MAX_ORDER = 10  # Maximum allowed element degree
    ERR_STOP = 0.5  # Stopping criterion for adaptivity (rel. error tolerance between the
    # fine mesh and coarse mesh solution in percent).
    NDOF_STOP = 40000  # Adaptivity process stops when the number of degrees of freedom grows over
    # this limit. This is mainly to prevent h-adaptivity to go on forever.

    # Problem constants
    E = 200e9  # Young modulus for steel: 200 GPa
    nu = 0.3  # Poisson ratio
    lamda = (E * nu) / ((1 + nu) * (1 - 2 * nu))
    mu = E / (2 * (1 + nu))

    # Load the mesh
    xmesh = Mesh()
    ymesh = Mesh()
    xmesh.load(get_bracket_mesh())

    # initial mesh refinements
    xmesh.refine_element(1)
    xmesh.refine_element(4)

    # Create initial mesh for the vertical displacement component,
    # identical to the mesh for the horizontal displacement
    # (bracket.mesh becomes a master mesh)
    ymesh.copy(xmesh)

    # Initialize the shapeset and the cache
    shapeset = H1Shapeset()
    xpss = PrecalcShapeset(shapeset)
    ypss = PrecalcShapeset(shapeset)

    # Create the x displacement space
    xdisp = H1Space(xmesh, shapeset)
    set_bc(xdisp)
    xdisp.set_uniform_order(P_INIT)

    # Create the x displacement space
    ydisp = H1Space(ymesh, shapeset)
    set_bc(ydisp)
    ydisp.set_uniform_order(P_INIT)

    # Enumerate basis functions
    ndofs = xdisp.assign_dofs()
    ydisp.assign_dofs(ndofs)

    # Initialize the weak formulation
    wf = WeakForm(2)
    set_wf_forms(wf)

    # Matrix solver
    solver = DummySolver()

    # adaptivity loop
    it = 1
    done = False
    cpu = 0.0

#.........这里部分代码省略.........
开发者ID:Zhonghua,项目名称:hermes2d,代码行数:103,代码来源:test_examples.py

示例10: get_example_mesh

# 需要导入模块: from hermes2d import Mesh [as 别名]
# 或者: from hermes2d.Mesh import refine_element [as 别名]
#! /usr/bin/env python

from hermes2d import Mesh, H1Shapeset, PrecalcShapeset, H1Space, \
        BaseView

from hermes2d.forms import set_forms
from hermes2d.examples import get_example_mesh
domain_mesh = get_example_mesh()

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

bview = BaseView()
bview.show(space)
bview.wait()
开发者ID:Richardma,项目名称:hermes2d,代码行数:25,代码来源:02.py


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