source: inundation/ga/storm_surge/examples/beach.py @ 653

Last change on this file since 653 was 653, checked in by ole, 20 years ago

Work towards polygon setting

File size: 2.6 KB
Line 
1"""Example of the inundationmodel.
2
3A wave of water is washed up ontp a hypothetical beach.
4
5To run:
6
7python beach.py
8"""
9
10######################
11# Module imports
12#
13
14import sys
15from os import sep, path
16sys.path.append('..'+sep+'pyvolution')
17
18from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
19     Transmissive_boundary, Time_boundary, Constant_height, Weir
20
21from pmesh2domain import pmesh_to_domain_instance
22from config import data_dir
23
24######################
25# Domain
26name = 'beach'
27print 'Creating domain from %s.tsh' %name
28domain = pmesh_to_domain_instance(name + '.tsh', Domain)
29
30#HACK to remove internal boundary (until we get a solution)
31for b in domain.boundary.keys():
32    if domain.boundary[b] == 'internal':
33        del domain.boundary[b]
34
35domain = Domain(domain.coordinates, domain.triangles, domain.boundary)
36print "Number of triangles = ", len(domain)
37
38domain.store = True
39domain.set_name(name)
40print "Output being written to " + data_dir + sep + \
41      domain.filename + "." + domain.format
42
43
44def 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
51def inside(p,polygon):
52    return True
53
54def 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
80friction([0],[1])   
81
82domain.set_quantity('elevation', x_slope)
83domain.set_quantity('level', x_slope)
84domain.set_quantity('friction', 0.07)
85
86print domain.get_extent()
87import sys; sys.exit()
88
89######################
90# Boundary conditions
91
92print 'Boundaries'
93Br = Reflective_boundary(domain)
94Bt = Transmissive_boundary(domain)
95
96#Constant inflow
97Bd = Dirichlet_boundary([0.0, -1.0, 0.0])
98
99print 'Available boundary tags are', domain.get_boundary_tags()
100
101#Set boundary conditions
102tags = {}
103tags['ocean'] = Bd
104tags['wall'] = Br
105tags['exterior'] = Br
106tags['external'] = Br
107domain.set_boundary(tags)
108
109
110domain.check_integrity()
111
112######################
113#Evolution
114for t in domain.evolve(yieldstep = 0.5, finaltime = 100):
115    domain.write_time()
116   
117print 'Done'
118
119   
Note: See TracBrowser for help on using the repository browser.