1 | """ |
---|
2 | Shallow water domain with VTK viewer. We are just over |
---|
3 | |
---|
4 | Ole Nielsen, Duncan Gray |
---|
5 | Geoscience Australia, 2006 |
---|
6 | |
---|
7 | Stephen Roberts, Jack Kelly |
---|
8 | ANU 2006 |
---|
9 | """ |
---|
10 | |
---|
11 | #Subversion keywords: |
---|
12 | # |
---|
13 | #$LastChangedDate: 2006-01-13 12:33:38 +1100 (Fri, 13 Jan 2006) $ |
---|
14 | #$LastChangedRevision: 2205 $ |
---|
15 | #$LastChangedBy: steve $ |
---|
16 | |
---|
17 | |
---|
18 | from shallow_water import * |
---|
19 | Shallow_Water_Domain = Domain #Rename |
---|
20 | |
---|
21 | #Shallow water domain with VTK viewer |
---|
22 | class Domain(Shallow_Water_Domain): |
---|
23 | |
---|
24 | def __init__(self, coordinates, vertices, boundary = None, |
---|
25 | tagged_elements = None, geo_reference = None, |
---|
26 | use_inscribed_circle=False): |
---|
27 | |
---|
28 | Shallow_Water_Domain.__init__(self, coordinates, vertices, boundary, |
---|
29 | tagged_elements, geo_reference, use_inscribed_circle) |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | def initialise_visualiser(self,scale_z=1.0,rect=None): |
---|
34 | #Realtime visualisation |
---|
35 | if self.visualiser is None: |
---|
36 | from vtk_realtime_visualiser import Visualiser |
---|
37 | self.visualiser = Visualiser(self,scale_z,rect) |
---|
38 | self.visualiser.coloring['stage'] = False |
---|
39 | self.visualiser.coloring['elevation'] = False |
---|
40 | self.visualiser.setup['elevation']=True |
---|
41 | self.visualiser.updating['stage']=True |
---|
42 | self.visualiser.qcolor['stage'] = (0.1,0.4,0.99) |
---|
43 | self.visualise = True |
---|
44 | if self.visualise_color_stage == True: |
---|
45 | self.visualiser.coloring['stage'] = True |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | def evolve(self, yieldstep = None, finaltime = None, |
---|
51 | skip_initial_step = False): |
---|
52 | """Specialisation of basic evolve method from parent class |
---|
53 | """ |
---|
54 | |
---|
55 | import time |
---|
56 | first = True |
---|
57 | #Call check integrity here rather than from user scripts |
---|
58 | #self.check_integrity() |
---|
59 | |
---|
60 | msg = 'Parameter beta_h must be in the interval [0, 1[' |
---|
61 | assert 0 <= self.beta_h < 1.0, msg |
---|
62 | msg = 'Parameter beta_w must be in the interval [0, 1[' |
---|
63 | assert 0 <= self.beta_w < 1.0, msg |
---|
64 | |
---|
65 | self.distribute_to_vertices_and_edges() |
---|
66 | |
---|
67 | #Initialise real time viz if requested |
---|
68 | if self.visualise is True and self.time == 0.0 and self.visualiser is None: |
---|
69 | self.initialise_visualiser() |
---|
70 | #self.visualiser.update_timer() |
---|
71 | print "Warning: Enabling the visualiser with domain.visualise is not" |
---|
72 | print "recommended. Controlling the visualiser manually allows for much better" |
---|
73 | print "control over visualiser parameters." |
---|
74 | |
---|
75 | if self.visualise is True: |
---|
76 | self.visualiser.start() |
---|
77 | # Things go haywire if we start evolving before the vis is ready |
---|
78 | self.visualiser.idle.wait() |
---|
79 | self.visualiser.idle.clear() |
---|
80 | |
---|
81 | #Store model data, e.g. for visualisation |
---|
82 | if self.store is True and self.time == 0.0: |
---|
83 | self.initialise_storage() |
---|
84 | #print 'Storing results in ' + self.writer.filename |
---|
85 | else: |
---|
86 | pass |
---|
87 | |
---|
88 | #Call basic machinery from parent class |
---|
89 | for t in Generic_Domain.evolve(self, yieldstep, finaltime, |
---|
90 | skip_initial_step): |
---|
91 | #Real time viz |
---|
92 | if self.visualise is True: |
---|
93 | self.visualiser.redraw_ready.set() |
---|
94 | self.visualiser.idle.wait() |
---|
95 | self.visualiser.idle.clear() |
---|
96 | self.visualiser.unpaused.wait() |
---|
97 | |
---|
98 | #Store model data, e.g. for subsequent visualisation |
---|
99 | if self.store is True: |
---|
100 | self.store_timestep(self.quantities_to_be_stored) |
---|
101 | |
---|
102 | #FIXME: Could maybe be taken from specified list |
---|
103 | #of 'store every step' quantities |
---|
104 | |
---|
105 | #Pass control on to outer loop for more specific actions |
---|
106 | yield(t) |
---|
107 | |
---|
108 | #==================================== End of Updated Shallow Water VTK domain ============= |
---|
109 | if __name__ == "__main__": |
---|
110 | pass |
---|
111 | |
---|
112 | # Profiling stuff |
---|
113 | import profile |
---|
114 | profiler = profile.Profile() |
---|