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

Last change on this file since 8202 was 8202, checked in by steve, 13 years ago

Trying to well balnace the gravity term

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
13import anuga
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
29#output_dir = 'step_'+time
30output_dir = '.'
31output_file = 'data_step_'+time
32
33#copy_code_files(output_dir,__file__)
34#start_screen_catcher(output_dir+sep)
35
36interactive_visualisation = True
37
38#------------------------------------------------------------------------------
39# Setup domain
40#------------------------------------------------------------------------------
41dx = 1000.
42dy = dx
43L = 100000.
44W = 10*dx
45
46# structured mesh
47points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2))
48
49domain = Domain(points, vertices, boundary) 
50
51domain.set_name(output_file)               
52domain.set_datadir(output_dir) 
53
54#------------------------------------------------------------------------------
55# Setup Algorithm
56#------------------------------------------------------------------------------
57domain.set_timestepping_method('rk2')
58domain.set_default_order(2)
59
60print domain.get_timestepping_method()
61
62#domain.use_edge_limiter = True
63#domain.tight_slope_limiters = False
64#domain.use_centroid_velocities = False
65
66
67#------------------------------------------------------------------------------
68# Setup initial conditions
69#------------------------------------------------------------------------------
70domain.set_quantity('elevation',-100.0)
71domain.set_quantity('friction', 0.00)
72domain.set_quantity('stage', 0.0)
73
74def stage(x,y):
75    z = num.zeros_like(x)
76    num.putmask(z, (2*L/5 < x) * (x < 3*L/5) , 1.0)
77    return z
78
79domain.set_quantity('stage', stage  )           
80
81#-----------------------------------------------------------------------------
82# Setup boundary conditions
83#------------------------------------------------------------------------------
84from math import sin, pi, exp
85Br = anuga.Reflective_boundary(domain)      # Solid reflective wall
86Bt = anuga.Transmissive_boundary(domain)    # Continue all values on boundary
87Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values
88amplitude = 1
89Bw = anuga.Time_boundary(domain=domain,     # Time dependent boundary
90## Sine wave
91                  f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0])
92## Sawtooth?
93#                   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])
94## Sharp rise, linear fall
95#                   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])
96#                   f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0])
97#                   f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0])
98
99# Associate boundary tags with boundary objects
100domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br})
101
102
103#===============================================================================
104if interactive_visualisation:
105    from anuga.visualiser import RealtimeVisualiser
106    vis = RealtimeVisualiser(domain)
107    vis.render_quantity_height("stage", zScale =10000, dynamic=True)
108    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
109    vis.start()
110#===============================================================================
111
112
113#------------------------------------------------------------------------------
114# Evolve system through time
115#------------------------------------------------------------------------------
116
117for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.):
118    domain.write_time()
119    if interactive_visualisation:
120        vis.update()
121
122if interactive_visualisation:
123    vis.evolveFinished()
124
Note: See TracBrowser for help on using the repository browser.