Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
FoleyLab committed Mar 16, 2020
2 parents 0a47c95 + a8635ef commit 3a2048e
Show file tree
Hide file tree
Showing 24 changed files with 7,051 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*.pptx
.ipynb_checkpoints/
.DS_Store
__pycache__/
Expand Down
196 changes: 196 additions & 0 deletions example/Cooling_Opt.ipynb
@@ -0,0 +1,196 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Optimization of a radiative cooling structure\n",
"This notebook will optimize a multi-layer structure inspired by Raman 𝑒𝑡 𝑎𝑙. , Nature 515, 540-546 (2014), utilizing analytic gradients of the three terms that dominate\n",
"the radiative flux: absorption of solar radiation, absorption of atmospheric thermal radiation (both warming), and thermal emission (cooling). \n",
"\n",
"**Note that the explit angle and polarization dependence will be included in these gradients, and so each gradient evaluation will be ~14 times slower than comparable gradient evaluations when angle- and polarization dependence are ignored as in other optimization demos [see, for example, here](http://localhost:8888/notebooks/CODE/wptherml/example/Incandescent_Opt.ipynb)**."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Temperature not specified!\n",
" Proceeding with default T = 300 K\n",
"xs is \n",
"[230, 485, 688, 13, 73, 34, 54]\n",
" This structure is net cooling with net power out being 63.525923254487594\n",
" This structure is net cooling with net power out being 26.93358430958938\n",
" This structure is net cooling with net power out being 26.987684491357246\n",
" This structure is net cooling with net power out being 31.257424595611454\n",
" This structure is net cooling with net power out being 59.933261081356505\n",
" This structure is net cooling with net power out being 68.59349206988524\n",
" This structure is net cooling with net power out being 69.19255314674987\n",
" This structure is net cooling with net power out being 69.53944029636773\n",
" This structure is net cooling with net power out being 69.07278380133678\n",
" This structure is net cooling with net power out being 70.57523013190401\n",
" This structure is net cooling with net power out being 70.49876027675884\n",
" This structure is net cooling with net power out being 70.85380995302663\n",
" This structure is net cooling with net power out being 70.79612870829939\n",
" This structure is net cooling with net power out being 70.86055573829051\n",
" This structure is net cooling with net power out being 70.56282333077554\n",
" This structure is net cooling with net power out being 70.88045444055962\n",
" This structure is net cooling with net power out being 70.89025678075966\n",
" This structure is net cooling with net power out being 70.89100749911535\n",
" This structure is net cooling with net power out being 70.89121169266468\n",
" This structure is net cooling with net power out being 70.89166953716105\n",
" This structure is net cooling with net power out being 70.89224257525305\n",
" This structure is net cooling with net power out being 70.89260757037914\n",
" This structure is net cooling with net power out being 70.89261054829753\n",
" This structure is net cooling with net power out being 70.8926105873357\n",
"[300. 296.22235003 300. 200.02210915 277.76544865\n",
" 294.76122768 300. ]\n",
"70.8926105873357\n"
]
}
],
"source": [
"### Import WPTHERML class!\n",
"from wptherml.wpml import multilayer\n",
"from matplotlib import pyplot as plt\n",
"from wptherml.datalib import datalib\n",
"import numpy as np\n",
"from scipy.optimize import minimize\n",
"from scipy.optimize import basinhopping\n",
"import time\n",
"import numpy as np\n",
"\n",
"### Define structure!\n",
"structure = {\n",
"\n",
" 'Material_List': ['Air', 'SiO2', 'HfO2', 'SiO2', 'HfO2', 'SiO2', 'HfO2', 'SiO2', 'Ag', 'Air'],\n",
" 'Thickness_List': [0, 230e-9, 485e-9, 688e-9, 13e-9, 73e-9, 34e-9, 54e-9, 200e-9, 0],\n",
" 'Lambda_List': [300e-9, 20000e-9, 1000],\n",
" ### we will compute gradients wrt thickness of first 7 layers, Ag thickness will not change\n",
" 'Gradient_List': [1,2,3,4,5,6,7],\n",
" 'EXPLICIT_ANGLE': 1,\n",
" 'COOLING': 1\n",
" \n",
" }\n",
"\n",
"### create instance of multilayer class called cool_ml\n",
"cool_ml = multilayer(structure)\n",
"### get length of gradient vector\n",
"length = cool_ml.gradient_dimension\n",
"\n",
"def update_multilayer(x):\n",
" for i in range(0,len(x)):\n",
" cool_ml.d[i+1] = x[i]*1e-9\n",
" ### now we have the new structure, update fresnel quantities\n",
" cool_ml.fresnel_ea()\n",
" cool_ml.thermal_emission_ea()\n",
" ### now we have new emissivity, update thermal emission\n",
" cool_ml.cooling_power()\n",
"\n",
" ### return negative of cooling power - minimize functions want \n",
" ### to minimize, so trick them by passing negative of the objective you\n",
" ### want to maximize\n",
" return -cool_ml.cooling_power_val\n",
"\n",
"### given an array of thicknesses of the coating, update\n",
"### the structure and compute the gradient vector of conversion efficiency wrt layer thicknesses\n",
"def analytic_grad(x0):\n",
" cur = update_multilayer(x0)\n",
" cool_ml.fresnel_prime_ea()\n",
" cool_ml.thermal_emission_prime_ea()\n",
" cool_ml.cooling_power_prime()\n",
" ### now there will be three contributions to the\n",
" ### gradient vector... two warming contributions \n",
" ### (solar_power_grad and atmospheric_power_grad)\n",
" ### and one cooling contribution (radiative_power_grad)\n",
" ### and the total gradient is the sum of all three\n",
" g = cool_ml.cooling_power_grad\n",
" ### scale gradient to be in nm^-1 rather than over m^-1\n",
" return -g*1e-9\n",
"\n",
"### Function that gets the negative of the efficiency and the \n",
"### negative of the gradient for use in the l-bfgs-b algorithm\n",
"### also prints out the time for timing purposes!\n",
"def SuperFunc(x0):\n",
" en = update_multilayer(x0)\n",
" c_time = time.time()\n",
" if en<0:\n",
" print(\" This structure is net cooling with net power out being\",-en)\n",
" else:\n",
" print(\" This structure is net warming with net poer in being\",-en)\n",
" gr = analytic_grad(x0)\n",
" return en, gr\n",
"\n",
"\n",
"# the bounds for L-BFGS-B updates!\n",
"bfgs_xmin = np.ones(length)\n",
"bfgs_xmax = 300*np.ones(length)\n",
"\n",
"# rewrite the bounds in the way required by L-BFGS-B\n",
"bfgs_bounds = [(low, high) for low, high in zip(bfgs_xmin, bfgs_xmax)]\n",
"\n",
"### initialize the solution vector xs to be the thicknesses from \n",
"### Raman et al. paper\n",
"xs = [230, 485, 688, 13, 73, 34, 54]\n",
"\n",
"### print out initial solution vector and initial efficiency\n",
"print(\"xs is \")\n",
"print(xs)\n",
"pflux = -update_multilayer(xs)\n",
"if pflux>0:\n",
" print(\" This structure is net cooling with net power out being\",pflux) \n",
"else:\n",
" print(\" This structure is net warming with net poer in being\",pflux)\n",
"\n",
"\n",
"### run l-bfgs-b algorithm!\n",
"ret = minimize(SuperFunc, xs, method=\"L-BFGS-B\", jac=True, bounds=bfgs_bounds)\n",
"\n",
"### print optimal solution and its efficiency!\n",
"print(ret.x)\n",
"print(-update_multilayer(ret.x))\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}
137 changes: 136 additions & 1 deletion example/Example1.ipynb

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions example/Incandescent_Opt.ipynb
@@ -0,0 +1,163 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook demonstrates the local optimization of a filter coupled to a W thermal emitter,\n",
"and should reproduce the efficiency reported in Table II \"W + F$_{opt}$\" in \n",
"\"Accelerating the discovery of multi-layer nanostructures with analytic differentiation \n",
"of the transfer matrix equations\" by J. F. Varner, D. Wert, A. Matari, R. Nofal, and J. J. Foley IV."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from wptherml.wpml import multilayer\n",
"from matplotlib import pyplot as plt\n",
"from scipy.optimize import minimize\n",
"from scipy.optimize import basinhopping\n",
"import time\n",
"import numpy as np\n",
"\n",
"### This will define a thick tungsten slab\n",
"w_struct = {\n",
"\n",
" 'Material_List': ['Air', 'W', 'Air'],\n",
" 'Thickness_List': [0, 900e-9, 0],\n",
" 'Lambda_List': [300e-9, 4000e-9, 1000],\n",
" 'Temperature': 2700,\n",
" 'LIGHTBULB': 1\n",
"\n",
" }\n",
"\n",
"### create instance of the tungsten emitter structure\n",
"w = multilayer(w_struct)\n",
"\n",
"\n",
"### Create a global variable called emissivity that will NOT change from the original emissivity of W slab\n",
"e_emissivity = w.emissivity_array\n",
"\n",
"### This will define the base filter that will be optimized\n",
"structure = {\n",
" '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",
" ### Thicknesses just chosen arbitrarily, replace with \"optimal\" values\n",
" '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",
" 'Lambda_List': [300e-9, 4000e-9, 1000],\n",
" 'Temperature': 2700,\n",
" 'LIGHTBULB': 1\n",
"\n",
" }\n",
"### create instance called cc\n",
"cc = multilayer(structure)\n",
"\n",
"### get initial luminous efficiency of W-emitter / filter pair\n",
"cc.luminous_efficiency_filter(e_emissivity)\n",
"print(\" Filtered Multilayer Luminous Efficiency\", cc.luminous_efficiency_val*100)\n",
"\n",
"### How many elements in the filter will be varied over?\n",
"length = len(cc.luminous_efficiency_grad)\n",
"print(\"length is \",length)\n",
"\n",
"### given an array of thicknesses for the filter, update the filter and\n",
"### re-compute the luminous efficiency of the W-emitter / filter pair\n",
"def update_multilayer(x0):\n",
" ### use gradient_list to define which layers are updated!\n",
" dim = len(x0)\n",
" for i in range(1,dim+1):\n",
" cc.d[i] = x0[i-1]*1e-9\n",
" \n",
" cc.fresnel()\n",
" cc.thermal_emission()\n",
" cc.luminous_efficiency_filter(e_emissivity)\n",
" ### return the negative of the efficiency since the \n",
" ### scipy minimize functions find the MINIMUM not the MAXIMUM...\n",
" ### we of course want the MAXIMUM efficiency which is the same\n",
" ### as the MINIMUM of the negative of the efficiency\n",
" return -cc.luminous_efficiency_val*100\n",
"\n",
"### given an array of thicknesses for the filter, update the filter\n",
"### and compute the gradient of its transmissivity...\n",
"### use that to compute the gradient of the luminous efficiency\n",
"### return the negative of the luminous efficiency gradient \n",
"### scaled by 10^-7 \n",
"def analytic_grad(x0):\n",
" dim = len(x0)\n",
" g = np.zeros(dim)\n",
" cur = update_multilayer(x0)\n",
" cc.fresnel_prime()\n",
" cc.luminous_efficiency_filter_prime(e_emissivity)\n",
" g = cc.luminous_efficiency_grad\n",
" return -g*1e-7\n",
"\n",
"### Function that gets the negative of the efficiency and the \n",
"### negative of the gradient for use in the l-bfgs-b algorithm\n",
"### also prints out the time for timing purposes!\n",
"def SuperFunc(x0):\n",
" en = update_multilayer(x0)\n",
" c_time = time.time()\n",
" print(en,\",\",c_time)\n",
" gr = analytic_grad(x0)\n",
" return en, gr\n",
"\n",
"\n",
"# the bounds for L-BFGS-B updates!\n",
"bfgs_xmin = np.ones(length)\n",
"bfgs_xmax = 405*np.ones(length)\n",
"\n",
"# rewrite the bounds in the way required by L-BFGS-B\n",
"bfgs_bounds = [(low, high) for low, high in zip(bfgs_xmin, bfgs_xmax)]\n",
"\n",
"### initialize the solution vector xs to be the thicknesses from \n",
"### the structure dictionary\n",
"xs = np.zeros(length)\n",
"for i in range(0,length):\n",
" xs[i] = cc.d[i+1]*1e9\n",
"\n",
"### print out initial solution vector and initial efficiency\n",
"print(\"xs is \")\n",
"print(xs)\n",
"print(\"efficiency is \",update_multilayer(xs))\n",
"\n",
"### run l-bfgs-b algorithm!\n",
"ret = minimize(SuperFunc, xs, method=\"L-BFGS-B\", jac=True, bounds=bfgs_bounds)\n",
"\n",
"### print optimal solution and its efficiency!\n",
"print(ret.x)\n",
"print(update_multilayer(ret.x))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
459 changes: 459 additions & 0 deletions example/Incandescent_Plot.ipynb

Large diffs are not rendered by default.

0 comments on commit 3a2048e

Please sign in to comment.