{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f5513c65",
   "metadata": {},
   "source": [
    "# Share torque between a bonded core and a sleeve\n",
    "\n",
    "The core and the sleeve have equal twist per length because they are bonded. Predict which material carries more torque before editing the radii or either shear modulus. Run all cells after changing an input."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ee71410",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "a, b = .012, .020      # core and outer radii, m\n",
    "Gc, Gs = 79e9, 27e9   # core and sleeve shear moduli, Pa\n",
    "torque, length = 100., .60   # N m, m\n",
    "assert 0 < a < b and min(Gc,Gs,length) > 0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67fcf70f",
   "metadata": {},
   "source": [
    "## Compatibility sets the twist; equilibrium sets its magnitude\n",
    "The stresses differ across the material interface even though the tangential displacement is continuous. Check the torque independently by integrating the lever-arm weighted shear traction over the end face."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "952a7f40",
   "metadata": {},
   "outputs": [],
   "source": [
    "Jc,Js=np.pi*a**4/2,np.pi*(b**4-a**4)/2\n",
    "twist=torque/(Gc*Jc+Gs*Js)\n",
    "Tc,Ts=Gc*Jc*twist,Gs*Js*twist\n",
    "r1,r2=np.linspace(0,a,140),np.linspace(a,b,140)\n",
    "def integrate(y,x):\n",
    "    return np.sum(np.diff(x)*(y[1:]+y[:-1])/2)\n",
    "Tnum=integrate(2*np.pi*r1**2*Gc*twist*r1,r1)+integrate(2*np.pi*r2**2*Gs*twist*r2,r2)\n",
    "assert np.isclose(Tnum,torque,rtol=1e-4)\n",
    "print(f\"Torque shares {Tc:.2f} and {Ts:.2f} N m; end rotation {np.rad2deg(twist*length):.3f} degrees\")\n",
    "print(f\"Shear just inside/outside the interface: {Gc*a*twist/1e6:.2f} / {Gs*a*twist/1e6:.2f} MPa\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e19d99e",
   "metadata": {},
   "source": [
    "## Distinguish a local stress peak from a total torque\n",
    "The left panel is the actual section. The right panel sweeps the core radius at constant outer radius and material properties."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "defe2ad2",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig,ax=plt.subplots(1,2,figsize=(9,3.5),layout=\"constrained\")\n",
    "ax[0].plot(r1*1e3,Gc*twist*r1/1e6,label=\"Core\")\n",
    "ax[0].plot(r2*1e3,Gs*twist*r2/1e6,label=\"Sleeve\")\n",
    "ax[0].set(xlabel=\"Radius (mm)\",ylabel=\"End-face shear stress (MPa)\",title=\"Bonded cross section\")\n",
    "fraction=np.linspace(.01,.99,250)\n",
    "share=Gc*fraction**4/(Gc*fraction**4+Gs*(1-fraction**4))\n",
    "ax[1].plot(fraction,share,label=\"Core share\")\n",
    "ax[1].plot(fraction,1-share,\"--\",label=\"Sleeve share\")\n",
    "ax[1].set(xlabel=\"Core / outer radius\",ylabel=\"Fraction of torque\",title=\"Changing the core size\")\n",
    "for p in ax: p.legend(fontsize=8);p.grid(alpha=.22)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c908ff50",
   "metadata": {},
   "source": [
    "Set the two moduli equal. Does the stress jump persist? Find the radius fraction for equal torque share and verify by changing the input."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
