source: trunk/anuga_work/development/gareth/experimental/balanced_dev/runup.py

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

Major experimental changes to balanced_dev

File size: 4.2 KB
Line 
1"""Runup example from the manual, slightly modified
2"""
3#---------
4#Import Modules
5#--------
6from sys import path
7import anuga
8
9import numpy
10
11import struct
12#import scipy
13
14#from Numeric import *
15
16from math import sin, pi, exp
17from balanced_dev import *
18#from anuga_tsunami import *
19#from anuga.shallow_water_balanced2.swb2_domain import Domain as Domain
20#from anuga.shallow_water.shallow_water_domain import Domain as Domain
21#from shallow_water_balanced_steve.swb_domain import *
22#import shallow_water_balanced_steve.swb_domain
23#from shallow_water_balanced_steve.swb_domain import Domain as Domain
24#path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/shallow_water_balanced_steve')
25#from swb_domain import *
26#path.append('/home/gareth/storage/anuga_clean/anuga_jan12/trunk/anuga_work/development/gareth/balanced_basic')
27#from balanced_basic.swb2_domain import *
28#---------
29#Setup computational domain
30#---------
31points, vertices, boundary = anuga.rectangular_cross(40,40)
32
33domain=Domain(points,vertices,boundary)    # Create Domain
34domain.set_name('runup_v2')                         # Output to file runup.sww
35domain.set_datadir('.')                          # Use current folder
36domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
37domain.set_store_vertices_uniquely(True)
38#------------------
39# Define topography
40#------------------
41
42def topography(x,y):
43        return -x/2 #+0.05*numpy.sin((x+y)*50.0) #+0.1*(numpy.random.rand(len(x)) -0.5)       # Linear bed slope + small random perturbation
44
45def stagefun(x,y):
46    #stg=-0.2*(x<0.5) -0.1*(x>=0.5)
47    stg=-0.2 # Stage
48    #topo=topography(x,y) #Bed
49    return stg #*(stg>topo) + topo*(stg<=topo)
50
51domain.set_quantity('elevation',topography)     # Use function for elevation
52domain.get_quantity('elevation').smooth_vertex_values() # Steve's fix -- without this, substantial artificial velcities are generated everywhere in the domain. With this fix, there are artificial velocities near the coast, but not elsewhere.
53
54domain.set_quantity('friction',0.00)             # Constant friction
55
56domain.set_quantity('stage', stagefun)              # Constant negative initial stage
57
58#--------------------------
59# Setup boundary conditions
60#--------------------------
61Br=anuga.Reflective_boundary(domain)            # Solid reflective wall
62Bt=anuga.Transmissive_boundary(domain)          # Continue all values of boundary -- not used in this example
63Bd=anuga.Dirichlet_boundary([-0.2,0.,0.])       # Constant boundary values -- not used in this example
64Bw=anuga.Time_boundary(domain=domain, function=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.
65
66#----------------------------------------------
67# Associate boundary tags with boundary objects
68#----------------------------------------------
69domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
70
71#------------------------------
72#Evolve the system through time
73#------------------------------
74
75#xwrite=open("xvel.out","wb")
76#ywrite=open("yvel.out","wb")
77## Set print options to be compatible with file writing via the 'print' statement
78#numpy.set_printoptions(threshold=numpy.nan, linewidth=numpy.nan)
79
80for t in domain.evolve(yieldstep=0.2,finaltime=30.0):
81    print domain.timestepping_statistics()
82
83#    momx=domain.quantities['xmomentum'].centroid_values
84#    momy=domain.quantities['ymomentum'].centroid_values
85#    #mom2=domain.quantities['xmomentum'].vertex_values
86#    dep1=(domain.quantities['stage'].centroid_values-domain.quantities['elevation'].centroid_values+1.0e-06)
87#    #dep2=(domain.quantities['stage'].vertex_values-domain.quantities['elevation'].vertex_values+1.0e-06)
88#    velx=momx/dep1
89#    vely=momy/dep1
90#    #vel2=mom2/dep2
91#    #print vel1.max(), vel2.max()
92#    #print vel1.min(), vel2.min()
93#    #xwrite.write(velx)
94#    #print >> xwrite, str(velx)
95#    #print >> ywrite, str(vely)
96#    for i in velx:
97#        data=struct.pack('f',i)
98#        xwrite.write(data)
99#
100#    for j in vely:
101#        data2=struct.pack('f',j)
102#        ywrite.write(data2)
103#
104#    #print >> xwrite, \n
105#    #numpy.savetxt("xvel.txt",velx)
106#    #numpy.savetxt("yvel.txt",vely)
107#    #velx.tofile(xwrite," ")
108#    #vely.tofile(ywrite," ")
109#
110#xwrite.close()
111#ywrite.close()
112
113print 'Finished'
Note: See TracBrowser for help on using the repository browser.