{ "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", "