source: trunk/anuga_work/development/2010-projects/anuga_1d/sww/1dprofile_dispersion.py @ 8252

Last change on this file since 8252 was 8252, checked in by steve, 12 years ago

Jakir's tsunamu example

File size: 4.0 KB
Line 
1import os
2from math import *
3import random
4import numpy as np
5import time
6import anuga
7import csv
8from Scientific.IO.NetCDF import NetCDFFile
9from anuga_1d.sww.sww_domain import *
10from anuga_1d.config import g, epsilon
11from anuga_1d.base.generic_mesh import uniform_mesh
12
13
14#===========================================================================
15
16
17# Define functions for initial quantities
18## initial area for 1D SWE
19def initial_area(x):
20    return (stage(x)-sea_bed(x))*width(x)
21
22#--------------------------------------------
23def width(x):
24    return 1.0
25#---------------------------------------------
26# sea bed or bathymetry data
27
28def elevation():
29    x=[]
30    elevation=[]
31
32    f=open('gebco_1m.txt')
33    lines=f.readlines()
34    f.close
35    for line in lines[2:]:
36        val=[float(v) for v in line.split()]
37        y=val[1]
38        r=y-4152074.2
39        if abs(r)<810:# and val[0]<=max(x):
40    #if np.allclose(y,4243929.72563):
41            x.append(val[0])
42            elevation.append(val[2])
43    return x, elevation
44#-----------------------------------------------------
45# initial stage
46# Formula for solitary wave in 1D
47 
48def stage(x):
49    a=0.0*x
50    #a=gaussian_filtered(x)
51    y = 0.0*x
52    wd=abs(-6000)  # water depth
53    wh=2.5    # wave height
54    xm=908432.19999999995
55    k=10*sqrt(3.0*wh/(4.0*wd))/wd
56    for i in range(len(x)):
57            th=tanh(k*(x[i]-xm))**2
58            y[i]= wh*(1.0-th)#+a[i]
59    return y
60# --------------------------------------------------------
61
62
63# Initial momentum is zero
64
65def initial_momentum(x):
66    return 1.0
67
68
69# Length of channel (m)
70
71# Define cells for finite volume and their size
72# Define the number of cells
73x,elev=elevation()
74print x
75boundary = { (0,0) : 'left',  (len(x)-2, 1) : 'right'} 
76print boundary
77domain = Domain(x,boundary)
78print domain.boundary
79print type(x), len(x), type(elev),len(elev)
80
81
82# Set initial values of quantities - default to zero
83domain.set_quantity('elevation', elev, location='unique_vertices')
84#domain.add_quantity('stage',stage)
85domain.set_quantity('stage',stage)
86domain.set_quantity('xmomentum',initial_momentum)
87
88# Set boundry type, order, timestepping method and limiter
89print 'Available boundary tags: ', domain.get_boundary_tags()
90
91Bd = Dirichlet_boundary([0, 0, 0, 0, 0]) #(w,uh,z,h,u)
92Br = Reflective_boundary(domain)
93Bt = Transmissive_boundary(domain)
94domain.set_boundary({'left': Br , 'right' : Br})
95#domain.set_boundary({'exterior': Br})
96print 'Available boundary tags: ', domain.get_boundary_tags()
97domain.order = 2
98domain.set_timestepping_method(1)
99domain.set_CFL(1.0)
100domain.set_limiter("vanleer")
101#domain.h0=0.0001
102
103
104# Start timer
105t0 = time.time()
106
107# Set final time and yield time for simulation
108finaltime = 1.0
109yieldstep = 1.0
110
111#===================================================================
112# Time loop
113#===================================================================
114for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
115
116    w  = domain.quantities['stage'].vertex_values
117
118   
119   
120    domain.write_time()
121
122
123import pylab
124pylab.ion()
125
126x = domain.get_vertices().flatten()
127
128= domain.quantities['elevation'].vertex_values.flatten()
129= domain.quantities['stage'].vertex_values.flatten()
130= domain.quantities['height'].vertex_values.flatten()
131= domain.quantities['velocity'].vertex_values.flatten()
132uh = domain.quantities['xmomentum'].vertex_values.flatten()
133
134print x.shape
135print z.shape
136print w.shape
137print u.shape
138
139
140#print w
141#print z
142#print h
143#print u
144#print uh
145#print x
146
147#-------------------------------
148# Top plot
149#-------------------------------
150plot1 = pylab.subplot(211)
151
152zplot = pylab.plot(x, z, 'k')
153wplot = pylab.plot(x, w, 'k')
154
155#plot1.set_ylim(stage_lim)
156#pylab.xlabel('Position')
157pylab.ylabel('Bed/Stage')
158
159#-------------------------------
160# Bottom Plot
161#-------------------------------
162plot2 = pylab.subplot(212)
163
164uplot = pylab.plot(x, u, 'k')
165pylab.draw()
166
167#plot2.set_ylim(width_lim)
168#pylab.xlabel('Position')
169#pylab.ylabel('Velocity')
170
171
172#pylab.savefig('figure4.pdf')
173pylab.show()
174   
175   
176
Note: See TracBrowser for help on using the repository browser.