{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Create animations for plots in 2D\n\nUse the Output parser to extract info\n\nDownload Input files\n\n* :download:`dipole_2d.data <../../../../../examples/input_files/eddy_currents.data>`\n* :download:`dipole_2d.post.xml <../../../../../examples/input_files/eddy_currents.post.xml>`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting up\nStandard Loading of input, Parsing and Initializing RoxiePlotOutputs object\n\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from IPython.display import Image, display\n\nfrom roxieapi.commons.roxie_constants import PlotLabels\nfrom roxieapi.commons.types import Plot2D\nfrom roxieapi.output.parser import RoxieOutputParser\nfrom roxieapi.output.plots import RoxiePlotOutputs\n\nxml_file_path = \"../input_files/eddy_currents.post.xml\"\ndata_file_path = \"../input_files/eddy_currents.data\"\n\nplots = RoxiePlotOutputs(xml_file_path, data_file_path)\nparser = RoxieOutputParser(xml_file_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show available Coil plots\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "trans = plots.output.opt[1].step[1]\nprint(\"Coil Plots:\")\ndata_cols = trans.coilData.columns\nfor col in data_cols:\n if col in PlotLabels.plot2D_desc:\n lbl, desc = PlotLabels.lbl_desc_plot2D(col)\n print(f\" Plot {col}: {desc}\")\nfor hc_idx, hc in trans.harmonicCoils.items():\n data_cols = hc.strandData\n for col in data_cols:\n if col in PlotLabels.plot2D_desc:\n lbl, desc = PlotLabels.lbl_desc_plot2D(col)\n print(f\" Harmonic coil #{hc_idx}, Plot {col}: {desc}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show available Iron Mesh plots and Iron Mesh Plots for Eddy - Currents simulations\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(\"Iron mesh plots:\")\ndata_cols = plots.output.opt[1].step[1].meshData.columns\nfor col in data_cols:\n if col in PlotLabels.plotMesh2D_desc:\n lbl, desc = PlotLabels.lbl_desc_mesh2D(col)\n print(f\" Plot {col}: {desc}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can animate all kinds of the above plots!\nLet's plot the current densioty in the coils\n-------------------\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot_created = Plot2D.create(\"My 2D Animation - J\")\nplot_created.add_coilPlot(\"14\", harm_coil=1)\nfigure = plots.plots2d.create_anim(\n plot_created,\n opt_step=1,\n start_trans_step=1,\n end_trans_step=2,\n anim_filename=\"current_dens_coils_animation.gif\",\n)\ndisplay(Image(filename=\"current_dens_coils_animation.gif\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Let's plot the Vector Potential Az in the Iron Mesh plots\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot_created = Plot2D.create(\"My 2D Animation - I\")\nplot_created.add_meshPlot(\"34\")\nfigure = plots.plots2d.create_anim(\n plot_created,\n opt_step=1,\n start_trans_step=1,\n end_trans_step=2,\n anim_filename=\"az_animation.gif\",\n)\ndisplay(Image(filename=\"az_animation.gif\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Let's plot the current density during the excitation\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot_created = Plot2D.create(\"My 2D Animation - Jz\")\nplot_created.add_meshPlot(\"jz\")\nfigure = plots.plots2d.create_anim(\n plot_created,\n opt_step=1,\n start_trans_step=1,\n end_trans_step=2,\n anim_filename=\"jz_animation.gif\",\n)\ndisplay(Image(filename=\"jz_animation.gif\"))" ] } ], "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.11.13" } }, "nbformat": 4, "nbformat_minor": 0 }