source: anuga_core/source/anuga/examples/run_sw_rectangle.py @ 3740

Last change on this file since 3740 was 3697, checked in by ole, 18 years ago

Played with limiter example: run_sw_rectangle.py

File size: 5.5 KB
Line 
1#!/usr/bin/env python
2"""
3  Example showing improved wet dry limiting.
4  This script runs the same simulation twice and stores the outputs in
5  old_limiter.sww and new_limiter.sww respectively.
6 
7  Authors: Steve Roberts
8  October
9"""
10
11#-----------------------------------------------------------------
12# Common structures
13#-----------------------------------------------------------------
14import time
15from Numeric import array
16from anuga.shallow_water import Domain
17from anuga.shallow_water import Reflective_boundary
18from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular
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 = 30
36points, vertices, boundary = rectangular(M, M, len1 = 1.0, len2 = 1.0)
37
38yieldstep = 0.002
39finaltime = 0.06
40rect = [0.0, 0.0, 1.0, 1.0]
41
42
43#-----------------------------------------------------------------
44# Create domain for "old limiter" scenario
45#-----------------------------------------------------------------
46domain = Domain(points, vertices, boundary)
47domain.set_name('old_limiter_second_order')
48print 'Number of triangles =', len(domain)
49
50# Turn on the visualisation
51try:
52    domain.initialise_visualiser()
53except:
54    pass
55
56
57#-----------------------------------------------------------------
58# Boundaries and Initial conditions
59#-----------------------------------------------------------------
60R = Reflective_boundary(domain)
61domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
62domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00))
63
64#-----------------------------------------------------------------
65# Values for old limiter
66#-----------------------------------------------------------------
67domain.default_order = 2
68domain.beta_w      = 0.9
69domain.beta_w_dry  = 0.9
70domain.beta_uh     = 0.9
71domain.beta_uh_dry = 0.9
72domain.beta_vh     = 0.9
73domain.beta_vh_dry = 0.9
74
75#-----------------------------------------------------------------
76# Evolve
77#-----------------------------------------------------------------
78t0 = time.time()
79for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
80    domain.write_time()
81
82print 'That took %.2f seconds' %(time.time()-t0)
83print 'Note the small timesteps and the irregular flow'
84#raw_input('press return to continue')
85
86
87#-----------------------------------------------------------------
88# Create domain for "new limiter" scenario (2 order)
89#-----------------------------------------------------------------
90domain = Domain(points, vertices, boundary)
91domain.set_name('new_limiter_second_order')
92print 'Number of triangles =', len(domain)
93
94# Turn on the visualisation
95try:
96    domain.initialise_visualiser()
97except:
98    pass
99
100#-----------------------------------------------------------------
101# Boundaries and Initial conditions
102#-----------------------------------------------------------------
103R = Reflective_boundary(domain)
104domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
105domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00))
106
107#-----------------------------------------------------------------
108# Values for new limiter
109#-----------------------------------------------------------------
110domain.set_default_order(2)
111domain.minimum_allowed_height = 0.001
112domain.beta_w      = 1.0
113domain.beta_w_dry  = 0.2
114domain.beta_uh     = 1.0
115domain.beta_uh_dry = 0.2
116domain.beta_vh     = 1.0
117domain.beta_vh_dry = 0.2
118
119#-----------------------------------------------------------------
120# Evolve
121#-----------------------------------------------------------------
122t0 = time.time()
123for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
124    domain.write_time()
125
126print 'That took %.2f seconds' %(time.time()-t0)
127print 'Note more uniform and large timesteps'
128#raw_input('press return to continue')
129
130
131#-----------------------------------------------------------------
132# Create domain for "new limiter" scenario (1 order)
133#-----------------------------------------------------------------
134domain = Domain(points, vertices, boundary)
135domain.set_name('new_limiter_first_order')
136print 'Number of triangles =', len(domain)
137
138# Turn on the visualisation
139try:
140    domain.initialise_visualiser()
141except:
142    pass
143
144#-----------------------------------------------------------------
145# Boundaries and Initial conditions
146#-----------------------------------------------------------------
147R = Reflective_boundary(domain)
148domain.set_boundary( {'left': R, 'right': R, 'bottom': R, 'top': R} )
149domain.set_quantity('stage', Set_Stage(0.2, 0.4, 0.25, 0.75, 1.0, 0.00))
150
151#-----------------------------------------------------------------
152# Values for new limiter first order
153#-----------------------------------------------------------------
154domain.set_default_order(1)
155domain.minimum_allowed_height = 0.001
156domain.beta_w      = 1.0
157domain.beta_w_dry  = 0.2
158domain.beta_uh     = 1.0
159domain.beta_uh_dry = 0.2
160domain.beta_vh     = 1.0
161domain.beta_vh_dry = 0.2
162
163#-----------------------------------------------------------------
164# Evolve
165#-----------------------------------------------------------------
166t0 = time.time()
167for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
168    domain.write_time()
169
170print 'That took %.2f seconds' %(time.time()-t0)
171
172
Note: See TracBrowser for help on using the repository browser.