Exemplo n.º 1
0
def test_example_07():
    from hermes2d.examples.c07 import set_bc, set_forms

    set_verbose(False)

    # The following parameters can be changed:
    P_INIT = 2  # Initial polynomial degree of all mesh elements.
    INIT_REF_NUM = 4  # Number of initial uniform refinements

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_07_mesh())

    # Perform initial mesh refinements.
    for i in range(INIT_REF_NUM):
        mesh.refine_all_elements()

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Assemble and solve the matrix problem
    sln = Solution()
    ls.assemble()
    ls.solve_system(sln)
Exemplo n.º 2
0
def test_example_04():
    from hermes2d.examples.c04 import set_bc

    set_verbose(False)

    # Below you can play with the parameters CONST_F, P_INIT, and UNIFORM_REF_LEVEL.
    INIT_REF_NUM = 2  # number of initial uniform mesh refinements
    P_INIT = 2  # initial polynomial degree in all elements

    # Load the mesh file
    mesh = Mesh()
    mesh.load(get_example_mesh())

    # Perform initial mesh refinements
    for i in range(INIT_REF_NUM):
        mesh.refine_all_elements()

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize the linear system
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Assemble and solve the matrix problem
    sln = Solution()
    ls.assemble()
    ls.solve_system(sln)
Exemplo n.º 3
0
def test_plot_mesh3e():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_all_elements()
    mesh.refine_all_elements()

    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 4
0
def test_example_03():
    from hermes2d.examples.c03 import set_bc

    set_verbose(False)

    P_INIT = 5  # Uniform polynomial degree of mesh elements.

    # Problem parameters.
    CONST_F = 2.0

    # Load the mesh file
    mesh = Mesh()
    mesh.load(get_example_mesh())

    # Sample "manual" mesh refinement
    mesh.refine_all_elements()

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm(1)
    set_forms(wf)

    # Initialize the linear system
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Assemble and solve the matrix problem.
    sln = Solution()
    ls.assemble()
    ls.solve_system(sln)
Exemplo n.º 5
0
def test_example_05():
    from hermes2d.examples.c05 import set_bc
    from hermes2d.examples.c05 import set_forms as set_forms_surf

    set_verbose(False)

    P_INIT = 4  # initial polynomial degree in all elements
    CORNER_REF_LEVEL = 12  # number of mesh refinements towards the re-entrant corner

    # Load the mesh file
    mesh = Mesh()
    mesh.load(get_example_mesh())

    # Perform initial mesh refinements.
    mesh.refine_towards_vertex(3, CORNER_REF_LEVEL)

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Assemble and solve the matrix problem
    sln = Solution()
    ls.assemble()
    ls.solve_system(sln)
Exemplo n.º 6
0
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")
Exemplo n.º 7
0
def test_example_08():
    from hermes2d.examples.c08 import set_bc, set_forms

    set_verbose(False)

    # The following parameter can be changed:
    P_INIT = 4

    # Load the mesh file
    mesh = Mesh()
    mesh.load(get_sample_mesh())

    # Perform uniform mesh refinement
    mesh.refine_all_elements()

    # Create the x- and y- displacement space using the default H1 shapeset
    xdisp = H1Space(mesh, P_INIT)
    ydisp = H1Space(mesh, P_INIT)
    set_bc(xdisp, ydisp)

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

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(xdisp, ydisp)

    # Assemble and solve the matrix problem
    xsln = Solution()
    ysln = Solution()
    ls.assemble()
    ls.solve_system(xsln, ysln, lib="scipy")
Exemplo n.º 8
0
def test_plot_mesh3d():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_all_elements()
    mesh.refine_all_elements()

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
Exemplo n.º 9
0
def test_plot_mesh1b():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", method="orders", show=False)
    plot_mesh_mpl(mesh.nodes, mesh.elements)
    plot_mesh_mpl(mesh.nodes_dict, mesh.elements)
Exemplo n.º 10
0
def test_plot_mesh1c():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    assert raises(
        ValueError,
        'view.show(mesh, lib="mpl", method="something_unknown_123")')
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
def test_fe_solutions():
    mesh = Mesh()
    mesh.load(domain_mesh)

    space = H1Space(mesh, 1)
    space.set_uniform_order(2)
    space.assign_dofs()

    a = array([1, 2, 3, 8, 0.1])

    sln = Solution()
