{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from IPython.core.display import HTML\n", "from dolfin import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Create mesh and define function space\n", "mesh = UnitCubeMesh(32, 32, 32)\n", "V = FunctionSpace(mesh, \"Lagrange\", 1)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Define Dirichlet boundary at the bottom face\n", "def boundary(x):\n", " return x[0] < DOLFIN_EPS \n", "\n", "# Define boundary condition\n", "bc = DirichletBC(V, Constant(0.0), boundary)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Calling FFC just-in-time (JIT) compiler, this may take some time.\n" ] } ], "source": [ "# Define variational problem\n", "u = TrialFunction(V)\n", "v = TestFunction(V)\n", "f = Expression(\"10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2) + pow(x[2] - 0.5, 2)) / 0.02)\", degree=1)\n", "a = inner(grad(u), grad(v))*dx\n", "L = f*v*dx \n", "\n", "# Compute solution\n", "u = Function(V)\n", "solve(a == L, u, bc)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " FEniCS/DOLFIN X3DOM plot\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Number of vertices: 35937, number of cells: 196608
\n", " \n", "\n" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(X3DOM.html(u))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11+" } }, "nbformat": 4, "nbformat_minor": 0 }