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 | from anuga import rectangular_cross |
---|
14 | from anuga import Domain |
---|
15 | from anuga import Reflective_boundary |
---|
16 | from anuga import Dirichlet_boundary |
---|
17 | from anuga import Time_boundary |
---|
18 | from anuga import Transmissive_boundary |
---|
19 | from anuga import Transmissive_momentum_set_stage_boundary |
---|
20 | #from anuga.data_manager import start_screen_catcher, copy_code_files |
---|
21 | |
---|
22 | from math import cos |
---|
23 | import numpy as num |
---|
24 | from time import localtime, strftime, gmtime |
---|
25 | from os import sep |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | #------------------------------------------------------------------------------- |
---|
30 | # Copy scripts to time stamped output directory and capture screen |
---|
31 | # output to file |
---|
32 | #------------------------------------------------------------------------------- |
---|
33 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
34 | |
---|
35 | output_dir = 'wave_'+time |
---|
36 | output_file = 'wave' |
---|
37 | |
---|
38 | #copy_code_files(output_dir,__file__) |
---|
39 | #start_screen_catcher(output_dir+sep) |
---|
40 | |
---|
41 | interactive_visualisation = True |
---|
42 | |
---|
43 | #------------------------------------------------------------------------------ |
---|
44 | # Setup domain |
---|
45 | #------------------------------------------------------------------------------ |
---|
46 | dx = 1000. |
---|
47 | dy = dx |
---|
48 | L = 100000. |
---|
49 | W = 10*dx |
---|
50 | |
---|
51 | # structured mesh |
---|
52 | points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
53 | |
---|
54 | domain = Domain(points, vertices, boundary) |
---|
55 | |
---|
56 | domain.set_name(output_file) |
---|
57 | domain.set_datadir(output_dir) |
---|
58 | |
---|
59 | #------------------------------------------------------------------------------ |
---|
60 | # Setup Algorithm |
---|
61 | #------------------------------------------------------------------------------ |
---|
62 | |
---|
63 | domain.set_timestepping_method(2) |
---|
64 | domain.set_default_order(2) |
---|
65 | |
---|
66 | print domain.get_timestepping_method() |
---|
67 | |
---|
68 | #domain.use_edge_limiter = True |
---|
69 | #domain.tight_slope_limiters = False |
---|
70 | #domain.use_centroid_velocities = False |
---|
71 | |
---|
72 | domain.set_beta(1.9) |
---|
73 | |
---|
74 | domain.CFL = 1.0 |
---|
75 | |
---|
76 | #domain.beta_w = 1.0 |
---|
77 | #domain.beta_w_dry = 0.0 |
---|
78 | #domain.beta_uh = 1.0 |
---|
79 | #domain.beta_uh_dry = 0.0 |
---|
80 | #domain.beta_vh = 1.0 |
---|
81 | #domain.beta_vh_dry = 0.0 |
---|
82 | |
---|
83 | |
---|
84 | #------------------------------------------------------------------------------ |
---|
85 | # Setup initial conditions |
---|
86 | #------------------------------------------------------------------------------ |
---|
87 | domain.set_quantity('elevation',-100.0) |
---|
88 | domain.set_quantity('friction', 0.00) |
---|
89 | domain.set_quantity('stage', 0.0) |
---|
90 | |
---|
91 | #----------------------------------------------------------------------------- |
---|
92 | # Setup boundary conditions |
---|
93 | #------------------------------------------------------------------------------ |
---|
94 | from math import sin, pi, exp |
---|
95 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
96 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
97 | Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
98 | amplitude = 1 |
---|
99 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
100 | ## Sine wave |
---|
101 | f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0]) |
---|
102 | ## Sawtooth? |
---|
103 | # 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]) |
---|
104 | ## Sharp rise, linear fall |
---|
105 | # 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]) |
---|
106 | # f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0]) |
---|
107 | # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) |
---|
108 | |
---|
109 | # Associate boundary tags with boundary objects |
---|
110 | domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
111 | |
---|
112 | |
---|
113 | #=============================================================================== |
---|
114 | if interactive_visualisation: |
---|
115 | from anuga.visualiser import RealtimeVisualiser |
---|
116 | vis = RealtimeVisualiser(domain) |
---|
117 | vis.render_quantity_height("stage", zScale =10000, dynamic=True) |
---|
118 | vis.colour_height_quantity('stage', (1.0, 0.5, 0.5)) |
---|
119 | vis.start() |
---|
120 | #=============================================================================== |
---|
121 | |
---|
122 | |
---|
123 | #------------------------------------------------------------------------------ |
---|
124 | # Evolve system through time |
---|
125 | #------------------------------------------------------------------------------ |
---|
126 | |
---|
127 | for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.): |
---|
128 | domain.write_time() |
---|
129 | if interactive_visualisation: |
---|
130 | vis.update() |
---|
131 | |
---|
132 | if interactive_visualisation: |
---|
133 | vis.evolveFinished() |
---|
134 | |
---|