Exemplo n.º 13
0
def test_example_09():
    from hermes2d.examples.c09 import set_bc, temp_ext, set_forms

    # The following parameters can be changed:
    INIT_REF_NUM = 4  # number of initial uniform mesh refinements
    INIT_REF_NUM_BDY = 1  # number of initial uniform mesh refinements towards the boundary
    P_INIT = 4  # polynomial degree of all mesh elements
    TAU = 300.0  # time step in seconds

    # Problem constants
    T_INIT = 10  # temperature of the ground (also initial temperature)
    FINAL_TIME = 86400  # length of time interval (24 hours) in seconds

    # Global variable
    TIME = 0

    # Boundary markers.
    bdy_ground = 1
    bdy_air = 2

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_cathedral_mesh())

    # Perform initial mesh refinements
    for i in range(INIT_REF_NUM):
        mesh.refine_all_elements()
    mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY)

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Set initial condition
    tsln = Solution()
    tsln.set_const(mesh, T_INIT)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Time stepping
    nsteps = int(FINAL_TIME / TAU + 0.5)
    rhsonly = False

    # Assemble and solve
    ls.assemble()
    rhsonly = True
    ls.solve_system(tsln, lib="scipy")
Exemplo n.º 14
0
def test_example_02():
    set_verbose(False)
    P_INIT = 3

    # Load the mesh file
    domain_mesh = get_example_mesh()  # Original L-shape domain
    mesh = Mesh()
    mesh.load(domain_mesh)

    # Refine all elements (optional)
    mesh.refine_all_elements()

    # Create a shapeset and an H1 space
    space = H1Space(mesh)

    # Assign element orders and initialize the space
    space.set_uniform_order(P_INIT)  # Set uniform polynomial order
Exemplo n.º 15
0
def main():
    set_verbose(False)
    mesh = Mesh()
    print "Loading mesh..."
    mesh.load(get_GAMM_channel_mesh())
    #mesh.load("domain-quad.mesh")
    #mesh.refine_element(0, 2)
    mesh.refine_element(1, 2)
    mesh.refine_all_elements()
    mesh.refine_all_elements()
    mesh.refine_all_elements()
    mesh.refine_all_elements()

    print "Constructing edges..."
    nodes = mesh.nodes_dict
    edges = Edges(mesh)
    elements = mesh.elements
    print "Done."

    print "Solving..."
    state_on_elements = {}
    for e in mesh.active_elements:
        state_on_elements[e.id] = array([1., 50., 0., 1.e5])
    #print "initial state"
    #print state_on_elements
    tau = 1e-3
    t = 0.
    for i in range(100):
        A, rhs, dof_map = assembly(edges, state_on_elements, tau)
        #print "A:"
        #print A
        #print "rhs:"
        #print rhs
        #stop
        #print "x:"
        x = spsolve(A, rhs)
        #print x
        #print state_on_elements
        state_on_elements = set_fvm_solution(x, dof_map)
        #print state_on_elements
        t += tau
        print "t = ", t
    plot_state(state_on_elements, mesh)
    #print "state_on_elements:"
    #print state_on_elements
    print "Done."
Exemplo n.º 16
0
def test_example_06():
    from hermes2d.examples.c06 import set_bc, set_forms

    set_verbose(False)

    # The following parameters can be changed:

    UNIFORM_REF_LEVEL = 2
    # Number of initial uniform mesh refinements.
    CORNER_REF_LEVEL = 12
    # Number of mesh refinements towards the re-entrant corner.
    P_INIT = 6
    # Uniform polynomial degree of all mesh elements.

    # Boundary markers
    NEWTON_BDY = 1

    # Load the mesh file
    mesh = Mesh()
    mesh.load(get_example_mesh())

    # Perform initial mesh refinements.
    for i in range(UNIFORM_REF_LEVEL):
        mesh.refine_all_elements()
    mesh.refine_towards_vertex(3, CORNER_REF_LEVEL)

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Assemble and solve the matrix problem
    sln = Solution()
    ls.assemble()
    ls.solve_system(sln)
