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

Last change on this file since 9016 was 9016, checked in by davies, 11 years ago

Cleaning dev_audusse -- some problems remain

File size: 4.2 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 *
16#from balanced_dev import *
17from bal_and import *
18#from anuga_tsunami import *
19
20#---------
21#Setup computational domain
22#---------
23points, vertices, boundary = anuga.rectangular_cross(20,20, len1=1., len2=1.)
24
25domain=Domain(points,vertices,boundary)    # Create Domain
26domain.set_name('runup_sinusoid_v2')                         # Output to file runup.sww
27#domain.set_timestepping_method('euler')
28#domain.set_flow_algorithm('tsunami')
29#------------------
30# Define topography
31#------------------
32
33#### Pathological
34#scale_me=100.0
35#boundary_ws=-0.2#1999
36#init_ws=-0.2
37#bumpiness=50. # Higher = shorter wavelength oscillations in topography
38#tstep=0.2
39#lasttime=20.1
40
41### Sensible
42scale_me=1.0
43boundary_ws=-0.1
44init_ws=-0.2
45bumpiness=50. # Higher = shorter wavelength oscillations in topography
46tstep=0.2
47lasttime=150.
48
49#domain.minimum_allowed_height=domain.minimum_allowed_height*scale_me # Seems needed to make the algorithms behave
50
51def topography(x,y):
52        return (-x/2.0 +0.05*numpy.sin((x+y)*bumpiness))*scale_me
53
54def stagefun(x,y):
55    stge=init_ws*scale_me# +0.1*(x>0.9)*scale_me
56    #topo=topography(x,y)
57    return stge#*(stge>topo) + (topo)*(stge<=topo)
58
59domain.set_quantity('elevation',topography)     # Use function for elevation
60domain.get_quantity('elevation').smooth_vertex_values() 
61domain.set_quantity('friction',0.00)             # Constant friction
62
63print '#-#', domain.minimum_allowed_height
64#domain.minimum_allowed_height=0.001
65#def frict_change(x,y):
66#       return 0.2*(x>0.5)+0.1*(x<=0.5)
67#
68#domain.set_quantity('friction',frict_change)
69
70domain.set_quantity('stage', stagefun)              # Constant negative initial stage
71domain.get_quantity('stage').smooth_vertex_values()
72
73#print domain.forcing_terms
74#assert 0==1
75# Experiment with rain.
76# rainin = anuga.shallow_water.forcing.Rainfall(domain, rate=0.001) #, center=(0.,0.), radius=1000. )
77# domain.forcing_terms.append(rainin)
78
79#--------------------------
80# Setup boundary conditions
81#--------------------------
82Br=anuga.Reflective_boundary(domain)            # Solid reflective wall
83Bt=anuga.Transmissive_boundary(domain)          # Continue all values of boundary -- not used in this example
84Bd=anuga.Dirichlet_boundary([boundary_ws*scale_me,0.,0.])       # Constant boundary values -- not used in this example
85def waveform(t):
86    return boundary_ws*scale_me
87    #return -0.2*scale_me #-0.1 #(0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1
88def waveform2(t):
89    return [ (0.1*sin(2*pi*t)-0.3)*exp(-t), 0., 0.]
90
91Bt2=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain,waveform)
92Bw=anuga.Time_boundary(domain=domain, waveform2) # Time varying boundary -- get rid of the 0.0 to do a runup.
93
94#----------------------------------------------
95# Associate boundary tags with boundary objects
96#----------------------------------------------
97domain.set_boundary({'left': Br, 'right': Bt2, 'top': Br, 'bottom':Br})
98
99#------------------------------
100#Evolve the system through time
101#------------------------------
102
103for t in domain.evolve(yieldstep=tstep,finaltime=lasttime):
104#for t in domain.evolve(yieldstep=0.2,finaltime=60.):
105    print domain.timestepping_statistics()
106    #print domain.boundary_flux_integral
107    xx = domain.quantities['xmomentum'].centroid_values
108    yy = domain.quantities['ymomentum'].centroid_values
109    dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values
110    dd_raw=1.0*dd
111    dd = dd*(dd>1.0e-03)+1.0e-03*(dd<=1.0e-03)
112    vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5
113    vv = vv*(dd>1.0e-03)
114    print 'Peak velocity is: ', vv.max(), vv.argmax(), dd[vv.argmax()]
115    print 'Volume is', sum(dd_raw*domain.areas)   
116    #print 'Volume less flux int', sum(dd_raw*domain.areas) - domain.boundary_flux_integral
117
118
119vel_final_inds=(vv>1.0e-01).nonzero()
120print 'vel_final_inds', vel_final_inds
121
122print 'Finished'
Note: See TracBrowser for help on using the repository browser.