Commit 18e4961e authored by Jeremy BLEYER's avatar Jeremy BLEYER

Correct 2018 bugs in modal analysis and hmogenization

parent 874cba7d
......@@ -106,15 +106,13 @@ can be solved using the ``SLEPcEigenSolver``. ::
eigensolver = SLEPcEigenSolver(K, M)
eigensolver.parameters['problem_type'] = 'gen_hermitian'
eigensolver.parameters["spectrum"] = "smallest real"
eigensolver.parameters['spectral_transform'] = 'shift-and-invert'
eigensolver.parameters['spectral_shift'] = 0.
The problem type is specified to be a generalized eigenvalue problem with
Hermitian matrices. By default, SLEPc computes the largest eigenvalues, here
we instead look for the smallest eigenvalues (they should all be real). To
improve convergence of the eigensolver for finding the smallest eigenvalues
(by default it computes the largest ones), a spectral transform is performed
Hermitian matrices. By default, SLEPc computes the largest eigenvalues. Here
we instead look for the smallest eigenvalues (they should all be real). A
spectral transform is therefore performed
using the keyword ``shift-invert`` i.e. the original problem is transformed into
an equivalent problem with eigenvalues given by :math:`\dfrac{1}{\lambda - \sigma}`
instead of :math:`\lambda` where :math:`\sigma` is the value of the spectral shift.
......
......@@ -33,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"metadata": {},
"outputs": [
{
......@@ -819,7 +819,7 @@
{
"data": {
"text/html": [
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAgAElEQVR4nO3dQXIiy5Ym4KgdxBLaMOsNaAU9YN4TrYElMM0xS2ANLIE10Asosxi8p0ENSc1ycs17kIYeQiABjnPCw7/P7Ldnpbzcqyh5nPMnAqlLAAA0pYv+BAAAeC4FEACgMQogAEBjFEAAgMYogAAAjVEAAQAaowACADRGAQQAaIwCCADQGAUQAKAxCiAAQGMUQACAxiiAAACNUQABABqjAAIANEYBBABojAIIANAYBRAAoDEKIABAYxRAAIDGKIAAAI1RAAEAGqMAAgA0RgEEAGiMAggA0BgFEACgMQogAEBjFEAAgMYogAAAjVEAAQAaowACADRGAQQAaIwCCADQGAUQAKAxCiA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4Mwu4AAehrHaUAAAAASUVORK5CYII=\" width=\"640\">"
],
"text/plain": [
"<IPython.core.display.HTML object>"
......@@ -837,7 +837,7 @@
"%matplotlib notebook\n",
"\n",
"a = 1. # unit cell width\n",
"b = sqrt(3)/2. # unit cell height\n",
"b = sqrt(3.)/2. # unit cell height\n",
"c = 0.5 # horizontal offset of top boundary\n",
"R = 0.2 # inclusion radius\n",
"vol = a*b # unit cell volume\n",
......@@ -846,9 +846,10 @@
" [a, 0.],\n",
" [a+c, b],\n",
" [c, b]])\n",
"mesh = Mesh(\"hexag_incl.xml\")\n",
"subdomains = MeshFunction(\"size_t\", mesh, \"hexag_incl_physical_region.xml\")\n",
"facets = MeshFunction(\"size_t\", mesh, \"hexag_incl_facet_region.xml\")\n",
"fname = \"hexag_incl\"\n",
"mesh = Mesh(fname + \".xml\")\n",
"subdomains = MeshFunction(\"size_t\", mesh, fname + \"_physical_region.xml\")\n",
"facets = MeshFunction(\"size_t\", mesh, fname + \"_facet_region.xml\")\n",
"plt.figure()\n",
"plot(subdomains)\n",
"plt.show()"
......@@ -897,42 +898,41 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# class used to define the periodic boundary map\n",
"class PeriodicBoundary(SubDomain):\n",
" def __init__(self, vertices):\n",
" def __init__(self, vertices, tolerance=DOLFIN_EPS):\n",
" \"\"\" vertices stores the coordinates of the 4 unit cell corners\"\"\"\n",
" SubDomain.__init__(self)\n",
" SubDomain.__init__(self, tolerance)\n",
" self.tol = tolerance\n",
" self.vv = vertices\n",
" self.a1 = self.vv[1,:]-self.vv[0,:] # first vector generating periodicity\n",
" self.a2 = self.vv[3,:]-self.vv[0,:] # second vector generating periodicity\n",
" # check if UC vertices form indeed a parallelogram\n",
" assert np.linalg.norm(self.vv[2, :]-self.vv[3, :] - self.a1) <= 1e-8\n",
" assert np.linalg.norm(self.vv[2, :]-self.vv[1, :] - self.a2) <= 1e-8\n",
" assert np.linalg.norm(self.vv[2, :]-self.vv[3, :] - self.a1) <= self.tol\n",
" assert np.linalg.norm(self.vv[2, :]-self.vv[1, :] - self.a2) <= self.tol\n",
" \n",
" def inside(self, x, on_boundary):\n",
" # return True if on left or bottom boundary AND NOT on one of the \n",
" # bottom-right or top-left vertices\n",
" return bool((near(x[0], self.vv[0,0] + x[1]*self.a2[0]/self.vv[3,1]) or \n",
" near(x[1], self.vv[0,1] + x[0]*self.a1[1]/self.vv[1,0])) and \n",
" (not ((near(x[0], self.vv[1,0]) and near(x[1], self.vv[1,1])) or \n",
" (near(x[0], self.vv[3,0]) and near(x[1], self.vv[3,1])))) and on_boundary)\n",
" return bool((near(x[0], self.vv[0,0] + x[1]*self.a2[0]/self.vv[3,1], self.tol) or \n",
" near(x[1], self.vv[0,1] + x[0]*self.a1[1]/self.vv[1,0], self.tol)) and \n",
" (not ((near(x[0], self.vv[1,0], self.tol) and near(x[1], self.vv[1,1], self.tol)) or \n",
" (near(x[0], self.vv[3,0], self.tol) and near(x[1], self.vv[3,1], self.tol)))) and on_boundary)\n",
"\n",
" def map(self, x, y):\n",
" if near(x[0], self.vv[2,0]) and near(x[1], self.vv[2,1]): # if on top-right corner\n",
" if near(x[0], self.vv[2,0], self.tol) and near(x[1], self.vv[2,1], self.tol): # if on top-right corner\n",
" y[0] = x[0] - (self.a1[0]+self.a2[0])\n",
" y[1] = x[1] - (self.a1[1]+self.a2[1])\n",
" elif near(x[0], self.vv[1,0] + x[1]*self.a2[0]/self.vv[2,1]): # if on right boundary\n",
" elif near(x[0], self.vv[1,0] + x[1]*self.a2[0]/self.vv[2,1], self.tol): # if on right boundary\n",
" y[0] = x[0] - self.a1[0]\n",
" y[1] = x[1] - self.a1[1]\n",
" else: # should be on top boundary\n",
" y[0] = x[0] - self.a2[0]\n",
" y[1] = x[1] - self.a2[1]\n",
"\n",
"V = VectorFunctionSpace(mesh, \"CG\", 2, constrained_domain=PeriodicBoundary(vertices))"
" y[1] = x[1] - self.a2[1]"
]
},
{
......@@ -944,7 +944,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -971,7 +971,17 @@
"\n",
"The previous problem is very similar to a standard linear elasticity problem, except for the periodicity constraint which has now been included in the FunctionSpace definition and for the presence of an eigenstrain term $\\boldsymbol{E}$. It can easily be shown that the variational formulation of the previous problem reads as: Find $\\boldsymbol{v}\\in V$ such that:\n",
"\\begin{equation}\n",
"\\int_{\\mathcal{A}} (\\boldsymbol{E}+\\nabla^s\\boldsymbol{v}):\\mathbb{C}(\\boldsymbol{y}):\\nabla^s\\widehat{\\boldsymbol{v}}\\text{ d} \\Omega = 0 \\quad \\forall \\widehat{\\boldsymbol{v}}\\in V\n",
"F(\\boldsymbol{v},\\widehat{\\boldsymbol{v}}) = \\int_{\\mathcal{A}} (\\boldsymbol{E}+\\nabla^s\\boldsymbol{v}):\\mathbb{C}(\\boldsymbol{y}):\\nabla^s\\widehat{\\boldsymbol{v}}\\text{ d} \\Omega = 0 \\quad \\forall \\widehat{\\boldsymbol{v}}\\in V\n",
"\\end{equation}\n",
"\n",
"The above problem is not well-posed because of the existence of rigid body translations. One way to circumvent this issue would be to fix one point but instead we will add an additional constraint of zero-average of the fluctuation field $v$ as is classically done in homogenization theory. This is done by considering an additional vectorial Lagrange multiplier $\\lambda$ and considering the following variational problem: Find $(\\boldsymbol{v},\\boldsymbol{\\lambda})\\in V\\times \\mathbb{R}^2$ such that:\n",
"\\begin{equation}\n",
"\\int_{\\mathcal{A}} (\\boldsymbol{E}+\\nabla^s\\boldsymbol{v}):\\mathbb{C}(\\boldsymbol{y}):\\nabla^s\\widehat{\\boldsymbol{v}}\\text{ d} \\Omega + \\int_{\\mathcal{A}} \\boldsymbol{\\lambda}\\cdot\\widehat{\\boldsymbol{v}} \\text{ d} \\Omega + \\int_{\\mathcal{A}} \\widehat{\\boldsymbol{\\lambda}}\\cdot\\boldsymbol{v} \\text{ d} \\Omega = 0 \\quad \\forall (\\widehat{\\boldsymbol{v}}, \\widehat{\\boldsymbol{\\lambda}})\\in V\\times\\mathbb{R}^2\n",
"\\end{equation}\n",
"\n",
"Which can be summarized as:\n",
"\\begin{equation}\n",
"a(\\boldsymbol{v},\\widehat{\\boldsymbol{v}}) + b(\\boldsymbol{\\lambda},\\widehat{\\boldsymbol{v}}) + b(\\widehat{\\boldsymbol{\\lambda}}, \\boldsymbol{v}) = L(\\widehat{\\boldsymbol{v}}) \\quad \\forall (\\widehat{\\boldsymbol{v}}, \\widehat{\\boldsymbol{\\lambda}})\\in V\\times\\mathbb{R}^2\n",
"\\end{equation}\n",
"\n",
"This readily translates into the following FEniCS code:"
......@@ -979,25 +989,31 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"v_ = TestFunction(V)\n",
"dv = TrialFunction(V)\n",
"v = Function(V)\n",
"Ve = VectorElement(\"CG\", mesh.ufl_cell(), 2)\n",
"Re = VectorElement(\"R\", mesh.ufl_cell(), 0)\n",
"W = FunctionSpace(mesh, MixedElement([Ve, Re]), constrained_domain=PeriodicBoundary(vertices, tolerance=1e-10))\n",
"V = FunctionSpace(mesh, Ve)\n",
"\n",
"v_,lamb_ = TestFunctions(W)\n",
"dv, dlamb = TrialFunctions(W)\n",
"w = Function(W)\n",
"dx = Measure('dx')(subdomain_data=subdomains)\n",
"\n",
"Eps = Constant(((0, 0), (0, 0)))\n",
"F = sum([inner(sigma(dv, i, Eps), eps(v_))*dx(i) for i in range(nphases)])\n",
"a, L = lhs(F), rhs(F)"
"a, L = lhs(F), rhs(F)\n",
"a += dot(lamb_,dv)*dx + dot(dlamb,v_)*dx"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We have used a general implementation using a sum over the different phases for the functional `F`. We then used the `lhs` and `rhs` functions to respectively extract the corresponding bilinear and linear forms.\n",
"We have used a general implementation using a sum over the different phases for the functional `F`. We then used the `lhs` and `rhs` functions to respectively extract the corresponding bilinear $a$ and linear $L$ forms.\n",
"\n",
"## Resolution\n",
"\n",
......@@ -1006,7 +1022,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 16,
"metadata": {},
"outputs": [
{
......@@ -1016,9 +1032,9 @@
"Solving Exx case...\n",
"Solving Eyy case...\n",
"Solving Exy case...\n",
"[[35749.31 8205.86 5181.94]\n",
" [ 8205.78 28273.8 1331.63]\n",
" [ 5181.91 1331.65 14136.7 ]]\n"
"[[ 6.56e+04 1.74e+04 -2.10e-02]\n",
" [ 1.74e+04 6.56e+04 -4.07e-02]\n",
" [-2.45e-02 -4.21e-02 2.41e+04]]\n"
]
}
],
......@@ -1036,7 +1052,8 @@
"for (j, case) in enumerate([\"Exx\", \"Eyy\", \"Exy\"]):\n",
" print(\"Solving {} case...\".format(case))\n",
" Eps.assign(Constant(macro_strain(j)))\n",
" solve(lhs(F) == rhs(F), v, [], solver_parameters={\"linear_solver\": \"cg\"})\n",
" solve(a == L, w, [], solver_parameters={\"linear_solver\": \"cg\"})\n",
" (v, lamb) = split(w)\n",
" Sigma = np.zeros((3,))\n",
" for k in range(3):\n",
" Sigma[k] = assemble(sum([stress2Voigt(sigma(v, i, Eps))[k]*dx(i) for i in range(nphases)]))/vol\n",
......@@ -1056,14 +1073,14 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"35749.30527415909 36479.26730142249\n"
"65570.19577075752 65570.2553898389\n"
]
}
],
......@@ -1082,15 +1099,15 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Apparent Young modulus: 33465.46042796117\n",
"Apparent Poisson ratio: 0.18363742779286404\n"
"Apparent Young modulus: 58239.72435202466\n",
"Apparent Poisson ratio: 0.21012531632724085\n"
]
}
],
......@@ -1103,799 +1120,19 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"/* Put everything inside the global mpl namespace */\n",
"window.mpl = {};\n",
"\n",
"\n",
"mpl.get_websocket_type = function() {\n",
" if (typeof(WebSocket) !== 'undefined') {\n",
" return WebSocket;\n",
" } else if (typeof(MozWebSocket) !== 'undefined') {\n",
" return MozWebSocket;\n",
" } else {\n",
" alert('Your browser does not have WebSocket support.' +\n",
" 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
" 'Firefox 4 and 5 are also supported but you ' +\n",
" 'have to enable WebSockets in about:config.');\n",
" };\n",
"}\n",
"\n",
"mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
" this.id = figure_id;\n",
"\n",
" this.ws = websocket;\n",
"\n",
" this.supports_binary = (this.ws.binaryType != undefined);\n",
"\n",
" if (!this.supports_binary) {\n",
" var warnings = document.getElementById(\"mpl-warnings\");\n",
" if (warnings) {\n",
" warnings.style.display = 'block';\n",
" warnings.textContent = (\n",
" \"This browser does not support binary websocket messages. \" +\n",
" \"Performance may be slow.\");\n",
" }\n",
" }\n",
"\n",
" this.imageObj = new Image();\n",
"\n",
" this.context = undefined;\n",
" this.message = undefined;\n",
" this.canvas = undefined;\n",
" this.rubberband_canvas = undefined;\n",
" this.rubberband_context = undefined;\n",
" this.format_dropdown = undefined;\n",
"\n",
" this.image_mode = 'full';\n",
"\n",
" this.root = $('<div/>');\n",
" this._root_extra_style(this.root)\n",
" this.root.attr('style', 'display: inline-block');\n",
"\n",
" $(parent_element).append(this.root);\n",
"\n",
" this._init_header(this);\n",
" this._init_canvas(this);\n",
" this._init_toolbar(this);\n",
"\n",
" var fig = this;\n",
"\n",
" this.waiting = false;\n",
"\n",
" this.ws.onopen = function () {\n",
" fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
" fig.send_message(\"send_image_mode\", {});\n",
" if (mpl.ratio != 1) {\n",
" fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
" }\n",
" fig.send_message(\"refresh\", {});\n",
" }\n",
"\n",
" this.imageObj.onload = function() {\n",
" if (fig.image_mode == 'full') {\n",
" // Full images could contain transparency (where diff images\n",
" // almost always do), so we need to clear the canvas so that\n",
" // there is no ghosting.\n",
" fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
" }\n",
" fig.context.drawImage(fig.imageObj, 0, 0);\n",
" };\n",
"\n",
" this.imageObj.onunload = function() {\n",
" fig.ws.close();\n",
" }\n",
"\n",
" this.ws.onmessage = this._make_on_message_function(this);\n",
"\n",
" this.ondownload = ondownload;\n",
"}\n",
"\n",
"mpl.figure.prototype._init_header = function() {\n",
" var titlebar = $(\n",
" '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
" 'ui-helper-clearfix\"/>');\n",
" var titletext = $(\n",
" '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
" 'text-align: center; padding: 3px;\"/>');\n",
" titlebar.append(titletext)\n",
" this.root.append(titlebar);\n",
" this.header = titletext[0];\n",
"}\n",
"\n",
"\n",
"\n",
"mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
"\n",
"}\n",
"\n",
"\n",
"mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
"\n",
"}\n",
"\n",
"mpl.figure.prototype._init_canvas = function() {\n",
" var fig = this;\n",
"\n",
" var canvas_div = $('<div/>');\n",
"\n",
" canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
"\n",
" function canvas_keyboard_event(event) {\n",
" return fig.key_event(event, event['data']);\n",
" }\n",
"\n",
" canvas_div.keydown('key_press', canvas_keyboard_event);\n",
" canvas_div.keyup('key_release', canvas_keyboard_event);\n",
" this.canvas_div = canvas_div\n",
" this._canvas_extra_style(canvas_div)\n",
" this.root.append(canvas_div);\n",
"\n",
" var canvas = $('<canvas/>');\n",
" canvas.addClass('mpl-canvas');\n",
" canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
"\n",
" this.canvas = canvas[0];\n",
" this.context = canvas[0].getContext(\"2d\");\n",
"\n",
" var backingStore = this.context.backingStorePixelRatio ||\n",
"\tthis.context.webkitBackingStorePixelRatio ||\n",
"\tthis.context.mozBackingStorePixelRatio ||\n",
"\tthis.context.msBackingStorePixelRatio ||\n",
"\tthis.context.oBackingStorePixelRatio ||\n",
"\tthis.context.backingStorePixelRatio || 1;\n",
"\n",
" mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
"\n",
" var rubberband = $('<canvas/>');\n",
" rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
"\n",
" var pass_mouse_events = true;\n",
"\n",
" canvas_div.resizable({\n",
" start: function(event, ui) {\n",
" pass_mouse_events = false;\n",
" },\n",
" resize: function(event, ui) {\n",
" fig.request_resize(ui.size.width, ui.size.height);\n",
" },\n",
" stop: function(event, ui) {\n",
" pass_mouse_events = true;\n",
" fig.request_resize(ui.size.width, ui.size.height);\n",
" },\n",
" });\n",
"\n",
" function mouse_event_fn(event) {\n",
" if (pass_mouse_events)\n",
" return fig.mouse_event(event, event['data']);\n",
" }\n",
"\n",
" rubberband.mousedown('button_press', mouse_event_fn);\n",
" rubberband.mouseup('button_release', mouse_event_fn);\n",
" // Throttle sequential mouse events to 1 every 20ms.\n",
" rubberband.mousemove('motion_notify', mouse_event_fn);\n",
"\n",
" rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
" rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
"\n",
" canvas_div.on(\"wheel\", function (event) {\n",
" event = event.originalEvent;\n",
" event['data'] = 'scroll'\n",
" if (event.deltaY < 0) {\n",
" event.step = 1;\n",
" } else {\n",
" event.step = -1;\n",
" }\n",
" mouse_event_fn(event);\n",
" });\n",
"\n",
" canvas_div.append(canvas);\n",
" canvas_div.append(rubberband);\n",
"\n",
" this.rubberband = rubberband;\n",
" this.rubberband_canvas = rubberband[0];\n",
" this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
" this.rubberband_context.strokeStyle = \"#000000\";\n",
"\n",
" this._resize_canvas = function(width, height) {\n",
" // Keep the size of the canvas, canvas container, and rubber band\n",
" // canvas in synch.\n",
" canvas_div.css('width', width)\n",
" canvas_div.css('height', height)\n",
"\n",
" canvas.attr('width', width * mpl.ratio);\n",
" canvas.attr('height', height * mpl.ratio);\n",
" canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
"\n",
" rubberband.attr('width', width);\n",
" rubberband.attr('height', height);\n",
" }\n",
"\n",
" // Set the figure to an initial 600x600px, this will subsequently be updated\n",
" // upon first draw.\n",
" this._resize_canvas(600, 600);\n",
"\n",
" // Disable right mouse context menu.\n",
" $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
" return false;\n",
" });\n",
"\n",
" function set_focus () {\n",
" canvas.focus();\n",
" canvas_div.focus();\n",
" }\n",
"\n",
" window.setTimeout(set_focus, 100);\n",
"}\n",
"\n",
"mpl.figure.prototype._init_toolbar = function() {\n",
" var fig = this;\n",
"\n",
" var nav_element = $('<div/>')\n",
" nav_element.attr('style', 'width: 100%');\n",
" this.root.append(nav_element);\n",
"\n",
" // Define a callback function for later on.\n",
" function toolbar_event(event) {\n",
" return fig.toolbar_button_onclick(event['data']);\n",
" }\n",
" function toolbar_mouse_event(event) {\n",
" return fig.toolbar_button_onmouseover(event['data']);\n",
" }\n",
"\n",
" for(var toolbar_ind in mpl.toolbar_items) {\n",
" var name = mpl.toolbar_items[toolbar_ind][0];\n",
" var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
" var image = mpl.toolbar_items[toolbar_ind][2];\n",
" var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
"\n",
" if (!name) {\n",
" // put a spacer in here.\n",
" continue;\n",
" }\n",
" var button = $('<button/>');\n",
" button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
" 'ui-button-icon-only');\n",
" button.attr('role', 'button');\n",
" button.attr('aria-disabled', 'false');\n",
" button.click(method_name, toolbar_event);\n",
" button.mouseover(tooltip, toolbar_mouse_event);\n",
"\n",
" var icon_img = $('<span/>');\n",
" icon_img.addClass('ui-button-icon-primary ui-icon');\n",
" icon_img.addClass(image);\n",
" icon_img.addClass('ui-corner-all');\n",
"\n",
" var tooltip_span = $('<span/>');\n",
" tooltip_span.addClass('ui-button-text');\n",
" tooltip_span.html(tooltip);\n",
"\n",
" button.append(icon_img);\n",
" button.append(tooltip_span);\n",
"\n",
" nav_element.append(button);\n",
" }\n",
"\n",
" var fmt_picker_span = $('<span/>');\n",
"\n",
" var fmt_picker = $('<select/>');\n",
" fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
" fmt_picker_span.append(fmt_picker);\n",
" nav_element.append(fmt_picker_span);\n",
" this.format_dropdown = fmt_picker[0];\n",
"\n",
" for (var ind in mpl.extensions) {\n",
" var fmt = mpl.extensions[ind];\n",
" var option = $(\n",
" '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
" fmt_picker.append(option)\n",
" }\n",
"\n",
" // Add hover states to the ui-buttons\n",
" $( \".ui-button\" ).hover(\n",
" function() { $(this).addClass(\"ui-state-hover\");},\n",
" function() { $(this).removeClass(\"ui-state-hover\");}\n",
" );\n",
"\n",
" var status_bar = $('<span class=\"mpl-message\"/>');\n",
" nav_element.append(status_bar);\n",
" this.message = status_bar[0];\n",
"}\n",
"\n",
"mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
" // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
" // which will in turn request a refresh of the image.\n",
" this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
"}\n",
"\n",
"mpl.figure.prototype.send_message = function(type, properties) {\n",
" properties['type'] = type;\n",
" properties['figure_id'] = this.id;\n",
" this.ws.send(JSON.stringify(properties));\n",
"}\n",
"\n",
"mpl.figure.prototype.send_draw_message = function() {\n",
" if (!this.waiting) {\n",
" this.waiting = true;\n",
" this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
" }\n",
"}\n",
"\n",
"\n",
"mpl.figure.prototype.handle_save = function(fig, msg) {\n",
" var format_dropdown = fig.format_dropdown;\n",
" var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
" fig.ondownload(fig, format);\n",
"}\n",
"\n",
"\n",
"mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
" var size = msg['size'];\n",
" if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
" fig._resize_canvas(size[0], size[1]);\n",
" fig.send_message(\"refresh\", {});\n",
" };\n",
"}\n",
"\n",
"mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
" var x0 = msg['x0'] / mpl.ratio;\n",
" var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
" var x1 = msg['x1'] / mpl.ratio;\n",
" var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
" x0 = Math.floor(x0) + 0.5;\n",
" y0 = Math.floor(y0) + 0.5;\n",