.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_hertz_contact_fit.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_auto_examples_plot_hertz_contact_fit.py: Hertz Contact Fit ================= This example creates an ideal elastic loading segment for a spherical indenter, adds a small displacement offset, and fits the first part of the curve with the Hertz contact equation. .. GENERATED FROM PYTHON SOURCE LINES 9-16 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from micromechanics.indentation import Indentation from micromechanics.indentation.hertz import hertzEquation .. GENERATED FROM PYTHON SOURCE LINES 17-20 Start from an empty :class:`Indentation` object. In a real workflow the depth and force arrays would usually come from an instrument file. Here they are generated explicitly so the fitted contact point and modulus are known. .. GENERATED FROM PYTHON SOURCE LINES 20-24 .. code-block:: Python indentation = Indentation("") indentation.output["verbose"] = 2 .. rst-class:: sphx-glr-script-out .. code-block:: none *WARNING*: Poisson Ratio different than in file. 0.3 0.18 Open Agilent file: /home/runner/work/micromechanics/micromechanics/micromechanics/indentation/data/Example.xls .. GENERATED FROM PYTHON SOURCE LINES 25-28 The Hertz equation describes elastic contact between a spherical indenter and a flat sample. ``true_h0`` shifts the apparent zero of depth, which mimics the practical problem of finding the first physical contact point. .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python true_h0 = 0.018 true_reduced_modulus = 9500.0 depth = np.linspace(0.0, 0.18, 80) force = hertzEquation(depth.copy(), true_h0, true_reduced_modulus) .. GENERATED FROM PYTHON SOURCE LINES 35-38 Assign the synthetic loading curve to the indentation object and fit only the low-load elastic part of the curve. The force range should be chosen before plastic deformation or pop-in events dominate the response. .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python indentation.setRawData(depth.copy(), force.copy(), np.arange(len(depth), dtype=float)) fit_h0, fit_reduced_modulus = indentation.hertzFit(forceRange=(0.02, 6.0), correctH=False, plot=False) .. rst-class:: sphx-glr-script-out .. code-block:: none Depth range (0.018227848101265823, 0.02278481012658228) Optimal parameters (h0,prefactor) [1.8e-02 9.5e+03] .. GENERATED FROM PYTHON SOURCE LINES 44-47 Plot the measured curve and the fitted Hertz curve. The dashed line marks the recovered contact point; for this synthetic data it should coincide with the known offset used above. .. GENERATED FROM PYTHON SOURCE LINES 47-58 .. code-block:: Python fit_depth = np.linspace(depth.min(), depth.max(), 200) fit_force = hertzEquation(fit_depth.copy(), fit_h0, fit_reduced_modulus) fig, ax = plt.subplots() ax.plot(depth, force, "o", label="synthetic loading segment") ax.plot(fit_depth, fit_force, "-", label="Hertz fit") ax.axvline(fit_h0, color="k", linestyle="dashed", label="fitted contact") ax.set_xlabel(r"depth [$\mathrm{\mu m}$]") ax.set_ylabel(r"force [$\mathrm{mN}$]") ax.legend() .. image-sg:: /auto_examples/images/sphx_glr_plot_hertz_contact_fit_001.png :alt: plot hertz contact fit :srcset: /auto_examples/images/sphx_glr_plot_hertz_contact_fit_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.130 seconds) .. _sphx_glr_download_auto_examples_plot_hertz_contact_fit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hertz_contact_fit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hertz_contact_fit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hertz_contact_fit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_