1 | """Simple water flow example using ANUGA |
---|
2 | |
---|
3 | Water driven up a linear slope and time varying boundary, |
---|
4 | similar to a beach environment |
---|
5 | """ |
---|
6 | |
---|
7 | #------------------------------------------------------------------------------ |
---|
8 | # Import necessary modules |
---|
9 | #------------------------------------------------------------------------------ |
---|
10 | |
---|
11 | import sys |
---|
12 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
13 | from anuga.shallow_water import Domain |
---|
14 | from anuga.shallow_water import Reflective_boundary |
---|
15 | from anuga.shallow_water import Dirichlet_boundary |
---|
16 | from anuga.shallow_water import Time_boundary |
---|
17 | from anuga.shallow_water import Transmissive_boundary |
---|
18 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
19 | from anuga.geospatial_data.geospatial_data import * |
---|
20 | from math import cos |
---|
21 | |
---|
22 | #------------------------------------------------------------------------------ |
---|
23 | # Setup computational domain |
---|
24 | #------------------------------------------------------------------------------ |
---|
25 | dx = 100. |
---|
26 | dy = dx |
---|
27 | L = 100000. |
---|
28 | W = dx |
---|
29 | |
---|
30 | # structured mesh |
---|
31 | points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), |
---|
32 | L, W, (0.0, -W/2)) # Basic mesh |
---|
33 | #points, vertices, boundary = rectangular_cross(666, 3, 100000, 3000, (0.0, -0.0)) # Basic mesh |
---|
34 | #points, vertices, boundary = rectangular_cross(530, 10, 5300, 100, (-5000.0, -50.0)) # Basic mesh |
---|
35 | #points, vertices, boundary = rectangular_cross(1000, 100, 20, 3) # Basic mesh |
---|
36 | domain = Domain(points, vertices, boundary) |
---|
37 | |
---|
38 | |
---|
39 | ## # unstructured mesh |
---|
40 | ## poly_domain = [[0,-W],[0,W],[L,W],[L,-W]] |
---|
41 | ## meshname = 'test.msh' |
---|
42 | ## from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
43 | ## # Create mesh |
---|
44 | ## create_mesh_from_regions(poly_domain, |
---|
45 | ## boundary_tags={'left': [0], 'top': [1], |
---|
46 | ## 'right': [2], 'bottom': [3]}, |
---|
47 | ## maximum_triangle_area = 1000, |
---|
48 | ## filename=meshname) |
---|
49 | |
---|
50 | ## # Create domain |
---|
51 | ## domain = Domain(meshname, use_cache=True, verbose = True) |
---|
52 | |
---|
53 | domain.set_timestepping_method('euler') |
---|
54 | domain.set_default_order(2) |
---|
55 | domain.set_name('myexample9') |
---|
56 | domain.set_datadir('.') # Use current directory for output |
---|
57 | |
---|
58 | domain.beta_w = 100.0 |
---|
59 | domain.beta_w_dry = 0.2 |
---|
60 | domain.beta_uh = 100.0 |
---|
61 | domain.beta_uh_dry = 0.2 |
---|
62 | domain.beta_vh = 100.0 |
---|
63 | domain.beta_vh_dry = 0.2 |
---|
64 | domain.beta_h = 100.0 |
---|
65 | |
---|
66 | #------------------------------------------------------------------------------ |
---|
67 | # Setup initial conditions |
---|
68 | #------------------------------------------------------------------------------ |
---|
69 | #domain.set_quantity('elevation', topography) # Use function for elevation |
---|
70 | domain.set_quantity('elevation',-100) |
---|
71 | domain.set_quantity('friction', 0.00) |
---|
72 | domain.set_quantity('stage', 0.0) |
---|
73 | |
---|
74 | #----------------------------------------------------------------------------- |
---|
75 | # Setup boundary conditions |
---|
76 | #------------------------------------------------------------------------------ |
---|
77 | from math import sin, pi, exp |
---|
78 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
79 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
80 | Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
81 | amplitude = 1 |
---|
82 | #Bw = Transmissive_Momentum_Set_Stage_boundary(domain=domain, |
---|
83 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
84 | ## Sine wave |
---|
85 | f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0]) |
---|
86 | ## Sawtooth? |
---|
87 | # 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]) |
---|
88 | ## Sharp rise, linear fall |
---|
89 | # 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]) |
---|
90 | # f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0]) |
---|
91 | # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) |
---|
92 | |
---|
93 | # Associate boundary tags with boundary objects |
---|
94 | domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
95 | |
---|
96 | ## from anuga.visualiser import RealtimeVisualiser |
---|
97 | ## vis = RealtimeVisualiser(domain) |
---|
98 | ## vis.render_quantity_height("elevation", dynamic=False) |
---|
99 | ## vis.render_quantity_height("stage", dynamic=True, zScale=100.0) |
---|
100 | ## #vis.colour_height_quantity('stage', (0.0, 0.0, 0.8)) |
---|
101 | ## vis.colour_height_quantity('stage', (lambda q:q['stage'], -1, 1)) |
---|
102 | ## vis.start() |
---|
103 | |
---|
104 | #------------------------------------------------------------------------------ |
---|
105 | # Evolve system through time |
---|
106 | #------------------------------------------------------------------------------ |
---|
107 | |
---|
108 | for t in domain.evolve(yieldstep = 20.0, finaltime = 40*60.): |
---|
109 | domain.write_time() |
---|
110 | #vis.update() |
---|
111 | |
---|
112 | #vis.evolveFinished() |
---|
113 | #vis.join() |
---|