source: anuga_core/source/anuga/examples/visualise_rectangle.py @ 3958

Last change on this file since 3958 was 3958, checked in by jack, 17 years ago

Updated the visualisers to work with the new general_mesh structure.

File size: 3.1 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 offline 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)
51v.render_quantity_height("stage", dynamic=True)
52
53# Colour the stage:
54# Either with an RGB value as a 3-tuple of Floats,
55#v.colour_height_quantity('stage', (0.0, 0.0, 0.8))
56# Or with a function of the quantities at that point, such as the stage height:
57# 0 and 1 are the minimum and maximum values of the stage.
58v.colour_height_quantity('stage', (lambda q:q['stage'], 0, 1))
59# Or with the magnitude of the momentum at that point:
60# Needs the sqrt function from Numeric. Again, 0 and 10 define the colour range.
61#v.colour_height_quantity('stage', (lambda q:sqrt((q['xmomentum'] ** 2) +
62#                                                 (q['ymomentum'] ** 2)), 0, 10))
63
64# Draw some axes on the visualiser so we can see how big the wave is
65v.render_axes()
66
67# Increase the number of labels on the axes
68v.alter_axes(vtkCubeAxesActor2D.SetNumberOfLabels, (5,))
69
70# Draw a yellow polygon at height 2
71v.overlay_polygon([(0, 0), (0, 0.1), (0.1, 0)], 2, colour=(1.0, 1.0, 0.0))
72
73# Start the visualiser (in its own thread).
74v.start()
75
76#-----------------------------------------------------------------
77# Boundaries and Initial conditions
78#-----------------------------------------------------------------
79R = Reflective_boundary(domain)
80domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
81domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 2.0, 0.00))
82
83#-----------------------------------------------------------------
84# Evolve
85#-----------------------------------------------------------------
86t0 = time.time()
87for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
88    v.update()
89    domain.write_time()
90# Unhook the visualiser from the evolve loop.
91# It won't shutdown cleanly unless you do this.
92v.evolveFinished()
93
94print 'That took %.2f seconds' %(time.time()-t0)
95
96# Wait for the visualiser to be closed
97v.join()
Note: See TracBrowser for help on using the repository browser.