1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Will Powers example of a simple sinusoidal wave which showed diffusive effects of |
---|
4 | thefirst order and standard second order method. Problem resolved if "rk2" timestepping |
---|
5 | and higher beta = 2 limiter used. Also new edge limiter with rk2 resolves problem |
---|
6 | """ |
---|
7 | |
---|
8 | #------------------------------------------------------------------------------ |
---|
9 | # Import necessary modules |
---|
10 | #------------------------------------------------------------------------------ |
---|
11 | |
---|
12 | import sys |
---|
13 | import anuga |
---|
14 | #from anuga import Domain |
---|
15 | from swb_domain import * |
---|
16 | |
---|
17 | from math import cos |
---|
18 | import numpy as num |
---|
19 | from time import localtime, strftime, gmtime |
---|
20 | from os import sep |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | #------------------------------------------------------------------------------- |
---|
25 | # Copy scripts to time stamped output directory and capture screen |
---|
26 | # output to file |
---|
27 | #------------------------------------------------------------------------------- |
---|
28 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
29 | |
---|
30 | #output_dir = 'step_'+time |
---|
31 | output_dir = '.' |
---|
32 | output_file = 'data_step_'+time |
---|
33 | |
---|
34 | #copy_code_files(output_dir,__file__) |
---|
35 | #start_screen_catcher(output_dir+sep) |
---|
36 | |
---|
37 | interactive_visualisation = True |
---|
38 | |
---|
39 | #------------------------------------------------------------------------------ |
---|
40 | # Setup domain |
---|
41 | #------------------------------------------------------------------------------ |
---|
42 | dx = 1000. |
---|
43 | dy = dx |
---|
44 | L = 100000. |
---|
45 | W = 10*dx |
---|
46 | |
---|
47 | # structured mesh |
---|
48 | points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
49 | |
---|
50 | |
---|
51 | #anuga.create_mesh_from_regions(bounding_polygon, |
---|
52 | # boundary_tags, |
---|
53 | # maximum_triangle_area=maximum_triangle_area, |
---|
54 | # interior_regions=interior_regions, |
---|
55 | # filename=mesh_filename, |
---|
56 | # interior_holes=interior_holes, |
---|
57 | # hole_tags=hole_tags, |
---|
58 | # poly_geo_reference=poly_geo_reference, |
---|
59 | # mesh_geo_reference=mesh_geo_reference, |
---|
60 | # minimum_triangle_angle=minimum_triangle_angle, |
---|
61 | # fail_if_polygons_outside=fail_if_polygons_outside, |
---|
62 | # use_cache=False, |
---|
63 | # verbose=verbose) |
---|
64 | |
---|
65 | domain = Domain(points, vertices, boundary) |
---|
66 | |
---|
67 | domain.set_name(output_file) |
---|
68 | domain.set_datadir(output_dir) |
---|
69 | |
---|
70 | #------------------------------------------------------------------------------ |
---|
71 | # Setup Algorithm |
---|
72 | #------------------------------------------------------------------------------ |
---|
73 | domain.set_timestepping_method('rk2') |
---|
74 | domain.set_default_order(2) |
---|
75 | |
---|
76 | print domain.get_timestepping_method() |
---|
77 | |
---|
78 | #domain.use_edge_limiter = True |
---|
79 | #domain.tight_slope_limiters = False |
---|
80 | #domain.use_centroid_velocities = False |
---|
81 | |
---|
82 | |
---|
83 | #------------------------------------------------------------------------------ |
---|
84 | # Setup initial conditions |
---|
85 | #------------------------------------------------------------------------------ |
---|
86 | domain.set_quantity('elevation',-100.0) |
---|
87 | domain.set_quantity('friction', 0.00) |
---|
88 | domain.set_quantity('stage', 0.0) |
---|
89 | |
---|
90 | def stage(x,y): |
---|
91 | z = num.zeros_like(x) |
---|
92 | num.putmask(z, (2*L/5 < x) * (x < 3*L/5) , 1.0) |
---|
93 | return z |
---|
94 | |
---|
95 | domain.set_quantity('stage', stage ) |
---|
96 | |
---|
97 | #----------------------------------------------------------------------------- |
---|
98 | # Setup boundary conditions |
---|
99 | #------------------------------------------------------------------------------ |
---|
100 | from math import sin, pi, exp |
---|
101 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
102 | Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary |
---|
103 | Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
104 | amplitude = 1 |
---|
105 | Bw = anuga.Time_boundary(domain=domain, # Time dependent boundary |
---|
106 | ## Sine wave |
---|
107 | f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0]) |
---|
108 | ## Sawtooth? |
---|
109 | # f=lambda t: [(-8.0*(sin((1./180.)*t*2*pi))+(1./2.)*sin((2./180.)*t*2*pi)+(1./3.)*sin((3./180.)*t*2*pi)), 0.0, 0.0]) |
---|
110 | ## Sharp rise, linear fall |
---|
111 | # f=lambda t: [(5.0*(-((t-0.)/300.)*(t<300.)-cos((t-300.)*2.*pi*(1./240.))*(t>=300. and t<420.)+(1.-(t-420.)/300.)*(t>=420. and t <720.))), 0.0, 0.0]) |
---|
112 | # f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0]) |
---|
113 | # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) |
---|
114 | |
---|
115 | # Associate boundary tags with boundary objects |
---|
116 | domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
117 | |
---|
118 | |
---|
119 | #=============================================================================== |
---|
120 | if interactive_visualisation: |
---|
121 | from anuga.visualiser import RealtimeVisualiser |
---|
122 | vis = RealtimeVisualiser(domain) |
---|
123 | vis.render_quantity_height("stage", zScale =10000, dynamic=True) |
---|
124 | vis.colour_height_quantity('stage', (1.0, 0.5, 0.5)) |
---|
125 | vis.start() |
---|
126 | #=============================================================================== |
---|
127 | |
---|
128 | |
---|
129 | #------------------------------------------------------------------------------ |
---|
130 | # Evolve system through time |
---|
131 | #------------------------------------------------------------------------------ |
---|
132 | |
---|
133 | for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.): |
---|
134 | domain.write_time() |
---|
135 | if interactive_visualisation: |
---|
136 | vis.update() |
---|
137 | |
---|
138 | if interactive_visualisation: |
---|
139 | vis.evolveFinished() |
---|
140 | |
---|