コード例 #1
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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)
コード例 #2
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)
コード例 #3
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
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
コード例 #4
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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")
コード例 #5
0
ファイル: test_plots.py プロジェクト: xj361685640/hermes-1
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")
コード例 #6
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)
コード例 #7
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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)
コード例 #8
0
ファイル: test_plots.py プロジェクト: hpfem/hermes2d
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")
コード例 #9
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)
コード例 #10
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")
コード例 #11
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)
コード例 #12
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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)
コード例 #13
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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)
コード例 #14
0
ファイル: test_basics.py プロジェクト: Zhonghua/hermes2d
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()
コード例 #15
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")
コード例 #16
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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")
コード例 #17
0
ファイル: test_examples.py プロジェクト: Richardma/hermes2d
def test_example_08():
    from hermes2d.examples.c08 import set_bc, set_forms

    set_verbose(False)

    mesh = Mesh()
    mesh.load(cylinder_mesh)
    #mesh.refine_element(0)
    #mesh.refine_all_elements()
    mesh.refine_towards_boundary(5, 3)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    xvel = H1Space(mesh, shapeset)
    yvel = H1Space(mesh, shapeset)
    press = H1Space(mesh, shapeset)
    xvel.set_uniform_order(2)
    yvel.set_uniform_order(2)
    press.set_uniform_order(1)

    set_bc(xvel, yvel, press)

    ndofs = 0
    ndofs += xvel.assign_dofs(ndofs)
    ndofs += yvel.assign_dofs(ndofs)
    ndofs += press.assign_dofs(ndofs)

    xprev = Solution()
    yprev = Solution()

    xprev.set_zero(mesh)
    yprev.set_zero(mesh)

    # initialize the discrete problem
    wf = WeakForm(3)
    set_forms(wf, xprev, yprev)

    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(xvel, yvel, press)
    sys.set_pss(pss)
    #dp.set_external_fns(xprev, yprev)

    # visualize the solution

    EPS_LOW = 0.0014

    for i in range(3):
        psln = Solution()
        sys.assemble()
        sys.solve_system(xprev, yprev, psln)
コード例 #18
0
ファイル: test_examples.py プロジェクト: Richardma/hermes2d
def test_example_07():
    from hermes2d.examples.c07 import set_bc, set_forms

    set_verbose(False)

    mesh = Mesh()
    mesh.load(sample_mesh)
    #mesh.refine_element(0)
    #mesh.refine_all_elements()
    #mesh.refine_towards_boundary(5, 3)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create an H1 space
    xdisp = H1Space(mesh, shapeset)
    ydisp = H1Space(mesh, shapeset)
    xdisp.set_uniform_order(8)
    ydisp.set_uniform_order(8)

    set_bc(xdisp, ydisp)

    ndofs = xdisp.assign_dofs(0)
    ndofs += ydisp.assign_dofs(ndofs)

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

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

    xsln = Solution()
    ysln = Solution()
    old_flag = set_warn_integration(False)
    sys.assemble()
    set_warn_integration(old_flag)
    sys.solve_system(xsln, ysln)

    E = float(200e9)
    nu = 0.3
    stress = VonMisesFilter(xsln, ysln, E / (2*(1 + nu)),
            (E * nu) / ((1 + nu) * (1 - 2*nu)))
コード例 #19
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)
コード例 #20
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()
コード例 #21
0
ファイル: test_basics.py プロジェクト: FranzGrenvicht/hermes
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()
コード例 #22
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
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)
コード例 #23
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
def test_example_04():
    from hermes2d.examples.c04 import set_bc

    set_verbose(False)

    mesh = Mesh()
    mesh.load(domain_mesh)
    # mesh.refine_element(0)
    # mesh.refine_all_elements()
    mesh.refine_towards_boundary(5, 3)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

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

    set_bc(space)

    space.assign_dofs()

    xprev = Solution()
    yprev = Solution()

    # initialize the discrete problem
    wf = WeakForm()
    set_forms(wf, -4)

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

    # assemble the stiffness matrix and solve the system
    sys.assemble()
    sln = Solution()
    sys.solve_system(sln)
    assert abs(sln.l2_norm() - 1.22729) < 1e-4
    assert abs(sln.h1_norm() - 2.90006) < 1e-4
コード例 #24
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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)
コード例 #25
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
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)

    mesh = Mesh()
    mesh.load(domain_mesh)
    mesh.refine_towards_vertex(3, 12)
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

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

    set_bc(space)

    space.assign_dofs()

    xprev = Solution()
    yprev = Solution()

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

    sln = Solution()
    solver = DummySolver()
    sys = LinSystem(wf, solver)
    sys.set_spaces(space)
    sys.set_pss(pss)
    sys.assemble()
    sys.solve_system(sln)
    assert abs(sln.l2_norm() - 0.535833) < 1e-4
    assert abs(sln.h1_norm() - 1.332908) < 1e-4
