Commit b7bef5d1 authored by Jeremy BLEYER's avatar Jeremy BLEYER

Added beam buckling example

parent 5682d82b
......@@ -10,8 +10,8 @@ Introduction
-------------
This program performs a dynamic modal analysis of an elastic cantilever beam
represented by a 3D solid continuum. The eigenmodes are computed using the
**SLEPcEigensolver** and compared against an analytical solution of beam theory.
represented by a 3D solid continuum. The eigenmodes are computed using the
**SLEPcEigensolver** and compared against an analytical solution of beam theory.
The corresponding file can be obtained from :download:`cantilever_modal.py`.
......@@ -20,14 +20,14 @@ The first four eigenmodes of this demo will look as follows:
.. image:: vibration_modes.gif
:scale: 80 %
The first two fundamental modes are on top with bending along the weak axis (left) and along
the strong axis (right), the next two modes are at the bottom.
The first two fundamental modes are on top with bending along the weak axis (left) and along
the strong axis (right), the next two modes are at the bottom.
---------------
Implementation
---------------
After importing the relevant modules, the geometry of a beam of length :math:`L=20`
After importing the relevant modules, the geometry of a beam of length :math:`L=20`
and rectangular section of size :math:`B\times H` with :math:`B=0.5, H=1` is first defined::
from fenics import *
......@@ -43,7 +43,7 @@ and rectangular section of size :math:`B\times H` with :math:`B=0.5, H=1` is fir
Material parameters and elastic constitutive relations are classical (here we
take :math:`\nu=0`) and we also introduce the material density :math:`\rho` for
take :math:`\nu=0`) and we also introduce the material density :math:`\rho` for
later definition of the mass matrix::
E, nu = 1e5, 0.
......@@ -59,7 +59,7 @@ later definition of the mass matrix::
dim = v.geometric_dimension()
return 2.0*mu*eps(v) + lmbda*tr(eps(v))*Identity(dim)
Standard FunctionSpace is defined and boundary conditions correspond to a
Standard FunctionSpace is defined and boundary conditions correspond to a
fully clamped support at :math:`x=0`::
V = VectorFunctionSpace(mesh, 'Lagrange', degree=1)
......@@ -73,7 +73,7 @@ fully clamped support at :math:`x=0`::
bc = DirichletBC(V, Constant((0.,0.,0.)), left)
The system stiffness matrix :math:`[K]` and mass matrix :math:`[M]` are
The system stiffness matrix :math:`[K]` and mass matrix :math:`[M]` are
respectively obtained from assembling the corresponding variational forms::
k_form = inner(sigma(du),eps(u_))*dx
......@@ -86,14 +86,14 @@ respectively obtained from assembling the corresponding variational forms::
M = PETScMatrix()
assemble(m_form, tensor=M)
Matrices :math:`[K]` and :math:`[M]` are first defined as PETSc Matrix and
Matrices :math:`[K]` and :math:`[M]` are first defined as PETSc Matrix and
forms are assembled into it to ensure that they have the right type.
Note that boundary conditions have been applied to the stiffness matrix using
``assemble_system`` so as to preserve symmetry (a dummy ``l_form`` and right-hand side
vector have been introduced to call this function).
vector have been introduced to call this function).
Modal dynamic analysis consists in solving the following generalized
Modal dynamic analysis consists in solving the following generalized
eigenvalue problem :math:`[K]\{U\}=\lambda[M]\{U\}` where the eigenvalue
is related to the eigenfrequency :math:`\lambda=\omega^2`. This problem
can be solved using the ``SLEPcEigenSolver``. ::
......@@ -121,7 +121,7 @@ We now ask SLEPc to extract the first 6 eigenvalues by calling its solve functio
and extract the corresponding eigenpair (first two arguments of ``get_eigenpair``
correspond to the real and complex part of the eigenvalue, the last two to the
real and complex part of the eigenvector)::
N_eig = 6 # number of eigenvalues
print "Computing %i first eigenvalues..." % N_eig
eigensolver.solve(N_eig)
......@@ -136,31 +136,31 @@ real and complex part of the eigenvector)::
file_results = XDMFFile("modal_analysis.xdmf")
file_results.parameters["flush_output"] = True
file_results.parameters["functions_share_mesh"] = True
# Extraction
for i in range(N_eig):
# Extract eigenpair
r, c, rx, cx = eigensolver.get_eigenpair(i)
# 3D eigenfrequency
freq_3D = sqrt(r)/2/pi
# Beam eigenfrequency
if i % 2 == 0: # exact solution should correspond to weak axis bending
I_bend = H*B**3/12.
else: #exact solution should correspond to strong axis bending
I_bend = B*H**3/12.
freq_beam = alpha(i/2)**2*sqrt(E*I_bend/(rho*B*H*L**4))/2/pi
print("Solid FE: {0:8.5f} [Hz] Beam theory: {1:8.5f} [Hz]".format(freq_3D, freq_beam))
# Initialize function and assign eigenvector (renormalize by stiffness matrix)
eigenmode = Function(V,name="Eigenvector "+str(i))
eigenmode.vector()[:] = rx/omega
eigenmode.vector()[:] = rx
The beam analytical solution is obtained using the eigenfrequencies of a clamped
beam in bending given by :math:`\omega_n = \alpha_n^2\sqrt{\dfrac{EI}{\rho S L^4}}`
where :math:`S=BH` is the beam section, :math:`I` the bending inertia and
where :math:`S=BH` is the beam section, :math:`I` the bending inertia and
:math:`\alpha_n` is the solution of the following nonlinear equation:
.. math::
......@@ -173,9 +173,9 @@ and the other along the strong axis (:math:`I=I_{\text{strong}} = BH^3/12`). Sin
for the considered numerical values, the strong axis bending frequency will be twice that corresponsing
to bending along the weak axis. The solution :math:`\alpha_n` are computed using the
``scipy.optimize.root`` function with initial guess given by :math:`(2n+1)\pi/2`.
With ``Nx=400``, we obtain the following comparison between the FE eigenfrequencies
and the beam theory eigenfrequencies :
and the beam theory eigenfrequencies :
===== ============= =================
......@@ -184,11 +184,11 @@ Mode Eigenfrequencies
# Solid FE [Hz] Beam theory [Hz]
===== ============= =================
1 2.04991 2.01925
2 4.04854 4.03850
2 4.04854 4.03850
3 12.81504 12.65443
4 25.12717 25.30886
4 25.12717 25.30886
5 35.74168 35.43277
6 66.94816 70.86554
6 66.94816 70.86554
===== ============= =================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Eulerian buckling of a beam\n",
"\n",
"In this numerical tour, we will compute the critical buckling load of a straight beam under normal compression, the classical Euler buckling problem. Usually, buckling is an important mode of failure for slender beams so that a standard Euler-Bernoulli beam model is sufficient. However, since FEniCS does not support Hermite elements ensuring $C^1$-formulation for the transverse deflection, implementing such models is not straightforward and requires using advanced DG formulations for instance, see the `fenics-shell` [implemntation of the Love-Kirchhoff plate model](http://fenics-shells.readthedocs.io/en/latest/demo/kirchhoff-love-clamped/demo_kirchhoff-love-clamped.py.html) or the [FEniCS documented demo on the biharmonic equation](http://fenics.readthedocs.io/projects/dolfin/en/2017.2.0/demos/biharmonic/python/demo_biharmonic.py.html).\n",
"\n",
"As a result, we will simply formulate the buckling problem using a Timoshenko beam model.\n",
"\n",
"## Timoshenko beam model formulation\n",
"\n",
"We first formulate the stiffness bilinear form of the Timoshenko model given by:\n",
"\\begin{equation}\n",
"k((w,\\theta),(\\widehat{w},\\widehat{\\theta}))= \\int_0^L EI \\dfrac{d\\theta}{dx}\\dfrac{d\\widehat{\\theta}}{dx} dx + \\int_0^L \\kappa \\mu S \\left(\\dfrac{dw}{dx}-\\theta\\right)\\left(\\dfrac{d\\widehat{w}}{dx}-\\widehat{\\theta}\\right) dx\n",
"\\end{equation}\n",
"where $I=bh^3/12$ is the bending inertia for a rectangular beam of width $b$ and height $h$, $S=bh$ the cross-section area, $E$ the material Young modulus and $\\mu$ the shear modulus and $\\kappa=5/6$ the shear correction factor. We will use a $P^2/P^1$ interpolation for the mixed field $(w,\\theta)$. "
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"For issues related to shear-locking and reduced integration formulation, we refer to the :ref:`ReissnerMindlinQuads` tour."
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"from dolfin import *\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib notebook\n",
"\n",
"L = 10.\n",
"thick = Constant(0.03)\n",
"width = Constant(0.01)\n",
"E = Constant(70e3)\n",
"nu = Constant(0.)\n",
"\n",
"EI = E*width*thick**3/12\n",
"GS = E/2/(1+nu)*thick*width\n",
"kappa = Constant(5./6.)\n",
"\n",
"\n",
"N = 100\n",
"mesh = IntervalMesh(N, 0, L) \n",
"\n",
"U = FiniteElement(\"CG\", mesh.ufl_cell(), 2)\n",
"T = FiniteElement(\"CG\", mesh.ufl_cell(), 1)\n",
"V = FunctionSpace(mesh, U*T)\n",
"\n",
"u_ = TestFunction(V)\n",
"du = TrialFunction(V)\n",
"(w_, theta_) = split(u_)\n",
"(dw, dtheta) = split(du)\n",
"\n",
"\n",
"k_form = EI*inner(grad(theta_), grad(dtheta))*dx + kappa*GS*dot(grad(w_)[0]-theta_, grad(dw)[0]-dtheta)*dx\n",
"l_form = Constant(1.)*u_[0]*dx"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"As in the :ref:`ModalAnalysis` tour, a dummy linear form `l_form` is used to call the `assemble_system` function which retains the symmetric structure of the associated matrix when imposing boundary conditions. Here, we will consider clamped conditions on the left side :math:`x=0` and simple supports on the right side :math:`x=L`."
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(<dolfin.cpp.la.PETScMatrix; proxy of <Swig Object of type 'std::shared_ptr< dolfin::PETScMatrix > *' at 0x7f9df3cf8780> >,\n",
" <dolfin.cpp.la.Vector; proxy of <Swig Object of type 'std::shared_ptr< dolfin::Vector > *' at 0x7f9df3cf8ae0> >)"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def both_ends(x, on_boundary):\n",
" return on_boundary\n",
"def left_end(x, on_boundary):\n",
" return near(x[0], 0) and on_boundary\n",
"\n",
"bc = [DirichletBC(V.sub(0), Constant(0.), both_ends),\n",
" DirichletBC(V.sub(1), Constant(0.), left_end)]\n",
"\n",
"K = PETScMatrix()\n",
"assemble_system(k_form, l_form, bc, A_tensor=K)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Construction of the geometric stiffness matrix\n",
"\n",
"The buckling analysis amounts to solving an eigenvalue problem of the form:\n",
"\n",
"\\begin{equation}\n",
"(\\mathbf{K}+\\lambda\\mathbf{K_G})\\mathbf{U} = 0\n",
"\\end{equation}\n",
"\n",
"in which the geometric stiffness matrix $\\mathbf{K_G}$ depends (linearly) on a prestressed state, the amplitude of which is represented by $\\lambda$. The eigenvalue/eigenvector $(\\lambda,\\mathbf{U})$ solving the previous generalized eigenproblem respectively correspond to the critical buckling load and its associated buckling mode. For a beam in which the prestressed state correspond to a purely compression state of intensity $N_0>0$, the geometric stiffness bilinear form is given by:\n",
"\n",
"\\begin{equation}\n",
"k_G((w,\\theta),(\\widehat{w},\\widehat{\\theta}))= -\\int_0^L N_0 \\dfrac{dw}{dx}\\dfrac{d\\widehat{w}}{dx} dx\n",
"\\end{equation}\n",
"\n",
"which is assembled below into the `KG` `PETScMatrix` (up to the negative sign)."
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"N0 = Constant(1e-3)\n",
"kg_form = N0*dot(grad(w_), grad(dw))*dx\n",
"KG = PETScMatrix()\n",
"assemble(kg_form, tensor=KG)\n",
"for bci in bc:\n",
" bci.zero(KG)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that we made use of the `zero` method of `DirichletBC` making the rows of the matrix associated with the boundary condition zero. If we used instead the `apply` method, the rows would have been replaced with a row of zeros with a 1 on the diagonal (as for the stiffness matrix `K`). As a result, we would have obtained an eigenvalue equal to 1 for each row with a boundary condition which can make more troublesome the computation of eigenvalues if they happen to be close to 1. Replacing with a full row of zeros in `KG` results in infinite eigenvalues for each boundary condition which is more suitable when looking for the lowest eigenvalues of the buckling problem.\n",
"\n",
"## Setting and solving the eigenvalue problem\n",
"\n",
"Up to the negative sign cancelling from the previous definition of `KG`, we now formulate the generalized eigenvalue problem $\\mathbf{KU}=-\\lambda\\mathbf{K_G U}$ using the `SLEPcEigenSolver`. The only difference from what has already been discussed in the dynamic modal analysis numerical tour is that buckling eigenvalue problem may be more difficult to solve than modal analysis in certain cases, it is therefore beneficial to prescribe a value of the spectral shift close to the critical buckling load."
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Computing 3 first eigenvalues...\n"
]
},
{
"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",
" this.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",