Exemplo n.º 17
0
def test_matrix():
    set_verbose(False)

    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_element_id(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()
Exemplo n.º 18
0
def test_mesh_create1():
    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],
       ], [])
    assert compare(mesh.nodes, [[0, 0], [1, 0], [1, 1], [0, 1]])
    assert mesh.elements_markers == [[2, 3, 0, 1, 0]]
    assert mesh.elements == [[2, 3, 0, 1]]
    # not yet implemented:
    #assert mesh.boundaries == [[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 0, 1]]
    #assert mesh.nurbs is None
    mesh.refine_all_elements()
    assert compare(mesh.nodes, [(0, 0), (1, 0), (1, 1), (0, 1),
        (1, 0.5), (0.5, 0), (0, 0.5), (0.5, 1), (0.5, 0.5)])
    assert mesh.elements == [[2, 7, 8, 4], [7, 3, 6, 8], [8, 6, 0, 5],
            [4, 8, 5, 1]]
    mesh.refine_all_elements()
    assert mesh.nodes_dict == {0: (0.0, 0.0), 1: (1.0, 0.0), 2: (1.0, 1.0), 3:
            (0.0, 1.0), 4: (1.0, 0.5), 5: (0.5, 0.0), 6: (0.0, 0.5), 7: (0.5,
                1.0), 8: (0.5, 0.5), 9: (0.5, 0.75), 10: (0.25, 1.0), 12:
            (0.75, 1.0), 13: (0.25, 0.5), 14: (0.0, 0.75), 15: (0.5, 0.25), 16:
            (0.25, 0.0), 17: (0.0, 0.25), 18: (0.75, 0.25), 19: (1.0, 0.25),
            20: (0.75, 0.0), 21: (0.75, 0.5), 22: (1.0, 0.75), 23: (0.75,
                0.75), 36: (0.25, 0.75), 47: (0.25, 0.25)}
    assert mesh.elements == [[2, 12, 23, 22], [12, 7, 9, 23], [23, 9, 8, 21],
            [22, 23, 21, 4], [7, 10, 36, 9], [10, 3, 14, 36], [36, 14, 6, 13],
            [9, 36, 13, 8], [8, 13, 47, 15], [13, 6, 17, 47], [47, 17, 0, 16],
            [15, 47, 16, 5], [4, 21, 18, 19], [21, 8, 15, 18], [18, 15, 5, 20],
            [19, 18, 20, 1]]
Exemplo n.º 19
0
    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")
Exemplo n.º 20
0
def test_example_11():
    from hermes2d.examples.c11 import set_bc, set_wf_forms, set_hp_forms

    SOLVE_ON_COARSE_MESH = True  # If true, coarse mesh FE problem is solved in every adaptivity step.
    P_INIT_U = 2  # Initial polynomial degree for u
    P_INIT_V = 2  # Initial polynomial degree for v
    INIT_REF_BDY = 3  # Number of initial boundary refinements
    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.
    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.

    CAND_LIST = CandList.H2D_HP_ANISO  # Predefined list of element refinement candidates.
    # Possible values are are attributes of the class CandList:
    # P_ISO, P_ANISO, H_ISO, H_ANISO, HP_ISO, HP_ANISO_H, HP_ANISO_P, HP_ANISO
    # See the Sphinx tutorial (http://hpfem.org/hermes2d/doc/src/tutorial-2.html#adaptive-h-fem-and-hp-fem) for details.

    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.
    CONV_EXP = 1  # Default value is 1.0. This parameter influences the selection of
    # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
    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 = 60000  # 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.

    H2DRS_DEFAULT_ORDER = -1  # A default order. Used to indicate an unkonwn order or a maximum support order

    # Load the mesh
    umesh = Mesh()
    vmesh = Mesh()
    umesh.load(get_bracket_mesh())
    if MULTI == False:
        umesh.refine_towards_boundary(1, INIT_REF_BDY)

    # Create initial mesh (master mesh).
    vmesh.copy(umesh)

    # Initial mesh refinements in the vmesh towards the boundary
    if MULTI == True:
        vmesh.refine_towards_boundary(1, INIT_REF_BDY)

    # Create the x displacement space
    uspace = H1Space(umesh, P_INIT_U)
    vspace = H1Space(vmesh, P_INIT_V)

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

    # Initialize refinement selector
    selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

    # Initialize the coarse mesh problem
    ls = LinSystem(wf)
    ls.set_spaces(uspace, vspace)

    u_sln_coarse = Solution()
    v_sln_coarse = Solution()
    u_sln_fine = Solution()
    v_sln_fine = Solution()

    # Assemble and Solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(u_sln_fine, v_sln_fine, lib="scipy")

    # Either solve on coarse mesh or project the fine mesh solution
    # on the coarse mesh.
    if SOLVE_ON_COARSE_MESH:
        ls.assemble()
        ls.solve_system(u_sln_coarse, v_sln_coarse, lib="scipy")

    # Calculate element errors and total error estimate
    hp = H1Adapt(ls)
    hp.set_solutions([u_sln_coarse, v_sln_coarse], [u_sln_fine, v_sln_fine])
    set_hp_forms(hp)
    err_est = hp.calc_error() * 100
Exemplo n.º 21
0
def test_example_01():
    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_all_elements()
    mesh.refine_all_elements()
    mesh.refine_all_elements()
Exemplo n.º 22
0
#! /usr/bin/env python

import sys
from hermes2d import Mesh

