{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Create a discipline from analytical expressions\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import division, unicode_literals" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from numpy import array\n\nfrom gemseo.api import configure_logger, create_discipline\n\nconfigure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\nA simple :class:`.MDODiscipline` can be created\nusing analytic formulas, e.g. $y_1=2x^2$ and $y_2=5+3x^2z^3$,\nthanks to the :class:`.AnalyticDiscipline` class\nwhich is a quick alternative to model a simple analytic MDO problem.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create the dictionary of analytic outputs\nFirst of all, we have to define the output expressions in a dictionary\nwhere keys are output names and values are formula with :code:`string`\nformat:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "expressions_dict = {\"y_1\": \"2*x**2\", \"y_2\": \"5+3*x**2+z**3\"}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create the discipline\nThen, we create and instantiate the corresponding\n:class:`.AnalyticDiscipline`,\nwhich is a particular :class:`.MDODiscipline`.\nFor that, we use the API function :meth:`~gemseo.api.create_discipline` with:\n\n- :code:`discipline_name=\"AnalyticDiscipline\"`,\n- :code:`name=\"analytic\"`,\n- :code:`expressions_dict=expr_dict`.\n\nIn practice, we write:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "disc = create_discipline(\"AnalyticDiscipline\", expressions_dict=expressions_dict)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
|g| takes care of the grammars and\n :meth:`!MDODiscipline._run` method generation\n from the :code:`expressions_dict` argument.\n In the background, |g| considers that :code:`x` is a monodimensional\n float input parameter and :code:`y_1` and :code:`y_2` are\n monodimensional float output parameters.