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

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

bal_dev: Updates

File size: 3.4 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#---------
18#Setup computational domain
19#---------
20points, vertices, boundary = anuga.rectangular_cross(40,40, len1=1., len2=1.)
21
22domain=Domain(points,vertices,boundary)    # Create Domain
23domain.set_name('runup_sinusoid_v2')                         # Output to file runup.sww
24domain.set_datadir('.')                          # Use current folder
25domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
26#domain.set_store_vertices_uniquely(True)
27domain.minimum_allowed_height=0.001
28
29#------------------
30# Define topography
31#------------------
32scale_me=1.0
33
34#domain.minimum_allowed_height=domain.minimum_allowed_height*scale_me # Seems needed to make the algorithms behave
35
36def topography(x,y):
37        return (-x/2.0 +0.05*numpy.sin((x+y)*50.0))*scale_me
38
39def stagefun(x,y):
40    stge=-0.2*scale_me #-0.1*(x>0.5) -0.2*(x<=0.5)
41    #topo=topography(x,y)
42    return stge#*(stge>topo) + (topo)*(stge<=topo)
43
44domain.set_quantity('elevation',topography)     # Use function for elevation
45domain.get_quantity('elevation').smooth_vertex_values() 
46
47domain.set_quantity('friction',0.00)             # Constant friction
48
49#def frict_change(x,y):
50#       return 0.2*(x>0.5)+0.1*(x<=0.5)
51#
52#domain.set_quantity('friction',frict_change)
53
54domain.set_quantity('stage', stagefun)              # Constant negative initial stage
55domain.get_quantity('stage').smooth_vertex_values()
56
57# Experiment with rain.
58# rainin = anuga.shallow_water.forcing.Rainfall(domain, rate=0.001) #, center=(0.,0.), radius=1000. )
59# domain.forcing_terms.append(rainin)
60
61#--------------------------
62# Setup boundary conditions
63#--------------------------
64Br=anuga.Reflective_boundary(domain)            # Solid reflective wall
65Bt=anuga.Transmissive_boundary(domain)          # Continue all values of boundary -- not used in this example
66Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.])       # Constant boundary values -- not used in this example
67def waveform(t):
68    return (0.0*sin(t*2*pi)-0.1)*exp(-t)-0.1
69Bt2=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain,waveform)
70#Bw=anuga.Time_boundary(domain=domain,
71#       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.
72
73#----------------------------------------------
74# Associate boundary tags with boundary objects
75#----------------------------------------------
76domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
77
78#------------------------------
79#Evolve the system through time
80#------------------------------
81
82for t in domain.evolve(yieldstep=0.1,finaltime=20.0):
83    print domain.timestepping_statistics()
84    xx = domain.quantities['xmomentum'].centroid_values
85    yy = domain.quantities['ymomentum'].centroid_values
86    dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values
87    dd = (dd)*(dd>1.0e-06)+1.0e-03
88    vv = ( (xx/dd)**2 + (yy/dd)**2 )**0.5
89    vv = vv*(dd>1.0e-03)
90    print 'Peak velocity is: ', vv.max(), vv.argmax()
91
92print 'Finished'
Note: See TracBrowser for help on using the repository browser.