.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/analysis/directional_stiffness.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_analysis_directional_stiffness.py: Effective properties of a cubic material ======================================== This tutorial studies the directional stiffness of a cubic material .. GENERATED FROM PYTHON SOURCE LINES 7-15 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from matplotlib import cm, colors from simcoon import simmit as sim import os .. GENERATED FROM PYTHON SOURCE LINES 16-18 Define a grid of directions in 3D space using spherical coordinates (θ, φ) and compute the components of the unit vector n. .. GENERATED FROM PYTHON SOURCE LINES 18-32 .. code-block:: Python phi = np.linspace(0, 2 * np.pi, 128) # azimuthal angle in the xy-plane theta = np.linspace(0, np.pi, 128).reshape(128, 1) # polar angle n_1 = np.sin(theta) * np.cos(phi) n_2 = np.sin(theta) * np.sin(phi) n_3 = np.cos(theta) * np.ones(128) n = ( np.array([n_1 * n_1, n_2 * n_2, n_3 * n_3, n_1 * n_2, n_1 * n_3, n_2 * n_3]) .transpose(1, 2, 0) .reshape(128, 128, 1, 6) ) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Use Simcoon to obtain the cubic stiffness matrix L and its inverse (compliance M). .. GENERATED FROM PYTHON SOURCE LINES 34-42 .. code-block:: Python C11 = 185000.0 C12 = 158000.0 C44 = 39700.0 L = sim.L_cubic([C11, C12, C44], "Cii") M = np.linalg.inv(L) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Compute the directional stiffness E(n) = 1 / (nᵀ·M·n) for all directions. .. GENERATED FROM PYTHON SOURCE LINES 44-52 .. code-block:: Python S = (n @ M @ n.reshape(128, 128, 6, 1)).reshape(128, 128) E = 1.0 / S x = E * n_1 y = E * n_2 z = E * n_3 .. GENERATED FROM PYTHON SOURCE LINES 53-54 Plot the directional stiffness as a 3D surface. .. GENERATED FROM PYTHON SOURCE LINES 54-82 .. code-block:: Python fig = plt.figure(figsize=plt.figaspect(1)) ax = fig.add_subplot(111, projection="3d") norm = colors.Normalize(vmin=np.min(E), vmax=np.max(E), clip=False) surf = ax.plot_surface( x, y, z, rstride=1, cstride=1, norm=norm, facecolors=cm.bone(norm(E)), linewidth=0, antialiased=False, shade=False, ) ax.set_xlabel(r"$E_x$") ax.set_ylabel(r"$E_y$") ax.set_zlabel(r"$E_z$") scalarmap = cm.ScalarMappable(cmap=plt.cm.bone, norm=norm) cbar = fig.colorbar(scalarmap, ax=ax, shrink=0.7, pad=0.15) cbar.set_label(r"Directional stiffness $E$", rotation=270, labelpad=20) plt.tight_layout() plt.show() .. image-sg:: /examples/analysis/images/sphx_glr_directional_stiffness_001.png :alt: directional stiffness :srcset: /examples/analysis/images/sphx_glr_directional_stiffness_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.433 seconds) .. _sphx_glr_download_examples_analysis_directional_stiffness.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: directional_stiffness.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: directional_stiffness.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: directional_stiffness.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_