[4713] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | This is called Netherlands because it shows a dam with a gap in it and |
---|
| 4 | stylised housed behind it and below the water surface. |
---|
| 5 | |
---|
| 6 | """ |
---|
| 7 | |
---|
[5153] | 8 | #------------------------------------------------------------------------------ |
---|
| 9 | # Import necessary modules |
---|
| 10 | #------------------------------------------------------------------------------ |
---|
| 11 | |
---|
| 12 | from anuga.shallow_water import Domain |
---|
| 13 | from anuga.shallow_water import Reflective_boundary, Dirichlet_boundary |
---|
| 14 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
| 15 | import os |
---|
| 16 | |
---|
| 17 | #from anuga.visualiser import RealtimeVisualiser |
---|
[4713] | 18 | #import rpdb |
---|
| 19 | #rpdb.set_active() |
---|
| 20 | |
---|
| 21 | |
---|
[5153] | 22 | #------------------------------------------------------------------------------ |
---|
| 23 | # Setup computational domain |
---|
| 24 | #------------------------------------------------------------------------------ |
---|
[4713] | 25 | |
---|
[5153] | 26 | N = 150 # size = 45000 |
---|
| 27 | N = 130 # size = 33800 |
---|
| 28 | N = 600 # Size = 720000 |
---|
| 29 | N = 100 |
---|
| 30 | |
---|
| 31 | points, elements, boundary = rectangular_cross(N, N) |
---|
| 32 | domain = Domain(points, elements, boundary, use_inscribed_circle=True) |
---|
| 33 | |
---|
| 34 | domain.check_integrity() |
---|
| 35 | |
---|
| 36 | domain.set_name(os.path.splitext(__file__)[0]) |
---|
| 37 | domain.set_timestepping_method('rk3') |
---|
| 38 | domain.set_default_order(2) |
---|
| 39 | domain.set_store_vertices_uniquely(True) # Store as internally represented |
---|
| 40 | domain.tight_slope_limiters = True |
---|
| 41 | print domain.statistics() |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | # Setup order and all the beta's for the limiters (these should become defaults |
---|
| 45 | |
---|
| 46 | #domain.beta_w = 1.0 |
---|
| 47 | #domain.beta_w_dry = 0.2 |
---|
| 48 | #domain.beta_uh = 1.0 |
---|
| 49 | #domain.beta_uh_dry = 0.2 |
---|
| 50 | #domain.beta_vh = 1.0 |
---|
| 51 | #domain.beta_vh_dry = 0.2 |
---|
| 52 | |
---|
| 53 | #domain.alpha_balance = 100.0 |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | #------------------------------------------------------------------------------ |
---|
| 58 | # Setup initial conditions |
---|
| 59 | #------------------------------------------------------------------------------ |
---|
| 60 | |
---|
[4713] | 61 | class Weir: |
---|
| 62 | """Set a bathymetry for simple weir with a hole. |
---|
| 63 | x,y are assumed to be in the unit square |
---|
| 64 | """ |
---|
| 65 | |
---|
| 66 | def __init__(self, stage): |
---|
| 67 | self.inflow_stage = stage |
---|
| 68 | |
---|
| 69 | def __call__(self, x, y): |
---|
| 70 | from Numeric import zeros, Float |
---|
| 71 | |
---|
| 72 | N = len(x) |
---|
| 73 | assert N == len(y) |
---|
| 74 | |
---|
| 75 | z = zeros(N, Float) |
---|
| 76 | for i in range(N): |
---|
[5153] | 77 | z[i] = -x[i]/20 # General slope |
---|
[4713] | 78 | |
---|
[5153] | 79 | # Flattish bit to the left |
---|
[4713] | 80 | if x[i] <= 0.3: |
---|
| 81 | #z[i] = -x[i]/5 |
---|
| 82 | z[i] = -x[i]/20 |
---|
| 83 | |
---|
| 84 | |
---|
[5153] | 85 | # Weir |
---|
[4713] | 86 | if x[i] > 0.3 and x[i] < 0.4: |
---|
| 87 | z[i] = -x[i]/20+1.2 |
---|
| 88 | |
---|
[5153] | 89 | # Dip |
---|
[4713] | 90 | #if x[i] > 0.6 and x[i] < 0.9: |
---|
| 91 | # z[i] = -x[i]/20-0.5 #-y[i]/5 |
---|
| 92 | |
---|
[5153] | 93 | # Hole in weir |
---|
[4713] | 94 | #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4: |
---|
| 95 | if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6: |
---|
| 96 | #z[i] = -x[i]/5 |
---|
| 97 | z[i] = -x[i]/20 |
---|
| 98 | |
---|
[5153] | 99 | # Poles |
---|
[4713] | 100 | #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\ |
---|
| 101 | # x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 102 | # z[i] = -x[i]/20+0.4 |
---|
| 103 | |
---|
| 104 | if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\ |
---|
| 105 | #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 106 | z[i] = -x[i]/20+0.4 |
---|
| 107 | |
---|
| 108 | |
---|
[5153] | 109 | # Wall |
---|
[4713] | 110 | if x[i] > 0.995: |
---|
| 111 | z[i] = -x[i]/20+0.3 |
---|
| 112 | |
---|
| 113 | return z/2 |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | inflow_stage = 0.5 |
---|
| 117 | manning = 0.0 |
---|
| 118 | |
---|
[5153] | 119 | domain.set_quantity('elevation', Weir(inflow_stage)) |
---|
| 120 | domain.set_quantity('friction', manning) |
---|
| 121 | domain.set_quantity('stage', expression='elevation + 0.0') |
---|
[4713] | 122 | |
---|
| 123 | |
---|
[5153] | 124 | #------------------------------------------------------------------------------ |
---|
| 125 | # Setup boundary conditions |
---|
| 126 | #------------------------------------------------------------------------------ |
---|
[4713] | 127 | |
---|
[5153] | 128 | Br = Reflective_boundary(domain) |
---|
| 129 | Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0]) # Constant inflow |
---|
| 130 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
[4713] | 131 | |
---|
| 132 | |
---|
[5153] | 133 | #------------------------------------------------------------------------------ |
---|
| 134 | # Evolve system through time |
---|
| 135 | #------------------------------------------------------------------------------ |
---|
[4713] | 136 | |
---|
| 137 | |
---|
[5153] | 138 | if N <= 150: |
---|
| 139 | # Initialise real-time visualiser |
---|
[4713] | 140 | |
---|
[5153] | 141 | pass |
---|
| 142 | #vis = RealtimeVisualiser(domain) |
---|
| 143 | #vis.render_quantity_height("elevation", dynamic=False) |
---|
| 144 | #vis.render_quantity_height("stage", dynamic=True) |
---|
| 145 | #vis.colour_height_quantity('stage', (0.0, 0.0, 0.8)) |
---|
| 146 | #vis.start() |
---|
[4713] | 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | import time |
---|
| 151 | t0 = time.time() |
---|
| 152 | |
---|
| 153 | for t in domain.evolve(yieldstep = 0.005, finaltime = None): |
---|
[5153] | 154 | print domain.timestepping_statistics() |
---|
[4713] | 155 | print domain.quantities['stage'].get_values(location='centroids', |
---|
| 156 | indices=[0]) |
---|
[5153] | 157 | |
---|
| 158 | #vis.update() |
---|
[4713] | 159 | #time.sleep(0.1) |
---|
| 160 | #raw_input('pause>') |
---|
| 161 | #V.update_quantity('stage') |
---|
| 162 | #rpdb.set_active() |
---|
| 163 | #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral() |
---|
[5153] | 164 | #vis.evolveFinished() |
---|
[4713] | 165 | |
---|
| 166 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 167 | |
---|
[5153] | 168 | #vis.join() |
---|