Changeset 8563
- Timestamp:
- Sep 9, 2012, 8:30:25 AM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh_ext.c
r8556 r8563 3 3 #include <stdio.h> 4 4 5 #include "util_ext.h" 6 5 7 #define DDATA(p) ((double*)(((PyArrayObject *)p)->data)) 6 8 #define IDATA(p) ((long*)(((PyArrayObject *)p)->data)) 9 #define DIMENSHAPE(p, d) (((PyArrayObject *)p)->dimensions[d]) 10 11 12 #ifndef NDEBUG 13 #define ASSERT(condition, message) \ 14 do {\ 15 if(!(condition)) { \ 16 printf("Assertion `%s` failed in %s line %d: %s\n", \ 17 #condition, __FILE__, __LINE__, message); \ 18 exit(EXIT_FAILURE); \ 19 } \ 20 } while (0) 21 #else 22 #define ASSERT(condition, message) do { } while (0) 23 #endif 24 25 static PyObject *BoundaryDictionaryConstruct( PyObject *self, PyObject *args ) 26 { 27 int aDimen, bDimen, ok, numTriangle, volID, edgeID; 28 char *defaultTag; 29 char errorMsg[50]; 30 long *neighbours; 31 PyObject *pyobj_dictKey, *pyobj_dictVal; 32 PyObject *pyobj_neighbours; 33 PyObject *pyobj_boundary; 34 Py_ssize_t pos; 35 36 ok = PyArg_ParseTuple( args, "isOO", &numTriangle, &defaultTag, &pyobj_neighbours, &pyobj_boundary ); 37 if( !ok ){ 38 report_python_error(AT, "could not parse input arguments"); 39 return NULL; 40 } 41 42 neighbours = IDATA( pyobj_neighbours ); 43 aDimen = DIMENSHAPE( pyobj_neighbours, 0 ); 44 bDimen = DIMENSHAPE( pyobj_neighbours, 1 ); 45 46 pos = 0; 47 if( PyDict_Size( pyobj_boundary ) ){ 48 // iterate through dictionary entries 49 while( PyDict_Next( pyobj_boundary, &pos, &pyobj_dictKey, &pyobj_dictVal ) ){ 50 volID = PyLong_AsLong( PyTuple_GetItem( pyobj_dictKey, 0 ) ); 51 edgeID = PyLong_AsLong( PyTuple_GetItem( pyobj_dictKey, 1 ) ); 52 53 if (!(volID<aDimen && edgeID<bDimen)) { 54 sprintf(errorMsg, "Segment (%d, %d) does not exist", volID, edgeID); 55 report_python_error(AT, errorMsg); 56 return NULL; 57 } 58 } 59 } 60 61 for(volID=0; volID<numTriangle; volID++){ 62 for(edgeID=0; edgeID<3; edgeID++){ 63 if( neighbours[volID*3+edgeID] < 0 ){ 64 pyobj_dictKey = PyTuple_New( 2 ); 65 PyTuple_SetItem( pyobj_dictKey, 0, PyInt_FromLong( volID ) ); 66 PyTuple_SetItem( pyobj_dictKey, 1, PyInt_FromLong( edgeID ) ); 67 68 if( !PyDict_Contains( pyobj_boundary, pyobj_dictKey ) ) 69 PyDict_SetItem( pyobj_boundary, pyobj_dictKey, PyString_FromString( defaultTag ) ); 70 } 71 } 72 } 73 74 return Py_BuildValue("O", pyobj_boundary); 75 } 7 76 8 77 9 78 10 79 /* 11 80 static PyObject *BoundaryDictionaryConstruct( PyObject *self, PyObject *args ) 12 81 { 13 int i, j, initSize,ok, numTriangle;82 int i, j, ok, numTriangle; 14 83 char *defaultTag; 15 84 long *neighbours; … … 20 89 ok = PyArg_ParseTuple( args, "isOO", &numTriangle, &defaultTag, &pyobj_neighbours, &pyobj_boundary ); 21 90 if( !ok ){ 22 fprintf( stderr, "BuildBoundaryFromScratch func: argument parsing error\n");23 exit(1);91 report_python_error(AT, "could not parse input arguments"); 92 return NULL; 24 93 } 25 94 … … 41 110 return Py_BuildValue("O", pyobj_boundary); 42 111 } 112 */ 43 113 44 114 static PyMethodDef MF_module_methods[] = { -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r8505 r8563 199 199 return sides 200 200 201 def calc_sides_zip(triangles): 202 '''Build dictionary mapping from sides (2-tuple of points) 203 to left hand side neighbouring triangle 204 ''' 205 206 sides = {} 207 208 209 triangles = num.array(triangles,num.int) 210 211 212 a = triangles[:,0] 213 b = triangles[:,1] 214 c = triangles[:,2] 215 216 id = num.arange(len(triangles)) 217 face = num.ones(len(triangles),num.int) 218 219 sides.update(dict(zip(zip(a,b),zip(id,2*face)))) 220 sides.update(dict(zip(zip(b,c),zip(id,0*face)))) 221 sides.update(dict(zip(zip(c,a),zip(id,1*face)))) 222 223 return sides 224 225 def calc_sides_c(triangles): 226 '''Build dictionary mapping from sides (2-tuple of points) 227 to left hand side neighbouring triangle 228 ''' 229 230 sides = {} 231 232 233 triangles = num.array(triangles,num.int) 234 ntriangles = len(triangles) 235 236 # print 'calc_sides' 237 # print type(triangles) 238 239 print ntriangles 240 241 from pmesh2domain_ext import sides_dictionary_construct 242 sides = sides_dictionary_construct(triangles, sides) 243 244 245 # old_sides = {} 246 # 247 # for id, triangle in enumerate(triangles): 248 # a = int(triangle[0]) 249 # b = int(triangle[1]) 250 # c = int(triangle[2]) 251 # 252 # old_sides[a,b] = (id, 2) #(id, face) 253 # old_sides[b,c] = (id, 0) #(id, face) 254 # old_sides[c,a] = (id, 1) #(id, face) 255 256 257 #print sides 258 #print old_sides 259 260 261 return sides -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py
r8556 r8563 693 693 mesh = Mesh(points, vertices, {(5,0): 'x'}) 694 694 except AssertionError: 695 pass 696 except RuntimeError: 695 697 pass 696 698 else: -
trunk/anuga_core/source/anuga/file_conversion/sww2dem.py
r8562 r8563 329 329 330 330 331 332 #333 334 331 interp = Interpolate(vertex_points, volumes, verbose = verbose) 335 332
Note: See TracChangeset
for help on using the changeset viewer.