[647] | 1 | """Example of shallow water wave equation analytical solution |
---|
| 2 | consists of a parabolic profile in a parabolic basin. Analytical |
---|
| 3 | solutiuon to this problem was derived by Carrier and Greenspan |
---|
| 4 | and used by Yoon and Chou. |
---|
| 5 | |
---|
| 6 | Copyright 2004 |
---|
| 7 | Christopher Zoppou, Stephen Roberts, Ole Nielsen, Duncan Gray |
---|
| 8 | Geoscience Australia |
---|
| 9 | |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | ###################### |
---|
| 13 | # Module imports |
---|
| 14 | import sys |
---|
| 15 | from os import sep |
---|
| 16 | sys.path.append('..'+sep+'pyvolution') |
---|
| 17 | |
---|
| 18 | from shallow_water import Transmissive_boundary, Reflective_boundary, \ |
---|
| 19 | Dirichlet_boundary, Domain |
---|
| 20 | from math import sqrt, cos, sin, pi |
---|
| 21 | from mesh_factory import strang_mesh |
---|
| 22 | from pmesh2domain import pmesh_to_domain_instance |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | ###################### |
---|
| 26 | # Domain |
---|
| 27 | filename = 'Sydney_UBD.tsh' |
---|
| 28 | print 'Creating domain from', filename |
---|
| 29 | domain = pmesh_to_domain_instance(filename, Domain) |
---|
| 30 | print 'Number of triangles = ', len(domain) |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | domain.default_order = 2 |
---|
| 34 | domain.smooth = True |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | # Provide file name for storing output |
---|
| 38 | domain.store = True |
---|
| 39 | domain.format = 'sww' |
---|
| 40 | domain.filename = 'sydney' |
---|
| 41 | |
---|
| 42 | print 'Number of triangles = ', len(domain) |
---|
| 43 | |
---|
| 44 | #Reduction operation for get_vertex_values |
---|
| 45 | from util import mean |
---|
| 46 | domain.reduction = mean |
---|
| 47 | #domain.reduction = min #Looks better near steep slopes |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | ###################### |
---|
| 51 | #Initial condition |
---|
| 52 | # |
---|
| 53 | print 'Initial condition' |
---|
| 54 | |
---|
| 55 | #Set bed-elevation and friction(None) |
---|
| 56 | def x_slope(x,y): |
---|
| 57 | n = x.shape[0] |
---|
| 58 | z = 0*x |
---|
| 59 | return z |
---|
| 60 | |
---|
| 61 | domain.set_quantity('elevation', x_slope) |
---|
| 62 | |
---|
| 63 | #Set the initial water level |
---|
| 64 | def level(x,y): |
---|
| 65 | z = x_slope(x,y) |
---|
| 66 | n = x.shape[0] |
---|
| 67 | h = 0*x |
---|
| 68 | return h |
---|
| 69 | |
---|
| 70 | domain.set_quantity('level', level) |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | ############ |
---|
| 74 | #Boundary |
---|
| 75 | tags = {} |
---|
| 76 | #tags['input'] = Dirichlet_boundary([10.0, 0.0, 0.0]) |
---|
| 77 | tags['reflective'] = Reflective_boundary(domain) |
---|
| 78 | #tags['far'] = Transmissive_boundary(domain) |
---|
| 79 | tags['far'] = Dirichlet_boundary([10.0, 0.0, 0.0]) |
---|
| 80 | domain.set_boundary(tags) |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | ###################### |
---|
| 84 | #Evolution |
---|
| 85 | import time |
---|
| 86 | t0 = time.time() |
---|
| 87 | for t in domain.evolve(yieldstep = 10.0, finaltime = 5): |
---|
| 88 | domain.write_time() |
---|
| 89 | |
---|
| 90 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 91 | |
---|
| 92 | |
---|