{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Robust optimization of a power-to-power system \n\nThe robust design optimization of the Levelized Cost Of Electricity for a\nhydrogen-based power-to-power system for a dwelling in Belgium.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "In this first example, a robust design optimization is performed on a \ngrid-connected household in Brussels, supported by a photovoltaic-hydrogen system.\nTo optimize the system, 4 design variables are considered: the photovoltaic array capacity, \nelectrolyzer stack capacity, fuel cell stack capacity and\nhydrogen tank capacity. \nThe mean and standard deviation of the Levelized Cost Of Electricity (LCOE) are selected as objectives.\nThe CAPEX, OPEX, replacement cost and lifetime of the components are \nconsidered uncertain, as well as the wholesale electricity price, electricity demand,\ninterest rate and inflation rate. A detailed illustration of the energy system model and the stochastic space is provided in `lab:pvh2model`. \n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "After 150 generations, a trade-off exists between minimizing the LCOE mean and LCOE standard deviation:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import rheia.POST_PROCESS.post_process as rheia_pp\nimport matplotlib.pyplot as plt\n\ncase = 'H2_POWER'\n\neval_type = 'ROB'\n\nmy_opt_plot = rheia_pp.PostProcessOpt(case, eval_type)\n\nresult_dir = 'run_tutorial'\n\ny, x = my_opt_plot.get_fitness_population(result_dir)\n\nplt.plot(y[0], y[1], '-o')\nplt.xlabel('LCOE mean [euro/MWh]')\nplt.ylabel('LCOE standard deviation [euro/MWh]')\nplt.xticks([y[0][0], y[0][-1]])\nplt.yticks([y[1][0], y[1][-1]])\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The Pareto front illustrates a trade-off between minimizing the LCOE mean and LCOE standard deviation. \nThis means that no single design exists that simulateounsly achieves the minimum LCOE mean and minimum LCOE standard deviation.\nThe optimized LCOE mean design achieves an LCOE mean of 247 euro/MWh and a LCOE standard deviation of 46 euro/MWh.\nInstead, the robust design (i.e. the design with the lowest standard deviation) achieves an\nLCOE mean of 302 euro/MWh and a LCOE standard deviation of 38 euro/MWh.\nThe designs that correspond to this Pareto front have the following PV array capacity:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.plot(y[0],x[0],'-o')\nplt.xlabel('LCOE mean [euro/MWh]')\nplt.ylabel('system capacity [kWp]')\nplt.legend(['PV array'])\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Electrolyzer array and fuel cell array capacity:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "for x_in in x[1:3]:\n    plt.plot(y[0],x_in,'-o')\n\nplt.xlabel('LCOE mean [euro/MWh]')\nplt.ylabel('system capacity [kW]')\nplt.legend(['electrolyzer array, fuel cell array'])\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Hydrogen storage tank capacity:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "plt.plot(y[0],x[3],'-o')\nplt.xlabel('LCOE mean [euro/MWh]')\nplt.ylabel('system capacity [kWh]')\nplt.legend(['storage tank'])\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "These results indicate that the optimized LCOE mean is achieved by a PV array.\nIn order to improve the robustness of the LCOE, the optimizer gradually increases\nthe electrolyzer, fuel cell and storage tank capacity.\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.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}