.. 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() # alternative mesh below (uncomment the line) # mesh = fd.mesh.rectangle_mesh(nx=51, ny=51) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Now define the problem to solve ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 29-50 .. 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 51-57 Add periodic constraint ------------------------------------------------------------------------------ Add a periodic conditions (ie a multipoint constraint) Some global dof are automatically added to the problem: - 'E_xx', 'E_yy', 'E_xy' that refere to the mean strain components - The global vector 'MeanStrain' is also added .. GENERATED FROM PYTHON SOURCE LINES 57-59 .. code-block:: Python pb.bc.add(fd.constraint.PeriodicBC(periodicity_type="small_strain")) .. rst-class:: sphx-glr-script-out .. code-block:: none 2D Periodic Boundary Condition: name = 'Periodicity' .. GENERATED FROM PYTHON SOURCE LINES 60-62 Add standard boundary conditions ------------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 62-78 .. 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", "E_xx", Exx) # EpsXX pb.bc.add("Dirichlet", "E_xy", Exy) # EpsXY pb.bc.add("Dirichlet", "E_yy", 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 79-80 Solve and plot stress field .. GENERATED FROM PYTHON SOURCE LINES 80-90 .. code-block:: Python pb.solve() # ------------------------------------------------------------------------------ # Post-treatment # ------------------------------------------------------------------------------ res = pb.get_results("Assembly", ["Disp", "Stress", "MeanStrain"]) # plot the deformed mesh with the shear stress (component=3). res.plot("Stress", "XY", "Node") .. 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 91-92 print the macroscopic strain tensor and stress tensor .. GENERATED FROM PYTHON SOURCE LINES 92-102 .. code-block:: Python print( "Strain tensor ([Exx, Eyy, Exy]): ", [pb.get_dof_solution(component)[0] for component in ["E_xx", "E_yy", "E_xy"]], ) # 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(-3.834512085632014e-12), np.float64(-5.082836196379503e-12), np.float64(2497.6680151186256)] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.209 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 `_