{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"active-ipynb",
"remove-input",
"remove-output"
]
},
"outputs": [],
"source": [
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
" import condacolab\n",
" condacolab.install_miniconda()\n",
" !conda install -c conda-forge pyoptsparse\n",
" else:\n",
" missing_packages.append('pyoptsparse')\n",
"if missing_packages:\n",
" raise EnvironmentError('This notebook requires the following packages '\n",
" 'please install them and restart this notebook\\'s runtime: {\",\".join(missing_packages)}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Phases of a Trajectory\n",
"\n",
"Dymos uses the concept of *phases* to support intermediate boundary constraints and path constraints on variables in the system.\n",
"Each phase represents the trajectory of a dynamical system, and may be subject to different equations of motion, force models, and constraints.\n",
"Multiple phases may be assembled to form one or more trajectories by enforcing compatibility constraints between them.\n",
"\n",
"For implicit and explicit phases, the equations-of-motion or process equations are defined via an ordinary differential equation.\n",
"\n",
"An ODE is of the form\n",
"\n",
"\\begin{align} \n",
" \\frac{\\partial \\textbf x}{\\partial t} = \\textbf f(t, \\textbf x, \\textbf u)\n",
"\\end{align}\n",
"\n",
"where\n",
"$\\textbf x$ is the vector of *state variables* (the variable being integrated),\n",
"$t$ is *time* (or *time-like*),\n",
"$\\textbf u$ is the vector of *parameters* (an input to the ODE),\n",
"and\n",
"$\\textbf f$ is the *ODE function*.\n",
"\n",
"Dymos can treat the parameters $\\textbf u$ as either static **parameters** or dynamic **controls**.\n",
"In addition, Dymos automatically calculates the first and second time-derivatives of the controls.\n",
"These derivatives can then be utilized as via constraints or as additional parameters to the ODE.\n",
"Subsequently, the optimal control problem as solved by Dymos can be expressed as:\n",
"\n",
"\\begin{align}\n",
" \\textrm{Minimize}:& \\quad J = \\textbf f_{obj}(t, \\textbf x, \\textbf u, \\dot{\\textbf u}, \\ddot{\\textbf u}) \\\\\n",
" \\textrm{subject to:}& \\\\\n",
" &\\textrm{system dynamics} \\quad &\\frac{\\partial \\textbf x}{\\partial t} &= \\textbf f_{ode}(t, \\textbf x, \\textbf u, \\dot{\\textbf u}, \\ddot{\\textbf u}) \\\\\n",
" &\\textrm{initial time bounds} \\quad &t_{0,lb} &\\,\\le\\, t_0 \\,\\le\\, t_{0,ub} \\\\\n",
" &\\textrm{elapsed time bounds} \\quad &t_{p,lb} &\\,\\le\\, t_p \\,\\le\\, t_{p,ub} \\\\\n",
" &\\textrm{state bounds} \\quad &\\textbf x_{lb} &\\,\\le\\, \\textbf x \\,\\le\\, \\textbf x_{ub} \\\\\n",
" &\\textrm{control bounds} \\quad &\\textbf u_{lb} &\\,\\le\\, \\textbf u \\,\\le\\, \\textbf u_{ub} \\\\\n",
" &\\textrm{nonlinear boundary constraints} \\quad &\\textbf g_{b,lb} &\\,\\le\\, \\textbf g_{b}(t, \\textbf x, \\textbf u, \\dot{\\textbf u}, \\ddot{\\textbf u}) \\,\\le\\, \\textbf g_{b,ub} \\\\\n",
" &\\textrm{nonlinear path constraints} \\quad &\\textbf g_{p,lb} &\\,\\le\\, \\textbf g_{p}(t, \\textbf x, \\textbf u, \\dot{\\textbf u}, \\ddot{\\textbf u}) \\,\\le\\, \\textbf g_{p,ub} \\\\\n",
"\\end{align}\n",
"\n",
"The ability to utilize control derivatives in the equations of motion provides some unique capabilities, namely the ability to\n",
"easily solve problems using _differential inclusion_, which will be demonstrated in the examples.\n",
"\n",
"The solution techniques used by the Phase classes in Dymos generally fall into three categories:\n",
"implicit, explicit, and analytic. They differ in underlying details but mostly allow for the same\n",
"general form of the optimal control problem.\n",
"\n",
"Implicit solution techniques (using the _Radau Pseudospectral Method_ or _Gauss-Lobatto Collocation_ solve the ODE \"all at once\" and iteratively change the values of the state variables until the rates of change from the dynamics agree with the rates of change obtained by fitting polynomials to the states over time.\n",
"Typically, some parameters and control variables affect the path of the state variables.\n",
"\n",
"Explicit solution techniques are typical _shooting_ techniques that propagate the dynamics forward in time from some given initial condition.\n",
"Like the implicit techniques, using an explicit numerical integration allows for some set of parameters or controls to affect the dynamics of the system.\n",
"\n",
"With an analytic solution, there is no numeric integration occuring because the solution is known analytically. These phases are a fast way to propagate simple dynamics when an analytic solution is avaiable.\n",
"The downside to analytic solutions is that they don't allow for the input of a general time-varying control.\n",
"Such systems are only controlled static _parameters_ of the phase.\n",
"\n",
"## Features of Implicit and Explicit Phases\n",
"\n",
"[Analytic Phases](analytic_phases.ipynb)\n",
"\n",
"[Segments](segments.ipynb)\n",
"\n",
"[Variables](variables.ipynb)\n",
"\n",
"[Constraints](constraints.ipynb)\n",
"\n",
"[Objective](objective.ipynb)\n",
"\n",
"[Timeseries Outputs](timeseries.ipynb)\n"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".md",
"format_name": "markdown"
}
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}