Debian Codegraph @

python/demo/undocumented/projection-interpolation/demo_projection-interpolation.py

raw
1 """This script demonstrate how to project and interpolate functions
2 between different finite element spaces."""
3
4 # Copyright (C) 2008 Anders Logg
5 #
6 # This file is part of DOLFIN.
7 #
8 # DOLFIN is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # DOLFIN is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
20 #
21 # First added: 2008-10-06
22 # Last changed: 2012-11-12
23
24 from dolfin import *
25 import matplotlib.pyplot as plt
26
27
28 # Create mesh and define function spaces
29 mesh = UnitSquareMesh(64, 64)
30 P1 = FunctionSpace(mesh, "CG", 1)
31
32 # Define function
33 v = Expression("sin(10.0*x[0])*sin(10.0*x[1])", degree=2)
34
35 # Compute projection (L2-projection)
36 Pv = project(v, V=P1)
37
38 # Compute interpolation (evaluating dofs)
39 PIv = Function(P1)
40 PIv.interpolate(v)
41
42 # Plot functions
43 plt.figure()
44 plot(v, mesh=mesh, title="v")
45 plt.figure()
46 plot(Pv, title="Pv")
47 plt.figure()
48 plot(PIv, title="PI v")
49 plt.show()