{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Test :class:`WP2` class\n\nDefine a :class:`BarSet` bar configuration and use it with :class:`WP2` to compute\nelastic wave propagation in simple test cases.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nfrom elwaspatid import WP2, BarSet"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define a few parameters\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "E = 201e9  # Young modulus [Pa]\nrho = 7800  # Density [kg/m3]\nd = 0.020  # diameter [m]\nk = 2.4  # diameters ratio [-]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create the bar configurations: two bars in contact.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nm = 15\nbc = BarSet([E, E], [rho, rho], [.1, .13], [d, d], nmin=nm)  # same section\nbc2 = BarSet([E, E], [rho, rho], [.1, .13], [d, k*d], nmin=nm)  # section increase\nbc3 = BarSet([E, E], [rho, rho], [.1, .13], [k*d, d], nmin=nm)  # section reduction\nbc4 = BarSet([E, E], [rho, rho], [.1, .3], [d, d], nmin=nm)  # same section"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Define the incident wave vector\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "comp = np.zeros(20)  # incident wave\n#comp[0:20] = -1e3  # heavyside, compression (<0)\ncomp[0:7] = -2e3\ncomp[15:] = -1e3"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two identical bars, free-ends\nContact interface between the two bars: \n\n1. compression pulses cross the interface,\n2. are reflected as traction pulses on the free end (right), \n3. and traction is then reflected as compression on the contact interface,\n   as if this was a free end.\n\nAnd so on. Which means the pulse is trapped in the second bar.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2 = WP2(bc, comp, nstep=100, left='free', right='free')\ntest2.plot('2b_free')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two identical bars, free and fixed ends\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2 = WP2(bc, comp, nstep=100, left='free', right='fixed')\ntest2.plot('2b_freefixed')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two different bars, infinite-ends\nCompression pulses cross the interface and are partly reflected because of the \ndifference of impedance between the bars. At both end, no reflection occur \nsince infinite ends amounts to anechoic condition.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2f = WP2(bc3, comp, nstep=100, left='infinite', right='infinite')\ntest2f.plot('2b_anech')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two identical bars with traction pulse\nThe traction pulses do not cross the contact interface. The pulse is trapped \nin the firt bar.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2t = WP2(bc, -comp, nstep=100, left='free', right='free')\ntest2t.plot('2b_trac')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two bars, cross-section increase\nCompression is reflected as traction. \nRecall that the limit case of cross-section increase is the fixed end.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2a = WP2(bc2, comp, nstep=100, left='free', right='free')\ntest2a.plot('2b_incre')\n# test2av = WP2(bc2, comp, nstep=100, left='free', right='free', Vinit=10)\n# test2av.plot('2baugmv')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Two bars, cross-section reduction\nCompression is reflected as compression\nRecall that the limit case of cross-section reduction is the free end.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2d = WP2(bc3, comp, nstep=100, left='free', right='free')\ntest2d.plot('2b_reduc')\n# test2dv = WP2(bc3, comp, nstep=100, left='free', right='free', Vinit=10)\n# test2dv.plot('2bdimiv')\ntest2d.plotInterface(figname='interf')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## First bar with initial velocity\nPositive velocity: compression\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAs the first bar (=stricker) impacts the second bar, a compression pulse \ndevelops in both bars. The stricker being shorter that the second bar, the \ncompression pulse reaches the left end of the stricker and is reflected as \ntraction with the same magnitude as the compression pulse: traction cancels\ncompression and the force is null (traction can be considered as an unloading\nwave).\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2v = WP2(bc4, comp, nstep=100, left='free', right='free', Vinit=10)\ntest2v.plot('2b_veloc')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Negative velocity\nNothing happens, the left bar travels to the left.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "test2vn = WP2(bc4, comp, nstep=100, left='free', right='free', Vinit=-10)\ntest2vn.plot('2b_negveloc')\n\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
}