.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02-constraints/Periodic_BC_2D_Plate_with_hole.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_02-constraints_Periodic_BC_2D_Plate_with_hole.py: 2D periodic boundary condition ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Periodic boundary conditions are enforced on a 2D geometry with plane stress assumption (plate with hole). A mean strain tensor is enforced, and the resulting mean stress is estimated. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: Python import fedoo as fd import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 14-16 Dimension of the problem ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 16-18 .. code-block:: Python fd.ModelingSpace("2Dstress") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 19-21 Definition of the Geometry ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python mesh = fd.mesh.hole_plate_mesh(name="Domain") # alternative mesh below (uncomment the line) # Mesh.rectangle_mesh(Nx=51, Ny=51, x_min=-50, x_max=50, y_min=-50, y_max=50, ElementShape = 'quad4', name ="Domain") .. GENERATED FROM PYTHON SOURCE LINES 27-29 Adding virtual nodes related the macroscopic strain ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: Python strain_nodes = mesh.add_virtual_nodes(2) # The position of the virtual node has no importance. # For a problem in 2D with a 2D periodicity, we need 3 independant strain component # 2 nodes (with 2 dof per node in 2D) are required .. GENERATED FROM PYTHON SOURCE LINES 35-36 Now define the problem to solve .. GENERATED FROM PYTHON SOURCE LINES 36-57 .. code-block:: Python # ------------------------------------------------------------------------------ # Material definition # ------------------------------------------------------------------------------ fd.constitutivelaw.ElasticIsotrop(1e5, 0.3, name="ElasticLaw") # ------------------------------------------------------------------------------ # Mechanical weak formulation # ------------------------------------------------------------------------------ wf = fd.weakform.StressEquilibrium("ElasticLaw") # ------------------------------------------------------------------------------ # Global Matrix assembly # ------------------------------------------------------------------------------ fd.Assembly.create(wf, mesh, name="Assembly") # ------------------------------------------------------------------------------ # Static problem based on the just defined assembly # ------------------------------------------------------------------------------ pb = fd.problem.Linear("Assembly") .. GENERATED FROM PYTHON SOURCE LINES 58-65 Add periodic constraint ~~~~~~~~~~~~~~~~~~~~~~~~~~ Add a periodic conditions (ie a multipoint constraint) linked to the strain dof based on virtual nodes: - the dof 'DispX' of the node strain_nodes[0] will be arbitrary associated to the EXX strain component - the dof 'DispY' of the node strain_nodes[1] will be arbitrary associated to the EYY strain component - the dof 'DispY' of the node strain_nodes[0] will be arbitrary associated to the EXY strain component - the dof 'DispX' of the node strain_nodes[1] is not used and will be blocked to avoid singularity .. GENERATED FROM PYTHON SOURCE LINES 65-71 .. code-block:: Python pb.bc.add( fd.constraint.PeriodicBC( [strain_nodes[0], strain_nodes[1], strain_nodes[0]], ["DispX", "DispY", "DispY"] ) ) .. rst-class:: sphx-glr-script-out .. code-block:: none 2D Periodic Boundary Condition: name = 'Periodicity' .. GENERATED FROM PYTHON SOURCE LINES 72-73 Add standard boundary conditions .. GENERATED FROM PYTHON SOURCE LINES 73-93 .. code-block:: Python # ------------------------------------------------------------------------------ # Macroscopic strain components to enforce Exx = 0 Eyy = 0 Exy = 0.1 # Mean strain: Dirichlet (strain) or Neumann (associated mean stress) can be enforced pb.bc.add("Dirichlet", [strain_nodes[0]], "DispX", Exx) # EpsXX pb.bc.add("Dirichlet", [strain_nodes[0]], "DispY", Exy) # EpsXY pb.bc.add( "Dirichlet", [strain_nodes[1]], "DispX", 0 ) # nothing (blocked to avoir singularity) pb.bc.add("Dirichlet", [strain_nodes[1]], "DispY", Eyy) # EpsYY # Block one node to avoid singularity center = mesh.nearest_node(mesh.bounding_box.center) pb.bc.add("Dirichlet", center, "Disp", 0) .. rst-class:: sphx-glr-script-out .. code-block:: none List of boundary conditions: number of bc = 2 0: Dirichlet -> 'DispX' for 1 nodes set to 0 1: Dirichlet -> 'DispY' for 1 nodes set to 0 .. GENERATED FROM PYTHON SOURCE LINES 94-95 Solve and plot stress field .. GENERATED FROM PYTHON SOURCE LINES 95-107 .. code-block:: Python pb.solve() # ------------------------------------------------------------------------------ # Post-treatment # ------------------------------------------------------------------------------ res = pb.get_results("Assembly", ["Disp", "Stress"]) # plot the deformed mesh with the shear stress (component=3). res.plot("Stress", "XY", "Node") # simple matplotlib alternative if pyvista is not installed: # fd.util.field_plot_2d("Assembly", disp = pb.get_dof_solution(), dataname = 'Stress', component=3, scale_factor = 1, plot_edge = True, nb_level = 6, type_plot = "smooth") .. image-sg:: /examples/02-constraints/images/sphx_glr_Periodic_BC_2D_Plate_with_hole_001.png :alt: Periodic BC 2D Plate with hole :srcset: /examples/02-constraints/images/sphx_glr_Periodic_BC_2D_Plate_with_hole_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 108-109 print the macroscopic strain tensor and stress tensor .. GENERATED FROM PYTHON SOURCE LINES 109-119 .. code-block:: Python print( "Strain tensor ([Exx, Eyy, Exy]): ", [pb.get_disp("DispX")[-2], pb.get_disp("DispY")[-1], pb.get_disp("DispY")[-2]], ) # Compute the mean stress tensor surf = mesh.bounding_box.volume # total surface of the domain = volume in 2d mean_stress = [1 / surf * mesh.integrate_field(res["Stress"][i]) for i in [0, 1, 3]] print("Stress tensor ([Sxx, Syy, Sxy]): ", mean_stress) .. rst-class:: sphx-glr-script-out .. code-block:: none Strain tensor ([Exx, Eyy, Exy]): [np.float64(0.0), np.float64(0.0), np.float64(0.1)] Stress tensor ([Sxx, Syy, Sxy]): [np.float64(-4.118837182431889e-12), np.float64(-9.570732117936132e-12), np.float64(2497.6680151186065)] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.337 seconds) .. _sphx_glr_download_examples_02-constraints_Periodic_BC_2D_Plate_with_hole.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Periodic_BC_2D_Plate_with_hole.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Periodic_BC_2D_Plate_with_hole.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: Periodic_BC_2D_Plate_with_hole.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_