m = Mesh()
m.load(sys.argv[1])
m.plot(lib="mpl", method="simple")
Exemplo n.º 23
0
def test_example_10():
    from hermes2d.examples.c10 import set_bc, set_forms
    from hermes2d.examples import get_motor_mesh

    # The following parameters can be changed:
    SOLVE_ON_COARSE_MESH = True  # If true, coarse mesh FE problem is solved in every adaptivity step
    P_INIT = 2  # Initial polynomial degree of all mesh elements.
    THRESHOLD = 0.2  # 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.

    CAND_LIST = CandList.H2D_HP_ANISO_H  # Predefined list of element refinement candidates.
    # Possible values are are attributes of the class CandList:
    # H2D_P_ISO, H2D_P_ANISO, H2D_H_ISO, H2D_H_ANISO, H2D_HP_ISO, H2D_HP_ANISO_H, H2D_HP_ANISO_P, H2D_HP_ANISO
    # See User Documentation for details.

    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.

    ERR_STOP = 1.0  # Stopping criterion for adaptivity (rel. error tolerance between the
    # fine mesh and coarse mesh solution in percent).
    CONV_EXP = 1.0
    # Default value is 1.0. This parameter influences the selection of
    # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
    # fine mesh and coarse mesh solution in percent).
    NDOF_STOP = 60000  # Adaptivity process stops when the number of degrees of freedom grows
    # over this limit. This is to prevent h-adaptivity to go on forever.

    H2DRS_DEFAULT_ORDER = -1  # A default order. Used to indicate an unkonwn order or a maximum support order

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_motor_mesh())

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the discrete problem
    wf = WeakForm()
    set_forms(wf)

    # Initialize refinement selector.
    selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

    # Initialize the linear system.
    ls = LinSystem(wf)
    ls.set_spaces(space)

    sln_coarse = Solution()
    sln_fine = Solution()

    # Assemble and solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(sln_fine)

    # Either solve on coarse mesh or project the fine mesh solution
    # on the coarse mesh.
    if SOLVE_ON_COARSE_MESH:
        ls.assemble()
        ls.solve_system(sln_coarse)

    # Calculate element errors and total error estimate
    hp = H1Adapt(ls)
    hp.set_solutions([sln_coarse], [sln_fine])
    err_est = hp.calc_error() * 100
Exemplo n.º 24
0
def test_plot_mesh4():
    mesh = Mesh()
    mesh.load(domain_mesh)

    view = MeshView("Solution")
    view.show(mesh, lib="mpl", show=False, method="orders")
Exemplo n.º 25
0
def test_mesh_create2():
    m = Mesh()
    m.create([
            [0, -1],
            [1, -1],
            [-1, 0],
            [0, 0],
            [1, 0],
            [-1, 1],
            [0, 1],
            [0.707106781, 0.707106781],
        ], [
            [0, 1, 4, 3, 0],
            [3, 4, 7, 0],
            [3, 7, 6, 0],
            [2, 3, 6, 5, 0],
        ], [
            [0, 1, 1],
            [1, 4, 2],
            [3, 0, 4],
            [4, 7, 2],
            [7, 6, 2],
            [2, 3, 4],
            [6, 5, 2],
            [5, 2, 3],
        ], [
            [4, 7, 45],
            [7, 6, 45],
        ])
    assert compare(m.nodes, [
            [0, -1],
            [1, -1],
            [-1, 0],
            [0, 0],
            [1, 0],
            [-1, 1],
            [0, 1],
            [0.707106781, 0.707106781],
        ], eps=1e-4)
    assert m.elements_markers == [
            [0, 1, 4, 3, 0],
            [3, 4, 7, 0],
            [3, 7, 6, 0],
            [2, 3, 6, 5, 0],
        ]
    assert m.elements == [
            [0, 1, 4, 3],
            [3, 4, 7],
            [3, 7, 6],
            [2, 3, 6, 5],
        ]
    # This is not yet implemented:
    #assert m.boundaries == [
    #        [0, 1, 1],
    #        [1, 4, 2],
    #        [3, 0, 4],
    #        [4, 7, 2],
    #        [7, 6, 2],
    #        [2, 3, 4],
    #        [6, 5, 2],
    #        [5, 2, 3],
    #    ]
    #assert mesh.nurbs == ...
    m.refine_all_elements()
    assert m.elements == [
            [0, 11, 20, 19], [11, 1, 9, 20], [20, 9, 4, 8], [19, 20, 8, 3],
            [3, 8, 34], [8, 4, 33], [34, 33, 7], [33, 34, 8], [3, 34, 10],
            [34, 7, 12], [10, 12, 6], [12, 10, 34], [2, 18, 16, 15],
            [18, 3, 10, 16], [16, 10, 6, 17], [15, 16, 17, 5]
            ]
