{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib ipympl\n",
    "import pyvisco as visco\n",
    "from pyvisco import styles\n",
    "styles.format_fig()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "# Verification - Comparison with APDL 2021 R1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Raw measurement data in frequency domain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Load Eplexor raw measurement data\n",
    "modul = 'E'\n",
    "epl_raw = visco.load.file('./freq_raw/freq_Eplexor_raw.xls')\n",
    "df_raw, arr_RefT, units = visco.load.Eplexor_raw(epl_raw, modul)\n",
    "\n",
    "#Load user provided aT\n",
    "RefT = -5\n",
    "shift = visco.load.file('./freq_raw/freq_Eplexor_raw__shift_factors.csv')\n",
    "df_aT = visco.load.user_shift(shift)\n",
    "\n",
    "#Or use shift algorithmn from this notebook (uncomment following line)\n",
    "#df_aT = visco.master.get_aT(df_raw, RefT)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cf467fa6c0f14c1cba1efcbd55e5ae73",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 86764 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 86764 characters]' width=800.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Create master curve\n",
    "df_master = visco.master.get_curve(df_raw, df_aT, RefT)\n",
    "fig_master_shift = visco.master.plot_shift(df_raw, df_master, units)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "efdc204c8a6d4968a848c3f2a3225d18",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 41112 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 41112 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Shift functions\n",
    "df_WLF = visco.shift.fit_WLF(df_master.RefT, df_aT)\n",
    "df_poly_C, df_poly_K = visco.shift.fit_poly(df_aT)\n",
    "\n",
    "fig_shift, df_shift = visco.shift.plot(df_aT, df_WLF, df_poly_C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7b31af6839184c43b76d063cc28227a8",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 42912 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 42912 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Smooth master curve\n",
    "win = 5\n",
    "df_master = visco.master.smooth(df_master, win)\n",
    "fig_smooth = visco.master.plot_smooth(df_master, units)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "08c77dbe1b234b6ebed05c00ccfc2628",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 37656 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 37656 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Discretize number of Prony terms\n",
    "df_dis = visco.prony.discretize(df_master)\n",
    "fig_dis = visco.prony.plot_dis(df_master, df_dis, units)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "62985f50f951478b821e0d283ff6cc68",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 41976 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 41976 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Fit Prony series parameter\n",
    "prony, df_GMaxw = visco.prony.fit(df_dis)\n",
    "fig_fit = visco.prony.plot_fit(df_master, df_GMaxw, units)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "98059a3eae0340999d26c9917ce26790",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 45672 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 45672 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Plot Generalized Maxwell model\n",
    "fig_GMaxw = visco.prony.plot_GMaxw(df_GMaxw, units);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "37d4caceef224b14823fd7f4479deddd",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 50220 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 50220 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Compare Python fit with ANSYS APDL\n",
    "df_prony_ANSYS = visco.verify.load_prony_ANSYS('./freq_raw/prony_terms.MPL')\n",
    "prony_ANSYS = visco.verify.prep_prony_ANSYS(df_prony_ANSYS, prony)\n",
    "nprony = prony_ANSYS['df_terms'].shape[0]\n",
    "df_GMaxw_ANSYS = visco.prony.calc_GMaxw(**prony_ANSYS, decades = nprony)\n",
    "fig_fit_ANSYS = visco.verify.plot_fit_ANSYS(df_master, df_GMaxw, df_GMaxw_ANSYS, units)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2c845ed29de44a8faec4550bf0424847",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 19172 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 19172 characters]' width=800.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig_coeff = visco.prony.plot_param([prony, prony_ANSYS], ['Python', 'Ansys'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.7"
  },
  "voila": {
   "template": "classic"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
