[2229] | 1 | """ |
---|
| 2 | Author: John Jakeman |
---|
| 3 | Created: 12/12/2005 |
---|
| 4 | Main Cairns script using new interface |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | #------------------------------- |
---|
| 8 | # Module imports |
---|
| 9 | #------------------------------- |
---|
| 10 | import sys, os |
---|
| 11 | from pyvolution.shallow_water import Domain, Reflective_boundary,\ |
---|
[2312] | 12 | File_boundary, Transmissive_Momentum_Set_Stage_boundary,\ |
---|
| 13 | Transmissive_boundary, Dirichlet_boundary |
---|
[2229] | 14 | from pyvolution.mesh_factory import rectangular_cross |
---|
| 15 | from pyvolution.pmesh2domain import pmesh_to_domain_instance |
---|
| 16 | from Numeric import array, zeros, Float, allclose |
---|
[2270] | 17 | #import cairns_project |
---|
| 18 | import project |
---|
[2229] | 19 | from caching import cache |
---|
| 20 | from utilities.polygon import read_polygon, Polygon_function |
---|
| 21 | |
---|
[2312] | 22 | from conversion import convert_latlon_to_xycoords |
---|
| 23 | |
---|
[2229] | 24 | #------------------------------- |
---|
| 25 | # Domain |
---|
| 26 | #------------------------------- |
---|
| 27 | print 'Creating domain' |
---|
[2312] | 28 | |
---|
[2270] | 29 | """ |
---|
| 30 | M = 36 #float(len1)/m |
---|
| 31 | N = 10 #float(len2)/n |
---|
[2229] | 32 | |
---|
| 33 | points, elements, boundary = rectangular_cross(M, N, len1=6393693.9504678631, |
---|
| 34 | len2=1781111.2941870166, |
---|
| 35 | origin = (0.0, 0.0)) |
---|
| 36 | |
---|
| 37 | #points, elements, boundary = rectangular_cross(N, M, len1=58.0, len2=1.0, origin=(145.0,-24.0)) |
---|
| 38 | |
---|
[2270] | 39 | domain = cache(Domain, (points, elements, boundary)) |
---|
[2229] | 40 | |
---|
[2270] | 41 | """ |
---|
[2312] | 42 | |
---|
[2270] | 43 | domain = cache(pmesh_to_domain_instance, |
---|
| 44 | (project.mesh_filename, Domain), |
---|
| 45 | dependencies = [project.mesh_filename]) |
---|
| 46 | |
---|
[2229] | 47 | domain.check_integrity() |
---|
| 48 | print 'Number of triangles = ', len(domain) |
---|
| 49 | print 'The extent is ', domain.get_extent() |
---|
| 50 | |
---|
| 51 | #--------------------------------------------------------- |
---|
| 52 | #Decide which quantities are to be stored at each timestep |
---|
| 53 | domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] |
---|
| 54 | |
---|
| 55 | #------------------------------- |
---|
| 56 | # Initial Conditions |
---|
| 57 | #------------------------------- |
---|
| 58 | print 'Initial values' |
---|
| 59 | |
---|
[2312] | 60 | latlong_origin = 145, -24 |
---|
| 61 | r0 = convert_latlon_to_xycoords(-173,-20,latlong_origin) |
---|
| 62 | r1 = convert_latlon_to_xycoords(-173,-15,latlong_origin) |
---|
| 63 | r2 = convert_latlon_to_xycoords(-171,-15,latlong_origin) |
---|
| 64 | r3 = convert_latlon_to_xycoords(-171,-20,latlong_origin) |
---|
| 65 | |
---|
| 66 | #p0 = read_polygon('cairns_fault.xya') |
---|
[2229] | 67 | #p0 = read_polygon('cairns_fault_degrees.xya') |
---|
[2312] | 68 | p0 = [r0, r1, r2, r3] |
---|
| 69 | domain.set_quantity('stage',Polygon_function([(p0,1.0)])) |
---|
[2229] | 70 | |
---|
| 71 | #print domain.quantities['stage'].vertex_values |
---|
| 72 | |
---|
| 73 | domain.set_quantity('elevation', |
---|
[2270] | 74 | filename = project.bathymetry_filename[:-4] + '.xya', |
---|
[2229] | 75 | alpha = 10.0, |
---|
| 76 | verbose = True, |
---|
| 77 | use_cache = True) |
---|
| 78 | |
---|
| 79 | # Need to increase elevation by the same amount as the stage |
---|
| 80 | # At present unsure how to achieve this |
---|
| 81 | #domain.set_quantity('elevation',Polygon_function([domain.quantities['elevation'].vertex_values+1000.0])) |
---|
| 82 | |
---|
| 83 | domain.set_quantity('friction', 0.0) |
---|
| 84 | |
---|
| 85 | #------------------------------- |
---|
| 86 | # Boundary conditions |
---|
| 87 | #------------------------------- |
---|
| 88 | print 'Boundaries' |
---|
| 89 | |
---|
| 90 | #Bts = Transmissive_Momentum_Set_Stage_boundary(domain, tide_function) |
---|
[2312] | 91 | #Bd = Dirichlet_boundary([0,0,0]) |
---|
[2270] | 92 | Br = Reflective_boundary(domain) |
---|
| 93 | domain.set_boundary({'border': Br, 'border': Br, 'border': Br, 'border': Br}) |
---|
[2229] | 94 | |
---|
[2270] | 95 | #Bt = Transmissive_boundary(domain) |
---|
[2312] | 96 | #domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) |
---|
[2229] | 97 | |
---|
| 98 | #------------------------------- |
---|
| 99 | # Setup domain runtime parameters |
---|
| 100 | #------------------------------- |
---|
[2270] | 101 | |
---|
[2312] | 102 | #domain.visualise = True |
---|
| 103 | #domain.visualise_color_stage = True |
---|
[2229] | 104 | |
---|
[2312] | 105 | #Set domain.visualise = False for large problem sizes |
---|
| 106 | domain.visualise = False |
---|
| 107 | domain.visualise_color_stage = False |
---|
[2270] | 108 | |
---|
[2229] | 109 | base = os.path.basename(sys.argv[0]) |
---|
| 110 | domain.filename, _ = os.path.splitext(base) |
---|
| 111 | domain.default_order = 2 |
---|
| 112 | domain.store = True #Store for visualisation purposes |
---|
| 113 | |
---|
| 114 | #------------------------------- |
---|
| 115 | # Evolve |
---|
| 116 | #------------------------------- |
---|
| 117 | import time |
---|
| 118 | t0 = time.time() |
---|
[2270] | 119 | yieldstep = 60.0 |
---|
[2312] | 120 | finaltime = 21600.0 |
---|
[2229] | 121 | |
---|
| 122 | for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): |
---|
| 123 | domain.write_time() |
---|
| 124 | |
---|
| 125 | print 'That took %.2f seconds' %(time.time()-t0) |
---|