source: trunk/anuga_work/shallow_water_balanced_steve/run_step.py @ 8335

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

Added in new test function for balanced code

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