File: demo_nonmatching-interpolation.py.rst

package info (click to toggle)
dolfin 2019.2.0~legacy20240219.1c52e83-18
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 31,700 kB
  • sloc: xml: 104,040; cpp: 102,227; python: 24,356; sh: 460; makefile: 330; javascript: 226
file content (58 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

.. _demo_nonmataching_interpolation:

Interpolation from a non-matching mesh
======================================

This example demonstrates how to interpolate functions between
finite element spaces on non-matching meshes.

.. note::

   Interpolation on non-matching meshes is not presently support in
   parallel. See
   https://bitbucket.org/fenics-project/dolfin/issues/162.

First, the modules :py:mod:`dolfin` and matplotlib are imported: ::

  from dolfin import *
  import matplotlib.pyplot as plt

Next, we create two different meshes. In this case we create unit
square meshes with different size cells ::

  mesh0 = UnitSquareMesh(16, 16)
  mesh1 = UnitSquareMesh(64, 64)

On each mesh we create a finite element space. On the coarser mesh we use linear
Lagrange elements, and on the finer mesh cubic Lagrange elements ::

  P1 = FunctionSpace(mesh0, "Lagrange", 1)
  P3 = FunctionSpace(mesh1, "Lagrange", 3)

We interpolate the function :math:`\sin(10x) \sin(10y)` ::

  v = Expression("sin(10.0*x[0])*sin(10.0*x[1])", degree=5)

into the ``P3`` finite element space ::

  # Create function on P3 and interpolate v
  v3 = Function(P3)
  v3.interpolate(v)

We now interpolate the function ``v3`` into the ``P1`` space ::

  # Create function on P1 and interpolate v3
  v1 = Function(P1)
  v1.interpolate(v3)

The interpolated functions, ``v3`` and ``v1`` can ve visualised using
the ``plot`` function ::

  plt.figure()
  plot(v3, title='v3')

  plt.figure()
  plot(v1, title='v1')

  plt.show()