source: trunk/anuga_work/development/gareth/tests/wave/run_wave.py @ 8446

Last change on this file since 8446 was 8446, checked in by davies, 13 years ago

bal_dev: Updates

File size: 5.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
13import anuga
14#from anuga import Domain
15
16from balanced_dev import *
17#from balanced_dev import Domain as Domain
18
19from math import cos
20import numpy as num
21from time import localtime, strftime, gmtime
22from os import sep
23
24
25
26#-------------------------------------------------------------------------------
27# Copy scripts to time stamped output directory and capture screen
28# output to file
29#-------------------------------------------------------------------------------
30time = strftime('%Y%m%d_%H%M%S',localtime())
31
32output_dir = '.'
33output_file = 'data_wave_'+time
34
35#copy_code_files(output_dir,__file__)
36#start_screen_catcher(output_dir+sep)
37
38interactive_visualisation = False
39
40#------------------------------------------------------------------------------
41# Setup domain
42#------------------------------------------------------------------------------
43dx = 1000.
44dy = dx
45L = 100000.
46W = 10*dx
47
48# structured mesh
49points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2))
50
51domain = Domain(points, vertices, boundary) 
52
53domain.set_name(output_file)               
54domain.set_datadir(output_dir) 
55
56#------------------------------------------------------------------------------
57# Setup Algorithm
58#------------------------------------------------------------------------------
59#domain.set_timestepping_method('rk2')
60#domain.set_default_order(2)
61#domain.set_beta(2.0)
62
63#print domain.get_timestepping_method()
64
65#domain.use_edge_limiter = True
66#domain.tight_slope_limiters = False
67#domain.use_centroid_velocities = False
68
69
70#------------------------------------------------------------------------------
71# Setup initial conditions
72#------------------------------------------------------------------------------
73domain.set_quantity('elevation',-100.0)
74domain.set_quantity('friction', 0.00)
75domain.set_quantity('stage', 0.0)           
76
77#-----------------------------------------------------------------------------
78# Setup boundary conditions
79#------------------------------------------------------------------------------
80from math import sin, pi, exp
81Br = anuga.Reflective_boundary(domain)      # Solid reflective wall
82Bt = anuga.Transmissive_boundary(domain)    # Continue all values on boundary
83#Bz = swb2_boundary_conditions.zero_mass_flux_zero_momentum_boundary(domain) # Strong reflections
84#Bz1 = swb2_boundary_conditions.zero_mass_flux_zero_t_transmissive_n_momentum_boundary(domain) # Strong reflections
85#Bz2 = swb2_boundary_conditions.zero_mass_flux_zero_n_transmissive_t_momentum_boundary(domain) # Strong reflections
86Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Strong reflections
87Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values
88amplitude = 1
89wave_length = 300.0
90Bw = anuga.Time_boundary(domain=domain,     # Time dependent boundary
91## Sine wave
92                  f=lambda t: [(-amplitude*sin((1./wave_length)*t*2*pi)), 0.0, 0.0])
93## Sawtooth?
94#                   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])
95## Sharp rise, linear fall
96#                   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])
97#                   f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0])
98#                   f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0])
99def waveform(t):
100    return -amplitude*sin((1./wave_length)*t*2*pi)
101
102def waveform2(t):
103    return 0.
104
105Bw2 = anuga.shallow_water.boundaries.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, waveform)
106Bf_in = swb2_boundary_conditions.Characteristic_boundary(domain, waveform)
107#Bw3 = swb2_boundary_conditions.Transmissive_momentum_nudge_stage_boundary(domain, waveform)
108Bf=swb2_boundary_conditions.Characteristic_boundary(domain,waveform2)
109                   
110
111
112# Associate boundary tags with boundary objects
113domain.set_boundary({'left': Bw2, 'right': Bf, 'top': Br, 'bottom': Br})
114
115
116#===============================================================================
117if interactive_visualisation:
118    from anuga.visualiser import RealtimeVisualiser
119    vis = RealtimeVisualiser(domain)
120    vis.render_quantity_height("stage", zScale =10000, dynamic=True)
121    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
122    vis.start()
123#===============================================================================
124
125
126#------------------------------------------------------------------------------
127# Evolve system through time
128#------------------------------------------------------------------------------
129
130for t in domain.evolve(yieldstep = 10.0, finaltime = 60*60.*3.):
131    domain.write_time()
132    if interactive_visualisation:
133        vis.update()
134
135if interactive_visualisation:
136    vis.evolveFinished()
137
Note: See TracBrowser for help on using the repository browser.