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)
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)
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)
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
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)
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)
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
FN_DX, FN_DY, H1OrthoHP, RefSystem, ) from hermes2d.forms import set_forms from hermes2d.examples import ( get_example_mesh, get_sample_mesh, get_cylinder_mesh, get_07_mesh, get_cathedral_mesh, get_bracket_mesh, ) domain_mesh = get_example_mesh() sample_mesh = get_sample_mesh() cylinder_mesh = get_cylinder_mesh() def test_example_01(): mesh = Mesh() mesh.load(domain_mesh) mesh.refine_all_elements() mesh.refine_all_elements() mesh.refine_all_elements() def test_example_02(): set_verbose(False)
#! /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()
#! /usr/bin/env python from hermes2d import Mesh, MeshView, H1Shapeset, PrecalcShapeset, H1Space, \ WeakForm, Solution, ScalarView, LinSystem, DummySolver from hermes2d.forms import set_forms 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()
# 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.
# # You can use this example to visualize all shape functions # on the reference square and reference triangle domains, # just load the corresponding mesh at the beginning of the file. # Import modules from hermes2d import Mesh, H1Shapeset, PrecalcShapeset, H1Space, \ BaseView from hermes2d.forms import set_forms from hermes2d.examples import get_example_mesh 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 # P_INIT to all mesh elements. # View the basis functions bview = BaseView()