Changeset 1266
- Timestamp:
- May 2, 2005, 12:02:12 AM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/netherlands.py
r991 r1266 7 7 8 8 ###################### 9 # Module imports 9 # Module imports 10 10 # 11 11 from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ … … 14 14 from mesh_factory import rectangular 15 15 from Numeric import array 16 16 17 17 18 18 class Weir: … … 20 20 x,y are assumed to be in the unit square 21 21 """ 22 22 23 23 def __init__(self, stage): 24 24 self.inflow_stage = stage 25 25 26 def __call__(self, x, y): 27 from Numeric import zeros, Float 28 26 def __call__(self, x, y): 27 from Numeric import zeros, Float 28 29 29 N = len(x) 30 assert N == len(y) 30 assert N == len(y) 31 31 32 32 z = zeros(N, Float) … … 38 38 #z[i] = -x[i]/5 39 39 z[i] = -x[i]/20 40 41 40 41 42 42 #Weir 43 43 if x[i] > 0.3 and x[i] < 0.4: … … 53 53 #z[i] = -x[i]/5 54 54 z[i] = -x[i]/20 55 55 56 56 #Poles 57 57 #if x[i] > 0.65 and x[i] < 0.8 and y[i] > 0.55 and y[i] < 0.65 or\ … … 65 65 #Wall 66 66 if x[i] > 0.995: 67 z[i] = -x[i]/20+0.3 67 z[i] = -x[i]/20+0.3 68 68 69 69 return z/2 70 71 72 70 71 72 73 73 ###################### 74 74 # Domain … … 79 79 N = 130 #size = 33800 80 80 N = 600 #Size = 720000 81 N = 3081 N = 50 82 82 83 83 #N = 15 … … 89 89 #Create shallow water domain 90 90 domain = Domain(points, vertices, boundary) 91 91 92 92 domain.check_integrity() 93 93 domain.default_order = 2 … … 101 101 102 102 103 if N > 40:103 if N > 150: 104 104 domain.visualise = False 105 105 domain.checkpoint = False … … 113 113 domain.visualise = True 114 114 domain.checkpoint = False 115 domain.store = False 115 domain.store = False 116 116 117 117 118 118 #Set bed-slope and friction 119 inflow_stage = 0. 08119 inflow_stage = 0.1 120 120 manning = 0.02 121 121 Z = Weir(inflow_stage) … … 139 139 #Set boundary conditions 140 140 domain.set_boundary({'left': Bd, 'right': Br, 'bottom': Br, 'top': Br}) 141 141 142 142 143 143 ###################### … … 151 151 t0 = time.time() 152 152 153 for t in domain.evolve(yieldstep = 0. 1, finaltime = 7.0):153 for t in domain.evolve(yieldstep = 0.005, finaltime = 10.0): 154 154 domain.write_time() 155 156 print 'That took %.2f seconds' %(time.time()-t0) 157 155 156 157 print 'That took %.2f seconds' %(time.time()-t0) -
inundation/ga/storm_surge/pyvolution/realtime_visualisation_new.py
r1265 r1266 2 2 3 3 class Surface: 4 def __init__(self,domain,scale =1.0/1.0):4 def __init__(self,domain,scale_z=1.0): 5 5 """Create visualisation of domain 6 6 """ … … 10 10 self.stage_model = faces(frame=self.frame) 11 11 self.domain = domain 12 self.scale = scale12 self.scale_z = scale_z 13 13 14 14 self.vertices = domain.vertex_coordinates … … 29 29 self.range_bed = self.max_bed - self.min_bed 30 30 31 print self.max_x, self.min_x, self.max_y, self.min_y, self.min_bed32 print self.max_bed, self.range_x, self.range_y, self.range_xy, self.range_bed33 34 print 'Calculating triangles'31 #print self.max_x, self.min_x, self.max_y, self.min_y, 32 #self.min_bed print self.max_bed, self.range_x, self.range_y, 33 #self.range_xy, self.range_bed 34 #print 'Calculating triangles' 35 35 36 36 self.pos = zeros( (6*len(domain),3), Float) … … 38 38 self.normals = zeros( (6*len(domain),3), Float) 39 39 40 print 'keys',self.domain.quantities.keys()41 print 'shape of stage',shape(self.stage)40 #print 'keys',self.domain.quantities.keys() 41 #print 'shape of stage',shape(self.stage) 42 42 43 43 self.update_all() … … 50 50 def update_bed(self): 51 51 52 print 'update bed arrays'52 #print 'update bed arrays' 53 53 c0 = 0.3 54 54 c1 = 0.3 55 55 c2 = 0.3 56 56 self.update_arrays(self.bed, (c0,c1,c2) ) 57 print 'update bed image' 57 58 #print 'update bed image' 58 59 self.bed_model.pos = self.pos 59 60 self.bed_model.color = self.colour … … 65 66 c1 = 0.4 66 67 c2 = 0.99 67 print 'update stage arrays'68 #print 'update stage arrays' 68 69 self.update_arrays(self.stage, (c0,c1,c2) ) 69 print 'update stage image'70 #print 'update stage image' 70 71 self.stage_model.pos = self.pos 71 72 self.stage_model.color = self.colour 72 73 self.stage_model.normal = self.normals 73 74 74 def calc_normal(self,v): 75 76 from math import sqrt 77 78 cross = zeros(3,Float) 79 normal = zeros(3,Float) 75 76 77 def update_arrays(self,quantity,qcolor): 78 79 col = asarray(qcolor) 80 81 N = len(self.domain) 82 83 scale_z = self.scale_z 84 min_x = self.min_x 85 min_y = self.min_y 86 range_xy = self.range_xy 87 88 vertices = self.vertices 89 pos = self.pos 90 normals = self.normals 91 colour = self.colour 92 93 try: 94 update_arrays_weave(vertices,quantity,col,pos,normals,colour,N,min_x,min_y,range_xy,scale_z) 95 except: 96 update_arrays_python(vertices,quantity,col,pos,normals,colour,N,min_x,min_y,range_xy,scale_z) 97 98 99 100 def update_arrays_python(vertices,quantity,col,pos,normals,colour,N,min_x,min_y,range_xy,scale_z): 101 102 from math import sqrt 103 normal = zeros( 3, Float) 104 v = zeros( (3,3), Float) 105 s = 1.0 106 107 for i in range( N ): 108 109 for j in range(3): 110 v[j,0] = (vertices[i,2*j ]-min_x)/range_xy 111 v[j,1] = (vertices[i,2*j+1]-min_y)/range_xy 112 v[j,2] = quantity[i,j]*scale_z 80 113 81 114 v10 = v[1,:]-v[0,:] … … 92 125 normal[2] = normal[2]/norm 93 126 94 return normal 95 96 97 98 def update_arrays(self, quantity, qcolor): 99 100 col = asarray(qcolor) 101 v = zeros( (3,3), Float) 102 normal = zeros( 3, Float) 103 N = len(self.domain) 104 scale = self.scale 105 106 107 108 for i in range( N ): 109 110 for j in range(3): 111 v[j,0] = 2.0*(self.vertices[i,2*j ]-self.min_x)/self.range_xy-1.0 112 v[j,1] = 2.0*(self.vertices[i,2*j+1]-self.min_y)/self.range_xy-1.0 113 v[j,2] = quantity[i,j]*scale 114 115 116 117 normal = self.calc_normal(v) 118 119 self.pos[6*i ,:] = v[0,:] 120 self.pos[6*i+1,:] = v[1,:] 121 self.pos[6*i+2,:] = v[2,:] 122 self.pos[6*i+3,:] = v[0,:] 123 self.pos[6*i+4,:] = v[2,:] 124 self.pos[6*i+5,:] = v[1,:] 125 126 127 128 self.colour[6*i ,:] = col 129 self.colour[6*i+1,:] = col 130 self.colour[6*i+2,:] = col 131 self.colour[6*i+3,:] = col 132 self.colour[6*i+4,:] = col 133 self.colour[6*i+5,:] = col 134 135 self.normals[6*i ,:] = normal 136 self.normals[6*i+1,:] = normal 137 self.normals[6*i+2,:] = normal 138 self.normals[6*i+3,:] = -normal 139 self.normals[6*i+4,:] = -normal 140 self.normals[6*i+5,:] = -normal 141 142 143 144 145 #scene.width = 1000 146 #scene.height = 800 127 pos[6*i ,:] = v[0,:] 128 pos[6*i+1,:] = v[1,:] 129 pos[6*i+2,:] = v[2,:] 130 pos[6*i+3,:] = v[0,:] 131 pos[6*i+4,:] = v[2,:] 132 pos[6*i+5,:] = v[1,:] 133 134 135 136 colour[6*i ,:] = s*col 137 colour[6*i+1,:] = s*col 138 colour[6*i+2,:] = s*col 139 colour[6*i+3,:] = s*col 140 colour[6*i+4,:] = s*col 141 colour[6*i+5,:] = s*col 142 143 s = 15.0/8.0 - s 144 145 normals[6*i ,:] = normal 146 normals[6*i+1,:] = normal 147 normals[6*i+2,:] = normal 148 normals[6*i+3,:] = -normal 149 normals[6*i+4,:] = -normal 150 normals[6*i+5,:] = -normal 151 152 153 154 def update_arrays_weave(vertices,quantity,col,pos,normals,colour,N,min_x,min_y,range_xy,scale_z): 155 156 import weave 157 from weave import converters 158 159 from math import sqrt 160 normal = zeros( 3, Float) 161 v = zeros( (3,3), Float) 162 v10 = zeros( 3, Float) 163 v20 = zeros( 3, Float) 164 165 code1 = """ 166 double s = 1.0; 167 168 for (int i=0; i<N ; i++ ) { 169 for (int j=0; j<3 ; j++) { 170 v(j,0) = (vertices(i,2*j )-min_x)/range_xy; 171 v(j,1) = (vertices(i,2*j+1)-min_y)/range_xy; 172 v(j,2) = quantity(i,j)*scale_z; 173 } 174 175 176 for (int j=0; j<3; j++) { 177 v10(j) = v(1,j)-v(0,j); 178 v20(j) = v(2,j)-v(0,j); 179 } 180 181 normal(0) = v10(1)*v20(2) - v20(1)*v10(2); 182 normal(1) = v10(2)*v20(0) - v20(2)*v10(0); 183 normal(2) = v10(0)*v20(1) - v20(0)*v10(1); 184 185 double norm = sqrt(normal(0)*normal(0) + normal(1)*normal(1) + normal(2)*normal(2)); 186 187 normal(0) = normal(0)/norm; 188 normal(1) = normal(1)/norm; 189 normal(2) = normal(2)/norm; 190 191 for (int j=0; j<3; j++) { 192 pos(6*i ,j) = v(0,j); 193 pos(6*i+1,j) = v(1,j); 194 pos(6*i+2,j) = v(2,j); 195 pos(6*i+3,j) = v(0,j); 196 pos(6*i+4,j) = v(2,j); 197 pos(6*i+5,j) = v(1,j); 198 199 colour(6*i ,j) = s*col(j); 200 colour(6*i+1,j) = s*col(j); 201 colour(6*i+2,j) = s*col(j); 202 colour(6*i+3,j) = s*col(j); 203 colour(6*i+4,j) = s*col(j); 204 colour(6*i+5,j) = s*col(j); 205 206 normals(6*i ,j) = normal(j); 207 normals(6*i+1,j) = normal(j); 208 normals(6*i+2,j) = normal(j); 209 normals(6*i+3,j) = -normal(j); 210 normals(6*i+4,j) = -normal(j); 211 normals(6*i+5,j) = -normal(j); 212 } 213 214 s = 15.0/8.0 - s; 215 } 216 """ 217 218 weave.inline(code1, ['vertices','quantity','col','pos','normals','colour','N', 219 'min_x','min_y','range_xy','scale_z','v','normal','v10','v20'], 220 type_converters = converters.blitz, compiler='gcc'); 221 222 223 scene.width = 1000 224 scene.height = 800 147 225 148 226 #Original 149 #scene.center = (0.5,0.5,0)150 #scene.forward = vector(-0.1, 0.5, -0.5)227 scene.center = (0.5,0.5,0) 228 scene.forward = vector(-0.1, 0.5, -0.5) 151 229 152 230 #Temporary (for bedslope) … … 161 239 162 240 163 #scene.ambient = 0.4241 scene.ambient = 0.4 164 242 #scene.lights = [(0.6, 0.3, 0.2), (0.1, -0.5, 0.4), (-0.1, 0.1, -0.4), 165 243 # (-0.2, 0.2, 0.1)] 166 244 245 scene.lights = [(0.6, 0.3, 0.2), (0.1, -0.5, 0.4)] 246 247 167 248 168 249 def create_surface(domain): … … 173 254 def update(domain): 174 255 256 #print 'start visual update' 175 257 surface = domain.surface 176 258 surface.update_stage() 177 178 179 259 #print 'end visual update' 260 -
inundation/ga/storm_surge/zeus/anuga-workspace.zwi
r1231 r1266 2 2 <workspace name="anuga-workspace"> 3 3 <mode>Debug</mode> 4 <active> steve</active>4 <active>pyvolution</active> 5 5 <project name="pyvolution">pyvolution.zpi</project> 6 6 <project name="steve">steve.zpi</project>
Note: See TracChangeset
for help on using the changeset viewer.