Debian Codegraph @

python/demo/undocumented/special-functions/demo_special-functions.py

raw
1 """This demo program plots a bunch of nonlinear
2 special functions that are available in UFL."""
3
4 # Copyright (C) 2010 Martin S. Alnaes
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: 2011-10-24
22 # Last changed: 2011-10-24
23
24
25 from dolfin import *
26 import matplotlib.pyplot as plt
27
28
29 # Form compiler options
30 parameters["form_compiler"]["optimize"] = True
31 parameters["form_compiler"]["cpp_optimize"] = True
32
33 n = 100
34 eps = 1e-8
35
36 mesh = IntervalMesh(n, -2.0, +2.0)
37 x = SpatialCoordinate(mesh)[0]
38
39 plot(cos(x), title='cos', mesh=mesh)
40 plot(sin(x), title='sin', mesh=mesh)
41 plot(tan(x), title='tan', mesh=mesh)
42
43 mesh = IntervalMesh(n, 0.0+eps, 1.0-eps)
44 x = SpatialCoordinate(mesh)[0]
45
46 plt.figure(); plot(acos(x), title='acos', mesh=mesh)
47 plt.figure(); plot(asin(x), title='asin', mesh=mesh)
48 plt.figure(); plot(atan(x), title='atan', mesh=mesh)
49 plt.figure(); plot(exp(x), title='exp', mesh=mesh)
50 plt.figure(); plot(ln(x), title='ln', mesh=mesh)
51 plt.figure(); plot(sqrt(x), title='sqrt', mesh=mesh)
52 plt.figure(); plot(bessel_J(0, x), title='bessel_J(0, x)', mesh=mesh)
53 plt.figure(); plot(bessel_J(1, x), title='bessel_J(1, x)', mesh=mesh)
54 plt.figure(); plot(bessel_Y(0, x), title='bessel_Y(0, x)', mesh=mesh)
55 plt.figure(); plot(bessel_Y(1, x), title='bessel_Y(1, x)', mesh=mesh)
56 plt.figure(); plot(bessel_I(0, x), title='bessel_I(0, x)', mesh=mesh)
57 plt.figure(); plot(bessel_I(1, x), title='bessel_I(1, x)', mesh=mesh)
58 plt.figure(); plot(bessel_K(0, x), title='bessel_K(0, x)', mesh=mesh)
59 plt.figure(); plot(bessel_K(1, x), title='bessel_K(1, x)', mesh=mesh)
60 plt.show()