source: anuga_core/source/anuga/shallow_water_balanced/run_wave_shelf.py @ 7734

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

Adding extra balanced code

File size: 4.8 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_shelf_'+time
30output_file = 'wave_shelf'
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 = 150000.
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#------------------------------------------------------------------------------
69depth = -100.0
70def topography(x,y):
71    z = (x*0.0)+depth
72
73    N = len(x)
74    for i in range(N):
75        if  40000.0 < x[i] < 60000.0:
76            z[i] = depth*( 1.0 - (x[i] - 40000.0)/20000.0)
77
78        if x[i] > 58000.0:
79            z[i] = 0.1*depth
80
81        if x[i] > 100000.0:
82            z[i] = 0.1*depth*(1.0 - (x[i] - 75000.0)/50000)
83    return z
84
85domain.set_quantity('elevation',topography)
86domain.set_quantity('friction', 0.00)
87domain.set_quantity('stage', 0.0)           
88
89#-----------------------------------------------------------------------------
90# Setup boundary conditions
91#------------------------------------------------------------------------------
92from math import sin, pi, exp
93Br = Reflective_boundary(domain)      # Solid reflective wall
94Bt = Transmissive_boundary(domain)    # Continue all values on boundary
95Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values
96amplitude = 1
97wave_length = 2000.0
98Bw = Time_boundary(domain=domain,     # Time dependent boundary 
99## Sine wave
100                  f=lambda t: [(amplitude*sin((1./wave_length)*t*2*pi)), 0.0, 0.0])
101## Sawtooth?
102#                   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])
103## Sharp rise, linear fall
104#                   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])
105#                   f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0])
106#                   f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0])
107
108# Associate boundary tags with boundary objects
109domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br})
110
111
112#===============================================================================
113if interactive_visualisation:
114    from anuga.visualiser import RealtimeVisualiser
115    vis = RealtimeVisualiser(domain)
116    vis.render_quantity_height("stage", zScale =10000, dynamic=True)
117    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
118    vis.start()
119#===============================================================================
120
121
122#------------------------------------------------------------------------------
123# Evolve system through time
124#------------------------------------------------------------------------------
125
126min = 60.0
127hr = 60*min
128
129for t in domain.evolve(yieldstep = min, finaltime = 5*hr):
130    domain.write_time()
131    if interactive_visualisation:
132        vis.update()
133
134    if domain.get_time()> 2*hr:
135        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
136
137if interactive_visualisation:
138    vis.evolveFinished()
139
Note: See TracBrowser for help on using the repository browser.