{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Displacement and contact loss\nThis example illustrates the loss of contact when two bars in contact do not\nhave the same impedance. \n \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 Waveprop, WP2, BarSingle, BarSet \nplt.close('all')\n\nE = 210e9  # [MPa]\nrho = 7800  # [kg/m3]\nL = 1  # [m]\nd = 0.02  # [m]\n\nincw = np.zeros(80)  # incident wave\nincw[0:20] = 1  # /!\\ traction pulse"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Small impedance against large impedance\nThe impacting bar stays in contact with the right bar during one back-and-forth\ntravel of the compression wave in it. Then contact ceases and the left bar\nstrarts travelling to the left.\nA Heaviside compression pulse travels down the right bar.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "L = 1  # [m]\nbar = BarSet([E, E], [rho, rho], [L, 0.5*L], [d, 2*d], nmin=6)\ntestk = WP2(bar, left='free', right='infinite', Vinit=5)\ntestk.plot()\ntestk.plotInterface(0, 'interface')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Large impedance against small impedance\nIn that case, the impacting bar stays in contact indefinitly with the right\nbar and a \"stair\" compression pulse develops in the right bar, with steps of\ndecreasing amplitude.\nSee also `sphx_glr_auto_examples_plot_2_ElasticImpact.py`\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "bar = BarSet([E, E], [rho, rho], [L, L], [d, 0.5*d], nmin=6)\ntestl = WP2(bar, nstep=150, left='free', right='infinite', Vinit=5)\ntestl.plot()\n\ntestl.plotInterface(0, 'interface2')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Contact loss detection\n*Did not find yet a combination of bar set and initial conditions (or incident\nwave) showing the usefulness of automatic contact loss detection.*\n\nThis example however shows how to:\n\n- modify the section of a bar in a :class:`BarSet`.\n- set contact loss detection;\n\n### Second bar with section increase\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "bar = BarSet([E, E], [rho, rho], [.2*L, L], [.8*d, d], nmin=12)\nbar.changeSection(iseg=1, l=L/4, d=2*d)  # first section change on second bar\nbar.changeSection(iseg=1, l=L/2, d=4*d)  # second section change on second bar\nbar.plotProperties('Z')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### No contact loss\nCheck that no force cross the interface after separation of the two bars.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "testm = WP2(bar, nstep=150, left='free', right='infinite', Vinit=5, contactLoss=None)\ntestm.plot()\ntestm.plotInterface(0, 'NoCL')\nprint(testm.contact)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Contact loss\nAgain, check that no force cross the interface after separation of the two bars.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "testc = WP2(bar, nstep=150, left='free', right='infinite', Vinit=5, contactLoss=1e-9)\ntestc.plot()\ntestc.plotInterface(0, 'CL')\nprint(testc.contact)\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
}