コード例 #26
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
def test_example_07():
    from hermes2d.examples.c07 import set_bc, set_forms

    set_verbose(False)

    P_INIT = 2  # Initial polynomial degree of all mesh elements.

    mesh = Mesh()
    mesh.load(get_07_mesh())

    # Initialize the shapeset and the cache
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # create finite element space
    space = H1Space(mesh, shapeset)
    space.set_uniform_order(P_INIT)
    set_bc(space)

    # Enumerate basis functions
    space.assign_dofs()

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

    # matrix solver
    solver = DummySolver()

    # Solve the problem
    sln = Solution()
    ls = LinSystem(wf, solver)
    ls.set_spaces(space)
    ls.set_pss(pss)
    ls.assemble()
    ls.solve_system(sln)
コード例 #27
0
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
コード例 #28
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
def test_example_09():
    from hermes2d.examples.c09 import set_bc, temp_ext, set_forms

    # The following parameters can be played with:
    P_INIT = 1  # polynomial degree of elements
    INIT_REF_NUM = 4  # number of initial uniform refinements
    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

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

    # for i in range(INIT_REF_NUM):
    #    mesh.refine_all_elements()
    # mesh.refine_towards_boundary(2, 5)

    # Set up shapeset
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # Set up spaces
    space = H1Space(mesh, shapeset)
    set_bc(space)
    space.set_uniform_order(P_INIT)

    # Enumerate basis functions
    space.assign_dofs()

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

    # Weak formulation
    wf = WeakForm(1)
    set_forms(wf, tsln)

    # Matrix solver
    solver = DummySolver()

    # Linear system
    ls = LinSystem(wf, solver)
    ls.set_spaces(space)
    ls.set_pss(pss)

    # Visualisation
    sview = ScalarView("Temperature", 0, 0, 450, 600)
    # title = "Time %s, exterior temperature %s" % (TIME, temp_ext(TIME))
    # Tview.set_min_max_range(0,20);
    # Tview.set_title(title);
    # Tview.fix_scale_width(3);

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

    # Assemble and solve
    ls.assemble()
    rhsonly = True
    ls.solve_system(tsln)
コード例 #29
0
ファイル: 03.py プロジェクト: davidquantum/hermes2dold
from hermes2d.examples import get_example_mesh

mesh = Mesh()
mesh.load(get_example_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)
コード例 #30
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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
コード例 #31
0
ファイル: test_examples.py プロジェクト: B-Rich/hermes-legacy
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
コード例 #32
0
ファイル: 04.py プロジェクト: davidquantum/hermes2dold
pss = PrecalcShapeset(shapeset)

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

set_bc(space)

space.assign_dofs()

xprev = Solution()
yprev = Solution()

# initialize the discrete problem
wf = WeakForm()
set_forms(wf, -4)

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

# assemble the stiffness matrix and solve the system
sys.assemble()
sln = Solution()
sys.solve_system(sln)

view = ScalarView("Solution")
view.show(sln, lib="mayavi")
# view.wait()
コード例 #33
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
コード例 #34
0
ファイル: test_examples.py プロジェクト: Zhonghua/hermes2d
def test_example_12():
    from hermes2d.examples.c12 import set_bc, set_forms
    from hermes2d.examples import get_example_mesh

    #  The following parameters can be changed:
    P_INIT = 1  # Initial polynomial degree of all mesh elements.
    THRESHOLD = 0.6  # 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.
    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.
    ERR_STOP = 0.01  # 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 to prevent h-adaptivity to go on forever.

    # Load the mesh
    mesh = Mesh()
    mesh.load(get_example_mesh())
    # mesh.load("hermes2d/examples/12.mesh")

    # Initialize the shapeset and the cache
    shapeset = H1Shapeset()
    pss = PrecalcShapeset(shapeset)

    # Create finite element space
    space = H1Space(mesh, shapeset)
    set_bc(space)
    space.set_uniform_order(P_INIT)

    # Enumerate basis functions
    space.assign_dofs()

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

    # Matrix solver
    solver = DummySolver()

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

    # Solve the coarse mesh problem
    ls = LinSystem(wf, solver)
    ls.set_spaces(space)
    ls.set_pss(pss)

    ls.assemble()
    ls.solve_system(sln_coarse)

    # Solve the fine mesh problem
    rs = RefSystem(ls)
    rs.assemble()
    rs.solve_system(sln_fine)

    # Calculate element errors and total error estimate
    hp = H1OrthoHP(space)
    err_est = hp.calc_error(sln_coarse, sln_fine) * 100
コード例 #35
0
# 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)

# Visualize the solution
sln.plot()

# Visualize the mesh
mesh.plot(space=space)
コード例 #36
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
コード例 #37
0
ファイル: 04.py プロジェクト: Zhonghua/hermes2d
#for i in range(UNIFORM_REF_LEVEL):
#    mesh.refine_all_elemenrs()

# Initialize the shapeset and the cache
shapeset = H1Shapeset()
pss = PrecalcShapeset(shapeset)

# Create an H1 space
space = H1Space(mesh, shapeset)
space.set_uniform_order(P_INIT)
set_bc(space)
space.assign_dofs()

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

# Initialize the linear system and solver
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)

# Visualize the solution
view = ScalarView("Solution")
view.show(sln, lib="mayavi")