{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Use :class:`Waveprop` to simulate SHPB test\nSimulate a test with Split Hopkinson Pressure Bars, assuming the sample has \npurely elastic behaviour.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nfrom elwaspatid import WP2, BarSet"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define material parameters.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "E = 201e9  # Young modulus [Pa]\nrho = 7800  # Density [kg/m3]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "SHPB bar configuration\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "b_kolsky = BarSet([E, E, 0.8*E, E], [rho, rho, rho, rho], [.6, 3, .05, 3.1],\n                   [0.028, 0.030, 0.025, 0.030], nmin=4)\ntestk = WP2(b_kolsky, nstep=400, left='free', right='free', Vinit=5)\ntestk.plot('shpb')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Get force at both ends of sample (segment index ``iseg=2``)\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "f1, v1, x1, ind1 = testk.getSignal(x=0, iseg=2, plot=False)\nf2, v2, x2, ind2 = testk.getSignal(x=0.05, iseg=2, plot=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Plot forces in the sample to see the buildup of equilibrium in the sample.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.figure('Fsample')\nplt.plot(testk.time*1e6, -f1/1000, '-', label='left')\nplt.plot(testk.time*1e6, -f2/1000, '-', label='right')\nplt.xlabel('time [\u00b5s]')\nplt.ylabel('force [kN]')\nplt.legend()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.15"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}