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: P_INIT = 1 # 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. 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.1 # 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_motor_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 discrete problem wf = WeakForm(1) set_forms(wf) # Matrix solver solver = DummySolver() # Adaptivity loop it = 1 ndofs = 0 done = False cpu = 0.0 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
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.1 # 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_motor_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 discrete problem wf = WeakForm(1)
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
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
# 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 views sview = ScalarView("Coarse solution", 0, 0, 600, 1000) #gview = VectorView("Gradient", 610, 0, 600, 1000) oview = OrderView("Polynomial orders", 1220, 0, 600, 1000) # Initialize refinement selector.