--- /dev/null
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Step-62"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Set parameters"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "%config InlineBackend.figure_formats = ['svg']\n",
+ "%matplotlib inline\n",
+ "import numpy as np\n",
+ "import h5py\n",
+ "import matplotlib.pyplot as plt\n",
+ "import subprocess\n",
+ "import scipy.constants as constants\n",
+ "import scipy.optimize\n",
+ "\n",
+ "# This considerably reduces the size of the svg data\n",
+ "plt.rcParams['svg.fonttype'] = 'none'\n",
+ "\n",
+ "h5_file = h5py.File('results.h5', 'w')\n",
+ "data = h5_file.create_group('data')\n",
+ "displacement = data.create_group('displacement')\n",
+ "calibration = data.create_group('calibration')\n",
+ "\n",
+ "# Set the parameters\n",
+ "for group in [displacement, calibration]:\n",
+ " # Dimensions of the domain\n",
+ " group.attrs['dimension_x'] = 0.02\n",
+ " group.attrs['dimension_y'] = 2e-5\n",
+ " \n",
+ " # Position of the probe that we use to measure the flux\n",
+ " group.attrs['probe_pos_x'] = 0.008\n",
+ " group.attrs['probe_pos_y'] = 0\n",
+ " group.attrs['probe_width_y'] = 2e-05\n",
+ " \n",
+ " # Number of points in the probe\n",
+ " group.attrs['nb_probe_points'] = 5\n",
+ " \n",
+ " # Global refinement\n",
+ " group.attrs['grid_level'] = 1\n",
+ "\n",
+ " # Cavity\n",
+ " group.attrs['cavity_resonance_frequency'] = 20e6\n",
+ " group.attrs['nb_mirror_pairs'] = 15\n",
+ "\n",
+ " # Material\n",
+ " group.attrs['poissons_ratio'] = 0.27\n",
+ " group.attrs['youngs_modulus'] = 270000000000.0\n",
+ " group.attrs['material_a_rho'] = 3200\n",
+ " if group == displacement:\n",
+ " group.attrs['material_b_rho'] = 2000\n",
+ " else:\n",
+ " group.attrs['material_b_rho'] = 3200 \n",
+ " group.attrs['lambda'] = (group.attrs['youngs_modulus'] * group.attrs['poissons_ratio'] /\n",
+ " ((1 + group.attrs['poissons_ratio']) *\n",
+ " (1 - 2 * group.attrs['poissons_ratio'])))\n",
+ " group.attrs['mu']= (group.attrs['youngs_modulus'] / (2 * (1 + group.attrs['poissons_ratio'])))\n",
+ "\n",
+ " # Force\n",
+ " group.attrs['max_force_amplitude'] = 1e20\n",
+ " group.attrs['force_sigma_x'] = 1\n",
+ " group.attrs['force_sigma_y'] = 1\n",
+ " group.attrs['max_force_width_x'] = 0.0003\n",
+ " group.attrs['max_force_width_y'] = 0.001\n",
+ " group.attrs['force_x_pos'] = -0.008\n",
+ " group.attrs['force_y_pos'] = 0\n",
+ "\n",
+ " # PML\n",
+ " group.attrs['pml_x'] = True\n",
+ " group.attrs['pml_y'] = False\n",
+ " group.attrs['pml_width_x'] = 0.0018\n",
+ " group.attrs['pml_width_y'] = 0.0005\n",
+ " group.attrs['pml_coeff'] = 1.6\n",
+ " group.attrs['pml_coeff_degree'] = 2\n",
+ "\n",
+ " # Frequency sweep\n",
+ " group.attrs['center_frequency'] = 20e6\n",
+ " group.attrs['frequency_range'] = 0.5e6\n",
+ " group.attrs['start_frequency'] = group.attrs['center_frequency'] - group.attrs['frequency_range'] / 2\n",
+ " group.attrs['stop_frequency'] = group.attrs['center_frequency'] + group.attrs['frequency_range'] / 2\n",
+ " group.attrs['nb_frequency_points'] = 400\n",
+ "\n",
+ " # Other parameters\n",
+ " if group == displacement:\n",
+ " group.attrs['simulation_name'] = 'phononic_cavity_displacement'\n",
+ " else:\n",
+ " group.attrs['simulation_name'] = 'phononic_cavity_calibration'\n",
+ " group.attrs['save_vtu_files'] = False\n",
+ " \n",
+ "h5_file.close()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Run simulation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "CompletedProcess(args=['mpiexec', './step-62'], returncode=0)"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Now you can run your simulation locally or in a cluster\n",
+ "subprocess.run(['mpiexec','./step-62'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Analyze data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
+ " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
+ "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
+ "<svg height=\"290pt\" version=\"1.1\" viewBox=\"0 0 389 290\" width=\"389pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ " <defs>\n",
+ " <style type=\"text/css\">\n",
+ "*{stroke-linecap:butt;stroke-linejoin:round;}\n",
+ " </style>\n",
+ " </defs>\n",
+ " <g id=\"figure_1\">\n",
+ " <g id=\"patch_1\">\n",
+ " <path d=\"M 0 290.75175 \n",
+ "L 389.28125 290.75175 \n",
+ "L 389.28125 0 \n",
+ "L 0 0 \n",
+ "z\n",
+ "\" style=\"fill:none;\"/>\n",
+ " </g>\n",
+ " <g id=\"axes_1\">\n",
+ " <g id=\"patch_2\">\n",
+ " <path d=\"M 43.78125 253.1955 \n",
+ "L 378.58125 253.1955 \n",
+ "L 378.58125 35.7555 \n",
+ "L 43.78125 35.7555 \n",
+ "z\n",
+ "\" style=\"fill:#ffffff;\"/>\n",
+ " </g>\n",
+ " <g id=\"matplotlib.axis_1\">\n",
+ " <g id=\"xtick_1\">\n",
+ " <g id=\"line2d_1\">\n",
+ " <defs>\n",
+ " <path d=\"M 0 0 \n",
+ "L 0 3.5 \n",
+ "\" id=\"m617721c33a\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n",
+ " </defs>\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"89.435795\" xlink:href=\"#m617721c33a\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_1\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 89.435795, 267.793937)\" x=\"89.435795\" y=\"267.793937\">19.8</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_2\">\n",
+ " <g id=\"line2d_2\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"150.308523\" xlink:href=\"#m617721c33a\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_2\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 150.308523, 267.793937)\" x=\"150.308523\" y=\"267.793937\">19.9</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_3\">\n",
+ " <g id=\"line2d_3\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"211.18125\" xlink:href=\"#m617721c33a\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_3\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 211.18125, 267.793937)\" x=\"211.18125\" y=\"267.793937\">20.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_4\">\n",
+ " <g id=\"line2d_4\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"272.053977\" xlink:href=\"#m617721c33a\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_4\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 272.053977, 267.793937)\" x=\"272.053977\" y=\"267.793937\">20.1</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_5\">\n",
+ " <g id=\"line2d_5\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"332.926705\" xlink:href=\"#m617721c33a\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_5\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 332.926705, 267.793937)\" x=\"332.926705\" y=\"267.793937\">20.2</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_6\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 211.18125, 281.472062)\" x=\"211.18125\" y=\"281.472062\">frequency (MHz)</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"matplotlib.axis_2\">\n",
+ " <g id=\"ytick_1\">\n",
+ " <g id=\"line2d_6\">\n",
+ " <defs>\n",
+ " <path d=\"M 0 0 \n",
+ "L -3.5 0 \n",
+ "\" id=\"m5085cc54b3\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n",
+ " </defs>\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"243.323554\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_7\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 247.122773)\" x=\"36.78125\" y=\"247.122773\">0.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_2\">\n",
+ " <g id=\"line2d_7\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"203.429476\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_8\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 207.228695)\" x=\"36.78125\" y=\"207.228695\">0.2</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_3\">\n",
+ " <g id=\"line2d_8\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"163.535398\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_9\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 167.334617)\" x=\"36.78125\" y=\"167.334617\">0.4</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_4\">\n",
+ " <g id=\"line2d_9\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"123.64132\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_10\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 127.440539)\" x=\"36.78125\" y=\"127.440539\">0.6</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_5\">\n",
+ " <g id=\"line2d_10\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"83.747242\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_11\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 87.546461)\" x=\"36.78125\" y=\"87.546461\">0.8</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_6\">\n",
+ " <g id=\"line2d_11\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"43.78125\" xlink:href=\"#m5085cc54b3\" y=\"43.853164\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_12\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 36.78125, 47.652383)\" x=\"36.78125\" y=\"47.652383\">1.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_13\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-90, 14.798438, 144.4755)\" x=\"14.798438\" y=\"144.4755\">amplitude^2 (a.u.)</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"line2d_12\">\n",
+ " <path clip-path=\"url(#pdfba9970d1)\" d=\"M 58.999432 243.309999 \n",
+ "L 170.370587 243.186291 \n",
+ "L 187.152542 242.985402 \n",
+ "L 194.780703 242.704851 \n",
+ "L 199.3576 242.327233 \n",
+ "L 202.408864 241.844129 \n",
+ "L 204.697313 241.207732 \n",
+ "L 206.222945 240.525399 \n",
+ "L 207.748577 239.453304 \n",
+ "L 208.511394 238.672035 \n",
+ "L 209.27421 237.630594 \n",
+ "L 210.037026 236.200996 \n",
+ "L 210.799842 234.167334 \n",
+ "L 211.562658 231.144176 \n",
+ "L 212.325474 226.395056 \n",
+ "L 213.08829 218.39477 \n",
+ "L 213.851106 203.693859 \n",
+ "L 214.613923 174.026098 \n",
+ "L 216.139555 45.639136 \n",
+ "L 216.902371 89.236544 \n",
+ "L 217.665187 159.983972 \n",
+ "L 218.428003 196.997182 \n",
+ "L 219.190819 214.954687 \n",
+ "L 219.953636 224.452124 \n",
+ "L 220.716452 229.955602 \n",
+ "L 221.479268 233.392639 \n",
+ "L 222.242084 235.670014 \n",
+ "L 223.0049 237.251643 \n",
+ "L 223.767716 238.392511 \n",
+ "L 224.530532 239.241402 \n",
+ "L 226.056165 240.395366 \n",
+ "L 227.581797 241.122327 \n",
+ "L 229.107429 241.609167 \n",
+ "L 231.395877 242.084662 \n",
+ "L 234.447142 242.463115 \n",
+ "L 239.024039 242.772681 \n",
+ "L 246.6522 243.013231 \n",
+ "L 260.38289 243.175159 \n",
+ "L 292.421168 243.272418 \n",
+ "L 363.363068 243.308318 \n",
+ "L 363.363068 243.308318 \n",
+ "\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\n",
+ " </g>\n",
+ " <g id=\"line2d_13\">\n",
+ " <path clip-path=\"url(#pdfba9970d1)\" d=\"M 58.999432 243.311864 \n",
+ "L 170.370587 243.187576 \n",
+ "L 187.152542 242.986329 \n",
+ "L 194.780703 242.705432 \n",
+ "L 199.3576 242.327459 \n",
+ "L 202.408864 241.843987 \n",
+ "L 204.697313 241.207191 \n",
+ "L 206.222945 240.524494 \n",
+ "L 207.748577 239.451915 \n",
+ "L 208.511394 238.670339 \n",
+ "L 209.27421 237.628534 \n",
+ "L 210.037026 236.198498 \n",
+ "L 210.799842 234.164308 \n",
+ "L 211.562658 231.140511 \n",
+ "L 212.325474 226.390637 \n",
+ "L 213.08829 218.389545 \n",
+ "L 213.851106 203.68813 \n",
+ "L 214.613923 174.021596 \n",
+ "L 216.139555 45.642454 \n",
+ "L 216.902371 89.23038 \n",
+ "L 217.665187 159.984195 \n",
+ "L 218.428003 197.001686 \n",
+ "L 219.190819 214.960534 \n",
+ "L 219.953636 224.458192 \n",
+ "L 220.716452 229.961522 \n",
+ "L 221.479268 233.3983 \n",
+ "L 222.242084 235.675398 \n",
+ "L 223.0049 237.256766 \n",
+ "L 223.767716 238.397397 \n",
+ "L 224.530532 239.246076 \n",
+ "L 226.056165 240.399685 \n",
+ "L 227.581797 241.126364 \n",
+ "L 229.107429 241.612978 \n",
+ "L 231.395877 242.088208 \n",
+ "L 234.447142 242.466401 \n",
+ "L 239.024039 242.775699 \n",
+ "L 246.6522 243.015975 \n",
+ "L 260.38289 243.177647 \n",
+ "L 292.421168 243.274681 \n",
+ "L 363.363068 243.310526 \n",
+ "L 363.363068 243.310526 \n",
+ "\" style=\"fill:none;stroke:#ff7f0e;stroke-linecap:square;stroke-width:1.5;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_3\">\n",
+ " <path d=\"M 43.78125 253.1955 \n",
+ "L 43.78125 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_4\">\n",
+ " <path d=\"M 378.58125 253.1955 \n",
+ "L 378.58125 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_5\">\n",
+ " <path d=\"M 43.78125 253.1955 \n",
+ "L 378.58125 253.1955 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_6\">\n",
+ " <path d=\"M 43.78125 35.7555 \n",
+ "L 378.58125 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"text_14\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:12px;font-style:normal;font-weight:400;\" transform=\"translate(171.555 16.318125)\">Transmission</text>\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:12px;font-style:normal;font-weight:400;\" transform=\"translate(112.328438 29.7555)\">freq = 20.00815MHz Q = 5091.3</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " </g>\n",
+ " <defs>\n",
+ " <clipPath id=\"pdfba9970d1\">\n",
+ " <rect height=\"217.44\" width=\"334.8\" x=\"43.78125\" y=\"35.7555\"/>\n",
+ " </clipPath>\n",
+ " </defs>\n",
+ "</svg>\n"
+ ],
+ "text/plain": [
+ "<matplotlib.figure.Figure at 0x7f2cf4228b38>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
+ " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
+ "<!-- Created with matplotlib (http://matplotlib.org/) -->\n",
+ "<svg height=\"290pt\" version=\"1.1\" viewBox=\"0 0 397 290\" width=\"397pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ " <defs>\n",
+ " <style type=\"text/css\">\n",
+ "*{stroke-linecap:butt;stroke-linejoin:round;}\n",
+ " </style>\n",
+ " </defs>\n",
+ " <g id=\"figure_1\">\n",
+ " <g id=\"patch_1\">\n",
+ " <path d=\"M 0 290.75175 \n",
+ "L 397.660937 290.75175 \n",
+ "L 397.660937 0 \n",
+ "L 0 0 \n",
+ "z\n",
+ "\" style=\"fill:none;\"/>\n",
+ " </g>\n",
+ " <g id=\"axes_1\">\n",
+ " <g id=\"patch_2\">\n",
+ " <path d=\"M 52.160938 253.1955 \n",
+ "L 386.960938 253.1955 \n",
+ "L 386.960938 35.7555 \n",
+ "L 52.160938 35.7555 \n",
+ "z\n",
+ "\" style=\"fill:#ffffff;\"/>\n",
+ " </g>\n",
+ " <g id=\"matplotlib.axis_1\">\n",
+ " <g id=\"xtick_1\">\n",
+ " <g id=\"line2d_1\">\n",
+ " <defs>\n",
+ " <path d=\"M 0 0 \n",
+ "L 0 3.5 \n",
+ "\" id=\"mb7c8d130cb\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n",
+ " </defs>\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"97.815483\" xlink:href=\"#mb7c8d130cb\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_1\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 97.815483, 267.793937)\" x=\"97.815483\" y=\"267.793937\">19.8</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_2\">\n",
+ " <g id=\"line2d_2\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"158.68821\" xlink:href=\"#mb7c8d130cb\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_2\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 158.68821, 267.793937)\" x=\"158.68821\" y=\"267.793937\">19.9</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_3\">\n",
+ " <g id=\"line2d_3\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"219.560938\" xlink:href=\"#mb7c8d130cb\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_3\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 219.560938, 267.793937)\" x=\"219.560938\" y=\"267.793937\">20.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_4\">\n",
+ " <g id=\"line2d_4\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"280.433665\" xlink:href=\"#mb7c8d130cb\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_4\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 280.433665, 267.793937)\" x=\"280.433665\" y=\"267.793937\">20.1</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"xtick_5\">\n",
+ " <g id=\"line2d_5\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"341.306392\" xlink:href=\"#mb7c8d130cb\" y=\"253.1955\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_5\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 341.306392, 267.793937)\" x=\"341.306392\" y=\"267.793937\">20.2</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_6\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-0, 219.560938, 281.472062)\" x=\"219.560938\" y=\"281.472062\">frequency (MHz)</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"matplotlib.axis_2\">\n",
+ " <g id=\"ytick_1\">\n",
+ " <g id=\"line2d_6\">\n",
+ " <defs>\n",
+ " <path d=\"M 0 0 \n",
+ "L -3.5 0 \n",
+ "\" id=\"mb6f7814b25\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n",
+ " </defs>\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"222.828373\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_7\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 226.627592)\" x=\"45.160938\" y=\"226.627592\">−1.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_2\">\n",
+ " <g id=\"line2d_7\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"186.887394\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_8\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 190.686613)\" x=\"45.160938\" y=\"190.686613\">−0.5</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_3\">\n",
+ " <g id=\"line2d_8\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"150.946415\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_9\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 154.745633)\" x=\"45.160938\" y=\"154.745633\">0.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_4\">\n",
+ " <g id=\"line2d_9\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"115.005435\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_10\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 118.804654)\" x=\"45.160938\" y=\"118.804654\">0.5</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_5\">\n",
+ " <g id=\"line2d_10\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"79.064456\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_11\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 82.863675)\" x=\"45.160938\" y=\"82.863675\">1.0</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"ytick_6\">\n",
+ " <g id=\"line2d_11\">\n",
+ " <g>\n",
+ " <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"52.160938\" xlink:href=\"#mb6f7814b25\" y=\"43.123477\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_12\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:end;\" transform=\"rotate(-0, 45.160938, 46.922695)\" x=\"45.160938\" y=\"46.922695\">1.5</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"text_13\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:10px;font-style:normal;font-weight:400;text-anchor:middle;\" transform=\"rotate(-90, 14.798438, 144.4755)\" x=\"14.798438\" y=\"144.4755\">phase (rad)</text>\n",
+ " </g>\n",
+ " </g>\n",
+ " <g id=\"line2d_12\">\n",
+ " <path clip-path=\"url(#p3e468d8608)\" d=\"M 67.379119 166.024468 \n",
+ "L 131.455674 202.631496 \n",
+ "L 160.442687 218.958165 \n",
+ "L 177.224642 228.180039 \n",
+ "L 187.904068 233.823839 \n",
+ "L 195.532229 237.618911 \n",
+ "L 200.871942 240.041934 \n",
+ "L 204.686023 241.556175 \n",
+ "L 207.737287 242.544312 \n",
+ "L 210.025736 243.074145 \n",
+ "L 211.551368 243.274447 \n",
+ "L 213.077 243.296555 \n",
+ "L 214.602633 243.060419 \n",
+ "L 215.365449 242.806402 \n",
+ "L 216.128265 242.429974 \n",
+ "L 216.891081 241.895939 \n",
+ "L 217.653897 241.154331 \n",
+ "L 218.416713 240.131859 \n",
+ "L 219.179529 238.716751 \n",
+ "L 219.942346 236.730351 \n",
+ "L 220.705162 233.870166 \n",
+ "L 221.467978 229.586474 \n",
+ "L 222.230794 222.791462 \n",
+ "L 222.99361 211.131255 \n",
+ "L 223.756426 189.428242 \n",
+ "L 225.282058 109.108975 \n",
+ "L 226.044875 82.899918 \n",
+ "L 226.807691 68.965345 \n",
+ "L 227.570507 61.056294 \n",
+ "L 228.333323 56.175162 \n",
+ "L 229.096139 52.964643 \n",
+ "L 229.858955 50.757375 \n",
+ "L 230.621771 49.194818 \n",
+ "L 231.384588 48.069323 \n",
+ "L 232.147404 47.253036 \n",
+ "L 232.91022 46.663208 \n",
+ "L 233.673036 46.244031 \n",
+ "L 235.198668 45.772806 \n",
+ "L 236.7243 45.639136 \n",
+ "L 238.249933 45.730986 \n",
+ "L 240.538381 46.150976 \n",
+ "L 242.82683 46.796841 \n",
+ "L 245.878094 47.883863 \n",
+ "L 249.692175 49.473546 \n",
+ "L 255.031888 51.957515 \n",
+ "L 261.897233 55.404039 \n",
+ "L 271.813842 60.649188 \n",
+ "L 286.307349 68.594483 \n",
+ "L 308.429017 81.004387 \n",
+ "L 345.044191 101.832791 \n",
+ "L 371.742756 117.108544 \n",
+ "L 371.742756 117.108544 \n",
+ "\" style=\"fill:none;stroke:#1f77b4;stroke-linecap:square;stroke-width:1.5;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_3\">\n",
+ " <path d=\"M 52.160938 253.1955 \n",
+ "L 52.160938 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_4\">\n",
+ " <path d=\"M 386.960938 253.1955 \n",
+ "L 386.960938 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_5\">\n",
+ " <path d=\"M 52.160938 253.1955 \n",
+ "L 386.960938 253.1955 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"patch_6\">\n",
+ " <path d=\"M 52.160938 35.7555 \n",
+ "L 386.960938 35.7555 \n",
+ "\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\n",
+ " </g>\n",
+ " <g id=\"text_14\">\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:12px;font-style:normal;font-weight:400;\" transform=\"translate(123.457813 16.318125)\">Phase (transmission coefficient)</text>\n",
+ " <text style=\"font-family:DejaVu Sans;font-size:12px;font-style:normal;font-weight:400;\" transform=\"translate(219.560938 29.7555)\"/>\n",
+ " </g>\n",
+ " </g>\n",
+ " </g>\n",
+ " <defs>\n",
+ " <clipPath id=\"p3e468d8608\">\n",
+ " <rect height=\"217.44\" width=\"334.8\" x=\"52.160938\" y=\"35.7555\"/>\n",
+ " </clipPath>\n",
+ " </defs>\n",
+ "</svg>\n"
+ ],
+ "text/plain": [
+ "<matplotlib.figure.Figure at 0x7f2cf60e0630>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "h5_file = h5py.File('results.h5', 'r')\n",
+ "data = h5_file['data']\n",
+ "\n",
+ "# Gaussian function that we use to fit the resonance\n",
+ "def resonance_f(freq, freq_m, quality_factor, max_amplitude):\n",
+ " omega = 2 * constants.pi * freq\n",
+ " omega_m = 2 * constants.pi * freq_m\n",
+ " gamma = omega_m / quality_factor\n",
+ " return max_amplitude * omega_m**2 * gamma**2 / (((omega_m**2 - omega**2)**2 + gamma**2 * omega**2))\n",
+ "\n",
+ "frequency = data['displacement']['frequency'][...]\n",
+ "# Average the probe points\n",
+ "displacement = np.mean(data['displacement']['displacement'], axis=0)\n",
+ "calibration_displacement = np.mean(data['calibration']['displacement'], axis=0)\n",
+ "reflection_coefficient = displacement / calibration_displacement\n",
+ "reflectivity = (np.abs(np.mean(data['displacement']['displacement'][...]**2, axis=0))/\n",
+ " np.abs(np.mean(data['calibration']['displacement'][...]**2, axis=0)))\n",
+ "\n",
+ "try:\n",
+ " x_data = frequency\n",
+ " y_data = reflectivity\n",
+ " quality_factor_guess = 1e3\n",
+ " freq_guess = x_data[np.argmax(y_data)]\n",
+ " amplitude_guess = np.max(y_data)\n",
+ " fit_result, covariance = scipy.optimize.curve_fit(resonance_f, x_data, y_data,\n",
+ " [freq_guess, quality_factor_guess, amplitude_guess])\n",
+ " freq_m = fit_result[0]\n",
+ " quality_factor = np.abs(fit_result[1])\n",
+ " max_amplitude = fit_result[2]\n",
+ " y_data_fit = resonance_f(x_data, freq_m, quality_factor, max_amplitude)\n",
+ "\n",
+ " fig = plt.figure()\n",
+ " plt.plot(frequency / 1e6, reflectivity, frequency / 1e6, y_data_fit)\n",
+ " plt.xlabel('frequency (MHz)')\n",
+ " plt.ylabel('amplitude^2 (a.u.)')\n",
+ " plt.title('Transmission\\n' + 'freq = ' + \"%.7g\" % (freq_guess / 1e6) + 'MHz Q = ' + \"%.6g\" % quality_factor)\n",
+ "except:\n",
+ " fig = plt.figure()\n",
+ " plt.plot(frequency / 1e6, reflectivity)\n",
+ " plt.xlabel('frequency (MHz)')\n",
+ " plt.ylabel('amplitude^2 (a.u.)')\n",
+ " plt.title('Transmission')\n",
+ "\n",
+ "fig = plt.figure()\n",
+ "plt.plot(frequency / 1e6, np.angle(reflection_coefficient))\n",
+ "plt.xlabel('frequency (MHz)')\n",
+ "plt.ylabel('phase (rad)')\n",
+ "plt.title('Phase (transmission coefficient)\\n')\n",
+ "\n",
+ "plt.show()\n",
+ "h5_file.close()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "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.5.3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}