| 1 |
""" |
| 2 |
.. _fea_hertzian_contact_pressure_example: |
| 3 |
|
| 4 |
Visualize Hertzian Contact Stress |
| 5 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 |
The following example demonstrates how to use PyVista to visualize |
| 7 |
Hertzian contact stress between a cylinder and a flat plate. |
| 8 |
|
| 9 |
This example loads a dataset, constructs a line to represent the point of |
| 10 |
contact between the cylinder and the block, and samples the stress along that |
| 11 |
line. Finally, it plots the dataset and the stress distribution. |
| 12 |
|
| 13 |
**Background** |
| 14 |
Hertzian contact stress refers to the stress that occurs between two curved |
| 15 |
surfaces that are in contact with each other. It is named after Heinrich Rudolf |
| 16 |
Hertz, a German physicist who first described the phenomenon in the late |
| 17 |
1800s. Hertzian contact stress is an important concept in materials science, |
| 18 |
engineering, and other fields where the behavior of materials under stress is a |
| 19 |
critical consideration. |
| 20 |
|
| 21 |
""" |
| 22 |
|
| 23 |
import matplotlib.pyplot as plt |
| 24 |
import numpy as np |
| 25 |
import pyvista as pv |
| 26 |
from pyvista import examples |
| 27 |
|
| 28 |
# %% |
| 29 |
# Load the dataset |
| 30 |
# ~~~~~~~~~~~~~~~~ |
| 31 |
# Start by loading the dataset from the examples module with |
| 32 |
# :func:`~pyvista.examples.downloads.download_fea_hertzian_contact_cylinder`. |
| 33 |
# This module provides access to a range of datasets, including FEA |
| 34 |
# (finite element analysis) datasets that are useful for stress analysis. |
| 35 |
|
| 36 |
mesh = examples.download_fea_hertzian_contact_cylinder() |
| 37 |
mesh |
| 38 |
|
| 39 |
|
| 40 |
# %% |
| 41 |
# Plot the Dataset |
| 42 |
# ~~~~~~~~~~~~~~~~ |
| 43 |
# Plot the dataset by part ID. |
| 44 |
|
| 45 |
mesh.plot(scalars='PartID', cmap=['green', 'blue'], show_scalar_bar=False) |
| 46 |
|
| 47 |
|
| 48 |
# %% |
| 49 |
# Creating a Line to Denote the Point of Contact |
| 50 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 51 |
# Construct a line to represent the point of contact between the cylinder and |
| 52 |
# the plate. |
| 53 |
|
| 54 |
ypos = 0.024 |
| 55 |
a = [0.1, ypos, 0.2 - 1e-4] |
| 56 |
b = [0.095, ypos, 0.2 - 1e-4] |
| 57 |
line = pv.Line(a, b, resolution=100) |
| 58 |
line.clear_data() |
| 59 |
line |
| 60 |
|
| 61 |
# %% |
| 62 |
# Sampling the Stress along the Line |
| 63 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 64 |
# We can sample the Z component stress along the contact edge and compare it |
| 65 |
# with expected pressure. |
| 66 |
# |
| 67 |
# The expected values array is the Hertzian contact pressure and is the |
| 68 |
# analytical solution to the non-adhesive contact problem. Computation of these |
| 69 |
# values is an exercise left up to the reader (the radius of the cylinder is |
| 70 |
# 0.05). See `Contact Mechanics |
| 71 |
# <https://en.wikipedia.org/wiki/Contact_mechanics>`_ |
| 72 |
|
| 73 |
# Sample the stress |
| 74 |
sampled = line.sample(mesh, tolerance=1e-3) |
| 75 |
x_coord = 0.1 - sampled.points[:, 0] |
| 76 |
samp_z_stress = -sampled['Stress'][:, 2] |
| 77 |
|
| 78 |
# Expected Hertzian contact pressure |
| 79 |
h_pressure = np.array( |
| 80 |
[ |
| 81 |
[0.0000, 1718094092], |
| 82 |
[0.0002, 1715185734], |
| 83 |
[0.0004, 1703502649], |
| 84 |
[0.0006, 1683850714], |
| 85 |
[0.0008, 1655946243], |
| 86 |
[0.001, 1619362676], |
| 87 |
[0.0012, 1573494764], |
| 88 |
[0.0014, 1517500856], |
| 89 |
[0.0016, 1450208504], |
| 90 |
[0.0018, 1369953775], |
| 91 |
[0.002, 1274289906], |
| 92 |
[0.0022, 1159408887], |
| 93 |
[0.0024, 1018830677], |
| 94 |
[0.0026, 839747409.8], |
| 95 |
[0.0028, 587969605.2], |
| 96 |
[0.003, 0], |
| 97 |
[0.005, 0], |
| 98 |
], |
| 99 |
) |
| 100 |
|
| 101 |
plt.plot(x_coord, samp_z_stress, '.', label='Z Component Stress') |
| 102 |
plt.plot(h_pressure[:, 0], h_pressure[:, 1], label='Hertzian contact pressure') |
| 103 |
plt.legend() |
| 104 |
plt.show() |
| 105 |
|
| 106 |
|
| 107 |
# %% |
| 108 |
# Visualizing the Z Stress Distribution |
| 109 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 110 |
# You can now visualize the Z stress distribution. Use :class:`pyvista.Plotter` to |
| 111 |
# create a plot window and add the dataset to it. |
| 112 |
|
| 113 |
pl = pv.Plotter() |
| 114 |
z_stress = np.abs(mesh['Stress'][:, 2]) |
| 115 |
pl.add_mesh( |
| 116 |
mesh, |
| 117 |
scalars=z_stress, |
| 118 |
clim=[0, 1.2e9], |
| 119 |
cmap='gouldian', |
| 120 |
scalar_bar_args={'title': 'Z Component Stress (Pa)', 'color': 'w'}, |
| 121 |
lighting=True, |
| 122 |
show_edges=False, |
| 123 |
ambient=0.2, |
| 124 |
) |
| 125 |
pl.camera_position = 'xz' |
| 126 |
pl.set_focus(a) |
| 127 |
pl.camera.zoom(2.5) |
| 128 |
pl.show() |