| 1 |
|
| 2 |
.. _demo_nonmataching_interpolation: |
| 3 |
|
| 4 |
Interpolation from a non-matching mesh |
| 5 |
====================================== |
| 6 |
|
| 7 |
This example demonstrates how to interpolate functions between |
| 8 |
finite element spaces on non-matching meshes. |
| 9 |
|
| 10 |
.. note:: |
| 11 |
|
| 12 |
Interpolation on non-matching meshes is not presently support in |
| 13 |
parallel. See |
| 14 |
https://bitbucket.org/fenics-project/dolfin/issues/162. |
| 15 |
|
| 16 |
First, the modules :py:mod:`dolfin` and matplotlib are imported: :: |
| 17 |
|
| 18 |
from dolfin import * |
| 19 |
import matplotlib.pyplot as plt |
| 20 |
|
| 21 |
Next, we create two different meshes. In this case we create unit |
| 22 |
square meshes with different size cells :: |
| 23 |
|
| 24 |
mesh0 = UnitSquareMesh(16, 16) |
| 25 |
mesh1 = UnitSquareMesh(64, 64) |
| 26 |
|
| 27 |
On each mesh we create a finite element space. On the coarser mesh we use linear |
| 28 |
Lagrange elements, and on the finer mesh cubic Lagrange elements :: |
| 29 |
|
| 30 |
P1 = FunctionSpace(mesh0, "Lagrange", 1) |
| 31 |
P3 = FunctionSpace(mesh1, "Lagrange", 3) |
| 32 |
|
| 33 |
We interpolate the function :math:`\sin(10x) \sin(10y)` :: |
| 34 |
|
| 35 |
v = Expression("sin(10.0*x[0])*sin(10.0*x[1])", degree=5) |
| 36 |
|
| 37 |
into the ``P3`` finite element space :: |
| 38 |
|
| 39 |
# Create function on P3 and interpolate v |
| 40 |
v3 = Function(P3) |
| 41 |
v3.interpolate(v) |
| 42 |
|
| 43 |
We now interpolate the function ``v3`` into the ``P1`` space :: |
| 44 |
|
| 45 |
# Create function on P1 and interpolate v3 |
| 46 |
v1 = Function(P1) |
| 47 |
v1.interpolate(v3) |
| 48 |
|
| 49 |
The interpolated functions, ``v3`` and ``v1`` can ve visualised using |
| 50 |
the ``plot`` function :: |
| 51 |
|
| 52 |
plt.figure() |
| 53 |
plot(v3, title='v3') |
| 54 |
|
| 55 |
plt.figure() |
| 56 |
plot(v1, title='v1') |
| 57 |
|
| 58 |
plt.show() |