{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Parametric scalable MDO problem - MDF\nWe define a scalable problem based on two strongly coupled disciplines\nand a weakly one, with the following properties:\n\n- 3 shared design parameters,\n- 2 local design parameters for the first strongly coupled discipline,\n- 2 coupling variables for the first strongly coupled discipline,\n- 4 local design parameters for the second strongly coupled discipline,\n- 3 coupling variables for the second strongly coupled discipline.\n\nWe would like to solve this MDO problem by means of an MDF formulation.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from __future__ import division, unicode_literals\n\nfrom matplotlib import pyplot as plt\n\nfrom gemseo.api import configure_logger, create_scenario, generate_n2_plot\nfrom gemseo.problems.scalable.parametric.problem import TMScalableProblem\n\nconfigure_logger()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Instantiation of the scalable problem\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "n_shared = 3\nn_local = [2, 4]\nn_coupling = [2, 3]\nproblem = TMScalableProblem(n_shared, n_local, n_coupling)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Display the coupling structure\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "generate_n2_plot(problem.disciplines, save=False, show=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Solve the MDO using an MDF formulation\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "scenario = create_scenario(problem.disciplines, \"MDF\", \"obj\", problem.design_space)\nscenario.add_constraint(\"cstr_0\", \"ineq\")\nscenario.add_constraint(\"cstr_1\", \"ineq\")\nscenario.execute({\"algo\": \"NLOPT_SLSQP\", \"max_iter\": 100})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Post-process the results\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "scenario.post_process(\"OptHistoryView\", save=False, show=False)\n# Workaround for HTML rendering, instead of ``show=True``\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.10"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}