source: anuga_work/development/demos/visualise_rectangle.py @ 5236

Last change on this file since 5236 was 4539, checked in by ole, 18 years ago

Moved files from examples to anuga_work

File size: 3.2 KB
Line 
1#!/usr/bin/env python
2##########
3# Demonstration of the VTK realtime Visualiser.
4# Based on run_sw_rectangle.py
5# Jack Kelly and Stephen Roberts
6# October 2006
7##########
8
9# Import the realtime visualiser
10from anuga.visualiser import RealtimeVisualiser
11from vtk import vtkCubeAxesActor2D
12
13import time
14from Numeric import array
15from anuga.shallow_water import Domain
16from anuga.shallow_water import Reflective_boundary
17from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
18
19
20class Set_Stage:
21    """Set an initial condition with constant water height, for x<x0
22    """
23
24    def __init__(self, x0=0.25, x1=0.75, y0=0.0, y1=1.0, h=5.0, h0=0.0):
25        self.x0 = x0
26        self.x1 = x1
27        self.y0 = y0
28        self.y1 = y1
29        self.= h
30        self.h0 = h0
31
32    def __call__(self, x, y):
33        return self.h0 + self.h*((x>self.x0)&(x<self.x1)&(y>self.y0)&(y<self.y1))
34
35M = 20
36points, vertices, boundary = rectangular(M, M, len1 = 1.0, len2 = 1.0)
37
38yieldstep = 0.002
39finaltime = 0.8
40rect = [0.0, 0.0, 1.0, 1.0]
41
42domain = Domain(points, vertices, boundary)
43
44# Turn on the visualisation. The argument to the realtime visualier
45# is a domain object.
46v = RealtimeVisualiser(domain)
47
48# Specify the height-based-quantities to render.
49# Remember to set dynamic=True for time-varying quantities
50v.render_quantity_height("elevation", dynamic=False)
51# Make the stage semitransparent
52v.render_quantity_height("stage", opacity=0.5, dynamic=True)
53
54# Colour the stage:
55# Either with an RGB value as a 3-tuple of Floats,
56#v.colour_height_quantity('stage', (0.0, 0.0, 0.8))
57# Or with a function of the quantities at that point, such as the stage height:
58# 0 and 1 are the minimum and maximum values of the stage.
59v.colour_height_quantity('stage', (lambda q:q['stage'], 0, 1))
60# Or with the magnitude of the momentum at that point:
61# Needs the sqrt function from Numeric. Again, 0 and 10 define the colour range.
62#v.colour_height_quantity('stage', (lambda q:sqrt((q['xmomentum'] ** 2) +
63#                                                 (q['ymomentum'] ** 2)), 0, 10))
64
65# Draw some axes on the visualiser so we can see how big the wave is
66v.render_axes()
67
68# Increase the number of labels on the axes
69v.alter_axes(vtkCubeAxesActor2D.SetNumberOfLabels, (5,))
70
71# Draw a yellow polygon at height 2
72v.overlay_polygon([(0, 0), (0, 0.1), (0.1, 0)], 2, colour=(1.0, 1.0, 0.0))
73
74# Start the visualiser (in its own thread).
75v.start()
76
77#-----------------------------------------------------------------
78# Boundaries and Initial conditions
79#-----------------------------------------------------------------
80R = Reflective_boundary(domain)
81domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
82domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 2.0, 0.00))
83
84#-----------------------------------------------------------------
85# Evolve
86#-----------------------------------------------------------------
87t0 = time.time()
88for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
89    v.update()
90    domain.write_time()
91# Unhook the visualiser from the evolve loop.
92# It won't shutdown cleanly unless you do this.
93v.evolveFinished()
94
95print 'That took %.2f seconds' %(time.time()-t0)
96
97# Wait for the visualiser to be closed
98v.join()
Note: See TracBrowser for help on using the repository browser.