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