.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/ex06_rubber-metal-spring.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_ex06_rubber-metal-spring.py: Hyperelastic Spring ------------------- .. topic:: A hyperelastic spring with rigid plane contacts. * read a mesh file * define an isotropic hyperelastic solid body * setup an elastic to rigid plane contact * export and plot the log. strain .. admonition:: This example requires external packages. :class: hint .. code-block:: pip install pypardiso A `meshed three-dimensional geometry <../_static/ex06_rubber-metal-spring_mesh.vtk>`_ of a rubber-metal spring is loaded by an external axial and lateral displacement. Simplified elastic-to-rigid contact definitions simulate the end stops caused by steel plates at the bottom and the top in direction :math:`z`. .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python import numpy as np import pypardiso import felupe as fem mesh = fem.mesh.read("ex06_rubber-metal-spring_mesh.vtk")[0] mesh.add_points([[0, 0, mesh.z.min()], [0, 0, mesh.z.max() + 0.1]]) mesh.plot().show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/images/sphx_glr_ex06_rubber-metal-spring_001.png :alt: ex06 rubber metal spring :srcset: /examples/images/sphx_glr_ex06_rubber-metal-spring_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/felupe-ja/checkouts/latest/felupe/docs/examples/images/sphx_glr_ex06_rubber-metal-spring_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 40-45 A numeric hexahedron-region created on the mesh in combination with a vector-valued displacement field represents the volume of the solid. Imported meshes may contain cells with negative volumes. This is fixed as proposed in the warning message. The Boundary conditions for the :math:`y`-symmetry plane as well as the fixed faces on the bottom and the top of the solid are generated on the displacement field. .. GENERATED FROM PYTHON SOURCE LINES 45-58 .. code-block:: Python region = fem.RegionHexahedron(mesh) mesh = mesh.flip(np.any(region.dV < 0, axis=0)) region = fem.RegionHexahedron(mesh) field = fem.FieldContainer([fem.Field(region, dim=3)]) boundaries = fem.dof.symmetry(field[0], axes=(0, 1, 0)) boundaries["fixed-contact"] = fem.Boundary(field[0], fz=mesh.z.max()) boundaries["fixed"] = fem.Boundary(field[0], fz=mesh.z.max() - 0.1) boundaries["move-x"] = fem.Boundary(field[0], fz=mesh.z.min(), skip=(0, 1, 1)) boundaries["move-y"] = fem.Boundary(field[0], fz=mesh.z.min(), skip=(1, 0, 1)) boundaries["move-z"] = fem.Boundary(field[0], fz=mesh.z.min(), skip=(1, 1, 0)) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/felupe-ja/envs/latest/lib/python3.12/site-packages/felupe/region/_region.py:387: UserWarning: Negative volumes for cells [ 0 1 2 ... 1467 1468 1469] Try ``mesh.flip(np.any(region.dV < 0, axis=0))`` and re-create the region. warnings.warn(message_negative_volumes) .. GENERATED FROM PYTHON SOURCE LINES 59-62 The material behavior is defined through a built-in hyperelastic isotropic Neo-Hookean material formulation. A solid body applies the material formulation on the displacement field. .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python umat = fem.NeoHookeCompressible(mu=1, lmbda=5) solid = fem.SolidBody(umat, field) .. GENERATED FROM PYTHON SOURCE LINES 66-70 The simplified elastic-to-rigid contact is defined by a multi-point constraint-like formulation which is only active in compression. First, the points on the surface of the solid body are determined. Then, the center (control) point is defined by one of the mesh points on the end faces in direction :math:`z`. .. GENERATED FROM PYTHON SOURCE LINES 70-91 .. code-block:: Python surface = np.unique(fem.RegionHexahedronBoundary(mesh).mesh_faces().cells) points = np.isin(np.arange(mesh.npoints), surface) bottom = fem.ContactRigidPlane( field, points=points, centerpoint=-2, normal=[0, 0, 1], friction=0.5, items=[solid], ) top = fem.ContactRigidPlane( field, points=points, centerpoint=-1, normal=[0, 0, -1], friction=0.5, items=[solid], ) .. GENERATED FROM PYTHON SOURCE LINES 92-94 The max. principal value of the logarithmic strain, projected to mesh points, will be added to the result file. .. GENERATED FROM PYTHON SOURCE LINES 94-104 .. code-block:: Python def log_strain(field, substep=None): "Project the max. principal log. strain from quadrature- to mesh-points." F = field.extract()[0] C = fem.math.dot(fem.math.transpose(F), F) strain = np.log(fem.math.eigvalsh(C)[-1]) / 2 return fem.project(strain, region) .. GENERATED FROM PYTHON SOURCE LINES 105-107 The simulation model is now ready to be solved. The results are saved within a XDMF- file, where additional point-data is passed to the ``point_data`` argument. .. GENERATED FROM PYTHON SOURCE LINES 107-133 .. code-block:: Python table = fem.math.linsteps([0, 1], num=4) axial = fem.Step( items=[solid, top, bottom], # , top, bottom ramp={boundaries["move-z"]: 40 * table}, boundaries=boundaries, ) lateral = fem.Step( items=[solid, top, bottom], ramp={boundaries["move-x"]: 40 * table}, boundaries=boundaries, ) job = fem.CharacteristicCurve(steps=[axial, lateral], boundary=boundaries["move-z"]) job.evaluate( filename="result.xdmf", solver=pypardiso.spsolve, point_data={"Logarithmic Strain (Max. Principal)": log_strain}, tol=1e-1, ) view = field.view( point_data={"Logarithmic Strain (Max. Principal)": log_strain(field)}, ) plotter = view.plot("Logarithmic Strain (Max. Principal)") plotter = top.plot(plotter=plotter, sym=(False, True, False), offset=0.1) plotter = bottom.plot(plotter=plotter, sym=(False, True, False), offset=0.1) plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/images/sphx_glr_ex06_rubber-metal-spring_002.png :alt: ex06 rubber metal spring :srcset: /examples/images/sphx_glr_ex06_rubber-metal-spring_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/felupe-ja/checkouts/latest/felupe/docs/examples/images/sphx_glr_ex06_rubber-metal-spring_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 134-137 The axial-compressive and lateral-shear force-displacement curves are obtained from the characteristic-curve job. The force is multiplied by two due to the fact that only one half of the geometry is simulated. .. GENERATED FROM PYTHON SOURCE LINES 137-145 .. code-block:: Python fig, ax = job.plot( xlabel=r"Displacement $d_Z$ in mm $\longrightarrow$", ylabel=r"Normal Force $F_Z$ in kN $\longrightarrow$", xaxis=2, yaxis=2, yscale=2 / 1000, ) .. image-sg:: /examples/images/sphx_glr_ex06_rubber-metal-spring_003.png :alt: ex06 rubber metal spring :srcset: /examples/images/sphx_glr_ex06_rubber-metal-spring_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 146-148 The shear lateral force-displacement curve is again obtained from the characteristic- curve job. .. GENERATED FROM PYTHON SOURCE LINES 148-155 .. code-block:: Python fig, ax = job.plot( xlabel=r"Displacement $d_X$ in mm $\longrightarrow$", ylabel=r"Normal Force $F_X$ in kN $\longrightarrow$", xaxis=0, yaxis=0, yscale=2 / 1000, ) .. image-sg:: /examples/images/sphx_glr_ex06_rubber-metal-spring_004.png :alt: ex06 rubber metal spring :srcset: /examples/images/sphx_glr_ex06_rubber-metal-spring_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.163 seconds) .. _sphx_glr_download_examples_ex06_rubber-metal-spring.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex06_rubber-metal-spring.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex06_rubber-metal-spring.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex06_rubber-metal-spring.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_