#! /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()
# 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) else: ls.project_global(sln_fine, sln_coarse) # View the solution and mesh sview.show(sln_coarse); mesh.plot(space=space) # Calculate error estimate wrt. fine mesh solution hp = H1Adapt(ls) hp.set_solutions([sln_coarse], [sln_fine]) err_est = hp.calc_error() * 100 print("Error estimate: %d" % err_est) # If err_est too large, adapt the mesh if (err_est < ERR_STOP): done = True else: done = hp.adapt(selector, THRESHOLD, STRATEGY, MESH_REGULARITY) if (ls.get_num_dofs() >= NDOF_STOP): done = True
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) # Visualize the approximation sln.plot() # Visualize the mesh mesh.plot(space=space)
# 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") # Visualize the solution view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600) E = float(200e9) nu = 0.3 l = (E * nu) / ((1 + nu) * (1 - 2 * nu)) mu = E / (2 * (1 + nu)) stress = VonMisesFilter(xsln, ysln, mu, l) view.show(stress) # Visualize the mesh mesh.plot(space=xdisp)
#! /usr/bin/env python import sys from hermes2d import Mesh m = Mesh() m.load(sys.argv[1]) m.plot(lib="mpl", method="simple")
# 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") # Visualize the solution view = ScalarView("Von Mises stress [Pa]", 50, 50, 1200, 600) E = float(200e9) nu = 0.3 l = (E * nu) / ((1 + nu) * (1 - 2*nu)) mu = E / (2*(1 + nu)) stress = VonMisesFilter(xsln, ysln, mu, l) view.show(stress) # Visualize the mesh mesh.plot(space=xdisp)
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") else: ls.project_global() # View the solution and meshes uview.show(u_sln_coarse) vview.show(v_sln_coarse) umesh.plot(space=uspace) vmesh.plot(space=vspace) # 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 print("Error estimate: %s" % err_est) # If err_est too large, adapt the mesh if err_est < ERR_STOP: done = True else: MULTI = False if MULTI == True else True