Changeset 8709
- Timestamp:
- Feb 21, 2013, 1:41:43 PM (12 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/caching/caching.py
r8697 r8709 959 959 960 960 if isinstance(T, FitInterpolate): 961 962 961 if hasattr(T,"D"): 963 962 T.D=sparse_matrix_ext.deserialise_dok(T.D) … … 965 964 T.AtA=sparse_matrix_ext.deserialise_dok(T.AtA) 966 965 if hasattr(T,"root"): 967 if hasattr(T.root,"root"): 968 mesh = T.mesh 969 extents = AABB(*mesh.get_extent(absolute=True)) 970 extents.grow(1.001) # To avoid round off error 971 extents = [extents.xmin, extents.xmax, extents.ymin, extents.ymax] 972 T.root.root=quad_tree_ext.deserialise(T.root.root,\ 973 mesh.triangles, mesh.vertex_coordinates, num.array(extents)) 974 966 T.build_quad_tree(verbose=verbose) 975 967 #--------------------------------------------------------------------------- 976 968 … … 1085 1077 1086 1078 (argsfile, compressed) = myopen(CD+FN+'_'+file_types[1], 'wb', compression) 1087 1088 1079 if argsfile is None: 1089 1080 msg = 'ERROR (caching): Could not open argsfile for writing: %s' %FN … … 1147 1138 T.AtA=sparse_matrix_ext.serialise_dok(T.AtA) 1148 1139 if hasattr(T,"root"): 1149 if hasattr(T.root,"root"): 1150 T.root.root=quad_tree_ext.serialise(T.root.root) 1140 T.root.root=None 1151 1141 1152 1142 … … 1189 1179 #else: 1190 1180 # pass # FIXME: Take care of access rights under Windows 1191 1192 # PADARN NOTE 17/12/12: See above - deserialise in case will be used.1193 #---------------------------------------------------------------------------1194 from anuga.fit_interpolate.general_fit_interpolate import FitInterpolate1195 1196 if isinstance(T, FitInterpolate):1197 if hasattr(T,"D"):1198 T.D=sparse_matrix_ext.deserialise_dok(T.D)1199 if hasattr(T,"AtA"):1200 T.AtA=sparse_matrix_ext.deserialise_dok(T.AtA)1201 if hasattr(T,"root"):1202 if hasattr(T.root,"root"):1203 mesh = T.mesh1204 extents = AABB(*mesh.get_extent(absolute=True))1205 extents.grow(1.001) # To avoid round off error1206 extents = [extents.xmin, extents.xmax, extents.ymin, extents.ymax]1207 T.root.root=quad_tree_ext.deserialise(T.root.root,\1208 mesh.triangles, mesh.vertex_coordinates, num.array(extents))1209 1210 1211 #---------------------------------------------------------------------------1212 1181 1213 1182 return(savetime) -
trunk/anuga_core/source/anuga/fit_interpolate/fitsmooth.c
r8692 r8709 17 17 #define ERRCODE 2 18 18 #define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} 19 20 #include "patchlevel.h" 21 22 // PYVERSION273 used to check python version for use of PyCapsule 23 #if PY_MAJOR_VERSION>=2 && PY_MINOR_VERSION>=7 && PY_MICRO_VERSION>=3 24 #define PYVERSION273 25 #endif 19 26 20 27 //------------------------ NET CDF READING ---------------------------- … … 462 469 // ---------------------------------------------------------------------------- 463 470 464 // --------------------- Capsule destructor methods --------------------------- 465 466 // PADARN NOTE 11/12/12: The following two 'destructor' functions will free the 467 // memory allocated to a quad_tree or sparse_dok. An error should be thrown 468 // if the pointer is already Null, as this shouldn't happen. 471 // If using python 2.7.3 or later, build with PyCapsules 469 472 470 473 // Delete capsule containing a quad tree - name of capsule must be exactly 471 // "quad tree". 474 // "quad tree". 475 476 #ifdef PYVERSION273 477 478 472 479 void delete_quad_tree_cap(PyObject * cap){ 473 480 quad_tree * kill = (quad_tree*) PyCapsule_GetPointer(cap,"quad tree"); … … 488 495 489 496 } 497 498 #else 499 500 // If using python earlier version, build with PyCObject 501 502 // Delete cobj containing a quad tree 503 void delete_quad_tree_cobj(void * cobj){ 504 quad_tree * kill = (quad_tree*) cobj; 505 if(kill!=NULL){ 506 delete_quad_tree(kill); 507 } 508 } 509 510 // Delete cobj containing a sparse_dok 511 void delete_dok_cobj(void *cobj){ 512 513 sparse_dok * kill = (sparse_dok*) cobj; 514 if(kill!=NULL){ 515 delete_dok_matrix(kill); 516 } 517 518 } 519 520 #endif 490 521 491 522 //----------------------- PYTHON WRAPPER FUNCTION ----------------------------- … … 520 551 int n = triangles->dimensions[0]; 521 552 553 #ifdef PYVERSION273 554 522 555 return PyCapsule_New((void*) _build_quad_tree(n, 556 (long*) triangles -> data, 557 (double*) vertex_coordinates -> data, 558 (double*) extents -> data), 559 "quad tree", 560 &delete_quad_tree_cap); 561 562 #else 563 564 return PyCObject_FromVoidPtr((void*) _build_quad_tree(n, 523 565 (long*) triangles -> data, 524 566 (double*) vertex_coordinates -> data, 525 567 (double*) extents -> data), 526 "quad tree", 527 &delete_quad_tree_cap); 528 568 &delete_quad_tree_cobj); 569 #endif 529 570 } 530 571 … … 575 616 } 576 617 618 #ifdef PYVERSION273 619 577 620 return PyCapsule_New((void*) smoothing_mat, 578 621 "sparse dok", 579 622 &delete_dok_cap); 580 623 624 #else 625 626 return PyCObject_FromVoidPtr((void*) smoothing_mat, 627 &delete_dok_cobj); 628 629 #endif 581 630 582 631 } … … 612 661 CHECK_C_CONTIG(triangles); 613 662 663 #ifdef PYVERSION273 614 664 quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree"); 615 665 #else 666 quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree); 667 #endif 616 668 617 669 sparse_dok * dok_AtA; // Should be an input argument? … … 633 685 } 634 686 687 #ifdef PYVERSION273 635 688 PyObject * AtA_cap = PyCapsule_New((void*) dok_AtA, 636 689 "sparse dok", 637 690 &delete_dok_cap); 691 #else 692 PyObject * AtA_cap = PyCObject_FromVoidPtr((void*) dok_AtA, 693 &delete_dok_cobj); 694 #endif 695 638 696 PyObject *Atz_ret = c_double_array_to_list(Atz,N); 639 697 … … 682 740 CHECK_C_CONTIG(z); 683 741 742 #ifdef PYVERSION273 684 743 quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree"); 685 744 #else 745 quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree); 746 #endif 686 747 687 748 sparse_dok * dok_AtA; // Should be an input argument? … … 709 770 } 710 771 772 #ifdef PYVERSION273 711 773 PyObject * AtA_cap = PyCapsule_New((void*) dok_AtA, 712 774 "sparse dok", 713 &delete_dok_cap); 775 &delete_dok_cap); 776 #else 777 PyObject * AtA_cap = PyCObject_FromVoidPtr((void*) dok_AtA, 778 &delete_dok_cobj); 779 #endif 714 780 PyObject * Atz_ret = PyList_New(zdims); 715 781 for(i=0;i<zdims;i++){ … … 746 812 CHECK_C_CONTIG(point); 747 813 814 #ifdef PYVERSION273 748 815 quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree"); 816 #else 817 quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree); 818 #endif 819 749 820 double xp,yp; 750 821 if(PyArray_TYPE(point)==7){ … … 804 875 805 876 // Extract quad_tree pointer from capsule 877 #ifdef PYVERSION273 806 878 quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree"); 879 #else 880 quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree); 881 #endif; 807 882 808 883 // Return the number of elements in the tree (stored in struct) … … 827 902 828 903 // Extract quad_tree pointer from capsule 904 #ifdef PYVERSION273 829 905 quad_tree * quadtree = (quad_tree*) PyCapsule_GetPointer(tree,"quad tree"); 906 #else 907 quad_tree * quadtree = (quad_tree*) PyCObject_AsVoidPtr(tree); 908 #endif 830 909 831 910 // Return the number of elements in the tree (stored in struct) … … 861 940 862 941 // Get pointers to sparse_dok objects from capsules 942 #ifdef PYVERSION273 863 943 sparse_dok * dok_AtA1 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap1,"sparse dok"); 864 944 sparse_dok * dok_AtA2 = (sparse_dok*) PyCapsule_GetPointer(AtA_cap2,"sparse dok"); 945 #else 946 sparse_dok * dok_AtA1 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap1); 947 sparse_dok * dok_AtA2 = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap2); 948 #endif 865 949 866 950 // Combine the partial AtA and Atz … … 896 980 897 981 // Get pointer to spars_dok struct 982 #ifdef PYVERSION273 898 983 sparse_dok * D_mat = (sparse_dok*) PyCapsule_GetPointer(D_cap,"sparse dok"); 899 984 #else 985 sparse_dok * D_mat = (sparse_dok*) PyCObject_AsVoidPtr(D_cap); 986 #endif 987 900 988 // Check to make sure that the specified size of the matrix is at least as big 901 989 // as the entries stored in the sparse_dok. … … 955 1043 956 1044 // Extract pointers to c structs from capsules 1045 #ifdef PYVERSION273 957 1046 sparse_dok * smoothing_mat = (sparse_dok*) PyCapsule_GetPointer(smoothing_mat_cap,"sparse dok"); 958 1047 sparse_dok * dok_AtA = (sparse_dok*) PyCapsule_GetPointer(AtA_cap,"sparse dok"); 1048 #else 1049 sparse_dok * smoothing_mat = (sparse_dok*) PyCObject_AsVoidPtr(smoothing_mat_cap); 1050 sparse_dok * dok_AtA = (sparse_dok*) PyCObject_AsVoidPtr(AtA_cap); 1051 #endif 959 1052 960 1053 // Add two sparse_dok matrices -
trunk/anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r8690 r8709 118 118 #self.root.set_last_triangle() 119 119 120 def build_quad_tree(self,verbose=False): 121 self.root = MeshQuadtree(self.mesh, verbose=verbose) 122 120 123 def __repr__(self): 121 124 return 'Interpolation object based on: ' + repr(self.mesh) -
trunk/anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r8690 r8709 259 259 # FIXME: This concat should roll into get_vertex_values 260 260 261 262 261 # Get interpolated values at centroids 263 262 interpolation_points = domain.get_centroid_coordinates() … … 268 267 verbose=False) 269 268 assert num.allclose(result, answer) 270 269 271 270 # Second call using the cache 272 271 result = interpolate(vertex_coordinates, triangles, -
trunk/anuga_core/source/anuga/operators/test_kinematic_viscosity_operator.py
r8690 r8709 770 770 kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1, use_dt_tol=False) 771 771 772 773 #print 'u'774 #print u.centroid_values775 #print u.boundary_values776 777 #print num.where(h.centroid_values > 0.0, 1.0, 0.0)778 772 assert num.allclose(u.centroid_values, num.where(h.centroid_values > 0.0, 1.0, 0.0), rtol=1.0e-1) 779 773 assert num.allclose(u.boundary_values, num.ones_like(u.boundary_values)) -
trunk/anuga_core/source/anuga/utilities/quad_tree_ext.c
r8691 r8709 13 13 14 14 15 15 /* 16 16 static int _serialise(quad_tree * quadtree, PyObject * serial_quadtree) 17 17 { … … 163 163 } 164 164 165 165 */ 166 166 167 167 static void delete_quad_tree_cap(PyObject * cap){ … … 175 175 //----------------------- PYTHON WRAPPER FUNCTION ----------------------------- 176 176 177 177 /* 178 178 static PyObject *serialise(PyObject *self, PyObject *args) { 179 179 … … 236 236 237 237 } 238 238 */ 239 239 240 240 //------------------------------------------------------------------------------ … … 249 249 // Method table for python module 250 250 static struct PyMethodDef MethodTable[] = { 251 {"serialise",serialise, METH_VARARGS, "Print out"},252 {"deserialise",deserialise, METH_VARARGS, "Print out"},251 // {"serialise",serialise, METH_VARARGS, "Print out"}, 252 // {"deserialise",deserialise, METH_VARARGS, "Print out"}, 253 253 {NULL, NULL, 0, NULL} // sentinel 254 254 };
Note: See TracChangeset
for help on using the changeset viewer.