[8104] | 1 | """Simple water flow example using ANUGA |
---|
| 2 | |
---|
| 3 | Water driven up a linear slope and time varying boundary, |
---|
| 4 | similar to a beach environment |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | #------------------------------------------------------------------------------ |
---|
| 8 | # Import necessary modules |
---|
| 9 | #------------------------------------------------------------------------------ |
---|
| 10 | import sys |
---|
| 11 | import anuga |
---|
| 12 | from math import cos |
---|
| 13 | from numpy import zeros, float |
---|
| 14 | from time import localtime, strftime, gmtime |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #------------------------------------------------------------------------------- |
---|
| 19 | # Copy scripts to time stamped output directory and capture screen |
---|
| 20 | # output to file |
---|
| 21 | #------------------------------------------------------------------------------- |
---|
| 22 | time = strftime('%Y%m%d_%H%M%S',localtime()) |
---|
| 23 | |
---|
| 24 | output_dir = 'dam_break_'+time |
---|
| 25 | output_file = 'dam_break' |
---|
| 26 | |
---|
[8212] | 27 | #anuga.copy_code_files(output_dir,__file__) |
---|
[8104] | 28 | #start_screen_catcher(output_dir+'_') |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | #------------------------------------------------------------------------------ |
---|
| 32 | # Setup domain |
---|
| 33 | #------------------------------------------------------------------------------ |
---|
[8341] | 34 | unit = 1.0 |
---|
| 35 | dx = unit/1.0 |
---|
[8104] | 36 | dy = dx |
---|
[8341] | 37 | L = 100*unit |
---|
| 38 | W = 10*unit |
---|
[8104] | 39 | |
---|
| 40 | # structured mesh |
---|
| 41 | points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) |
---|
| 42 | |
---|
| 43 | domain = anuga.Domain(points, vertices, boundary) |
---|
| 44 | |
---|
| 45 | domain.set_name(output_file) |
---|
| 46 | domain.set_datadir(output_dir) |
---|
| 47 | |
---|
| 48 | #------------------------------------------------------------------------------ |
---|
| 49 | # Setup Algorithm |
---|
| 50 | #------------------------------------------------------------------------------ |
---|
| 51 | domain.set_timestepping_method('rk2') |
---|
| 52 | domain.set_default_order(2) |
---|
| 53 | |
---|
| 54 | print domain.get_timestepping_method() |
---|
[8341] | 55 | print domain.s |
---|
[8104] | 56 | |
---|
| 57 | domain.use_edge_limiter = True |
---|
| 58 | domain.tight_slope_limiters = True |
---|
| 59 | domain.use_centroid_velocities = False |
---|
| 60 | |
---|
| 61 | domain.CFL = 1.0 |
---|
| 62 | |
---|
| 63 | domain.beta_w = 0.6 |
---|
| 64 | domain.beta_uh = 0.6 |
---|
| 65 | domain.beta_vh = 0.6 |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | #------------------------------------------------------------------------------ |
---|
| 69 | # Setup initial conditions |
---|
| 70 | #------------------------------------------------------------------------------ |
---|
| 71 | domain.set_quantity('elevation',0.0) |
---|
| 72 | domain.set_quantity('friction', 0.0) |
---|
| 73 | |
---|
[8341] | 74 | h0 = 10.0*unit |
---|
| 75 | h1 = 1.0*unit |
---|
[8104] | 76 | |
---|
| 77 | def height(x,y): |
---|
| 78 | z = zeros(len(x), float) |
---|
| 79 | for i in range(len(x)): |
---|
[8341] | 80 | if x[i]<=50.0*unit: |
---|
[8104] | 81 | z[i] = h0 |
---|
| 82 | else: |
---|
| 83 | z[i] = h1 |
---|
| 84 | return z |
---|
[8212] | 85 | domain.set_quantity('stage', height) |
---|
[8104] | 86 | |
---|
| 87 | #----------------------------------------------------------------------------- |
---|
| 88 | # Setup boundary conditions |
---|
| 89 | #------------------------------------------------------------------------------ |
---|
| 90 | from math import sin, pi, exp |
---|
| 91 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
| 92 | Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary |
---|
| 93 | Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values |
---|
| 94 | |
---|
| 95 | # Associate boundary tags with boundary objects |
---|
| 96 | domain.set_boundary({'left': Bt, 'right': Bt, 'top': Br, 'bottom': Br}) |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | #=============================================================================== |
---|
[8325] | 100 | from anuga.visualiser import RealtimeVisualiser |
---|
[8341] | 101 | wireframe = False |
---|
[8325] | 102 | vis = RealtimeVisualiser(domain) |
---|
[8341] | 103 | vis.render_quantity_height("stage", zScale=1, dynamic=True, wireframe=wireframe) |
---|
| 104 | vis.render_quantity_height("elevation", zScale=1, dynamic=False, wireframe=wireframe) |
---|
[8325] | 105 | vis.colour_height_quantity('stage', (0.0, 0.5, 1.0)) |
---|
| 106 | vis.colour_height_quantity('elevation', (0.5, 0.5, 0.5)) |
---|
| 107 | vis.start() |
---|
[8104] | 108 | #=============================================================================== |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | #------------------------------------------------------------------------------ |
---|
| 112 | # Evolve system through time |
---|
| 113 | #------------------------------------------------------------------------------ |
---|
[8341] | 114 | for t in domain.evolve(yieldstep = 0.1, finaltime = 5.0): |
---|
[8104] | 115 | #print domain.timestepping_statistics(track_speeds=True) |
---|
| 116 | print domain.timestepping_statistics() |
---|
[8325] | 117 | vis.update() |
---|
[8104] | 118 | |
---|
| 119 | |
---|
| 120 | #test against know data |
---|
| 121 | |
---|
[8325] | 122 | vis.evolveFinished() |
---|
[8104] | 123 | |
---|