Exemplo n.º 26
0
                            # 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.
CONV_EXP = 1             # Default value is 1.0. This parameter influences the selection of
                            # cancidates in hp-adaptivity. See get_optimal_refinement() for details.
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 = 60000        # 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.

H2DRS_DEFAULT_ORDER = -1 # A default order. Used to indicate an unkonwn order or a maximum support order

# Load the mesh
umesh = Mesh()
vmesh = Mesh()
umesh.load(get_bracket_mesh())
if MULTI == False:
    umesh.refine_towards_boundary(1, INIT_REF_BDY)
    
# Create initial mesh (master mesh).
vmesh.copy(umesh)

# Initial mesh refinements in the vmesh towards the boundary
if MULTI == True:
    vmesh.refine_towards_boundary(1, INIT_REF_BDY)

# Create the x displacement space
uspace = H1Space(umesh, P_INIT_U)
vspace = H1Space(vmesh, P_INIT_V)
Exemplo n.º 27
0
def test_example_22():
    from hermes2d.examples.c22 import set_bc, set_forms

    #  The following parameters can be changed:
    SOLVE_ON_COARSE_MESH = True  # if true, coarse mesh FE problem is solved in every adaptivity step
    INIT_REF_NUM = 1  # Number of initial uniform mesh refinements
    P_INIT = 2  # Initial polynomial degree of all mesh elements.
    THRESHOLD = 0.3  # This is a quantitative parameter of the adapt(...) function and
    # it has different meanings for various adaptive strategies (see below).
    STRATEGY = 0  # 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.
    CAND_LIST = CandList.H2D_HP_ANISO  # Predefined list of element refinement candidates.
    # Possible values are are attributes of the class CandList:
    # P_ISO, P_ANISO, H_ISO, H_ANISO, HP_ISO, HP_ANISO_H, HP_ANISO_P, HP_ANISO
    # See the Sphinx tutorial (http://hpfem.org/hermes2d/doc/src/tutorial-2.html#adaptive-h-fem-and-hp-fem) for details.
    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.
    CONV_EXP = 0.5
    ERR_STOP = 0.1  # Stopping criterion for adaptivity (rel. error tolerance between the
    # fine mesh and coarse mesh solution in percent).
    NDOF_STOP = 60000  # Adaptivity process stops when the number of degrees of freedom grows
    # over this limit. This is to prevent h-adaptivity to go on forever.

    H2DRS_DEFAULT_ORDER = -1  # A default order. Used to indicate an unkonwn order or a maximum support order

    # Problem parameters.
    SLOPE = 60  # Slope of the layer.

    # Load the mesh
    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],
    ], [])

    # Perform initial mesh refinements
    mesh.refine_all_elements()

    # Create an H1 space with default shapeset
    space = H1Space(mesh, P_INIT)
    set_bc(space)

    # Initialize the weak formulation
    wf = WeakForm()
    set_forms(wf)

    # Initialize refinement selector
    selector = H1ProjBasedSelector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER)

    # Initialize the coarse mesh problem
    ls = LinSystem(wf)
    ls.set_spaces(space)

    # Adaptivity loop
    iter = 0
    done = False
    sln_coarse = Solution()
    sln_fine = Solution()

    # Assemble and solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(sln_fine)

    # Either solve on coarse mesh or project the fine mesh solution
    # on the coarse mesh.
    if SOLVE_ON_COARSE_MESH:
        ls.assemble()
        ls.solve_system(sln_coarse)

    # Calculate error estimate wrt. fine mesh solution
    hp = H1Adapt(ls)
    hp.set_solutions([sln_coarse], [sln_fine])
    err_est = hp.calc_error() * 100
Exemplo n.º 28
0
#! /usr/bin/env python

# This example shows how to load a mesh, perform various types
# of "manual"  element refinements.

# Import modules
from hermes2d import Mesh, MeshView
from hermes2d.examples import get_example_mesh

# Load the mesh file
domain_mesh = get_example_mesh()
mesh = Mesh()
mesh.load(domain_mesh)

# Perform some sample initial refinements
mesh.refine_all_elements();           # Refines all elements.
#mesh.refine_towards_vertex(3, 4);    # Refines mesh towards vertex #3 (4x).
#mesh.refine_towards_boundary(2, 4);  # Refines all elements along boundary 2 (4x).

# Display the mesh
mesh.plot()
Exemplo n.º 29
0
 def get_mesh(self):
     from hermes2d import Mesh
     m = Mesh()
     m.create(self._nodes, self._elements, self._boundaries, self._curves)
     return m