Changeset 6717
- Timestamp:
- Apr 3, 2009, 3:03:07 PM (16 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r6309 r6717 92 92 """ 93 93 94 95 number_of_full_nodes=None 96 number_of_full_triangles=None 97 94 98 # Determine whether source is a mesh filename or coordinates 95 99 if type(source) == types.StringType: … … 117 121 118 122 # Expose Mesh attributes (FIXME: Maybe turn into methods) 123 self.triangles = self.mesh.triangles 119 124 self.centroid_coordinates = self.mesh.centroid_coordinates 120 125 self.vertex_coordinates = self.mesh.vertex_coordinates … … 205 210 # the ghost triangles. 206 211 if not num.allclose(self.tri_full_flag[:self.number_of_full_nodes], 1): 207 print ('WARNING: ' 208 'Not all full triangles are store before ghost triangles') 212 if self.numproc>1: 213 print ('WARNING: ' 214 'Not all full triangles are store before ghost triangles') 209 215 210 216 # Defaults … … 306 312 def get_normal(self, *args, **kwargs): 307 313 return self.mesh.get_normal(*args, **kwargs) 314 315 def get_triangle_containing_point(self, *args, **kwargs): 316 return self.mesh.get_triangle_containing_point(*args, **kwargs) 308 317 309 318 def get_intersecting_segments(self, *args, **kwargs): … … 1745 1754 1746 1755 ## 1747 # @brief ??1756 # @brief Sequential update of ghost cells 1748 1757 def update_ghosts(self): 1749 pass 1750 1758 # We must send the information from the full cells and 1759 # receive the information for the ghost cells 1760 # We have a list with ghosts expecting updates 1761 1762 1763 from Numeric import take,put 1764 1765 1766 #Update of ghost cells 1767 iproc = self.processor 1768 if self.full_send_dict.has_key(iproc): 1769 1770 # now store full as local id, global id, value 1771 Idf = self.full_send_dict[iproc][0] 1772 1773 # now store ghost as local id, global id, value 1774 Idg = self.ghost_recv_dict[iproc][0] 1775 1776 for i, q in enumerate(self.conserved_quantities): 1777 Q_cv = self.quantities[q].centroid_values 1778 put(Q_cv, Idg, take(Q_cv, Idf)) 1779 1780 1751 1781 ## 1752 1782 # @brief Extrapolate conserved quantities from centroid to vertices -
anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory.py
r6145 r6717 201 201 202 202 return points, elements, boundary 203 204 205 206 def rectangular_periodic(m_g, n_g, len1_g=1.0, len2_g=1.0, origin_g = (0.0, 0.0)): 207 208 209 """Setup a rectangular grid of triangles 210 with m+1 by n+1 grid points 211 and side lengths len1, len2. If side lengths are omitted 212 the mesh defaults to the unit square, divided between all the 213 processors 214 215 len1: x direction (left to right) 216 len2: y direction (bottom to top) 217 218 """ 219 220 processor = 0 221 numproc = 1 222 223 224 n = n_g 225 m_low = -1 226 m_high = m_g +1 227 228 m = m_high - m_low 229 230 delta1 = float(len1_g)/m_g 231 delta2 = float(len2_g)/n_g 232 233 len1 = len1_g*float(m)/float(m_g) 234 len2 = len2_g 235 origin = ( origin_g[0]+float(m_low)/float(m_g)*len1_g, origin_g[1] ) 236 237 #Calculate number of points 238 Np = (m+1)*(n+1) 239 240 class VIndex: 241 242 def __init__(self, n,m): 243 self.n = n 244 self.m = m 245 246 def __call__(self, i,j): 247 return j+i*(self.n+1) 248 249 class EIndex: 250 251 def __init__(self, n,m): 252 self.n = n 253 self.m = m 254 255 def __call__(self, i,j): 256 return 2*(j+i*self.n) 257 258 259 I = VIndex(n,m) 260 E = EIndex(n,m) 261 262 points = num.zeros( (Np,2), num.Float) 263 264 for i in range(m+1): 265 for j in range(n+1): 266 267 points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]] 268 269 #Construct 2 triangles per rectangular element and assign tags to boundary 270 #Calculate number of triangles 271 Nt = 2*m*n 272 273 274 elements = num.zeros( (Nt,3), num.Int) 275 boundary = {} 276 Idgl = [] 277 Idfl = [] 278 Idgr = [] 279 Idfr = [] 280 281 full_send_dict = {} 282 ghost_recv_dict = {} 283 nt = -1 284 for i in range(m): 285 for j in range(n): 286 287 i1 = I(i,j+1) 288 i2 = I(i,j) 289 i3 = I(i+1,j+1) 290 i4 = I(i+1,j) 291 292 #Lower Element 293 nt = E(i,j) 294 if i == 0: 295 Idgl.append(nt) 296 297 if i == 1: 298 Idfl.append(nt) 299 300 if i == m-2: 301 Idfr.append(nt) 302 303 if i == m-1: 304 Idgr.append(nt) 305 306 if i == m-1: 307 if processor == numproc-1: 308 boundary[nt, 2] = 'right' 309 else: 310 boundary[nt, 2] = 'ghost' 311 312 if j == 0: 313 boundary[nt, 1] = 'bottom' 314 elements[nt,:] = [i4,i3,i2] 315 316 #Upper Element 317 nt = E(i,j)+1 318 if i == 0: 319 Idgl.append(nt) 320 321 if i == 1: 322 Idfl.append(nt) 323 324 if i == m-2: 325 Idfr.append(nt) 326 327 if i == m-1: 328 Idgr.append(nt) 329 330 if i == 0: 331 if processor == 0: 332 boundary[nt, 2] = 'left' 333 else: 334 boundary[nt, 2] = 'ghost' 335 if j == n-1: 336 boundary[nt, 1] = 'top' 337 elements[nt,:] = [i1,i2,i3] 338 339 Idfl.extend(Idfr) 340 Idgr.extend(Idgl) 341 342 Idfl = num.array(Idfl, num.Int) 343 Idgr = num.array(Idgr, num.Int) 344 345 full_send_dict[processor] = [Idfl, Idfl] 346 ghost_recv_dict[processor] = [Idgr, Idgr] 347 348 349 return points, elements, boundary, full_send_dict, ghost_recv_dict 350 203 351 204 352 def oblique(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0)): -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py
r6712 r6717 794 794 [ 11.0, 11.0, 11.0]]) 795 795 796 797 def test_rectangular_periodic_and_ghosts(self): 798 799 from mesh_factory import rectangular_periodic 800 801 802 M=5 803 N=2 804 points, vertices, boundary, full_send_dict, ghost_recv_dict = rectangular_periodic(M, N) 805 806 assert num.allclose(ghost_recv_dict[0][0], [24, 25, 26, 27, 0, 1, 2, 3]) 807 assert num.allclose(full_send_dict[0][0] , [ 4, 5, 6, 7, 20, 21, 22, 23]) 808 809 #print 'HERE' 810 811 conserved_quantities = ['quant1', 'quant2'] 812 domain = Domain(points, vertices, boundary, conserved_quantities, 813 full_send_dict=full_send_dict, 814 ghost_recv_dict=ghost_recv_dict) 815 816 817 818 819 assert num.allclose(ghost_recv_dict[0][0], [24, 25, 26, 27, 0, 1, 2, 3]) 820 assert num.allclose(full_send_dict[0][0] , [ 4, 5, 6, 7, 20, 21, 22, 23]) 821 822 def xylocation(x,y): 823 return 15*x + 9*y 824 825 826 domain.set_quantity('quant1',xylocation,location='centroids') 827 domain.set_quantity('quant2',xylocation,location='centroids') 828 829 830 assert num.allclose(domain.quantities['quant1'].centroid_values, 831 [ 0.5, 1., 5., 5.5, 3.5, 4., 8., 8.5, 6.5, 7., 11., 11.5, 9.5, 832 10., 14., 14.5, 12.5, 13., 17., 17.5, 15.5, 16., 20., 20.5, 833 18.5, 19., 23., 23.5]) 834 835 836 837 assert num.allclose(domain.quantities['quant2'].centroid_values, 838 [ 0.5, 1., 5., 5.5, 3.5, 4., 8., 8.5, 6.5, 7., 11., 11.5, 9.5, 839 10., 14., 14.5, 12.5, 13., 17., 17.5, 15.5, 16., 20., 20.5, 840 18.5, 19., 23., 23.5]) 841 842 domain.update_ghosts() 843 844 845 assert num.allclose(domain.quantities['quant1'].centroid_values, 846 [ 15.5, 16., 20., 20.5, 3.5, 4., 8., 8.5, 6.5, 7., 11., 11.5, 9.5, 847 10., 14., 14.5, 12.5, 13., 17., 17.5, 15.5, 16., 20., 20.5, 848 3.5, 4., 8., 8.5]) 849 850 851 852 assert num.allclose(domain.quantities['quant2'].centroid_values, 853 [ 15.5, 16., 20., 20.5, 3.5, 4., 8., 8.5, 6.5, 7., 11., 11.5, 9.5, 854 10., 14., 14.5, 12.5, 13., 17., 17.5, 15.5, 16., 20., 20.5, 855 3.5, 4., 8., 8.5]) 856 857 858 assert num.allclose(domain.tri_full_flag, [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 859 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]) 860 861 #Test that points are arranged in a counter clock wise order 862 domain.check_integrity() 863 864 796 865 def test_that_mesh_methods_exist(self): 797 866 """test_that_mesh_methods_exist … … 819 888 domain.get_number_of_nodes() 820 889 domain.get_normal(0,0) 890 domain.get_triangle_containing_point([0.4,0.5]) 821 891 domain.get_intersecting_segments([[0.0, 0.0], [0.0, 1.0]]) 822 892 domain.get_disconnected_triangles() -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r6174 r6717 322 322 nodes, triangles, geo_reference=geo) 323 323 324 324 325 325 326 326 #------------------------------------------------------------- -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py
r6174 r6717 12 12 from neighbour_mesh import * 13 13 from mesh_factory import rectangular 14 from mesh_factory import rectangular_periodic 14 15 from anuga.config import epsilon 15 16 … … 397 398 raise "triangle edge duplicates not caught" 398 399 400 399 401 def test_rectangular_mesh_basic(self): 400 402 M=1 … … 418 420 assert mesh.boundary[(7,1)] == 'top' # top 419 421 assert mesh.boundary[(3,1)] == 'top' # top 422 423 424 425 420 426 421 427 … … 475 481 points, vertices, boundary = rectangular(2*N, N, len1=10, len2=10) 476 482 mesh = Mesh(points, vertices, boundary) 477 478 483 479 484 -
anuga_core/source/anuga/utilities/util_ext.h
r5897 r6717 261 261 262 262 B = (PyArrayObject*) PyObject_GetAttrString(O, name); 263 264 //printf("B = %p\n",(void*)B); 263 265 if (!B) { 264 PyErr_SetString(PyExc_RuntimeError, "util_ext.h: get_consecutive_array could not obtain array"); 266 printf("util_ext.h: get_consecutive_array could not obtain python object"); 267 printf(" %s\n",name); 268 fflush(stdout); 269 PyErr_SetString(PyExc_RuntimeError, "util_ext.h: get_consecutive_array could not obtain python object"); 265 270 return NULL; 266 271 } … … 273 278 274 279 if (!A) { 280 printf("util_ext.h: get_consecutive_array could not obtain array object"); 281 printf(" %s \n",name); 282 fflush(stdout); 275 283 PyErr_SetString(PyExc_RuntimeError, "util_ext.h: get_consecutive_array could not obtain array"); 276 284 return NULL; 277 285 } 286 287 278 288 return A; 279 289 }
Note: See TracChangeset
for help on using the changeset viewer.