source: trunk/anuga_core/source/anuga/shallow_water_balanced/run_step.py @ 7800

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

Adding extra balanced code

File size: 4.4 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
73def stage(x,y):
74    z = num.zeros_like(x)
75    num.putmask(z, x < L/2 , 1.0)
76    return z
77
78domain.set_quantity('stage', stage  )           
79
80#-----------------------------------------------------------------------------
81# Setup boundary conditions
82#------------------------------------------------------------------------------
83from math import sin, pi, exp
84Br = Reflective_boundary(domain)      # Solid reflective wall
85Bt = Transmissive_boundary(domain)    # Continue all values on boundary
86Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values
87amplitude = 1
88Bw = Time_boundary(domain=domain,     # Time dependent boundary 
89## Sine wave
90                  f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0])
91## Sawtooth?
92#                   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])
93## Sharp rise, linear fall
94#                   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])
95#                   f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0])
96#                   f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0])
97
98# Associate boundary tags with boundary objects
99domain.set_boundary({'left': Bd, 'right': Bt, 'top': Br, 'bottom': Br})
100
101
102#===============================================================================
103if interactive_visualisation:
104    from anuga.visualiser import RealtimeVisualiser
105    vis = RealtimeVisualiser(domain)
106    vis.render_quantity_height("stage", zScale =10000, dynamic=True)
107    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
108    vis.start()
109#===============================================================================
110
111
112#------------------------------------------------------------------------------
113# Evolve system through time
114#------------------------------------------------------------------------------
115
116for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.):
117    domain.write_time()
118    if interactive_visualisation:
119        vis.update()
120
121if interactive_visualisation:
122    vis.evolveFinished()
123
Note: See TracBrowser for help on using the repository browser.