.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_unloading_stiffness_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_unloading_stiffness_fit.py: Unloading Stiffness Fit ======================= This example shows how the unloading part of a force-depth curve is fitted to obtain the contact stiffness used by the Oliver-Pharr method. .. GENERATED FROM PYTHON SOURCE LINES 8-15 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from micromechanics.indentation import Indentation from micromechanics.indentation.definitions import Method .. GENERATED FROM PYTHON SOURCE LINES 16-20 Build a compact synthetic load-unload experiment. The loading segment rises linearly, while the unloading segment follows a power law with a known residual depth. The synthetic data makes it easy to see which part of the curve is used for the stiffness fit. .. GENERATED FROM PYTHON SOURCE LINES 20-29 .. code-block:: Python loading_depth = np.linspace(0.0, 1.0, 24) loading_force = np.linspace(0.0, 5.0, 24) unloading_depth = np.linspace(1.0, 0.25, 36) unloading_force = 5.0*((unloading_depth-0.1)/(1.0-0.1))**1.5 depth = np.r_[loading_depth, unloading_depth] force = np.r_[loading_force, unloading_force] .. GENERATED FROM PYTHON SOURCE LINES 30-33 ``iLHU`` stores the load-hold-unload indices as ``[load start, load end, unload start, unload end]``. Real instrument files populate this during loading or with ``identifyLoadHoldUnload``. .. GENERATED FROM PYTHON SOURCE LINES 33-40 .. code-block:: Python indentation = Indentation("") indentation.method = Method.ISO indentation.setRawData(depth, force, np.arange(len(depth), dtype=float)) indentation.iLHU = [[0, len(loading_depth)-1, len(loading_depth), len(depth)-1]] indentation.output["verbose"] = 3 .. 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 41-43 The fitting routine returns the stiffness, a mask marking the evaluated point, the unloading-fit mask, the optimized power-law parameters, and a success flag. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python stiffness, valid, mask, opt, powerlaw_fit = indentation.stiffnessFromUnloading(force, depth, plot=True) print(f"Fitted unloading stiffness: {stiffness[0]:.2f} mN/um") print(f"Power-law fit succeeded: {powerlaw_fit[0]}") .. image-sg:: /auto_examples/images/sphx_glr_plot_unloading_stiffness_fit_001.png :alt: plot unloading stiffness fit :srcset: /auto_examples/images/sphx_glr_plot_unloading_stiffness_fit_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Number of unloading segments:1 Method:1 Initial fitting values B,hf,m 6.755229140733971 0.21344081076517907 1.2589254117941673 Bounds (array([0. , 0. , 0.8]), array([ inf, 0.67857143, 10. ])) Optimal values B,hf,m 5.856069741415784 0.1000000000415452 1.4999999999144056 Fitted unloading stiffness: 8.33 mN/um Power-law fit succeeded: True .. GENERATED FROM PYTHON SOURCE LINES 49-51 The red dashed line in the figure is the tangent stiffness. This is the slope that later enters the Oliver-Pharr contact-depth and modulus calculation. .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: Python plt.plot(depth[valid], force[valid], "ro", label="stiffness point") plt.plot(depth[mask], force[mask], "C0o", fillstyle="none", label="fit domain") plt.legend() .. image-sg:: /auto_examples/images/sphx_glr_plot_unloading_stiffness_fit_002.png :alt: plot unloading stiffness fit :srcset: /auto_examples/images/sphx_glr_plot_unloading_stiffness_fit_002.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.188 seconds) .. _sphx_glr_download_auto_examples_plot_unloading_stiffness_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_unloading_stiffness_fit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_unloading_stiffness_fit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_unloading_stiffness_fit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_