source: inundation/examples/island.py @ 2635

Last change on this file since 2635 was 2635, checked in by ole, 18 years ago

Benfield meeting

File size: 3.8 KB
Line 
1"""Example of shallow water wave equation.
2
3Island surrounded by water.
4This example investigates onshore 'creep'
5
6"""
7
8
9#------------------------------------------------------------------------------
10# Import necessary modules
11#------------------------------------------------------------------------------
12
13# Standard modules
14from math import exp
15
16# Application specific imports
17from pyvolution.mesh_factory import rectangular
18from pyvolution.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary
19from pmesh.mesh_interface import create_mesh_from_regions
20from utilities.polygon import Polygon_function, read_polygon
21
22from pyvolution.quantity import Quantity
23from Numeric import allclose
24
25#------------------------------------------------------------------------------
26# Setup computational domain
27#------------------------------------------------------------------------------
28
29#Create basic mesh
30N = 40
31points, vertices, boundary = rectangular(N, N, 100, 100)
32
33
34create_mesh_from_regions( [[0,0], [100,0], [100,100], [0,100]],
35                          boundary_tags = {'bottom': [0],
36                                           'right': [1],
37                                           'top': [2],
38                                           'left': [3]},
39                          maximum_triangle_area = 25,
40                          filename = 'island.msh'
41                          , interior_regions=[ ([[50,25], [70,25], [70,75], [50,75]], 1)]
42                          )
43                         
44                                                   
45                         
46                           
47
48#Create shallow water domain
49#domain = Domain(points, vertices, boundary)
50domain = Domain(mesh_filename = 'island.msh')
51domain.smooth = False
52domain.set_name('island')
53domain.set_default_order(2)
54
55
56#I tried to introduce this parameter top control the h-limiter,
57#but it doesn't remove the 'lapping water'
58#NEW (ON): I think it has been fixed (or at least reduced significantly) now
59#
60# beta_h == 1.0 means that the largest gradients (on h) are allowed
61# beta_h == 0.0 means that constant (1st order) gradients are introduced
62# on h. This is equivalent to the constant depth used previously.
63domain.beta_h = 0.9
64
65
66#------------------------------------------------------------------------------
67# Setup initial conditions
68#------------------------------------------------------------------------------
69
70def island(x, y):
71    z = 0*x
72    for i in range(len(x)):
73        z[i] = 8*exp( -((x[i]-50)**2 + (y[i]-50)**2)/100 )
74
75        #z[i] += 0.5*exp( -((x[i]-10)**2 + (y[i]-10)**2)/50 )
76   
77    return z
78
79def slump(x, y):
80    z = 0*x
81    for i in range(len(x)):
82        z[i] -= 0.7*exp( -((x[i]-10)**2 + (y[i]-10)**2)/200 ) 
83   
84    return z
85
86domain.set_quantity('friction', 0.0)
87domain.set_quantity('elevation', island)
88domain.set_quantity('stage', 1)
89
90
91#------------------------------------------------------------------------------
92# Setup boundary conditions (all reflective)
93#------------------------------------------------------------------------------
94
95Br = Reflective_boundary(domain)
96Bd = Dirichlet_boundary([1, 0, 0])
97
98#domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
99domain.set_boundary({'left': Bd, 'right': Bd, 'top': Bd, 'bottom': Bd})
100domain.check_integrity()
101
102
103#------------------------------------------------------------------------------
104# Evolve system through time
105#------------------------------------------------------------------------------
106
107import time
108for t in domain.evolve(yieldstep = 1, finaltime = 500):
109    domain.write_time()
110    if allclose(t, 100):
111        Q = domain.get_quantity('stage')
112        Q_s = Quantity(domain)
113        Q_s.set_values(slump)
114        domain.set_quantity('stage', Q + Q_s)
115    #print '    Volume: ', domain.get_quantity('stage').get_integral()
116
117print 'Done'
Note: See TracBrowser for help on using the repository browser.