[451] | 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 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
| 12 | Transmissive_boundary, Constant_height |
---|
| 13 | |
---|
| 14 | from mesh_factory import rectangular |
---|
| 15 | from Numeric import array |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | class Weir: |
---|
| 19 | """Set a bathymetry for simple weir with a hole. |
---|
| 20 | x,y are assumed to be in the unit square |
---|
| 21 | """ |
---|
| 22 | |
---|
| 23 | def __init__(self, stage): |
---|
| 24 | self.inflow_stage = stage |
---|
| 25 | |
---|
| 26 | def __call__(self, x, y): |
---|
| 27 | from Numeric import zeros, Float |
---|
| 28 | |
---|
| 29 | N = len(x) |
---|
| 30 | assert N == len(y) |
---|
| 31 | |
---|
| 32 | z = zeros(N, Float) |
---|
| 33 | for i in range(N): |
---|
| 34 | z[i] = -x[i]/20 #General slope |
---|
| 35 | |
---|
| 36 | #Flattish bit to the left |
---|
| 37 | if x[i] <= 0.3: |
---|
| 38 | #z[i] = -x[i]/5 |
---|
| 39 | z[i] = -x[i]/20 |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | #Weir |
---|
| 43 | if x[i] > 0.3 and x[i] < 0.4: |
---|
| 44 | z[i] = -x[i]/20+1.2 |
---|
| 45 | |
---|
| 46 | #Dip |
---|
| 47 | #if x[i] > 0.6 and x[i] < 0.9: |
---|
| 48 | # z[i] = -x[i]/20-0.5 #-y[i]/5 |
---|
| 49 | |
---|
| 50 | #Hole in weir |
---|
| 51 | #if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.2 and y[i] < 0.4: |
---|
| 52 | if x[i] > 0.3 and x[i] < 0.4 and y[i] > 0.4 and y[i] < 0.6: |
---|
| 53 | #z[i] = -x[i]/5 |
---|
| 54 | z[i] = -x[i]/20 |
---|
| 55 | |
---|
| 56 | #Poles |
---|
| 57 | #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\ |
---|
| 58 | # x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 59 | # z[i] = -x[i]/20+0.4 |
---|
| 60 | |
---|
| 61 | if (x[i] - 0.72)**2 + (y[i] - 0.6)**2 < 0.05**2:# or\ |
---|
| 62 | #x[i] > 0.75 and x[i] < 0.9 and y[i] > 0.35 and y[i] < 0.45: |
---|
| 63 | z[i] = -x[i]/20+0.4 |
---|
| 64 | |
---|
| 65 | #Wall |
---|
| 66 | if x[i] > 0.995: |
---|
| 67 | z[i] = -x[i]/20+0.3 |
---|
| 68 | |
---|
| 69 | return z/2 |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | ###################### |
---|
| 74 | # Domain |
---|
| 75 | # |
---|
| 76 | |
---|
| 77 | N = 250 |
---|
| 78 | #N= 8 |
---|
| 79 | N = 16 |
---|
| 80 | #N = 4 |
---|
| 81 | #N = 102 |
---|
| 82 | N = 25 |
---|
| 83 | N = 16 |
---|
| 84 | N = 60 |
---|
| 85 | N = 150 #size = 45000 |
---|
| 86 | N = 130 #size = 33800 |
---|
| 87 | #N = 60 |
---|
| 88 | #N = 40 |
---|
| 89 | N = 260 |
---|
| 90 | #N = 150 |
---|
| 91 | N = 264 |
---|
| 92 | |
---|
| 93 | N = 600 #Size = 720000 |
---|
| 94 | N = 20 |
---|
| 95 | #N = 150 |
---|
| 96 | N = 110 |
---|
[479] | 97 | N = 60 |
---|
[451] | 98 | |
---|
[901] | 99 | #N = 140 |
---|
[649] | 100 | |
---|
[901] | 101 | N = 15 |
---|
| 102 | |
---|
[451] | 103 | print 'Creating domain' |
---|
| 104 | #Create basic mesh |
---|
| 105 | points, vertices, boundary = rectangular(N, N) |
---|
| 106 | |
---|
| 107 | #Create shallow water domain |
---|
| 108 | domain = Domain(points, vertices, boundary) |
---|
| 109 | |
---|
| 110 | domain.check_integrity() |
---|
| 111 | domain.default_order = 2 |
---|
| 112 | |
---|
| 113 | #Output params |
---|
| 114 | domain.smooth = True |
---|
| 115 | domain.reduction = min #Looks a lot better on top of steep slopes |
---|
| 116 | |
---|
| 117 | print "Number of triangles = ", len(domain) |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | if N > 40: |
---|
| 121 | domain.visualise = False |
---|
| 122 | domain.checkpoint = False |
---|
| 123 | domain.store = True #Store for visualisation purposes |
---|
| 124 | domain.format = 'sww' #Native netcdf visualisation format |
---|
| 125 | import sys, os |
---|
[479] | 126 | #FIXME: This was os.path.splitext but caused weird filenames based on root |
---|
| 127 | base = os.path.basename(sys.argv[0]) |
---|
[649] | 128 | domain.filename, _ = os.path.splitext(base) |
---|
[451] | 129 | else: |
---|
| 130 | domain.visualise = True |
---|
| 131 | domain.checkpoint = False |
---|
| 132 | domain.store = False |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | #Set bed-slope and friction |
---|
| 136 | inflow_stage = 0.08 |
---|
| 137 | manning = 0.02 |
---|
| 138 | Z = Weir(inflow_stage) |
---|
| 139 | |
---|
| 140 | print 'Field values' |
---|
| 141 | domain.set_quantity('elevation', Z) |
---|
| 142 | domain.set_quantity('friction', manning) |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | ###################### |
---|
| 146 | # Boundary conditions |
---|
| 147 | # |
---|
| 148 | print 'Boundaries' |
---|
| 149 | Br = Reflective_boundary(domain) |
---|
| 150 | Bt = Transmissive_boundary(domain) |
---|
| 151 | |
---|
| 152 | #Constant inflow |
---|
| 153 | Bd = Dirichlet_boundary([2*inflow_stage, 0.0, 0.0]) |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | #Set boundary conditions |
---|
| 157 | domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | ###################### |
---|
| 161 | #Initial condition |
---|
| 162 | # |
---|
| 163 | print 'Initial condition' |
---|
[773] | 164 | domain.set_quantity('stage', Constant_height(Z, 0.)) |
---|
[451] | 165 | |
---|
| 166 | #Evolve |
---|
| 167 | import time |
---|
| 168 | t0 = time.time() |
---|
| 169 | |
---|
[649] | 170 | for t in domain.evolve(yieldstep = 0.01, finaltime = 7.0): |
---|
[451] | 171 | domain.write_time() |
---|
| 172 | |
---|
| 173 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 174 | |
---|