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