Changeset 534
- Timestamp:
- Nov 15, 2004, 11:08:25 AM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/analytical solutions/Analytical_solution_Yoon_import_mesh.py
r514 r534 6 6 Geoscience Australia 7 7 8 Specific methods pertaining to the 2D shallow water equation9 are imported from shallow_water10 for use with the generic finite volume framework11 12 Conserved quantities are h, uh and vh stored as elements 0, 1 and 2 in the13 numerical vector named conserved_quantities.14 8 """ 15 9 … … 22 16 sys.path.append('..'+sep+'pyvolution') 23 17 24 from shallow_water import Transmissive_boundary, Reflective_boundary, \ 25 Dirichlet_boundary 26 from domain import Domain 27 from Numeric import array 18 from shallow_water import Domain, Dirichlet_boundary 28 19 from math import sqrt, cos, sin, pi 29 20 … … 34 25 # Not required for this problem 35 26 36 from domain import Strang_domain27 from mesh_factory import strang_mesh 37 28 38 29 … … 42 33 # two or three entries. Two entries are for points and three for triangles. 43 34 44 domain = Strang_domain('yoon_circle.pt') 35 points, elements = strang_mesh('yoon_circle.pt') 36 domain = Domain(points, elements) 45 37 46 38 domain.default_order = 2 … … 49 41 50 42 # Provide file name for storing output 51 domain.filename="yoon_strang_second_order" 43 domain.store = True 44 domain.format = 'sww' 45 domain.filename='yoon_strang_second_order' 52 46 53 print "Number of triangles = ", len(Volume.instances)47 print 'Number of triangles = ', len(domain) 54 48 55 domain.visualise = False 56 domain.checkpoint = False # 57 domain.store = True #Store for visualisation purposes 58 domain.format = 'sww' #Native netcdf visualisation format 59 60 #Reduction operation for get_vertex_values 61 from pytools.stats import mean 49 #Reduction operation for get_vertex_values 50 from util import mean 62 51 domain.reduction = mean 63 52 #domain.reduction = min #Looks better near steep slopes … … 90 79 return z 91 80 92 domain.set_ field_values(x_slope, None)81 domain.set_quantity('elevation', x_slope) 93 82 94 95 #Set the water depth 96 def height(x,y): 83 #Set the water level (w = z+h) 84 def level(x,y): 97 85 z = x_slope(x,y) 98 86 n = x.shape[0] … … 106 94 return h 107 95 108 domain.set_ conserved_quantities(height, None, None)96 domain.set_quantity('level', level) 109 97 98 99 ############ 100 #Boundary 101 domain.set_boundary({'exterior': Dirichlet_boundary([0.0, 0.0, 0.0])}) 110 102 111 ######################112 #Visualisation113 if domain.visualise:114 visualise.create_surface(domain)115 116 103 117 104 ###################### 118 105 #Evolution 119 120 106 import time 121 107 t0 = time.time() 122 for t in domain.evolve( max_timestep = 1.0,yieldstep = 10.0, finaltime = 300):108 for t in domain.evolve(yieldstep = 10.0, finaltime = 300): 123 109 domain.write_time() 124 110 125 # Remove the following if Visual Python not required126 if domain.visualise:127 visualise.update(domain, index=0, smooth=True)128 129 111 print 'That took %.2f seconds' %(time.time()-t0) 130 112 -
inundation/ga/storm_surge/pyvolution/mesh_factory.py
r488 r534 62 62 return points, elements, boundary 63 63 64 65 #FIXME: Get oblique and contracting and circular meshes from Chris66 64 67 65 … … 178 176 print 'Removed %d offending triangles out of %d' %(offending, len(lines)) 179 177 return points, triangles, values 178 179 180 181 def strang_mesh(filename): 182 """Read Strang generated mesh. 183 """ 184 185 from math import pi 186 from util import anglediff 187 188 189 fid = open(filename) 190 points = [] # List of x, y coordinates 191 triangles = [] # List of vertex ids as listed in the file 192 193 for line in fid.readlines(): 194 fields = line.split() 195 if len(fields) == 2: 196 # we are reading vertex coordinates 197 points.append([float(fields[0]), float(fields[1])]) 198 elif len(fields) == 3: 199 # we are reading triangle point id's (format ae+b) 200 triangles.append([int(float(fields[0]))-1, 201 int(float(fields[1]))-1, 202 int(float(fields[2]))-1]) 203 else: 204 raise 'wrong format in ' + filename 205 206 elements = [] #Final list of elements 207 208 for t in triangles: 209 #Get vertex coordinates 210 v0 = t[0] 211 v1 = t[1] 212 v2 = t[2] 213 214 x0 = points[v0][0] 215 y0 = points[v0][1] 216 x1 = points[v1][0] 217 y1 = points[v1][1] 218 x2 = points[v2][0] 219 y2 = points[v2][1] 220 221 #Check that points are arranged in counter clock-wise order 222 vec0 = [x1-x0, y1-y0] 223 vec1 = [x2-x1, y2-y1] 224 vec2 = [x0-x2, y0-y2] 225 226 a0 = anglediff(vec1, vec0) 227 a1 = anglediff(vec2, vec1) 228 a2 = anglediff(vec0, vec2) 229 230 if a0 < pi and a1 < pi and a2 < pi: 231 elements.append([v0, v1, v2]) 232 else: 233 elements.append([v0, v2, v1]) 234 235 return points, elements 236 237 238 239 #FIXME: These haven't been done yet 240 # def circular_mesh(m, n, radius=1.0, center = (0.0, 0.0), Triangle=Triangle, 241 # Mesh=Mesh, Point=Point): 242 # """Setup a circular grid of triangles 243 # with m+1 radial segments by n+1 points around the circuference 244 # and radius. If radius is are omitted the mesh defaults to the unit circle 245 # radius. 246 247 # radius: radius of circle 248 249 # Triangle refers to the actual class or subclass to be instantiated: 250 # e.g. if Volume is a subclass of Triangle, 251 # this function can be invoked with the keywords 252 # rectangular_mesh(...,Triangle=Volume, Mesh=Domain)""" 253 254 255 # from Numeric import array 256 # from visual import rate 257 # import math 258 259 # delta = radius/float(m) 260 261 # #Dictionary of vertex objects 262 # vertices = {} 263 # for i in range(n+1): 264 # theta = float(i)*(2*math.pi)/float(n) 265 # for j in range(m+1): 266 # delta = float(j)*radius/float(m) 267 # vertices[i,j] = Point(delta*math.cos(theta),delta*math.sin(theta)) 268 269 # #Construct 2 triangles per element 270 # elements = [] 271 # for i in range(n): 272 # for j in range(1,m): 273 # v1 = vertices[i,j+1] 274 # v2 = vertices[i,j] 275 # v3 = vertices[i+1,j+1] 276 # v4 = vertices[i+1,j] 277 278 # elements.append(Triangle(v4,v2,v3)) #Lower 279 # elements.append(Triangle(v1,v3,v2)) #Upper 280 281 # #Do the center 282 # v1 = vertices[0,0] 283 # for i in range(n): 284 # v2 = vertices[i,1] 285 # v3 = vertices[i+1,1] 286 287 # T = Triangle(v1,v2,v3) #center 288 # elements.append(T) 289 290 # return Mesh(elements) 291 292 # def oblique_mesh(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0), 293 # point_class=Point, element_class=Triangle, mesh_class=Mesh): 294 # """Setup a oblique grid of triangles 295 # with m segments in the x-direction and n segments in the y-direction 296 297 # Triangle refers to the actual class or subclass to be instantiated: 298 # e.g. if Volume is a subclass of Triangle, 299 # this function can be invoked with the keywords 300 # oblique_mesh(...,Triangle=Volume, Mesh=Domain) 301 # """ 302 303 # from Numeric import array 304 # from visual import rate 305 # import math 306 307 # from config import epsilon 308 309 # E = m*n*2 #Number of triangular elements 310 # P = (m+1)*(n+1) #Number of initial vertices 311 312 # initialise_consecutive_datastructure(P+E, E, 313 # point_class, 314 # element_class, 315 # mesh_class) 316 317 # deltax = lenx/float(m) 318 # deltay = leny/float(n) 319 # a = 0.75*lenx*math.tan(theta/180.*math.pi) 320 # x1 = lenx 321 # y1 = 0 322 # x2 = lenx 323 # y2 = leny 324 # x3 = 0.25*lenx 325 # y3 = leny 326 # x4 = x3 327 # y4 = 0 328 # a2 = a/(x1-x4) 329 # a1 = -a2*x4 330 # a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3) 331 # a3 = 1. - (a1 + a2*x3)/y3 - a4*x3 332 333 # # Dictionary of vertex objects 334 # vertices = {} 335 336 # for i in range(m+1): 337 # x = deltax*i 338 # for j in range(n+1): 339 # y = deltay*j 340 # if x > 0.25*lenx: 341 # y = a1 + a2*x + a3*y + a4*x*y 342 343 # vertices[i,j] = Point(x + origin[0],y + origin[1]) 344 345 # # Construct 2 elements per element 346 # elements = [] 347 # for i in range(m): 348 # for j in range(n): 349 # v1 = vertices[i,j+1] 350 # v2 = vertices[i,j] 351 # v3 = vertices[i+1,j+1] 352 # v4 = vertices[i+1,j] 353 354 # elements.append(element_class(v4,v3,v2)) #Lower 355 # elements.append(element_class(v1,v2,v3)) #Upper 356 357 # M = mesh_class(elements) 358 359 # #Set a default tagging 360 361 # for id, face in M.boundary: 362 363 # e = element_class.instances[id] 364 # x0, y0, x1, y1, x2, y2 = e.get_instance_vertex_coordinates() 365 366 # if face==2: 367 # #Left or right# 368 # if abs(x0-origin[0]) < epsilon: 369 # M.boundary[(id,face)] = 'left' 370 # elif abs(origin[0]+lenx-x0) < epsilon: 371 # M.boundary[(id,face)] = 'right' 372 # else: 373 # print face, id, id%m, m, n 374 # raise 'Left or Right Unknown boundary' 375 # elif face==1: 376 # #Top or bottom 377 # if x0 > 0.25*lenx and abs(y0-a1-a2*x0-origin[1]) < epsilon or\ 378 # x0 <= 0.25*lenx and abs(y0-origin[1]) < epsilon: 379 # M.boundary[(id,face)] = 'bottom' 380 # elif abs(origin[1]+leny-y0) < epsilon: 381 # M.boundary[(id,face)] = 'top' 382 # else: 383 # print face, id, id%m, m, n 384 # raise 'Top or Bottom Unknown boundary' 385 # else: 386 # print face, id, id%m, m, n 387 # raise 'Unknown boundary' 388 389 # return M 390 391 # def contracting_channel_mesh(m, n, x1 = 0.0, x2 = 1./3., x3 = 2./3., x4 = 1.0, 392 # y1 =0.0, y4 = -1./4., y8 = 1.0, 393 # origin = (0.0, 0.0), point_class=Point, 394 # element_class=Triangle, mesh_class=Mesh): 395 # """Setup a oblique grid of triangles 396 # with m segments in the x-direction and n segments in the y-direction 397 398 # Triangle refers to the actual class or subclass to be instantiated: 399 # e.g. if Volume is a subclass of Triangle, 400 # this function can be invoked with the keywords 401 # oblique_mesh(...,Triangle=Volume, Mesh=Domain) 402 # """ 403 404 # from Numeric import array 405 # from visual import rate# 406 407 # import math 408 409 # from config import epsilon 410 411 # E = m*n*2 #Number of triangular elements 412 # P = (m+1)*(n+1) #Number of initial vertices 413 414 # initialise_consecutive_datastructure(P+E, E, 415 # point_class, 416 # element_class, 417 # mesh_class) 418 419 # deltax = (x4 - x1)/float(m) 420 # deltay = (y8 - y1)/float(n) 421 # a = y4 - y1 422 423 # if y8 - a <= y1 + a: 424 # print a,y1,y4 425 # raise 'Constriction is too large reduce a' 426 427 # y2 = y1 428 # y3 = y4 429 # x5 = x4 430 # y5 = y8 - a 431 # x6 = x3 432 # y6 = y5 433 # x7 = x2 434 # y7 = y8 435 # x8 = x1 436 437 # a2 = a/(x3 - x2) 438 # a1 = a - a*x3/(x3 - x2) 439 # a4 = (-a + a2*(x7 - x6))/(x6 - x7)/y7 440 # a3 = (y7 - a1 - x7*a2 - a4*x7*y7)/y7 441 442 # # Dictionary of vertex objects 443 # vertices = {} 444 445 # for i in range(m+1): 446 # x = deltax*i 447 # for j in range(n+1): 448 # y = deltay*j 449 # if x > x2: 450 # if x < x3: 451 # y = a1 + a2*x + a3*y + a4*x*y 452 # else: 453 # y = a + y*(y5 - y4)/(y8 - y1) 454 455 # vertices[i,j] = Point(x + origin[0],y + origin[1]) 456 457 # # Construct 2 elements per element 458 # elements = [] 459 # for i in range(m): 460 # for j in range(n): 461 # v1 = vertices[i,j+1] 462 # v2 = vertices[i,j] 463 # v3 = vertices[i+1,j+1] 464 # v4 = vertices[i+1,j] 465 466 # elements.append(element_class(v4,v3,v2)) #Lower 467 # elements.append(element_class(v1,v2,v3)) #Upper 468 469 # M = mesh_class(elements) 470 471 # #Set a default tagging 472 473 # for id, face in M.boundary: 474 475 # e = element_class.instances[id] 476 # x_0, y_0, x_1, y_1, x_2, y_2 = e.get_instance_vertex_coordinates() 477 # lenx = x4 - x1 478 # if face==2: 479 # #Left or right# 480 # if abs(x_0-origin[0]) < epsilon: 481 # M.boundary[(id,face)] = 'left' 482 # elif abs(origin[0]+lenx-x_0) < epsilon: 483 # M.boundary[(id,face)] = 'right' 484 # else: 485 # print face, id, id%m, m, n 486 # raise 'Left or Right Unknown boundary' 487 # elif face==1: 488 # #Top or bottom 489 # if x_0 <= x2 and abs(y_0-y1-origin[1]) < epsilon or\ 490 # x_0 > x3 and abs(y_0-y3-origin[1]) < epsilon or\ 491 # x_0 > x2 and x_0 <= x3 and abs(y_0-(y2+(y3-y2)*(x_0-x2)/(x3-x2)+origin[1])) < epsilon: 492 # M.boundary[(id,face)] = 'bottom' 493 # elif x_0 <= x7 and abs(y_0-y8-origin[1]) < epsilon or\ 494 # x_0 > x6 and abs(y_0-y6-origin[1]) < epsilon or\ 495 # x_0 > x7 and x_0 <= x6 and abs(y_0-(y7+(y6-y7)*(x_0-x7)/(x6-x7)+origin[1])) < epsilon: 496 # M.boundary[(id,face)] = 'top' 497 # else: 498 # print face, id, id%m, m, n 499 # raise 'Top or Bottom Unknown boundary' 500 # else: 501 # print face, id, id%m, m, n 502 # raise 'Unknown boundary' 503 504 505 # # print id, face, M.boundary[(id,face)],x_0,y_0,x_1,y_1,x_2,y_2 506 507 # return M 508 509 510 511 # #Map from edge number to indices of associated vertices 512 # edge_map = ((1,2), (0,2), (0,1)) 513 514 515 516 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r527 r534 48 48 49 49 #Reduction operation for get_vertex_values 50 #from pytools.statsimport mean50 #from util import mean 51 51 #self.reduction = mean 52 52 self.reduction = min #Looks better near steep slopes … … 155 155 #Store model data, e.g. for visualisation 156 156 if self.store is True and self.time == 0.0: 157 self.initialise_storage() 157 self.initialise_storage() 158 print 'Storing results in ' + self.writer.filename 159 else: 160 print 'Results will not be stored.' 161 print 'To store results set domain.store = True' 158 162 159 163
Note: See TracChangeset
for help on using the changeset viewer.