1 | """Example of the inundationmodel. |
---|
2 | |
---|
3 | A wave of water is washed up ontp a hypothetical beach. |
---|
4 | |
---|
5 | To run: |
---|
6 | |
---|
7 | python beach.py |
---|
8 | """ |
---|
9 | |
---|
10 | ###################### |
---|
11 | # Module imports |
---|
12 | # |
---|
13 | |
---|
14 | import sys |
---|
15 | from os import sep, path |
---|
16 | sys.path.append('..'+sep+'pyvolution') |
---|
17 | |
---|
18 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
19 | Transmissive_boundary, Time_boundary, Constant_height, Weir |
---|
20 | |
---|
21 | from pmesh2domain import pmesh_to_domain_instance |
---|
22 | from config import data_dir |
---|
23 | |
---|
24 | ###################### |
---|
25 | # Domain |
---|
26 | name = 'beach' |
---|
27 | print 'Creating domain from %s.tsh' %name |
---|
28 | domain = pmesh_to_domain_instance(name + '.tsh', Domain) |
---|
29 | |
---|
30 | #HACK to remove internal boundary (until we get a solution) |
---|
31 | for b in domain.boundary.keys(): |
---|
32 | if domain.boundary[b] == 'internal': |
---|
33 | del domain.boundary[b] |
---|
34 | |
---|
35 | domain = Domain(domain.coordinates, domain.triangles, domain.boundary) |
---|
36 | print "Number of triangles = ", len(domain) |
---|
37 | |
---|
38 | domain.store = True |
---|
39 | domain.set_name(name) |
---|
40 | print "Output being written to " + data_dir + sep + \ |
---|
41 | domain.filename + "." + domain.format |
---|
42 | |
---|
43 | |
---|
44 | def x_slope(x, y): |
---|
45 | from Numeric import choose, greater, ones |
---|
46 | cut = 65 |
---|
47 | |
---|
48 | return choose( greater(x, cut), (-x/3, -cut/3*ones(x.shape) )) + cut/3 - 5 |
---|
49 | |
---|
50 | |
---|
51 | def inside(p,polygon): |
---|
52 | return True |
---|
53 | |
---|
54 | def friction(x, y): |
---|
55 | """Read friction from polygon file and set accordingly |
---|
56 | """ |
---|
57 | |
---|
58 | from Numeric import array |
---|
59 | x = array(x).astype('f') |
---|
60 | y = array(y).astype('f') |
---|
61 | |
---|
62 | #Get polygon |
---|
63 | fid = open('beach.poly') |
---|
64 | lines = fid.readlines() |
---|
65 | fid.close() |
---|
66 | polygon = [] |
---|
67 | for line in lines: |
---|
68 | fields = line.split(',') |
---|
69 | polygon.append( [float(fields[0]), float(fields[1])] ) |
---|
70 | |
---|
71 | print polygon |
---|
72 | |
---|
73 | z = 0*x |
---|
74 | for i in range(len(x)): |
---|
75 | if inside( (x[i], y[i]), polygon): |
---|
76 | z[i] = 1 |
---|
77 | else: |
---|
78 | z[i] = 0 |
---|
79 | |
---|
80 | friction([0],[1]) |
---|
81 | |
---|
82 | domain.set_quantity('elevation', x_slope) |
---|
83 | domain.set_quantity('level', x_slope) |
---|
84 | domain.set_quantity('friction', 0.07) |
---|
85 | |
---|
86 | print domain.get_extent() |
---|
87 | import sys; sys.exit() |
---|
88 | |
---|
89 | ###################### |
---|
90 | # Boundary conditions |
---|
91 | |
---|
92 | print 'Boundaries' |
---|
93 | Br = Reflective_boundary(domain) |
---|
94 | Bt = Transmissive_boundary(domain) |
---|
95 | |
---|
96 | #Constant inflow |
---|
97 | Bd = Dirichlet_boundary([0.0, -1.0, 0.0]) |
---|
98 | |
---|
99 | print 'Available boundary tags are', domain.get_boundary_tags() |
---|
100 | |
---|
101 | #Set boundary conditions |
---|
102 | tags = {} |
---|
103 | tags['ocean'] = Bd |
---|
104 | tags['wall'] = Br |
---|
105 | tags['exterior'] = Br |
---|
106 | tags['external'] = Br |
---|
107 | domain.set_boundary(tags) |
---|
108 | |
---|
109 | |
---|
110 | domain.check_integrity() |
---|
111 | |
---|
112 | ###################### |
---|
113 | #Evolution |
---|
114 | for t in domain.evolve(yieldstep = 0.5, finaltime = 100): |
---|
115 | domain.write_time() |
---|
116 | |
---|
117 | print 'Done' |
---|
118 | |
---|
119 | |
---|