|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "This notebook demonstrates the local optimization of a filter coupled to a W thermal emitter,\n", |
| 8 | + "and should reproduce the efficiency reported in Table II \"W + F$_{opt}$\" in \n", |
| 9 | + "\"Accelerating the discovery of multi-layer nanostructures with analytic differentiation \n", |
| 10 | + "of the transfer matrix equations\" by J. F. Varner, D. Wert, A. Matari, R. Nofal, and J. J. Foley IV." |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "metadata": {}, |
| 17 | + "outputs": [], |
| 18 | + "source": [ |
| 19 | + "from wptherml.wpml import multilayer\n", |
| 20 | + "from matplotlib import pyplot as plt\n", |
| 21 | + "from scipy.optimize import minimize\n", |
| 22 | + "from scipy.optimize import basinhopping\n", |
| 23 | + "import time\n", |
| 24 | + "import numpy as np\n", |
| 25 | + "\n", |
| 26 | + "### This will define a thick tungsten slab\n", |
| 27 | + "w_struct = {\n", |
| 28 | + "\n", |
| 29 | + " 'Material_List': ['Air', 'W', 'Air'],\n", |
| 30 | + " 'Thickness_List': [0, 900e-9, 0],\n", |
| 31 | + " 'Lambda_List': [300e-9, 4000e-9, 1000],\n", |
| 32 | + " 'Temperature': 2700,\n", |
| 33 | + " 'LIGHTBULB': 1\n", |
| 34 | + "\n", |
| 35 | + " }\n", |
| 36 | + "\n", |
| 37 | + "### create instance of the tungsten emitter structure\n", |
| 38 | + "w = multilayer(w_struct)\n", |
| 39 | + "\n", |
| 40 | + "\n", |
| 41 | + "### Create a global variable called emissivity that will NOT change from the original emissivity of W slab\n", |
| 42 | + "e_emissivity = w.emissivity_array\n", |
| 43 | + "\n", |
| 44 | + "### This will define the base filter that will be optimized\n", |
| 45 | + "structure = {\n", |
| 46 | + " 'Material_List' : ['Air', 'Ta2O5','SiO2','Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5','SiO2', 'Ta2O5', 'SiO2', 'Air'],\n", |
| 47 | + " ### Thicknesses just chosen arbitrarily, replace with \"optimal\" values\n", |
| 48 | + " 'Thickness_List': [0, 18e-9, 47e-9, 156e-9, 212e-9, 178e-9, 23e-9, 51e-9, 224e-9, 150e-9, 205e-9, 258e-9, 187e-9, 243e-9, 190e-9, 266e-9, 215e-9, 153e-9, 227e-9, 154e-9, 226e-9, 152e-9, 245e-9, 24e-9, 229e-9, 263e-9, 190e-9, 257e-9, 200e-9, 260e-9, 224e-9, 27e-9, 229e-9, 154e-9, 219e-9, 274e-9, 198e-9, 405e-9, 211e-9, 166e-9, 233e-9, 47e-9, 66e-9, 17e-9, 125e-9, 153e-9, 237e-9, 151e-9, 225e-9, 147e-9, 193e-9, 127e-9, 214e-9, 135e-9, 173e-9, 112e-9, 165e-9, 130e-9, 223e-9, 130e-9, 163e-9, 112e-9, 164e-9, 114e-9, 167e-9, 121e-9, 378e-9, 114e-9, 160e-9, 113e-9, 174e-9, 117e-9, 211e-9, 23e-9, 221e-9, 261e-9, 399e-9, 266e-9, 390e-9, 28e-9, 18e-9, 367e-9, 198e-9, 302e-9, 28e-9, 33e-9, 426e-9, 31e-9, 15e-9, 222e-9, 96e-9, 0 ],\n", |
| 49 | + " 'Lambda_List': [300e-9, 4000e-9, 1000],\n", |
| 50 | + " 'Temperature': 2700,\n", |
| 51 | + " 'LIGHTBULB': 1\n", |
| 52 | + "\n", |
| 53 | + " }\n", |
| 54 | + "### create instance called cc\n", |
| 55 | + "cc = multilayer(structure)\n", |
| 56 | + "\n", |
| 57 | + "### get initial luminous efficiency of W-emitter / filter pair\n", |
| 58 | + "cc.luminous_efficiency_filter(e_emissivity)\n", |
| 59 | + "print(\" Filtered Multilayer Luminous Efficiency\", cc.luminous_efficiency_val*100)\n", |
| 60 | + "\n", |
| 61 | + "### How many elements in the filter will be varied over?\n", |
| 62 | + "length = len(cc.luminous_efficiency_grad)\n", |
| 63 | + "print(\"length is \",length)\n", |
| 64 | + "\n", |
| 65 | + "### given an array of thicknesses for the filter, update the filter and\n", |
| 66 | + "### re-compute the luminous efficiency of the W-emitter / filter pair\n", |
| 67 | + "def update_multilayer(x0):\n", |
| 68 | + " ### use gradient_list to define which layers are updated!\n", |
| 69 | + " dim = len(x0)\n", |
| 70 | + " for i in range(1,dim+1):\n", |
| 71 | + " cc.d[i] = x0[i-1]*1e-9\n", |
| 72 | + " \n", |
| 73 | + " cc.fresnel()\n", |
| 74 | + " cc.thermal_emission()\n", |
| 75 | + " cc.luminous_efficiency_filter(e_emissivity)\n", |
| 76 | + " ### return the negative of the efficiency since the \n", |
| 77 | + " ### scipy minimize functions find the MINIMUM not the MAXIMUM...\n", |
| 78 | + " ### we of course want the MAXIMUM efficiency which is the same\n", |
| 79 | + " ### as the MINIMUM of the negative of the efficiency\n", |
| 80 | + " return -cc.luminous_efficiency_val*100\n", |
| 81 | + "\n", |
| 82 | + "### given an array of thicknesses for the filter, update the filter\n", |
| 83 | + "### and compute the gradient of its transmissivity...\n", |
| 84 | + "### use that to compute the gradient of the luminous efficiency\n", |
| 85 | + "### return the negative of the luminous efficiency gradient \n", |
| 86 | + "### scaled by 10^-7 \n", |
| 87 | + "def analytic_grad(x0):\n", |
| 88 | + " dim = len(x0)\n", |
| 89 | + " g = np.zeros(dim)\n", |
| 90 | + " cur = update_multilayer(x0)\n", |
| 91 | + " cc.fresnel_prime()\n", |
| 92 | + " cc.luminous_efficiency_filter_prime(e_emissivity)\n", |
| 93 | + " g = cc.luminous_efficiency_grad\n", |
| 94 | + " return -g*1e-7\n", |
| 95 | + "\n", |
| 96 | + "### Function that gets the negative of the efficiency and the \n", |
| 97 | + "### negative of the gradient for use in the l-bfgs-b algorithm\n", |
| 98 | + "### also prints out the time for timing purposes!\n", |
| 99 | + "def SuperFunc(x0):\n", |
| 100 | + " en = update_multilayer(x0)\n", |
| 101 | + " c_time = time.time()\n", |
| 102 | + " print(en,\",\",c_time)\n", |
| 103 | + " gr = analytic_grad(x0)\n", |
| 104 | + " return en, gr\n", |
| 105 | + "\n", |
| 106 | + "\n", |
| 107 | + "# the bounds for L-BFGS-B updates!\n", |
| 108 | + "bfgs_xmin = np.ones(length)\n", |
| 109 | + "bfgs_xmax = 405*np.ones(length)\n", |
| 110 | + "\n", |
| 111 | + "# rewrite the bounds in the way required by L-BFGS-B\n", |
| 112 | + "bfgs_bounds = [(low, high) for low, high in zip(bfgs_xmin, bfgs_xmax)]\n", |
| 113 | + "\n", |
| 114 | + "### initialize the solution vector xs to be the thicknesses from \n", |
| 115 | + "### the structure dictionary\n", |
| 116 | + "xs = np.zeros(length)\n", |
| 117 | + "for i in range(0,length):\n", |
| 118 | + " xs[i] = cc.d[i+1]*1e9\n", |
| 119 | + "\n", |
| 120 | + "### print out initial solution vector and initial efficiency\n", |
| 121 | + "print(\"xs is \")\n", |
| 122 | + "print(xs)\n", |
| 123 | + "print(\"efficiency is \",update_multilayer(xs))\n", |
| 124 | + "\n", |
| 125 | + "### run l-bfgs-b algorithm!\n", |
| 126 | + "ret = minimize(SuperFunc, xs, method=\"L-BFGS-B\", jac=True, bounds=bfgs_bounds)\n", |
| 127 | + "\n", |
| 128 | + "### print optimal solution and its efficiency!\n", |
| 129 | + "print(ret.x)\n", |
| 130 | + "print(update_multilayer(ret.x))\n", |
| 131 | + " " |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": null, |
| 137 | + "metadata": {}, |
| 138 | + "outputs": [], |
| 139 | + "source": [] |
| 140 | + } |
| 141 | + ], |
| 142 | + "metadata": { |
| 143 | + "kernelspec": { |
| 144 | + "display_name": "Python 3", |
| 145 | + "language": "python", |
| 146 | + "name": "python3" |
| 147 | + }, |
| 148 | + "language_info": { |
| 149 | + "codemirror_mode": { |
| 150 | + "name": "ipython", |
| 151 | + "version": 3 |
| 152 | + }, |
| 153 | + "file_extension": ".py", |
| 154 | + "mimetype": "text/x-python", |
| 155 | + "name": "python", |
| 156 | + "nbconvert_exporter": "python", |
| 157 | + "pygments_lexer": "ipython3", |
| 158 | + "version": "3.7.4" |
| 159 | + } |
| 160 | + }, |
| 161 | + "nbformat": 4, |
| 162 | + "nbformat_minor": 2 |
| 163 | +} |
0 commit comments