[2207] | 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) |
---|
[2334] | 38 | self.visualiser.coloring['stage'] = False |
---|
| 39 | self.visualiser.coloring['elevation'] = False |
---|
[2207] | 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 |
---|
[2334] | 46 | |
---|
[2207] | 47 | |
---|
| 48 | |
---|
| 49 | |
---|
[2778] | 50 | def evolve(self, |
---|
| 51 | yieldstep = None, |
---|
| 52 | finaltime = None, |
---|
| 53 | duration = None, |
---|
[2207] | 54 | skip_initial_step = False): |
---|
| 55 | """Specialisation of basic evolve method from parent class |
---|
| 56 | """ |
---|
| 57 | |
---|
| 58 | import time |
---|
| 59 | first = True |
---|
| 60 | #Call check integrity here rather than from user scripts |
---|
| 61 | #self.check_integrity() |
---|
| 62 | |
---|
| 63 | msg = 'Parameter beta_h must be in the interval [0, 1[' |
---|
| 64 | assert 0 <= self.beta_h < 1.0, msg |
---|
| 65 | msg = 'Parameter beta_w must be in the interval [0, 1[' |
---|
| 66 | assert 0 <= self.beta_w < 1.0, msg |
---|
| 67 | |
---|
| 68 | self.distribute_to_vertices_and_edges() |
---|
| 69 | |
---|
| 70 | #Initialise real time viz if requested |
---|
| 71 | if self.visualise is True and self.time == 0.0 and self.visualiser is None: |
---|
| 72 | self.initialise_visualiser() |
---|
| 73 | #self.visualiser.update_timer() |
---|
| 74 | print "Warning: Enabling the visualiser with domain.visualise is not" |
---|
| 75 | print "recommended. Controlling the visualiser manually allows for much better" |
---|
| 76 | print "control over visualiser parameters." |
---|
| 77 | |
---|
| 78 | if self.visualise is True: |
---|
| 79 | self.visualiser.start() |
---|
[2212] | 80 | # Things go haywire if we start evolving before the vis is ready |
---|
| 81 | self.visualiser.idle.wait() |
---|
| 82 | self.visualiser.idle.clear() |
---|
[2207] | 83 | |
---|
| 84 | #Store model data, e.g. for visualisation |
---|
| 85 | if self.store is True and self.time == 0.0: |
---|
| 86 | self.initialise_storage() |
---|
| 87 | #print 'Storing results in ' + self.writer.filename |
---|
| 88 | else: |
---|
| 89 | pass |
---|
| 90 | |
---|
| 91 | #Call basic machinery from parent class |
---|
[2778] | 92 | for t in Generic_Domain.evolve(self, |
---|
| 93 | yieldstep=yieldstep, |
---|
| 94 | finaltime = finaltime, |
---|
| 95 | duration = duration, |
---|
| 96 | skip_initial_step = skip_initial_step): |
---|
[2207] | 97 | #Real time viz |
---|
| 98 | if self.visualise is True: |
---|
[2212] | 99 | self.visualiser.redraw_ready.set() |
---|
| 100 | self.visualiser.idle.wait() |
---|
| 101 | self.visualiser.idle.clear() |
---|
[2268] | 102 | self.visualiser.unpaused.wait() |
---|
[2207] | 103 | |
---|
| 104 | #Store model data, e.g. for subsequent visualisation |
---|
| 105 | if self.store is True: |
---|
| 106 | self.store_timestep(self.quantities_to_be_stored) |
---|
| 107 | |
---|
| 108 | #FIXME: Could maybe be taken from specified list |
---|
| 109 | #of 'store every step' quantities |
---|
| 110 | |
---|
| 111 | #Pass control on to outer loop for more specific actions |
---|
| 112 | yield(t) |
---|
| 113 | |
---|
| 114 | #==================================== End of Updated Shallow Water VTK domain ============= |
---|
| 115 | if __name__ == "__main__": |
---|
| 116 | pass |
---|
| 117 | |
---|
| 118 | # Profiling stuff |
---|
| 119 | import profile |
---|
| 120 | profiler = profile.Profile() |
---|