[2229] | 1 | """ |
---|
| 2 | Example of shallow water wave equation |
---|
| 3 | consisting of an asymetrical converging channel. |
---|
| 4 | |
---|
| 5 | Copyright 2004 |
---|
| 6 | Christopher Zoppou, Stephen Roberts, Ole Nielsen, Duncan Gray |
---|
| 7 | Geoscience Australia, ANU |
---|
| 8 | |
---|
| 9 | Specific methods pertaining to the 2D shallow water equation |
---|
| 10 | are imported from shallow_water |
---|
| 11 | for use with the generic finite volume framework |
---|
| 12 | |
---|
| 13 | Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the |
---|
| 14 | numerical vector named conserved_quantities. |
---|
| 15 | |
---|
| 16 | """ |
---|
| 17 | |
---|
| 18 | ###################### |
---|
| 19 | # Module imports |
---|
| 20 | # |
---|
| 21 | |
---|
| 22 | #Were these used? |
---|
| 23 | #import visualise2_chris as visualise |
---|
| 24 | #import Image, ImageGrab |
---|
| 25 | |
---|
[3652] | 26 | from anuga.shallow_water import Domain |
---|
| 27 | from anuga.shallow_water import Transmissive_boundary, Reflective_boundary,\ |
---|
[2229] | 28 | Dirichlet_boundary , Transmissive_Momentum_Set_Stage_boundary |
---|
| 29 | |
---|
| 30 | from math import sqrt, cos, sin, pi |
---|
| 31 | from mesh_factory import oblique_cross |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | ###################### |
---|
| 35 | # Domain |
---|
| 36 | # |
---|
| 37 | leny = 30. |
---|
| 38 | lenx = 40. |
---|
[3657] | 39 | f = 2 |
---|
| 40 | n = 50*f |
---|
[2229] | 41 | m = 80*f |
---|
| 42 | theta = 25 |
---|
| 43 | h_bc = 1.5 |
---|
| 44 | p_bc = 5.0 |
---|
| 45 | |
---|
| 46 | points, elements, boundary = oblique_cross(m, n, lenx, leny, theta = theta) |
---|
| 47 | domain = Domain(points, elements, boundary) |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | print 'Number of Elements = ',domain.number_of_elements |
---|
| 51 | # Order of solver |
---|
| 52 | domain.default_order=2 |
---|
| 53 | domain.beta_w = 0.8 |
---|
| 54 | |
---|
| 55 | # Store output |
---|
| 56 | domain.store=True |
---|
| 57 | |
---|
| 58 | # Provide file name for storing output |
---|
[3846] | 59 | domain.set_name('oblique_cross_%g_%g_%g_%g_%g' % (n,m,theta,h_bc,p_bc)) |
---|
| 60 | print domain.get_name() |
---|
[2229] | 61 | |
---|
| 62 | # Output format |
---|
| 63 | domain.format="sww" #NET.CDF binary format |
---|
| 64 | # "dat" for ASCII |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | # Visualization smoothing |
---|
[3657] | 68 | domain.smooth=True |
---|
[2229] | 69 | domain.visualise=False |
---|
| 70 | |
---|
| 71 | ####################### |
---|
| 72 | #Bed-slope and friction |
---|
| 73 | class ConstantFunctionT: |
---|
| 74 | |
---|
| 75 | def __init__(self,value): |
---|
| 76 | self.value = value |
---|
| 77 | |
---|
| 78 | def __call__(self,t): |
---|
| 79 | return self.value |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | shock_hb = ConstantFunctionT(h_bc) |
---|
| 83 | shock_hh = ConstantFunctionT(h_bc) |
---|
| 84 | shock_pb = ConstantFunctionT(p_bc) |
---|
| 85 | shock_pp = ConstantFunctionT(p_bc) |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | def x_slope(x, y): |
---|
| 89 | return 0*x |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | def shock_h(x,y): |
---|
| 94 | n = x.shape[0] |
---|
| 95 | w = 0*x |
---|
| 96 | for i in range(n): |
---|
| 97 | if x[i]<0: |
---|
| 98 | w[i] = shock_hh(0.0) |
---|
| 99 | else: |
---|
| 100 | w[i] = 1.0 |
---|
| 101 | return w |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | def shock_p(x,y): |
---|
| 105 | n = x.shape[0] |
---|
| 106 | w = 0*x |
---|
| 107 | for i in range(n): |
---|
| 108 | if x[i]<0: |
---|
| 109 | w[i] = shock_pp(0.0) |
---|
| 110 | else: |
---|
| 111 | w[i] = 0.0 |
---|
| 112 | return w |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | domain.set_quantity('elevation', x_slope) |
---|
| 119 | domain.set_quantity('friction', 0.0) |
---|
| 120 | |
---|
| 121 | ###################### |
---|
| 122 | # Boundary conditions |
---|
| 123 | # |
---|
| 124 | R = Reflective_boundary(domain) |
---|
| 125 | T = Transmissive_boundary(domain) |
---|
| 126 | D = Dirichlet_boundary([shock_hb(0.0) , shock_pb(0.0), 0.0]) |
---|
| 127 | Bts = Transmissive_Momentum_Set_Stage_boundary(domain, shock_hb) |
---|
| 128 | |
---|
| 129 | domain.set_boundary({'left': D, 'right': T, 'top': R, 'bottom': R}) |
---|
| 130 | |
---|
| 131 | ###################### |
---|
| 132 | #Initial condition |
---|
| 133 | |
---|
| 134 | domain.set_quantity('stage', shock_h ) |
---|
| 135 | domain.set_quantity('xmomentum',shock_p ) |
---|
| 136 | |
---|
| 137 | class SetValueWhere: |
---|
| 138 | |
---|
| 139 | def __init__(self,quantity,value=0,xrange=0.0): |
---|
| 140 | self.quantity = quantity |
---|
| 141 | self.value = value |
---|
| 142 | self.xrange = xrange |
---|
| 143 | |
---|
| 144 | def __call__(self,x,y): |
---|
| 145 | n = x.shape[0] |
---|
| 146 | w = self.quantity.centroid_values |
---|
| 147 | for i in range(n): |
---|
| 148 | if x[i]<self.xrange: |
---|
| 149 | w[i] = self.value |
---|
| 150 | return w |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | Stage = domain.quantities['stage'] |
---|
| 154 | Xmom = domain.quantities['xmomentum'] |
---|
| 155 | Ymom = domain.quantities['ymomentum'] |
---|
| 156 | |
---|
| 157 | #for id, face in domain.boundary: |
---|
| 158 | # print '(',id,',',face,') ',domain.boundary[(id,face)] |
---|
| 159 | |
---|
| 160 | ###################### |
---|
| 161 | #Evolution |
---|
| 162 | import time |
---|
| 163 | t0 = time.time() |
---|
[3657] | 164 | for t in domain.evolve(yieldstep = 0.1, finaltime = 20.0): |
---|
[2229] | 165 | domain.write_time() |
---|
| 166 | id = 3399 |
---|
| 167 | print Stage.get_values(location='centroids',indices=[id]) |
---|
| 168 | print Xmom.get_values(location='centroids',indices=[id]) |
---|
| 169 | print Ymom.get_values(location='centroids',indices=[id]) |
---|
| 170 | vstage = Stage.get_values(location='centroids',indices=[id]) |
---|
| 171 | vxmom = Xmom.get_values(location='centroids',indices=[id]) |
---|
| 172 | id = 12719 |
---|
| 173 | print Stage.get_values(location='centroids',indices=[id]) |
---|
| 174 | print Xmom.get_values(location='centroids',indices=[id]) |
---|
| 175 | print Ymom.get_values(location='centroids',indices=[id]) |
---|
| 176 | tclean = 2.0 |
---|
| 177 | # if t > tclean-0.09 and t < tclean+0.01: |
---|
| 178 | # print 'Cleaning up Initial profile' |
---|
| 179 | # setstage = SetValueWhere(quantity=Stage,value=vstage[0],xrange=10) |
---|
| 180 | # setxmom = SetValueWhere(quantity=Xmom,value=vxmom[0],xrange=10) |
---|
| 181 | # Stage.set_values(setstage,location='centroids') |
---|
| 182 | # Xmom.set_values(setxmom,location='centroids') |
---|
| 183 | # Dnew = Dirichlet_boundary([vstage[0] , vxmom[0], 0.0]) |
---|
| 184 | # domain.set_boundary({'left': Dnew, 'right': T, 'top': R, 'bottom': R}) |
---|
| 185 | |
---|
| 186 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 187 | |
---|
| 188 | #FIXME: Compute average water depth on either side of shock and compare |
---|
| 189 | #to expected values. And also Froude numbers. |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | #print "saving file?" |
---|
| 193 | #im = ImageGrab.grab() |
---|
| 194 | #im.save("ccube.eps") |
---|