Skip to content

Commit

Permalink
re-run most notebooks to take advantage of nicer plotting defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Apr 6, 2024
1 parent ef0c24e commit 9d1b21d
Show file tree
Hide file tree
Showing 17 changed files with 2,151 additions and 1,804 deletions.
47 changes: 18 additions & 29 deletions tutorial/01 - Optimization and Math/01 - 2D Rosenbrock.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"outputs": [],
"source": [
"import aerosandbox as asb\n",
Expand All @@ -43,7 +43,8 @@
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"is_executing": true
}
},
{
Expand Down Expand Up @@ -241,9 +242,9 @@
"\n",
"sol = opti.solve()\n",
"\n",
"aspect_ratio_opt = sol.value(aspect_ratio)\n",
"wing_area_opt = sol.value(wing_area)\n",
"drag_opt = sol.value(drag)\n",
"aspect_ratio_opt = sol(aspect_ratio)\n",
"wing_area_opt = sol(wing_area)\n",
"drag_opt = sol(drag)\n",
"\n",
"print(f\"Minimum drag = {drag_opt} N\")\n",
"print(f\"Aspect ratio = {aspect_ratio_opt}\")\n",
Expand All @@ -263,7 +264,7 @@
"\n",
"We're finding a minimum achievable drag of 0.646 N, an aspect ratio of 296, and a wing area of $0.14\\ m^2$.\n",
"\n",
"What kind of lift-to-drag ratio does that correspond to? Recall that we can evaluate expressions with `sol.value()`:"
"What kind of lift-to-drag ratio does that correspond to? Recall that we can evaluate expressions with `sol()`:"
],
"metadata": {
"collapsed": false
Expand All @@ -282,7 +283,7 @@
}
],
"source": [
"L_over_D_opt = sol.value(lift / drag)\n",
"L_over_D_opt = sol(lift / drag)\n",
"print(f\"L/D = {L_over_D_opt}\")"
],
"metadata": {
Expand Down Expand Up @@ -354,4 +355,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,98 +28,6 @@
},
{
"cell_type": "code",
"execution_count": 103,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is Ipopt version 3.12.3, running with linear solver mumps.\n",
"NOTE: Other linear solvers might be more efficient (see Ipopt documentation).\n",
"\n",
"Number of nonzeros in equality constraint Jacobian...: 3\n",
"Number of nonzeros in inequality constraint Jacobian.: 6\n",
"Number of nonzeros in Lagrangian Hessian.............: 13\n",
"\n",
"Total number of variables............................: 5\n",
" variables with only lower bounds: 0\n",
" variables with lower and upper bounds: 0\n",
" variables with only upper bounds: 0\n",
"Total number of equality constraints.................: 1\n",
"Total number of inequality constraints...............: 2\n",
" inequality constraints with only lower bounds: 0\n",
" inequality constraints with lower and upper bounds: 0\n",
" inequality constraints with only upper bounds: 2\n",
"\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 0 2.7311812e+003 5.54e+003 2.47e+001 0.0 0.00e+000 - 0.00e+000 0.00e+000 0\n",
" 1 1.0164571e+004 2.51e+005 4.47e+002 1.6 6.53e+001 - 5.84e-001 5.00e-001f 2\n",
" 2 1.6042565e+003 2.19e+004 3.39e+003 0.0 6.16e-001 4.0 1.00e+000 1.00e+000f 1\n",
"Warning: SOC step rejected due to evaluation error\n",
" 3 5.5452390e+003 6.19e+001 1.07e+003 -1.9 1.26e+000 3.5 1.00e+000 5.00e-001h 2\n",
" 4 4.5726523e+003 1.95e-001 6.03e+001 -3.8 9.17e-002 3.0 1.00e+000 1.00e+000f 1\n",
" 5 4.3824598e+003 1.95e+000 3.37e+001 -5.6 9.37e-002 2.6 1.00e+000 1.00e+000f 1\n",
" 6 3.9046605e+003 1.78e+001 2.46e+001 -7.5 2.01e-001 2.1 1.00e+000 1.00e+000f 1\n",
" 7 3.2377521e+003 9.82e+001 1.24e+001 -9.4 2.99e-001 1.6 1.00e+000 1.00e+000f 1\n",
" 8 2.9148191e+003 2.42e+002 4.38e+000 -11.0 3.64e-001 1.1 1.00e+000 1.00e+000f 1\n",
" 9 2.8396309e+003 2.69e+002 2.33e+000 -11.0 5.23e-001 0.7 1.00e+000 1.00e+000h 1\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 10 2.7808251e+003 2.12e+002 9.53e-001 -11.0 6.03e-001 0.2 1.00e+000 1.00e+000h 1\n",
" 11 2.7530455e+003 1.23e+002 5.69e-001 -11.0 1.12e+000 -0.3 1.00e+000 1.00e+000h 1\n",
" 12 2.6822791e+003 2.26e+001 5.64e-001 -11.0 3.33e+000 -0.8 1.00e+000 1.00e+000h 1\n",
" 13 2.3967427e+003 7.64e+000 5.71e-001 -11.0 1.01e+001 -1.2 1.00e+000 1.00e+000f 1\n",
" 14 1.5145532e+003 2.62e+002 6.08e-001 -11.0 3.23e+001 -1.7 1.00e+000 1.00e+000f 1\n",
" 15 7.6624646e+002 7.03e+002 1.39e+000 -9.1 1.57e+002 -2.2 1.00e+000 1.71e-001f 1\n",
" 16 7.5485938e+002 7.01e+002 1.38e+000 -7.4 7.64e+001 -1.8 1.00e+000 3.51e-003f 1\n",
" 17 7.5470712e+002 7.01e+002 1.38e+000 -5.7 2.05e+001 -1.4 1.00e+000 1.31e-004h 1\n",
" 18 4.2617650e+002 3.49e+002 1.43e+000 -4.7 9.64e-001 -1.8 1.00e+000 1.00e+000f 1\n",
" 19 3.2848934e+002 6.14e+001 6.15e-001 -4.6 2.87e+000 -2.3 1.00e+000 1.00e+000h 1\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 20 3.0534050e+002 3.29e+001 9.81e-002 -6.8 8.76e+000 -2.8 1.00e+000 1.00e+000h 1\n",
" 21 3.0125313e+002 5.26e+001 3.58e-001 -3.6 8.06e+002 - 1.00e+000 5.58e-003f 1\n",
" 22 3.0218923e+002 2.52e+001 5.56e-002 -3.2 8.88e-002 - 1.00e+000 5.07e-001h 1\n",
" 23 3.0307666e+002 2.44e-003 1.21e-004 -5.3 1.23e-003 - 1.00e+000 1.00e+000h 1\n",
" 24 3.0307477e+002 2.64e-007 1.46e-008 -11.0 3.93e-004 - 1.00e+000 1.00e+000h 1\n",
" 25 3.0307477e+002 0.00e+000 1.07e-014 -11.0 5.08e-008 - 1.00e+000 1.00e+000h 1\n",
"\n",
"Number of Iterations....: 25\n",
"\n",
" (scaled) (unscaled)\n",
"Objective...............: 5.6476537149537931e+000 3.0307477258650493e+002\n",
"Dual infeasibility......: 1.0658141036401503e-014 5.7195675121676790e-013\n",
"Constraint violation....: 0.0000000000000000e+000 0.0000000000000000e+000\n",
"Complementarity.........: 1.0000000018060257e-011 5.3663837839665673e-010\n",
"Overall NLP error.......: 1.0000000018060257e-011 5.3663837839665673e-010\n",
"\n",
"\n",
"Number of objective function evaluations = 29\n",
"Number of objective gradient evaluations = 26\n",
"Number of equality constraint evaluations = 30\n",
"Number of inequality constraint evaluations = 30\n",
"Number of equality constraint Jacobian evaluations = 26\n",
"Number of inequality constraint Jacobian evaluations = 26\n",
"Number of Lagrangian Hessian evaluations = 25\n",
"Total CPU secs in IPOPT (w/o function evaluations) = 0.013\n",
"Total CPU secs in NLP function evaluations = 0.001\n",
"\n",
"EXIT: Optimal Solution Found.\n",
" solver : t_proc (avg) t_wall (avg) n_eval\n",
" nlp_f | 0 ( 0) 0 ( 0) 29\n",
" nlp_g | 0 ( 0) 0 ( 0) 30\n",
" nlp_grad_f | 0 ( 0) 0 ( 0) 27\n",
" nlp_hess_l | 1.00ms ( 40.00us) 1.00ms ( 40.00us) 25\n",
" nlp_jac_g | 0 ( 0) 0 ( 0) 27\n",
" total | 15.00ms ( 15.00ms) 14.37ms ( 14.37ms) 1\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"CasADi - WARNING(\"solver:nlp_f failed: NaN detected for output f, at (row 0, col 0).\") [.../casadi/core/oracle_function.cpp:265]\n"
]
}
],
"source": [
"import aerosandbox as asb\n",
"import aerosandbox.numpy as np\n",
Expand Down Expand Up @@ -185,8 +93,103 @@
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-04-05T23:41:32.216134Z",
"start_time": "2024-04-05T23:41:27.622855Z"
}
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is Ipopt version 3.14.11, running with linear solver MUMPS 5.4.1.\n",
"\n",
"Number of nonzeros in equality constraint Jacobian...: 3\n",
"Number of nonzeros in inequality constraint Jacobian.: 6\n",
"Number of nonzeros in Lagrangian Hessian.............: 13\n",
"\n",
"Total number of variables............................: 5\n",
" variables with only lower bounds: 0\n",
" variables with lower and upper bounds: 0\n",
" variables with only upper bounds: 0\n",
"Total number of equality constraints.................: 1\n",
"Total number of inequality constraints...............: 2\n",
" inequality constraints with only lower bounds: 0\n",
" inequality constraints with lower and upper bounds: 0\n",
" inequality constraints with only upper bounds: 2\n",
"\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 0 2.7311812e+03 5.54e+03 2.47e+01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0\n",
" 1 1.0164571e+04 2.51e+05 4.47e+02 1.6 6.53e+01 - 5.84e-01 5.00e-01f 2\n",
" 2 1.6042565e+03 2.19e+04 3.39e+03 0.0 6.16e-01 4.0 1.00e+00 1.00e+00f 1\n",
"Warning: SOC step rejected due to evaluation error\n",
" 3 5.5452390e+03 6.19e+01 1.07e+03 -1.9 1.26e+00 3.5 1.00e+00 5.00e-01h 2\n",
" 4 4.5726523e+03 1.95e-01 6.03e+01 -3.8 9.17e-02 3.0 1.00e+00 1.00e+00f 1\n",
" 5 4.3824598e+03 1.95e+00 3.37e+01 -5.6 9.37e-02 2.6 1.00e+00 1.00e+00f 1\n",
" 6 3.9046605e+03 1.78e+01 2.46e+01 -7.5 2.01e-01 2.1 1.00e+00 1.00e+00f 1\n",
" 7 3.2377521e+03 9.82e+01 1.24e+01 -9.4 2.99e-01 1.6 1.00e+00 1.00e+00f 1\n",
" 8 2.9148191e+03 2.42e+02 4.38e+00 -11.0 3.64e-01 1.1 1.00e+00 1.00e+00f 1\n",
" 9 2.8396309e+03 2.69e+02 2.33e+00 -11.0 5.23e-01 0.7 1.00e+00 1.00e+00h 1\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 10 2.7808251e+03 2.12e+02 9.53e-01 -11.0 6.03e-01 0.2 1.00e+00 1.00e+00h 1\n",
" 11 2.7530455e+03 1.23e+02 5.69e-01 -11.0 1.12e+00 -0.3 1.00e+00 1.00e+00h 1\n",
" 12 2.6822791e+03 2.26e+01 5.64e-01 -11.0 3.33e+00 -0.8 1.00e+00 1.00e+00h 1\n",
" 13 2.3967427e+03 7.64e+00 5.71e-01 -11.0 1.01e+01 -1.2 1.00e+00 1.00e+00f 1\n",
" 14 1.5145532e+03 2.62e+02 6.08e-01 -11.0 3.23e+01 -1.7 1.00e+00 1.00e+00f 1\n",
" 15 7.6624646e+02 7.03e+02 1.39e+00 -9.1 1.57e+02 -2.2 1.00e+00 1.71e-01f 1\n",
" 16 7.5485938e+02 7.01e+02 1.38e+00 -7.4 7.64e+01 -1.8 1.00e+00 3.51e-03f 1\n",
" 17 7.5470712e+02 7.01e+02 1.38e+00 -5.7 2.05e+01 -1.4 1.00e+00 1.31e-04h 1\n",
" 18 4.2617650e+02 3.49e+02 1.43e+00 -4.7 9.64e-01 -1.8 1.00e+00 1.00e+00f 1\n",
" 19 3.2848934e+02 6.14e+01 6.15e-01 -4.6 2.87e+00 -2.3 1.00e+00 1.00e+00h 1\n",
"iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls\n",
" 20 3.0534050e+02 3.29e+01 9.81e-02 -6.8 8.76e+00 -2.8 1.00e+00 1.00e+00h 1\n",
" 21 3.0125313e+02 5.26e+01 3.58e-01 -3.6 8.06e+02 - 1.00e+00 5.58e-03f 1\n",
" 22 3.0218923e+02 2.52e+01 5.56e-02 -3.2 8.88e-02 - 1.00e+00 5.07e-01h 1\n",
" 23 3.0307666e+02 2.44e-03 1.21e-04 -5.3 1.23e-03 - 1.00e+00 1.00e+00h 1\n",
" 24 3.0307477e+02 2.64e-07 1.46e-08 -11.0 3.93e-04 - 1.00e+00 1.00e+00h 1\n",
" 25 3.0307477e+02 9.09e-13 1.78e-14 -11.0 5.08e-08 - 1.00e+00 1.00e+00h 1\n",
"\n",
"Number of Iterations....: 25\n",
"\n",
" (scaled) (unscaled)\n",
"Objective...............: 5.6476537149537949e+00 3.0307477258650505e+02\n",
"Dual infeasibility......: 1.7763568394002505e-14 9.5326125202794660e-13\n",
"Constraint violation....: 1.0071132374435624e-14 9.0949470177292824e-13\n",
"Variable bound violation: 0.0000000000000000e+00 0.0000000000000000e+00\n",
"Complementarity.........: 1.0000000018060540e-11 5.3663837839667193e-10\n",
"Overall NLP error.......: 1.0000000018060540e-11 5.3663837839667193e-10\n",
"\n",
"\n",
"Number of objective function evaluations = 29\n",
"Number of objective gradient evaluations = 26\n",
"Number of equality constraint evaluations = 30\n",
"Number of inequality constraint evaluations = 30\n",
"Number of equality constraint Jacobian evaluations = 26\n",
"Number of inequality constraint Jacobian evaluations = 26\n",
"Number of Lagrangian Hessian evaluations = 25\n",
"Total seconds in IPOPT = 0.032\n",
"\n",
"EXIT: Optimal Solution Found.\n",
" solver : t_proc (avg) t_wall (avg) n_eval\n",
" nlp_f | 1.00ms ( 34.48us) 886.00us ( 30.55us) 29\n",
" nlp_g | 0 ( 0) 390.00us ( 13.00us) 30\n",
" nlp_grad_f | 0 ( 0) 342.00us ( 12.67us) 27\n",
" nlp_hess_l | 2.00ms ( 80.00us) 1.34ms ( 53.60us) 25\n",
" nlp_jac_g | 0 ( 0) 422.00us ( 15.63us) 27\n",
" total | 32.00ms ( 32.00ms) 32.05ms ( 32.05ms) 1\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"CasADi - 2024-04-05 19:41:32 WARNING(\"solver:nlp_f failed: NaN detected for output f, at (row 0, col 0).\") [.../casadi/core/oracle_function.cpp:377]\n"
]
}
],
"execution_count": 1
},
{
"cell_type": "markdown",
Expand All @@ -199,35 +202,39 @@
},
{
"cell_type": "code",
"execution_count": 104,
"source": [
"print(f\"Minimum drag = {sol(drag)} N\")\n",
"print(f\"Aspect ratio = {sol(aspect_ratio)}\")\n",
"print(f\"Wing area = {sol(wing_area)} m^2\")\n",
"print(f\"Airspeed = {sol(airspeed)} m/s\")\n",
"print(f\"Weight = {sol(weight)} N\")\n",
"print(f\"C_L = {sol(CL)}\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-04-05T23:41:32.223203Z",
"start_time": "2024-04-05T23:41:32.217147Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Minimum drag = 303.07477258650493 N\n",
"Minimum drag = 303.07477258650505 N\n",
"Aspect ratio = 8.459983146202207\n",
"Wing area = 16.44179489082042 m^2\n",
"Airspeed = 38.15135783274742 m/s\n",
"Weight = 7341.097000741735 N\n",
"C_L = 0.4987887182226509\n"
"Airspeed = 38.15135783274743 m/s\n",
"Weight = 7341.0970007417345 N\n",
"C_L = 0.4987887182226508\n"
]
}
],
"source": [
"print(f\"Minimum drag = {sol.value(drag)} N\")\n",
"print(f\"Aspect ratio = {sol.value(aspect_ratio)}\")\n",
"print(f\"Wing area = {sol.value(wing_area)} m^2\")\n",
"print(f\"Airspeed = {sol.value(airspeed)} m/s\")\n",
"print(f\"Weight = {sol.value(weight)} N\")\n",
"print(f\"C_L = {sol.value(CL)}\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
"execution_count": 2
},
{
"cell_type": "markdown",
Expand All @@ -240,25 +247,29 @@
},
{
"cell_type": "code",
"execution_count": 105,
"source": [
"print(f\"L/D = {sol(lift_cruise/drag)}\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
},
"ExecuteTime": {
"end_time": "2024-04-05T23:41:32.229240Z",
"start_time": "2024-04-05T23:41:32.224212Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"L/D = 24.222065525595628\n"
"L/D = 24.222065525595625\n"
]
}
],
"source": [
"print(f\"L/D = {sol.value(lift_cruise/drag)}\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
"execution_count": 3
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -293,4 +304,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading

0 comments on commit 9d1b21d

Please sign in to comment.