Changeset 541
- Timestamp:
- Nov 15, 2004, 1:51:59 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/analytical solutions/oblique_test_chris.py
r536 r541 12 12 # Module imports 13 13 # 14 15 #Were these used? 16 #import visualise2_chris as visualise 17 #import Image, ImageGrab 18 19 import sys 20 from os import sep 21 sys.path.append('..'+sep+'pyvolution') 22 23 24 from shallow_water import Domain, Constant_height 14 25 from shallow_water import Transmissive_boundary, Reflective_boundary,\ 15 26 Dirichlet_boundary 16 from domain import oblique_domain, rectangular_domain17 27 18 from shallow_water import Friction, Constant_height19 import visualise2_chris as visualise20 import Image, ImageGrab 28 from math import sqrt, cos, sin, pi 29 from mesh_factory import oblique 30 21 31 22 32 ###################### … … 28 38 lenx = 40. 29 39 30 domain = oblique_domain(m, n, lenx, leny ) 40 points, elements, boundary = oblique(m, n, lenx, leny) 41 domain = Domain(points, elements, boundary) 31 42 32 43 # Order of solver … … 51 62 return 0*x 52 63 53 domain.set_field_values(x_slope, Friction(0)) 64 domain.set_quantity('elevation', x_slope) 65 domain.set_quantity('friction', 0.0) 54 66 55 67 ###################### 56 68 # Boundary conditions 57 69 # 58 R = Reflective_boundary( )59 T = Transmissive_boundary( )70 R = Reflective_boundary(domain) 71 T = Transmissive_boundary(domain) 60 72 D = Dirichlet_boundary([1.0, 8.57, 0.0]) 61 73 … … 65 77 #Initial condition 66 78 h = 0.5 67 domain.set_conserved_quantities(Constant_height(x_slope, h), None, None) 79 domain.set_quantity('level', Constant_height(x_slope, h) ) 80 68 81 69 82 ###################### 70 # Visualisation using Visual Python, comment out if not required71 #visualise.create_surface(domain)72 73 ######################74 83 #Evolution 75 #raw_input('Press key to start simulation')76 84 import time 77 85 t0 = time.time() 78 for t in domain.evolve( max_timestep = 0.1,yieldstep = 0.5, finaltime = 50):86 for t in domain.evolve(yieldstep = 0.5, finaltime = 50): 79 87 domain.write_time() 80 81 # Remove the following if Visual Python not required82 # visualise.update(domain, index=0, smooth=True)83 88 84 89 print 'That took %.2f seconds' %(time.time()-t0) 85 90 86 print "saving file?"87 im = ImageGrab.grab()88 im.save("ccube.eps")91 #print "saving file?" 92 #im = ImageGrab.grab() 93 #im.save("ccube.eps") 89 94 90 95 -
inundation/ga/storm_surge/pyvolution/mesh_factory.py
r540 r541 63 63 64 64 65 # def oblique_mesh(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0), 66 # point_class=Point, element_class=Triangle, mesh_class=Mesh): 67 # """Setup a oblique grid of triangles 68 # with m segments in the x-direction and n segments in the y-direction 69 70 # Triangle refers to the actual class or subclass to be instantiated: 71 # e.g. if Volume is a subclass of Triangle, 72 # this function can be invoked with the keywords 73 # oblique_mesh(...,Triangle=Volume, Mesh=Domain) 74 # """ 75 76 # from Numeric import array 77 # from visual import rate 78 # import math 79 80 # from config import epsilon 81 82 # E = m*n*2 #Number of triangular elements 83 # P = (m+1)*(n+1) #Number of initial vertices 84 85 # initialise_consecutive_datastructure(P+E, E, 86 # point_class, 87 # element_class, 88 # mesh_class) 89 90 # deltax = lenx/float(m) 91 # deltay = leny/float(n) 92 # a = 0.75*lenx*math.tan(theta/180.*math.pi) 93 # x1 = lenx 94 # y1 = 0 95 # x2 = lenx 96 # y2 = leny 97 # x3 = 0.25*lenx 98 # y3 = leny 99 # x4 = x3 100 # y4 = 0 101 # a2 = a/(x1-x4) 102 # a1 = -a2*x4 103 # a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3) 104 # a3 = 1. - (a1 + a2*x3)/y3 - a4*x3 105 106 # # Dictionary of vertex objects 107 # vertices = {} 108 109 # for i in range(m+1): 110 # x = deltax*i 111 # for j in range(n+1): 112 # y = deltay*j 113 # if x > 0.25*lenx: 114 # y = a1 + a2*x + a3*y + a4*x*y 65 def oblique(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0)): 66 """Setup a oblique grid of triangles 67 with m segments in the x-direction and n segments in the y-direction 68 69 """ 70 71 from Numeric import array 72 import math 73 74 from config import epsilon 75 76 77 deltax = lenx/float(m) 78 deltay = leny/float(n) 79 a = 0.75*lenx*math.tan(theta/180.*math.pi) 80 x1 = lenx 81 y1 = 0 82 x2 = lenx 83 y2 = leny 84 x3 = 0.25*lenx 85 y3 = leny 86 x4 = x3 87 y4 = 0 88 a2 = a/(x1-x4) 89 a1 = -a2*x4 90 a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3) 91 a3 = 1. - (a1 + a2*x3)/y3 - a4*x3 92 93 # Dictionary of vertex objects 94 vertices = {} 95 points = [] 96 97 for i in range(m+1): 98 x = deltax*i 99 for j in range(n+1): 100 y = deltay*j 101 if x > 0.25*lenx: 102 y = a1 + a2*x + a3*y + a4*x*y 115 103 116 # vertices[i,j] = Point(x + origin[0],y + origin[1]) 117 118 # # Construct 2 elements per element 119 # elements = [] 120 # for i in range(m): 121 # for j in range(n): 122 # v1 = vertices[i,j+1] 123 # v2 = vertices[i,j] 124 # v3 = vertices[i+1,j+1] 125 # v4 = vertices[i+1,j] 126 127 # elements.append(element_class(v4,v3,v2)) #Lower 128 # elements.append(element_class(v1,v2,v3)) #Upper 129 130 # M = mesh_class(elements) 131 132 # #Set a default tagging 133 104 vertices[i,j] = len(points) 105 points.append([x + origin[0], y + origin[1]]) 106 107 # Construct 2 triangles per element 108 elements = [] 109 boundary = {} 110 for i in range(m): 111 for j in range(n): 112 v1 = vertices[i,j+1] 113 v2 = vertices[i,j] 114 v3 = vertices[i+1,j+1] 115 v4 = vertices[i+1,j] 116 117 #Update boundary dictionary and create elements 118 if i == m-1: 119 boundary[(len(elements), 2)] = 'right' 120 if j == 0: 121 boundary[(len(elements), 1)] = 'bottom' 122 elements.append([v4,v3,v2]) #Lower 123 124 if i == 0: 125 boundary[(len(elements), 2)] = 'left' 126 if j == n-1: 127 boundary[(len(elements), 1)] = 'top' 128 129 elements.append([v1,v2,v3]) #Upper 130 131 return points, elements, boundary 132 133 #OLD FORMULA FOR SETTING BOUNDARY TAGS - OBSOLETE NOW 134 134 # for id, face in M.boundary: 135 135 … … 159 159 # print face, id, id%m, m, n 160 160 # raise 'Unknown boundary' 161 161 # 162 162 # return M 163 164 163 165 164 166 def from_polyfile(name):
Note: See TracChangeset
for help on using the changeset viewer.