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