{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Interface reflection\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Interface between two materials\nAuthors: O. Castany, C. Molinaro, M. M\u00fcller\n\nInterface between two materials n1/n2.\nCalculations of the transmission and reflexion coefficients with varying incidence angle.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import elli\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.constants import c, pi"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Structure definition\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "n1 = 1\nn2 = 1.5\nfront = elli.IsotropicMaterial(elli.ConstantRefractiveIndex(n1))\nback = elli.IsotropicMaterial(elli.ConstantRefractiveIndex(n2))\n\n# Structure\ns = elli.Structure(front, [], back)\n\n# Parameters for the calculation\nlbda = 1000\nk0 = 2 * pi / lbda\nPhi_list = np.linspace(0, 89, 90)  # \u00a0range for the incidence angles"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Analytical calculation\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "Phi_i = np.deg2rad(Phi_list)\n\nPhi_t = np.arcsin((n1 * np.sin(Phi_i) / n2).astype(complex))\nkz1 = n1 * k0 * np.cos(Phi_i)\nkz2 = n2 * k0 * np.cos(Phi_t)\nr_s = (kz1 - kz2) / (kz1 + kz2)\nt_s = 1 + r_s\nr_p = (kz1 * n2**2 - kz2 * n1**2) / (kz1 * n2**2 + kz2 * n1**2)\nt_p = np.cos(Phi_i) * (1 - r_p) / np.cos(Phi_t)\n\n# Reflection and transmission coefficients, polarisation s and p\nR_th_ss = abs(r_s) ** 2\nR_th_pp = abs(r_p) ** 2\nt2_th_ss = abs(t_s) ** 2\nt2_th_pp = abs(t_p) ** 2\n# The power transmission coefficient is T = Re(kz2/kz1) \u00d7 |t|^2\ncorrection = np.real(kz2 / kz1)\nT_th_ss = correction * t2_th_ss\nT_th_pp = correction * t2_th_pp"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Calculation with pyElli\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data = elli.ResultList([s.evaluate(lbda, Phi_i) for Phi_i in Phi_list])\n\nR_pp = data.R_pp\nR_ss = data.R_ss\n\nT_pp = data.T_pp\nT_ss = data.T_ss\n\nt2_pp = np.abs(data.t_pp) ** 2\nt2_ss = np.abs(data.t_ss) ** 2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plotting\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(12.0, 6.0))\nplt.rcParams[\"axes.prop_cycle\"] = plt.cycler(\"color\", \"bgrcmk\")\nax = fig.add_axes([0.1, 0.1, 0.7, 0.8])\n\nd = np.vstack((R_ss, R_pp, t2_ss, t2_pp, T_ss, T_pp)).T\nlines1 = ax.plot(Phi_list, d)\nlegend1 = (\"R_ss\", \"R_pp\", \"t2_ss\", \"t2_pp\", \"T_ss\", \"T_pp\")\n\nd = np.vstack((R_th_ss, R_th_pp, t2_th_ss, t2_th_pp, T_th_ss, T_th_pp)).T\nlines2 = ax.plot(Phi_list, d, \".\")\nlegend2 = (\"R_th_ss\", \"R_th_pp\", \"t2_th_ss\", \"t2_th_pp\", \"T_th_ss\", \"T_th_pp\")\n\nax.legend(\n    lines1 + lines2,\n    legend1 + legend2,\n    loc=\"upper left\",\n    bbox_to_anchor=(1.05, 1),\n    borderaxespad=0.0,\n)\n\nax.set_title(\"Interface n$_1$={:} / n$_2$={:}\".format(n1, n2))\nax.set_xlabel(r\"Incidence angle $\\Phi_i$ \")\nax.set_ylabel(r\"Reflexion and transmission coefficients $R$, $T$, $|t|^2$\")\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.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}