[5162] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
| 3 | Will Powers example of a simple sinusoidal wave which showed diffusive effects of |
---|
| 4 | thefirst order and standard second order method. Problem resolved if "rk2" timestepping |
---|
| 5 | and higher beta = 2 limiter used. Also new edge limiter with rk2 resolves problem |
---|
| 6 | """ |
---|
| 7 | |
---|
| 8 | #------------------------------------------------------------------------------ |
---|
| 9 | # Import necessary modules |
---|
| 10 | #------------------------------------------------------------------------------ |
---|
| 11 | |
---|
| 12 | import sys |
---|
| 13 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
| 14 | from anuga.shallow_water import Domain |
---|
| 15 | from anuga.shallow_water import Reflective_boundary |
---|
| 16 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 17 | from anuga.shallow_water import Time_boundary |
---|
| 18 | from anuga.shallow_water import Transmissive_boundary |
---|
| 19 | from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary |
---|
| 20 | from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files |
---|
| 21 | |
---|
| 22 | from math import cos |
---|
| 23 | from Numeric import zeros, Float |
---|
| 24 | from time import localtime, strftime, gmtime |
---|
| 25 | from os import sep |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #------------------------------------------------------------------------------- |
---|
| 30 | # Copy scripts to time stamped output directory and capture screen |
---|
| 31 | # output to file |
---|
| 32 | #------------------------------------------------------------------------------- |
---|
| 33 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
| 34 | |
---|
| 35 | output_dir = 'wave_'+time |
---|
| 36 | output_file = 'wave' |
---|
| 37 | |
---|
| 38 | copy_code_files(output_dir,__file__) |
---|
| 39 | #start_screen_catcher(output_dir+sep) |
---|
| 40 | |
---|
| 41 | #------------------------------------------------------------------------------ |
---|
| 42 | # Setup domain |
---|
| 43 | #------------------------------------------------------------------------------ |
---|
[5300] | 44 | dx = 1000. |
---|
[5162] | 45 | dy = dx |
---|
| 46 | L = 100000. |
---|
| 47 | W = 10*dx |
---|
| 48 | |
---|
| 49 | # structured mesh |
---|
| 50 | points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
| 51 | |
---|
| 52 | domain = Domain(points, vertices, boundary) |
---|
| 53 | |
---|
| 54 | domain.set_name(output_file) |
---|
| 55 | domain.set_datadir(output_dir) |
---|
| 56 | |
---|
| 57 | #------------------------------------------------------------------------------ |
---|
| 58 | # Setup Algorithm |
---|
| 59 | #------------------------------------------------------------------------------ |
---|
[5175] | 60 | domain.set_timestepping_method('rk2') |
---|
| 61 | domain.set_default_order(2) |
---|
[5162] | 62 | |
---|
[5175] | 63 | print domain.get_timestepping_method() |
---|
[5162] | 64 | |
---|
[5175] | 65 | domain.use_edge_limiter = True |
---|
[5300] | 66 | domain.tight_slope_limiters = False |
---|
| 67 | domain.use_centroid_velocities = False |
---|
[5162] | 68 | |
---|
[5175] | 69 | domain.CFL = 1.0 |
---|
[5162] | 70 | |
---|
[5300] | 71 | domain.beta_w = 1.0 |
---|
[5175] | 72 | domain.beta_w_dry = 0.0 |
---|
[5300] | 73 | domain.beta_uh = 1.0 |
---|
[5175] | 74 | domain.beta_uh_dry = 0.0 |
---|
[5300] | 75 | domain.beta_vh = 1.0 |
---|
[5175] | 76 | domain.beta_vh_dry = 0.0 |
---|
| 77 | domain.beta_h = 0.0 |
---|
[5162] | 78 | |
---|
[5300] | 79 | interactive_visualisation = True |
---|
[5162] | 80 | |
---|
[5180] | 81 | |
---|
[5162] | 82 | #------------------------------------------------------------------------------ |
---|
| 83 | # Setup initial conditions |
---|
| 84 | #------------------------------------------------------------------------------ |
---|
| 85 | domain.set_quantity('elevation',-100.0) |
---|
| 86 | domain.set_quantity('friction', 0.00) |
---|
| 87 | domain.set_quantity('stage', 0.0) |
---|
| 88 | |
---|
| 89 | #----------------------------------------------------------------------------- |
---|
| 90 | # Setup boundary conditions |
---|
| 91 | #------------------------------------------------------------------------------ |
---|
| 92 | from math import sin, pi, exp |
---|
| 93 | Br = Reflective_boundary(domain) # Solid reflective wall |
---|
| 94 | Bt = Transmissive_boundary(domain) # Continue all values on boundary |
---|
| 95 | Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
| 96 | amplitude = 1 |
---|
| 97 | Bw = Time_boundary(domain=domain, # Time dependent boundary |
---|
| 98 | ## Sine wave |
---|
| 99 | f=lambda t: [(-amplitude*sin((1./300.)*t*2*pi)), 0.0, 0.0]) |
---|
| 100 | ## Sawtooth? |
---|
| 101 | # 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]) |
---|
| 102 | ## Sharp rise, linear fall |
---|
| 103 | # 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]) |
---|
| 104 | # f=lambda t: [amplitude*(1.-2.*(pi*(1./720.)*(t-720.))**2)/exp((pi*(1./720.)*(t-720.))**2) , 0.0, 0.0]) |
---|
| 105 | # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) |
---|
| 106 | |
---|
| 107 | # Associate boundary tags with boundary objects |
---|
| 108 | domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | #=============================================================================== |
---|
[5180] | 112 | if interactive_visualisation: |
---|
| 113 | from anuga.visualiser import RealtimeVisualiser |
---|
| 114 | vis = RealtimeVisualiser(domain) |
---|
| 115 | vis.render_quantity_height("stage", zScale =10000, dynamic=True) |
---|
| 116 | vis.colour_height_quantity('stage', (1.0, 0.5, 0.5)) |
---|
| 117 | vis.start() |
---|
[5162] | 118 | #=============================================================================== |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | #------------------------------------------------------------------------------ |
---|
| 122 | # Evolve system through time |
---|
| 123 | #------------------------------------------------------------------------------ |
---|
| 124 | |
---|
| 125 | for t in domain.evolve(yieldstep = 50.0, finaltime = 60*60.): |
---|
| 126 | domain.write_time() |
---|
[5180] | 127 | if interactive_visualisation: |
---|
| 128 | vis.update() |
---|
[5162] | 129 | |
---|
[5180] | 130 | if interactive_visualisation: |
---|
| 131 | vis.evolveFinished() |
---|
| 132 | |
---|