[1266] | 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 | # |
---|
[1597] | 11 | #import rpdb |
---|
| 12 | #rpdb.set_active() |
---|
[1585] | 13 | |
---|
[1266] | 14 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
[1387] | 15 | Transmissive_boundary, Constant_height, Constant_stage |
---|
[1266] | 16 | |
---|
| 17 | from mesh_factory import rectangular |
---|
| 18 | from Numeric import array |
---|
| 19 | |
---|
| 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 | |
---|
[1295] | 68 | |
---|
[1266] | 69 | #Wall |
---|
[1393] | 70 | if x[i] > 0.995: |
---|
| 71 | z[i] = -x[i]/20+0.3 |
---|
[1266] | 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 |
---|
[1697] | 85 | N = 50 |
---|
[1266] | 86 | |
---|
[1392] | 87 | |
---|
[1266] | 88 | #N = 15 |
---|
| 89 | |
---|
| 90 | print 'Creating domain' |
---|
| 91 | #Create basic mesh |
---|
[2105] | 92 | points, elements, boundary = rectangular(N, N) |
---|
[1266] | 93 | |
---|
| 94 | #Create shallow water domain |
---|
[2105] | 95 | domain = Domain(points, elements, boundary, use_inscribed_circle=True) |
---|
[1266] | 96 | |
---|
| 97 | domain.check_integrity() |
---|
| 98 | domain.default_order = 2 |
---|
| 99 | #domain.beta_h=0 |
---|
| 100 | |
---|
| 101 | #Output params |
---|
| 102 | domain.smooth = False |
---|
| 103 | domain.reduction = min #Looks a lot better on top of steep slopes |
---|
| 104 | |
---|
| 105 | print "Number of triangles = ", len(domain) |
---|
[1828] | 106 | print "Extent = ", domain.get_extent() |
---|
[1266] | 107 | |
---|
[1295] | 108 | #Set bed-slope and friction |
---|
[2105] | 109 | inflow_stage = 0.5 |
---|
[1393] | 110 | manning = 0.03 |
---|
[1295] | 111 | Z = Weir(inflow_stage) |
---|
[1266] | 112 | |
---|
[1636] | 113 | if N > 150: |
---|
[1266] | 114 | domain.visualise = False |
---|
| 115 | domain.checkpoint = False |
---|
| 116 | domain.store = True #Store for visualisation purposes |
---|
| 117 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 118 | import sys, os |
---|
| 119 | #FIXME: This was os.path.splitext but caused weird filenames based on root |
---|
| 120 | base = os.path.basename(sys.argv[0]) |
---|
| 121 | domain.filename, _ = os.path.splitext(base) |
---|
| 122 | else: |
---|
[1599] | 123 | domain.initialise_visualiser(rect=[0.0,0.0,1.0,1.0]) |
---|
[1688] | 124 | #domain.initialise_visualiser() |
---|
| 125 | #domain.visualiser.coloring['stage'] = False |
---|
[1295] | 126 | domain.visualise_timer = True |
---|
[1266] | 127 | domain.checkpoint = False |
---|
| 128 | domain.store = False |
---|
| 129 | |
---|
| 130 | |
---|
[1360] | 131 | |
---|
[1510] | 132 | |
---|
[1266] | 133 | print 'Field values' |
---|
| 134 | domain.set_quantity('elevation', Z) |
---|
| 135 | domain.set_quantity('friction', manning) |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | ###################### |
---|
| 139 | # Boundary conditions |
---|
| 140 | # |
---|
| 141 | print 'Boundaries' |
---|
| 142 | Br = Reflective_boundary(domain) |
---|
| 143 | Bt = Transmissive_boundary(domain) |
---|
| 144 | |
---|
| 145 | #Constant inflow |
---|
[1295] | 146 | Bd = Dirichlet_boundary([inflow_stage, 0.0, 0.0]) |
---|
[1266] | 147 | |
---|
| 148 | |
---|
| 149 | #Set boundary conditions |
---|
| 150 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | ###################### |
---|
| 154 | #Initial condition |
---|
| 155 | # |
---|
| 156 | print 'Initial condition' |
---|
[2105] | 157 | domain.set_quantity('stage', Constant_height(Z, 0.0)) |
---|
| 158 | #domain.set_quantity('stage', Constant_stage(inflow_stage/2.0)) |
---|
[1266] | 159 | |
---|
| 160 | #Evolve |
---|
| 161 | import time |
---|
| 162 | t0 = time.time() |
---|
| 163 | |
---|
[1393] | 164 | |
---|
[1688] | 165 | #from realtime_visualisation_new import Visualiser |
---|
| 166 | #V = Visualiser(domain,title='netherlands') |
---|
| 167 | #V.update_quantity('stage') |
---|
| 168 | #V.update_quantity('elevation') |
---|
[1585] | 169 | |
---|
[2105] | 170 | for t in domain.evolve(yieldstep = 0.005, finaltime = 15.0): |
---|
[1266] | 171 | domain.write_time() |
---|
[2105] | 172 | #domain.write_boundary() |
---|
| 173 | |
---|
[1751] | 174 | print domain.quantities['stage'].get_values(location='centroids', |
---|
| 175 | indices=[0]) |
---|
[1688] | 176 | #V.update_quantity('stage') |
---|
[1597] | 177 | #rpdb.set_active() |
---|
[1387] | 178 | #domain.visualiser.scale_z = 1.0 |
---|
[1393] | 179 | #domain.visualiser.update_quantity_color('xmomentum',scale_z = 4.0) |
---|
| 180 | #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral() |
---|
[1266] | 181 | |
---|
| 182 | |
---|
| 183 | print 'That took %.2f seconds' %(time.time()-t0) |
---|