| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Copyright (C) 2015-2015 Martin Sandve Alnæs |
| 3 |
# |
| 4 |
# This file is part of DOLFIN. |
| 5 |
# |
| 6 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU Lesser General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# DOLFIN is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU Lesser General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU Lesser General Public License |
| 17 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
# The bilinear form a(u, v) and linear form L(v) for |
| 20 |
# Poisson's equation with quadratic isoparametric elements. |
| 21 |
# |
| 22 |
# Compile this form with FFC: ffc -r uflacs -l dolfin PoissonDisc.ufl |
| 23 |
|
| 24 |
# Solving |
| 25 |
# -laplace u = 1 |
| 26 |
# u(r=1) = 0 |
| 27 |
|
| 28 |
from ufl_legacy import (Coefficient, dx, FiniteElement, VectorElement, |
| 29 |
dot, grad, Mesh, SpatialCoordinate, |
| 30 |
triangle, TestFunction, TrialFunction, FunctionSpace) |
| 31 |
|
| 32 |
degree = 2 |
| 33 |
cell = triangle |
| 34 |
|
| 35 |
coordinate_element = VectorElement("Lagrange", cell, degree) |
| 36 |
mesh = Mesh(coordinate_element) |
| 37 |
|
| 38 |
element = FiniteElement("Lagrange", cell, degree) |
| 39 |
V = FunctionSpace(mesh, element) |
| 40 |
|
| 41 |
u = TrialFunction(V) |
| 42 |
v = TestFunction(V) |
| 43 |
|
| 44 |
x = SpatialCoordinate(mesh) |
| 45 |
|
| 46 |
f = Coefficient(V) |
| 47 |
|
| 48 |
# Variational formulation |
| 49 |
a = dot(grad(u), grad(v))*dx |
| 50 |
L = f*v*dx |
| 51 |
|
| 52 |
# Exact solution |
| 53 |
uexact = (1.0 - x**2) / 4.0 |
| 54 |
|
| 55 |
# Error norm functional |
| 56 |
uh = Coefficient(V) |
| 57 |
M = (uh - uexact)**2*dx |