source: trunk/anuga_core/source/anuga/shallow_water_balanced/run_wave.py @ 7876

Last change on this file since 7876 was 7734, checked in by steve, 14 years ago

Adding extra balanced code

File size: 4.3 KB
Line 
1"""Simple water flow example using ANUGA
2
3Will Powers example of a simple sinusoidal wave which showed diffusive effects of
4thefirst order and standard second order method. Problem resolved if "rk2" timestepping
5and higher beta = 2 limiter used. Also new edge limiter with rk2 resolves problem
6"""
7
8#------------------------------------------------------------------------------
9# Import necessary modules
10#------------------------------------------------------------------------------
11
12import sys
13from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
14from swb_domain import *
15
16from math import cos
17import numpy as num
18from time import localtime, strftime, gmtime
19from os import sep
20
21
22
23#-------------------------------------------------------------------------------
24# Copy scripts to time stamped output directory and capture screen
25# output to file
26#-------------------------------------------------------------------------------
27time = strftime('%Y%m%d_%H%M%S',localtime())
28
29output_dir = 'wave_'+time
30output_file = 'wave'
31
32#copy_code_files(output_dir,__file__)
33#start_screen_catcher(output_dir+sep)
34
35interactive_visualisation = True
36
37#------------------------------------------------------------------------------
38# Setup domain
39#------------------------------------------------------------------------------
40dx = 1000.
41dy = dx
42L = 100000.
43W = 10*dx
44
45# structured mesh
46points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2))
47
48domain = Domain(points, vertices, boundary) 
49
50domain.set_name(output_file)               
51domain.set_datadir(output_dir) 
52
53#------------------------------------------------------------------------------
54# Setup Algorithm
55#------------------------------------------------------------------------------
56domain.set_timestepping_method('rk2')
57domain.set_default_order(2)
58
59print domain.get_timestepping_method()
60
61#domain.use_edge_limiter = True
62#domain.tight_slope_limiters = False
63#domain.use_centroid_velocities = False
64
65
66#------------------------------------------------------------------------------
67# Setup initial conditions
68#------------------------------------------------------------------------------
69domain.set_quantity('elevation',-100.0)
70domain.set_quantity('friction', 0.00)
71domain.set_quantity('stage', 0.0)           
72
73#-----------------------------------------------------------------------------
74# Setup boundary conditions
75#------------------------------------------------------------------------------
76from math import sin, pi, exp
77Br = Reflective_boundary(domain)      # Solid reflective wall
78Bt = Transmissive_boundary(domain)    # Continue all values on boundary
79Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values
80amplitude = 1
81wave_length = 1000.0
82Bw = Time_boundary(domain=domain,     # Time dependent boundary 
83## Sine wave
84                  f=lambda t: [(-amplitude*sin((1./wave_length)*t*2*pi)), 0.0, 0.0])
85## Sawtooth?
86#                   f=lambda t: [(-8.0*(sin((1./180.)*t*2*pi))+(1./2.)*sin((2./180.)*t*2*pi)+(1./3.)*sin((3./180.)*t*2*pi)), 0.0, 0.0])
87## Sharp rise, linear fall
88#                   f=lambda t: [(5.0*(-((t-0.)/300.)*(t<300.)-cos((t-300.)*2.*pi*(1./240.))*(t>=300. and t<420.)+(1.-(t-420.)/300.)*(t>=420. and t <720.))), 0.0, 0.0])
89#                   f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0])
90#                   f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0])
91
92# Associate boundary tags with boundary objects
93domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br})
94
95
96#===============================================================================
97if interactive_visualisation:
98    from anuga.visualiser import RealtimeVisualiser
99    vis = RealtimeVisualiser(domain)
100    vis.render_quantity_height("stage", zScale =10000, dynamic=True)
101    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
102    vis.start()
103#===============================================================================
104
105
106#------------------------------------------------------------------------------
107# Evolve system through time
108#------------------------------------------------------------------------------
109
110for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.):
111    domain.write_time()
112    if interactive_visualisation:
113        vis.update()
114
115if interactive_visualisation:
116    vis.evolveFinished()
117
Note: See TracBrowser for help on using the repository browser.