- Timestamp:
- Sep 4, 2009, 6:22:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r7276 r7484 118 118 k = triangles[i,j] #Index of vertex j in triangle i 119 119 assert num.allclose(V[j,:], nodes[k]) 120 121 122 def test_get_edge_midpoint_coordinates(self): 123 from mesh_factory import rectangular 124 125 #Create basic mesh 126 nodes, triangles, _ = rectangular(1, 3) 127 domain = General_mesh(nodes, triangles) 128 129 130 assert num.allclose(domain.get_nodes(), nodes) 131 132 133 M = domain.number_of_triangles 134 135 E = domain.get_edge_midpoint_coordinates() 136 assert E.shape[0] == 3*M 137 138 for i in range(M): 139 k0 = triangles[i,0] #Index of vertex 0 in triangle i 140 k1 = triangles[i,1] #Index of vertex 1 in triangle i 141 k2 = triangles[i,2] #Index of vertex 2 in triangle i 142 143 assert num.allclose(E[3*i+0,:], 0.5*(nodes[k1]+nodes[k2]) ) 144 assert num.allclose(E[3*i+1,:], 0.5*(nodes[k0]+nodes[k2]) ) 145 assert num.allclose(E[3*i+2,:], 0.5*(nodes[k1]+nodes[k0]) ) 146 147 def test_get_edge_midpoint_coordinates_with_geo_ref(self): 148 x0 = 314036.58727982 149 y0 = 6224951.2960092 150 geo = Geo_reference(56, x0, y0) 151 152 a = num.array([0.0, 0.0]) 153 b = num.array([0.0, 2.0]) 154 c = num.array([2.0, 0.0]) 155 d = num.array([0.0, 4.0]) 156 e = num.array([2.0, 2.0]) 157 f = num.array([4.0, 0.0]) 158 nodes = num.array([a, b, c, d, e, f]) 159 160 nodes_absolute = geo.get_absolute(nodes) 161 162 # bac, bce, ecf, dbe 163 triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.int) 164 165 domain = General_mesh(nodes, triangles, geo_reference=geo) 166 167 verts = domain.get_edge_midpoint_coordinates(triangle_id=0) # bac 168 msg = ("num.array(1/2[a+c,b+c,a+b])=\n%s\nshould be close to 'verts'=\n%s" 169 % (str(num.array([0.5*(a+c),0.5*(b+c),0.5*(a+b)])), str(verts))) 170 self.failUnless(num.allclose(num.array([0.5*(a+c),0.5*(b+c),0.5*(a+b)]), verts), msg) 171 172 173 verts = domain.get_edge_midpoint_coordinates(triangle_id=0, absolute=True) 174 msg = ("num.array([...])=\n%s\nshould be close to 'verts'=\n%s" 175 % (str(0.5*num.array([nodes_absolute[0]+nodes_absolute[2], 176 nodes_absolute[1]+nodes_absolute[2], 177 nodes_absolute[1]+nodes_absolute[0]])), 178 str(verts))) 179 self.assert_(num.allclose(0.5*num.array([nodes_absolute[0]+nodes_absolute[2], 180 nodes_absolute[1]+nodes_absolute[2], 181 nodes_absolute[1]+nodes_absolute[0]]), 182 verts), msg) 183 184 def test_get_edge_midpoint_coordinates_triangle_id(self): 185 """test_get_vertex_coordinates_triangle_id 186 Test that vertices for one triangle can be returned. 187 """ 188 from mesh_factory import rectangular 189 190 #Create basic mesh 191 nodes, triangles, _ = rectangular(1, 3) 192 domain = General_mesh(nodes, triangles) 193 194 195 assert num.allclose(domain.get_nodes(), nodes) 196 197 198 M = domain.number_of_triangles 199 200 for i in range(M): 201 E = domain.get_edge_midpoint_coordinates(triangle_id=i) 202 assert E.shape[0] == 3 203 204 205 k0 = triangles[i,0] #Index of vertex 0 in triangle i 206 k1 = triangles[i,1] #Index of vertex 0 in triangle i 207 k2 = triangles[i,2] #Index of vertex 0 in triangle i 208 209 assert num.allclose(E[0,:], 0.5*(nodes[k1]+nodes[k2])) 210 assert num.allclose(E[1,:], 0.5*(nodes[k0]+nodes[k2])) 211 assert num.allclose(E[2,:], 0.5*(nodes[k1]+nodes[k0])) 212 213 E0 = domain.get_edge_midpoint_coordinate(i, 0 ) 214 E1 = domain.get_edge_midpoint_coordinate(i, 1 ) 215 E2 = domain.get_edge_midpoint_coordinate(i, 2 ) 216 217 assert num.allclose(E0, 0.5*(nodes[k1]+nodes[k2])) 218 assert num.allclose(E1, 0.5*(nodes[k0]+nodes[k2])) 219 assert num.allclose(E2, 0.5*(nodes[k1]+nodes[k0])) 220 120 221 121 222 … … 356 457 357 458 if __name__ == "__main__": 358 suite = unittest.makeSuite(Test_General_Mesh, 'test') 459 #suite = unittest.makeSuite(Test_General_Mesh, 'test') 460 suite = unittest.makeSuite(Test_General_Mesh, 'test_get_edge_midpoint_coordinates') 359 461 runner = unittest.TextTestRunner() 360 462 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.