source: trunk/anuga_work/development/gareth/tests/runup_sinusoid/runup_sinusoid.py @ 8549

Last change on this file since 8549 was 8549, checked in by davies, 13 years ago

Bugfixes for balanced_dev

File size: 3.6 KB
Line 
1"""Runup example from the manual, slightly modified
2"""
3#---------
4#Import Modules
5#--------
6import anuga
7
8import numpy
9
10from math import sin, pi, exp
11#from anuga.shallow_water.shallow_water_domain import Domain as Domain
12#from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain
13#path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic')
14#from swb2_domain import *
15#from balanced_basic import *
16from balanced_dev import *
17#from anuga_tsunami import *
18#---------
19#Setup computational domain
20#---------
21points, vertices, boundary = anuga.rectangular_cross(40,40, len1=1., len2=1.)
22
23domain=Domain(points,vertices,boundary)    # Create Domain
24domain.set_name('runup_sinusoid_v2')                         # Output to file runup.sww
25domain.set_datadir('.')                          # Use current folder
26domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
27#domain.set_store_vertices_uniquely(True)
28#------------------
29# Define topography
30#------------------
31scale_me=1.0
32
33#domain.minimum_allowed_height=domain.minimum_allowed_height*scale_me # Seems needed to make the algorithms behave
34
35def topography(x,y):
36        return (-x/2.0 +0.05*numpy.sin((x+y)*50.0))*scale_me
37
38def stagefun(x,y):
39    stge=-0.2*scale_me #+0.01*(x>0.9)
40    #topo=topography(x,y)
41    return stge#*(stge>topo) + (topo)*(stge<=topo)
42
43domain.set_quantity('elevation',topography)     # Use function for elevation
44domain.get_quantity('elevation').smooth_vertex_values() 
45domain.set_quantity('friction',0.03)             # Constant friction
46
47#def frict_change(x,y):
48#       return 0.2*(x>0.5)+0.1*(x<=0.5)
49#
50#domain.set_quantity('friction',frict_change)
51
52domain.set_quantity('stage', stagefun)              # Constant negative initial stage
53domain.get_quantity('stage').smooth_vertex_values()
54
55# Experiment with rain.
56# rainin = anuga.shallow_water.forcing.Rainfall(domain, rate=0.001) #, center=(0.,0.), radius=1000. )
57# domain.forcing_terms.append(rainin)
58
59#--------------------------
60# Setup boundary conditions
61#--------------------------
62Br=anuga.Reflective_boundary(domain)            # Solid reflective wall
63Bt=anuga.Transmissive_boundary(domain)          # Continue all values of boundary -- not used in this example
64Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.])       # Constant boundary values -- not used in this example
65def waveform(t):
66    return (0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1
67Bt2=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain,waveform)
68#Bw=anuga.Time_boundary(domain=domain,
69#       f=lambda t: [(0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1,0.0,0.0]) # Time varying boundary -- get rid of the 0.0 to do a runup.
70
71#----------------------------------------------
72# Associate boundary tags with boundary objects
73#----------------------------------------------
74domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br})
75
76#------------------------------
77#Evolve the system through time
78#------------------------------
79
80for t in domain.evolve(yieldstep=0.2,finaltime=40.0):
81    print domain.timestepping_statistics()
82    xx = domain.quantities['xmomentum'].centroid_values
83    yy = domain.quantities['ymomentum'].centroid_values
84    dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values
85    dd_raw=1.0*dd
86    dd = (dd)*(dd>1.0e-03)+1.0e-03
87    vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5
88    vv = vv*(dd>1.0e-03)
89    print 'Peak velocity is: ', vv.max(), vv.argmax()
90    print 'Volume is', sum(dd_raw*domain.areas)   
91
92
93vel_final_inds=(vv>1.0e-01).nonzero()
94print 'vel_final_inds', vel_final_inds
95
96print 'Finished'
Note: See TracBrowser for help on using the repository browser.