{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains material from [cbe67701-uncertainty-quantification](https://ndcbe.github.io/cbe67701-uncertainty-quantification);\n", "content is available [on Github](https://github.com/ndcbe/cbe67701-uncertainty-quantification.git).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [6.1 Nonlinear Diffusion-Reaction Equation](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.01-Contributed-Example.html) | [Contents](toc.html) | [6.3 Sensitivity Analysis with Adjoint Operators](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.03-Sensitivity-Analysis-with-Adjoint-Operators.html)
"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"source": [
"# 6.2 A Simple Example of Adjoint Sensitivity Analysis"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"source": [
"Han Gao (hgao1@nd.edu)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"outputs": [],
"source": [
"## import all needed Python libraries here\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.ticker import LinearLocator, FormatStrFormatter\n",
"from matplotlib import cm\n",
"from mpl_toolkits.mplot3d import Axes3D"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"source": [
"Here we give a very simple example of adjoint sensitivity analysis (SA) with analytic solution.\n",
"\n",
"Consider a system $$Q=\\int_0^{t=1}u(t)dt$$\n",
"$$s.t.\\;\\dot{u}=bu$$\n",
"$$\\quad\\quad u(0)=a$$\n",
"We want to find the $\\frac{\\partial Q}{\\partial a}$ and $\\frac{\\partial Q}{\\partial b}$ by SA.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"outputs": [],
"source": [
"\"\"\"define hyperparameters of the problem\"\"\"\n",
"ts=0 # Start Time\n",
"te=1 # End Time\n",
"\"\"\"define the time domain of the problem\"\"\"\n",
"T=np.linspace(ts,te,1000)\n",
"\"\"\"define the QOI function \"\"\"\n",
"qoi=lambda a,b:a/b*(np.exp(b*te)-1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"source": [
"Itergrate the system we can get\n",
"$$u(t)=a\\cdot e^{bt}$$\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"nbpages": {
"level": 1,
"link": "[6.2 A Simple Example of Adjoint Sensitivity Analysis](https://ndcbe.github.io/cbe67701-uncertainty-quantification/06.02-Contributed-Example.html#6.2-A-Simple-Example-of-Adjoint-Sensitivity-Analysis)",
"section": "6.2 A Simple Example of Adjoint Sensitivity Analysis"
}
},
"outputs": [
{
"data": {
"text/plain": [
"
"
]
}
],
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}