Changeset 1761
- Timestamp:
- Aug 25, 2005, 10:06:22 AM (19 years ago)
- Location:
- inundation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/mesh_factory.py
r1638 r1761 20 20 from config import epsilon 21 21 22 #E = m*n*2 #Number of triangular elements 23 #P = (m+1)*(n+1) #Number of initial vertices 24 25 delta1 = float(len1)/m 26 delta2 = float(len2)/n 22 deltax = float(len1)/m 23 deltay = float(len2)/n 27 24 28 25 #Dictionary of vertex objects … … 34 31 vertices[i,j] = len(points) 35 32 points.append([i*delta1 + origin[0], j*delta2 + origin[1]]) 36 37 33 38 34 … … 120 116 i4 = index(i+1,j) 121 117 118 x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25 119 y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25 120 v5 = len(points) 121 points.append([x, y]) 122 123 #Create left triangle 124 if i == 0: 125 boundary[(len(elements), 1)] = 'left' 126 elements.append([v2,v5,v1]) 127 128 #Create bottom triangle 129 if j == 0: 130 boundary[(len(elements), 1)] = 'bottom' 131 elements.append([v4,v5,v2]) 132 133 #Create right triangle 134 if i == m-1: 135 boundary[(len(elements), 1)] = 'right' 136 elements.append([v3,v5,v4]) 137 138 #Create top triangle 139 if j == n-1: 140 boundary[(len(elements), 1)] = 'top' 141 elements.append([v1,v5,v3]) 142 122 143 #Update boundary dictionary and create elements 123 144 if i == m-1: … … 133 154 boundary[nt, 1] = 'top' 134 155 elements[nt,:] = [i1,i2,i3] #Upper element 156 157 return points, elements, boundary 158 159 160 def rectangular_cross(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): 161 162 """Setup a rectangular grid of triangles 163 with m+1 by n+1 grid points 164 and side lengths len1, len2. If side lengths are omitted 165 the mesh defaults to the unit square. 166 167 len1: x direction (left to right) 168 len2: y direction (bottom to top) 169 170 Return to lists: points and elements suitable for creating a Mesh or 171 FVMesh object, e.g. Mesh(points, elements) 172 """ 173 174 from config import epsilon 175 from Numeric import zeros, Float, Int 176 177 delta1 = float(len1)/m 178 delta2 = float(len2)/n 179 180 #Dictionary of vertex objects 181 vertices = {} 182 points = [] 183 184 for i in range(m+1): 185 for j in range(n+1): 186 vertices[i,j] = len(points) 187 points.append([delta1*i + origin[0], delta2*j + origin[1]]) 188 189 # Construct 4 triangles per element 190 elements = [] 191 boundary = {} 192 for i in range(m): 193 for j in range(n): 194 v1 = vertices[i,j+1] 195 v2 = vertices[i,j] 196 v3 = vertices[i+1,j+1] 197 v4 = vertices[i+1,j] 198 x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25 199 y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25 200 201 # Create centre point 202 v5 = len(points) 203 points.append([x, y]) 204 205 #Create left triangle 206 if i == 0: 207 boundary[(len(elements), 1)] = 'left' 208 elements.append([v2,v5,v1]) 209 210 #Create bottom triangle 211 if j == 0: 212 boundary[(len(elements), 1)] = 'bottom' 213 elements.append([v4,v5,v2]) 214 215 #Create right triangle 216 if i == m-1: 217 boundary[(len(elements), 1)] = 'right' 218 elements.append([v3,v5,v4]) 219 220 #Create top triangle 221 if j == n-1: 222 boundary[(len(elements), 1)] = 'top' 223 elements.append([v1,v5,v3]) 224 135 225 136 226 return points, elements, boundary -
inundation/validation/LWRU2/lwru2.py
r1753 r1761 74 74 from pyvolution.shallow_water import Domain, Reflective_boundary,\ 75 75 File_boundary, Transmissive_Momentum_Set_Stage_boundary 76 from pyvolution.mesh_factory import rectangular 76 from pyvolution.mesh_factory import rectangular_cross 77 77 from pyvolution.pmesh2domain import pmesh_to_domain_instance 78 78 from Numeric import array, zeros, Float, allclose … … 91 91 ####################### 92 92 # Domain 93 93 94 94 if read_mesh is True: 95 95 print 'Creating domain from', filenames.mesh_filename … … 101 101 102 102 103 104 else: 103 104 else: 105 105 print 'Creating regular mesh' 106 106 N = 100 107 points, vertices, boundary = rectangular (N, N/5*3,107 points, vertices, boundary = rectangular_cross(N, N/5*3, 108 108 len1=5.448, len2=3.402) 109 109 print 'Creating domain' 110 110 111 111 #domain = Domain(points, vertices, boundary) 112 112 domain = cache(Domain, (points, vertices, boundary)) … … 135 135 verbose = True, 136 136 use_cache = True) 137 137 138 138 domain.set_quantity('friction', 0.0) 139 139 domain.set_quantity('stage', 0.0) … … 157 157 #Set boundary conditions 158 158 if read_mesh is True: 159 domain.set_boundary({'wave': Bts, 'wall': Br}) 160 else: 159 domain.set_boundary({'wave': Bts, 'wall': Br}) 160 else: 161 161 domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br}) 162 162
Note: See TracChangeset
for help on using the changeset viewer.