[3689] | 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 | |
---|
| 8 | ###################### |
---|
| 9 | # Module imports |
---|
| 10 | # |
---|
| 11 | #import rpdb |
---|
| 12 | #rpdb.set_active() |
---|
| 13 | |
---|
| 14 | from anuga.shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
| 15 | Transmissive_boundary, Constant_height, Constant_stage |
---|
| 16 | |
---|
| 17 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
| 18 | from Numeric import array |
---|
[3962] | 19 | from anuga.visualiser import RealtimeVisualiser |
---|
[3689] | 20 | |
---|
| 21 | class Weir: |
---|
| 22 | """Set a bathymetry for simple weir with a hole. |
---|
| 23 | x,y are assumed to be in the unit square |
---|
| 24 | """ |
---|
| 25 | |
---|
| 26 | def __init__(self, stage): |
---|
| 27 | self.inflow_stage = stage |
---|
| 28 | |
---|
| 29 | def __call__(self, x, y): |
---|
| 30 | from Numeric import zeros, Float |
---|
| 31 | |
---|
| 32 | N = len(x) |
---|
| 33 | assert N == len(y) |
---|
| 34 | |
---|
| 35 | z = zeros(N, Float) |
---|
| 36 | for i in range(N): |
---|
| 37 | z[i] = -x[i]/20 #General slope |
---|
| 38 | |
---|
| 39 | #Flattish bit to the left |
---|
| 40 | if x[i] <= 0.3: |
---|
| 41 | #z[i] = -x[i]/5 |
---|
| 42 | z[i] = -x[i]/20 |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | #Weir |
---|
| 46 | if x[i] > 0.3 and x[i] < 0.4: |
---|
| 47 | z[i] = -x[i]/20+1.2 |
---|
| 48 | |
---|
| 49 | #Dip |
---|
| 50 | #if x[i] > 0.6 and x[i] < 0.9: |
---|
| 51 | # z[i] = -x[i]/20-0.5 #-y[i]/5 |
---|
| 52 | |
---|
| 53 | #Hole in weir |
---|
| 54 | #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4: |
---|
| 55 | if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6: |
---|
| 56 | #z[i] = -x[i]/5 |
---|
| 57 | z[i] = -x[i]/20 |
---|
| 58 | |
---|
| 59 | #Poles |
---|
| 60 | #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\ |
---|
| 61 | # x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 62 | # z[i] = -x[i]/20+0.4 |
---|
| 63 | |
---|
| 64 | if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\ |
---|
| 65 | #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 66 | z[i] = -x[i]/20+0.4 |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | #Wall |
---|
| 70 | if x[i] > 0.995: |
---|
| 71 | z[i] = -x[i]/20+0.3 |
---|
| 72 | |
---|
| 73 | return z/2 |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | ###################### |
---|
| 78 | # Domain |
---|
| 79 | # |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | N = 150 #size = 45000 |
---|
| 83 | N = 130 #size = 33800 |
---|
| 84 | N = 600 #Size = 720000 |
---|
[4305] | 85 | N = 50 |
---|
[3689] | 86 | |
---|
| 87 | |
---|
| 88 | #N = 15 |
---|
| 89 | |
---|
| 90 | print 'Creating domain' |
---|
| 91 | #Create basic mesh |
---|
| 92 | points, elements, boundary = rectangular_cross(N, N) |
---|
| 93 | |
---|
| 94 | #Create shallow water domain |
---|
| 95 | domain = Domain(points, elements, boundary, use_inscribed_circle=True) |
---|
| 96 | |
---|
| 97 | domain.check_integrity() |
---|
| 98 | |
---|
| 99 | #Setup order and all the beta's for the limiters (these should become defaults |
---|
| 100 | domain.default_order = 2 |
---|
| 101 | domain.beta_w = 1.0 |
---|
| 102 | domain.beta_w_dry = 0.2 |
---|
| 103 | domain.beta_uh = 1.0 |
---|
| 104 | domain.beta_uh_dry = 0.2 |
---|
| 105 | domain.beta_vh = 1.0 |
---|
| 106 | domain.beta_vh_dry = 0.2 |
---|
| 107 | |
---|
[3906] | 108 | domain.alpha_balance = 100.0 |
---|
[3876] | 109 | |
---|
[3689] | 110 | #Output params |
---|
| 111 | domain.smooth = False |
---|
| 112 | domain.reduction = min #Looks a lot better on top of steep slopes |
---|
| 113 | |
---|
| 114 | print "Number of triangles = ", len(domain) |
---|
| 115 | print "Extent = ", domain.get_extent() |
---|
| 116 | |
---|
| 117 | #Set bed-slope and friction |
---|
| 118 | inflow_stage = 0.5 |
---|
| 119 | manning = 0.03 |
---|
| 120 | Z = Weir(inflow_stage) |
---|
| 121 | |
---|
| 122 | if N > 150: |
---|
| 123 | domain.checkpoint = False |
---|
| 124 | domain.store = True #Store for visualisation purposes |
---|
| 125 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 126 | import sys, os |
---|
| 127 | #FIXME: This was os.path.splitext but caused weird filenames based on root |
---|
| 128 | base = os.path.basename(sys.argv[0]) |
---|
[3846] | 129 | basename, _ = os.path.splitext(base) |
---|
| 130 | domain.set_name(basename) |
---|
[3689] | 131 | else: |
---|
| 132 | domain.checkpoint = False |
---|
| 133 | domain.store = False |
---|
[3962] | 134 | vis = RealtimeVisualiser(domain) |
---|
| 135 | vis.render_quantity_height("elevation", dynamic=False) |
---|
| 136 | vis.render_quantity_height("stage", dynamic=True) |
---|
| 137 | vis.colour_height_quantity('stage', (0.0, 0.0, 0.8)) |
---|
| 138 | vis.start() |
---|
[3689] | 139 | |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | print 'Field values' |
---|
| 143 | domain.set_quantity('elevation', Z) |
---|
| 144 | domain.set_quantity('friction', manning) |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | ###################### |
---|
| 148 | # Boundary conditions |
---|
| 149 | # |
---|
| 150 | print 'Boundaries' |
---|
| 151 | Br = Reflective_boundary(domain) |
---|
| 152 | Bt = Transmissive_boundary(domain) |
---|
| 153 | |
---|
| 154 | #Constant inflow |
---|
| 155 | Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0]) |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | #Set boundary conditions |
---|
| 159 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | ###################### |
---|
| 163 | #Initial condition |
---|
| 164 | # |
---|
| 165 | print 'Initial condition' |
---|
[3842] | 166 | domain.set_quantity('stage', expression='elevation + 0.0') |
---|
[3689] | 167 | |
---|
| 168 | #Evolve |
---|
| 169 | import time |
---|
| 170 | t0 = time.time() |
---|
| 171 | |
---|
| 172 | for t in domain.evolve(yieldstep = 0.005, finaltime = None): |
---|
| 173 | domain.write_time() |
---|
| 174 | #domain.write_boundary() |
---|
| 175 | vis.update() |
---|
| 176 | print domain.quantities['stage'].get_values(location='centroids', |
---|
| 177 | indices=[0]) |
---|
| 178 | #time.sleep(0.1) |
---|
| 179 | #raw_input('pause>') |
---|
| 180 | #V.update_quantity('stage') |
---|
| 181 | #rpdb.set_active() |
---|
| 182 | #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral() |
---|
[3962] | 183 | vis.evolveFinished() |
---|
[3689] | 184 | |
---|
[3962] | 185 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
[3689] | 186 | |
---|
[3962] | 187 | |
---|
| 188 | v.join() |
---|