{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create a parametric function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this basic example we are going to create a parametric function:\n",
    "\n",
    "$$ d_{L,I}(E, F):  \\mathbb{R}^2  \\rightarrow \\mathbb{R} $$\n",
    "\n",
    "function from an existing \"full\" function:\n",
    "\n",
    "$$ d(E, F, L, I):  \\mathbb{R}^4  \\rightarrow \\mathbb{R} $$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot\n",
    "import math as m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the function with all parameters d(E, F, L, I)\n",
    "def d_func(X):\n",
    "    E, F, L, I = X\n",
    "    d = -F * L**3 / (3.0 * E * I)\n",
    "    return [d]\n",
    "beam = ot.PythonFunction(4, 1, d_func)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[-1.33333]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=1 values=[-1.33333]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Evaluate d\n",
    "x = [50.0, 1.0, 10.0, 5.0]\n",
    "beam(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the indices of the frozen parameters (L,I) from the full parameter list\n",
    "indices = [2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create the values of the frozen parameters (L,I)\n",
    "referencePoint = [10.0, 5.0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create the parametric function\n",
    "beam_LI = ot.ParametricFunction(beam, indices, referencePoint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[-1.33333]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=1 values=[-1.33333]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Evaluate d on (E,F) with fixed parameters (L,I)\n",
    "beam_LI([50.0, 1.0])"
   ]
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
