source: branches/inundation-numpy-branch/pyvolution/bed_w_file_boundary.py @ 7248

Last change on this file since 7248 was 3514, checked in by duncan, 19 years ago

Hi all,
I'm doing a change in the anuga structure, moving the code to

\anuga_core\source\anuga

After you have done an svn update, the PYTHONPATH has to be changed to;
PYTHONPATH = anuga_core/source/

This is part of changes required to make installation of anuga quicker and reducing the size of our sandpits.

If any imports are broken, try fixing them. With adding anuga. to them for example. If this seems to have really broken things, email/phone me.

Cheers
Duncan

File size: 2.1 KB
Line 
1"""Example of shallow water wave equation.
2
3Generate slope
4
5"""
6
7######################
8# Module imports
9#
10from mesh_factory import rectangular
11from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
12     Constant_height, Time_boundary, File_boundary
13from Numeric import array
14
15#Create basic mesh
16points, vertices, boundary = rectangular(10, 10, 100, 100)
17
18#Create shallow water domain
19domain = Domain(points, vertices, boundary)
20domain.smooth = False
21domain.visualise = True
22domain.default_order=2
23
24#######################
25#Bed-slope and friction
26def x_slope(x, y):
27    return -x/3
28
29#domain.set_quantity('elevation', x_slope)
30domain.set_quantity('elevation', lambda x,y: -x/3)
31domain.set_quantity('friction', 0.1)
32
33
34######################
35# Boundary conditions
36
37
38#Write file
39import os, time
40from config import time_format
41from math import sin, pi
42
43finaltime = 100
44filename = 'bed_w_boundary'
45fid = open(filename + '.txt', 'w')
46start = time.mktime(time.strptime('2000', '%Y'))
47dt = 5  #Five second intervals
48t = 0.0
49while t <= finaltime:
50    t_string = time.strftime(time_format, time.gmtime(t+start))   
51    fid.write('%s, %f %f %f\n' %(t_string, 10*sin(t*0.1*pi), 0.0, 0.0))
52   
53    t += dt
54   
55fid.close()
56
57
58#Convert ASCII file to NetCDF (Which is what we really like!)
59from anuga.pyvolution.data_manager import timefile2swww       
60timefile2swww(filename, quantity_names = domain.conserved_quantities)
61
62
63Br = Reflective_boundary(domain)
64Bd = Dirichlet_boundary([0.2,0.,0.])
65Bw = Time_boundary(domain=domain,
66                   f=lambda t: [(10*sin(t*0.1*pi)), 0.0, 0.0])
67
68Bf = File_boundary(filename + '.sww', domain)
69
70#domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br})
71domain.set_boundary({'left': Bf, 'right': Br, 'top': Br, 'bottom': Br})
72
73
74######################
75#Initial condition
76h = 0.5
77h = 0.0
78domain.set_quantity('stage', Constant_height(x_slope, h))
79
80domain.check_integrity()
81
82 
83######################
84#Evolution
85for t in domain.evolve(yieldstep = 1, finaltime = 100.0):
86    domain.write_time()
87
Note: See TracBrowser for help on using the repository browser.