{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Rankine power cycle\n\nDemonstrate the Sankey class with a practical example of a Rankine power cycle.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\n\nfrom matplotlib.sankey import Sankey\n\nfig = plt.figure(figsize=(8, 9))\nax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],\n                     title=\"Rankine Power Cycle: Example 8.6 from Moran and \"\n                     \"Shapiro\\n\\x22Fundamentals of Engineering Thermodynamics \"\n                     \"\\x22, 6th ed., 2008\")\nHdot = [260.431, 35.078, 180.794, 221.115, 22.700,\n        142.361, 10.193, 10.210, 43.670, 44.312,\n        68.631, 10.758, 10.758, 0.017, 0.642,\n        232.121, 44.559, 100.613, 132.168]  # MW\nsankey = Sankey(ax=ax, format='%.3G', unit=' MW', gap=0.5, scale=1.0/Hdot[0])\nsankey.add(patchlabel='\\n\\nPump 1', rotation=90, facecolor='#37c959',\n           flows=[Hdot[13], Hdot[6], -Hdot[7]],\n           labels=['Shaft power', '', None],\n           pathlengths=[0.4, 0.883, 0.25],\n           orientations=[1, -1, 0])\nsankey.add(patchlabel='\\n\\nOpen\\nheater', facecolor='#37c959',\n           flows=[Hdot[11], Hdot[7], Hdot[4], -Hdot[8]],\n           labels=[None, '', None, None],\n           pathlengths=[0.25, 0.25, 1.93, 0.25],\n           orientations=[1, 0, -1, 0], prior=0, connect=(2, 1))\nsankey.add(patchlabel='\\n\\nPump 2', facecolor='#37c959',\n           flows=[Hdot[14], Hdot[8], -Hdot[9]],\n           labels=['Shaft power', '', None],\n           pathlengths=[0.4, 0.25, 0.25],\n           orientations=[1, 0, 0], prior=1, connect=(3, 1))\nsankey.add(patchlabel='Closed\\nheater', trunklength=2.914, fc='#37c959',\n           flows=[Hdot[9], Hdot[1], -Hdot[11], -Hdot[10]],\n           pathlengths=[0.25, 1.543, 0.25, 0.25],\n           labels=['', '', None, None],\n           orientations=[0, -1, 1, -1], prior=2, connect=(2, 0))\nsankey.add(patchlabel='Trap', facecolor='#37c959', trunklength=5.102,\n           flows=[Hdot[11], -Hdot[12]],\n           labels=['\\n', None],\n           pathlengths=[1.0, 1.01],\n           orientations=[1, 1], prior=3, connect=(2, 0))\nsankey.add(patchlabel='Steam\\ngenerator', facecolor='#ff5555',\n           flows=[Hdot[15], Hdot[10], Hdot[2], -Hdot[3], -Hdot[0]],\n           labels=['Heat rate', '', '', None, None],\n           pathlengths=0.25,\n           orientations=[1, 0, -1, -1, -1], prior=3, connect=(3, 1))\nsankey.add(patchlabel='\\n\\n\\nTurbine 1', facecolor='#37c959',\n           flows=[Hdot[0], -Hdot[16], -Hdot[1], -Hdot[2]],\n           labels=['', None, None, None],\n           pathlengths=[0.25, 0.153, 1.543, 0.25],\n           orientations=[0, 1, -1, -1], prior=5, connect=(4, 0))\nsankey.add(patchlabel='\\n\\n\\nReheat', facecolor='#37c959',\n           flows=[Hdot[2], -Hdot[2]],\n           labels=[None, None],\n           pathlengths=[0.725, 0.25],\n           orientations=[-1, 0], prior=6, connect=(3, 0))\nsankey.add(patchlabel='Turbine 2', trunklength=3.212, facecolor='#37c959',\n           flows=[Hdot[3], Hdot[16], -Hdot[5], -Hdot[4], -Hdot[17]],\n           labels=[None, 'Shaft power', None, '', 'Shaft power'],\n           pathlengths=[0.751, 0.15, 0.25, 1.93, 0.25],\n           orientations=[0, -1, 0, -1, 1], prior=6, connect=(1, 1))\nsankey.add(patchlabel='Condenser', facecolor='#58b1fa', trunklength=1.764,\n           flows=[Hdot[5], -Hdot[18], -Hdot[6]],\n           labels=['', 'Heat rate', None],\n           pathlengths=[0.45, 0.25, 0.883],\n           orientations=[-1, 1, 0], prior=8, connect=(2, 0))\ndiagrams = sankey.finish()\nfor diagram in diagrams:\n    diagram.text.set_fontweight('bold')\n    diagram.text.set_fontsize('10')\n    for text in diagram.texts:\n        text.set_fontsize('10')\n# Notice that the explicit connections are handled automatically, but the\n# implicit ones currently are not.  The lengths of the paths and the trunks\n# must be adjusted manually, and that is a bit tricky.\n\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. admonition:: References\n\n   The use of the following functions, methods, classes and modules is shown\n   in this example:\n\n   - `matplotlib.sankey`\n   - `matplotlib.sankey.Sankey`\n   - `matplotlib.sankey.Sankey.add`\n   - `matplotlib.sankey.Sankey.finish`\n\n"
      ]
    }
  ],
  "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.14.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}