| 1 |
# Copyright (C) 2010 Anders Logg |
| 2 |
# |
| 3 |
# This file is part of DOLFIN. |
| 4 |
# |
| 5 |
# DOLFIN is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# DOLFIN is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public License |
| 16 |
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# First added: 2010-02-08 |
| 19 |
# Last changed: 2010-02-09 |
| 20 |
|
| 21 |
from dolfin import * |
| 22 |
import matplotlib.pyplot as plt |
| 23 |
|
| 24 |
|
| 25 |
# Create mesh and function spaces |
| 26 |
mesh = UnitSquareMesh(8, 8) |
| 27 |
P1 = FunctionSpace(mesh, "CG", 1) |
| 28 |
P2 = FunctionSpace(mesh, "CG", 2) |
| 29 |
|
| 30 |
# Create exact dual |
| 31 |
dual = Expression("sin(5.0*x[0])*sin(5.0*x[1])", degree=2) |
| 32 |
|
| 33 |
# Create P1 approximation of exact dual |
| 34 |
z1 = Function(P1) |
| 35 |
z1.interpolate(dual) |
| 36 |
|
| 37 |
# Create P2 approximation from P1 approximation |
| 38 |
z2 = Function(P2) |
| 39 |
z2.extrapolate(z1) |
| 40 |
|
| 41 |
# Plot approximations |
| 42 |
plt.figure() |
| 43 |
plot(z1, title="z1") |
| 44 |
plt.figure() |
| 45 |
plot(z2, title="z2") |
| 46 |
plt.show() |