~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to demo/plot/python/demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2008-09-16 08:41:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080916084120-i8k3u6lhx3mw3py3
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"This demo illustrate basic plotting."
 
2
 
 
3
__author__ = "Anders Logg (logg@simula.no)"
 
4
__date__ = "2007-05-29 -- 2008-12-07"
 
5
__copyright__ = "Copyright (C) 2007-2008 Anders Logg"
 
6
__license__  = "GNU LGPL Version 2.1"
 
7
 
 
8
from dolfin import *
 
9
from math import sqrt
 
10
 
 
11
import sys
 
12
 
 
13
# Read and plot mesh from file
 
14
mesh = Mesh("dolfin-2.xml.gz")
 
15
mesh.order()
 
16
 
 
17
# Decide which demos to run
 
18
try:
 
19
    demos = [int(sys.argv[-1])]
 
20
except:
 
21
    demos = [0, 1, 2, 3]
 
22
 
 
23
# Have some fun with the mesh
 
24
if 0 in demos:
 
25
 
 
26
    R = 0.15
 
27
    H = 0.025
 
28
    X = 0.3
 
29
    Y = 0.4
 
30
    dX = H
 
31
    dY = 1.5*H
 
32
    coordinates = mesh.coordinates()
 
33
    original = coordinates.copy()
 
34
 
 
35
    for i in xrange(100):
 
36
 
 
37
        if X < H or X > 1.0 - H:
 
38
            dX = -dX
 
39
        if Y < H or Y > 1.0 - H:
 
40
            dY = -dY
 
41
        X += dX
 
42
        Y += dY
 
43
 
 
44
        for j in xrange(mesh.numVertices()):
 
45
            x, y = coordinates[j]
 
46
            r = sqrt((x - X)**2 + (y - Y)**2)
 
47
            if r < R:
 
48
                coordinates[j] = [X + (r/R)**2*(x - X), Y + (r/R)**2*(y - Y)]
 
49
 
 
50
        plot(mesh)
 
51
 
 
52
        for j in xrange(mesh.numVertices()):
 
53
            coordinates[j] = original[j]
 
54
 
 
55
# Plot scalar function
 
56
if 1 in demos:
 
57
    V = FunctionSpace(mesh, "CG", 1)
 
58
    f = Function(V, "t * 100 * exp(-10.0 * (pow(x[0] - t, 2) + pow(x[1] - t, 2)))")
 
59
    f.t = 0.0
 
60
    for i in range(100):
 
61
        f.t += 0.01
 
62
        plot(f, rescale=True, title="Scalar function")
 
63
 
 
64
# Plot vector function
 
65
if 2 in demos:
 
66
    mesh = UnitSquare(16, 16)
 
67
    V = VectorFunctionSpace(mesh, "CG", 1)
 
68
    f = Function(V, ("-(x[1] - t)*exp(-10.0*(pow(x[0] - t, 2) + pow(x[1] - t, 2)))",
 
69
                     " (x[0] - t)*exp(-10.0*(pow(x[0] - t, 2) + pow(x[1] - t, 2)))"))
 
70
    f.t = 0.0
 
71
    for i in range(200):
 
72
        f.t += 0.005
 
73
        plot(f, rescale=True, title="Vector function")
 
74
 
 
75
if 3 in demos:
 
76
    import numpy
 
77
    mesh = UnitSquare(10, 10)
 
78
    V = VectorFunctionSpace(mesh, "CG", 1)
 
79
    f = Function(V, ("-(x[1] - t)*exp(-10.0*(pow(x[0] - t, 2) + pow(x[1] - t, 2)))",
 
80
                     " (x[0] - t)*exp(-10.0*(pow(x[0] - t, 2) + pow(x[1] - t, 2)))"))
 
81
 
 
82
    pts = numpy.array([
 
83
        [.24, .24],
 
84
        [.24, .74],
 
85
        [.74, .24],
 
86
        [.74, .74]
 
87
        ], dtype='d')
 
88
    f.t = 0.0
 
89
    for i in range(150):
 
90
        f.t += 0.005
 
91
        plot(f, eval_pts=pts, rescale=True, title="Vector function")
 
92
 
 
93
 
 
94
#    plot(f,eval_pts=pts)
 
95
#    interactive()