Changeset 22674
- Timestamp:
- 04/04/18 11:46:26 (7 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/modules/MeshPartition.m
r22069 r22674 3 3 % 4 4 % Usage: 5 % [element_partitioning,node_partitioning]=MeshPartition(md .mesh,numpartitions)");5 % [element_partitioning,node_partitioning]=MeshPartition(md,numpartitions)"); 6 6 % 7 7 % element_partitioning: Vector of partitioning area numbers, for every element. … … 14 14 end 15 15 16 %Get mesh info from md.mesh 17 numberofvertices = md.mesh.numberofvertices; 18 numberofelements = md.mesh.numberofelements; 19 elements = md.mesh.elements; 20 numberofelements2d = 0; 21 numberofvertices2d = 0; 22 numberoflayers = 1; 23 elements2d = []; 24 if isa(md.mesh,'mesh3dprisms') 25 elementtype = 'Penta'; 26 numberofelements2d = md.mesh.numberofelements2d; 27 numberofvertices2d = md.mesh.numberofvertices2d; 28 numberoflayers = md.mesh.numberoflayers; 29 elements2d = md.mesh.elements2d; 30 elseif isa(md.mesh,'mesh2d') 31 elementtype = 'Tria'; 32 elseif isa(md.mesh,'mesh2dvertical') 33 elementtype = 'Tria'; 34 end 35 16 36 % Call mex module 17 [element_partitioning, node_partitioning] = MeshPartition_matlab( md.mesh,numpartitions);37 [element_partitioning, node_partitioning] = MeshPartition_matlab(numberofvertices,elements,numberofvertices2d,elements2d,numberoflayers,meshelementtype,numpartitions); -
issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.cpp
r22069 r22674 15 15 WRAPPER(MeshPartition_python){ 16 16 17 /*Indexing: */18 int i,j;19 20 17 /* required input: */ 21 int meshelementtype;22 18 int numberofelements; 23 19 int numberofvertices; 24 int *elements 20 int *elements = NULL; 25 21 int elements_width; 26 27 22 int numberofelements2d=0; 28 23 int numberofvertices2d=0; 29 24 int* elements2d=NULL; 30 31 25 int numberoflayers; 32 26 int numareas=1; … … 42 36 43 37 /*checks on arguments on the matlab side: */ 44 C heckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&MeshPartitionUsage);38 CHECKARGUMENTS(NLHS,NRHS,&MeshPartitionUsage); 45 39 46 40 /*Fetch data: */ 47 FetchData(&numberofelements,mxGetAssignedField(MESH,0,"numberofelements")); 48 FetchData(&numberofvertices,mxGetAssignedField(MESH,0,"numberofvertices")); 49 FetchData(&elements,NULL,&elements_width,mxGetAssignedField(MESH,0,"elements")); 41 FetchData(&numberofvertices,NUMBEROFVERTICES); 42 FetchData(&elements,&numberofelements,&elements_width,ELEMENTS); 43 FetchData(&numberofvertices2d,NUMBEROFVERTICES2D); 44 FetchData(&elements2d,&numberofelements2d,NULL,ELEMENTS2D); 45 FetchData(&numberoflayers,NUMBEROFLAYERS); 46 FetchData(&numareas,NUMAREAS); 50 47 51 if(strcmp(mxGetClassName(MESH),"mesh3dprisms")==0){ 52 meshelementtype = PentaEnum; 53 FetchData(&numberofelements2d,mxGetAssignedField(MESH,0,"numberofelements2d")); 54 FetchData(&numberofvertices2d,mxGetAssignedField(MESH,0,"numberofvertices2d")); 55 FetchData(&elements2d,NULL,NULL,mxGetAssignedField(MESH,0,"elements2d")); 56 FetchData(&numberoflayers,mxGetAssignedField(MESH,0,"numberoflayers")); 57 } 58 else if(strcmp(mxGetClassName(MESH),"mesh2d")==0){ 59 meshelementtype = TriaEnum; 60 numberoflayers=1; 61 } 62 else if(strcmp(mxGetClassName(MESH),"mesh2dvertical")==0){ 63 meshelementtype = TriaEnum; 64 numberoflayers=1; 65 } 66 else{ 67 _error_("Mesh type "<<mxGetClassName(MESH)<<" not supported yet"); 68 } 69 FetchData(&numareas,NUMAREAS); 48 /*Get mesh element type and convert to Enum*/ 49 char* meshtype_str = NULL; 50 FetchData(&meshtype_str,MESHELEMENTTYPE); 51 int meshelementtype = StringToEnumx(meshtype_str); 52 xDelete<char>(meshtype_str); 70 53 71 54 /*Run partitioning algorithm based on a "clever" use of the Metis partitioner: */ … … 75 58 /*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */ 76 59 element_partitioning=xNew<double>(numberofelements); 77 for (i=0;i<numberofelements;i++){60 for(int i=0;i<numberofelements;i++){ 78 61 element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1. 79 62 } 80 63 81 64 node_partitioning=xNew<double>(numberofvertices); 82 for (i=0;i<numberofvertices;i++){65 for(int i=0;i<numberofvertices;i++){ 83 66 node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1. 84 67 } … … 90 73 /*Free ressources:*/ 91 74 xDelete<int>(elements); 92 xDelete<int>( 75 xDelete<int>(elements2d); 93 76 xDelete<int>(int_element_partitioning); 94 77 xDelete<int>(int_node_partitioning); -
issm/trunk-jpl/src/wrappers/MeshPartition/MeshPartition.h
r16329 r22674 27 27 #ifdef _HAVE_MATLAB_MODULES_ 28 28 /* serial input macros: */ 29 #define MESH prhs[0] 30 #define NUMAREAS prhs[1] 29 #define NUMBEROFVERTICES prhs[0] 30 #define ELEMENTS prhs[1] 31 #define NUMBEROFVERTICES2D prhs[2] 32 #define ELEMENTS2D prhs[3] 33 #define NUMBEROFLAYERS prhs[4] 34 #define MESHELEMENTTYPE prhs[5] 35 #define NUMAREAS prhs[6] 31 36 /* serial output macros: */ 32 37 #define ELEMENTPARTITIONING (mxArray**)&plhs[0] … … 36 41 #ifdef _HAVE_PYTHON_MODULES_ 37 42 /* serial input macros: */ 38 #define MESH PyTuple_GetItem(args,0) 39 #define NUMAREAS PyTuple_GetItem(args,1) 43 #define NUMBEROFVERTICES PyTuple_GetItem(args,0) 44 #define ELEMENTS PyTuple_GetItem(args,1) 45 #define NUMBEROFVERTICES2D PyTuple_GetItem(args,2) 46 #define ELEMENTS2D PyTuple_GetItem(args,3) 47 #define NUMBEROFLAYERS PyTuple_GetItem(args,4) 48 #define MESHELEMENTTYPE PyTuple_GetItem(args,5) 49 #define NUMAREAS PyTuple_GetItem(args,6) 40 50 /* serial output macros: */ 41 51 #define ELEMENTPARTITIONING output,0 … … 47 57 #define NLHS 2 48 58 #undef NRHS 49 #define NRHS 259 #define NRHS 7 50 60 51 61 #endif /* _MESHPARTITION_H */ -
issm/trunk-jpl/src/wrappers/python/Makefile.am
r22668 r22674 39 39 InterpFromMeshToGrid_python.la\ 40 40 IssmConfig_python.la\ 41 MeshPartition_python.la\ 41 42 MeshProfileIntersection_python.la\ 42 43 NodeConnectivity_python.la\ 43 44 Triangle_python.la\ 44 45 ProcessRifts_python.la 46 47 if CHACO 48 lib_LTLIBRARIES += Chaco_python.la 49 endif 45 50 endif 46 51 #}}} … … 101 106 BamgTriangulate_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB) 102 107 108 if CHACO 109 Chaco_python_la_SOURCES = ../Chaco/Chaco.cpp 110 Chaco_python_la_CXXFLAGS = ${AM_CXXFLAGS} 111 Chaco_python_la_LIBADD = ${deps} $(MPILIB) $(CHACOLIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB) 112 endif 113 103 114 ContourToMesh_python_la_SOURCES = ../ContourToMesh/ContourToMesh.cpp 104 115 ContourToMesh_python_la_CXXFLAGS = ${AM_CXXFLAGS} … … 133 144 IssmConfig_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB) 134 145 146 MeshPartition_python_la_SOURCES = ../MeshPartition/MeshPartition.cpp 147 MeshPartition_python_la_CXXFLAGS = ${AM_CXXFLAGS} 148 MeshPartition_python_la_LIBADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB) $(PROJ4LIB) 149 135 150 MeshProfileIntersection_python_la_SOURCES = ../MeshProfileIntersection/MeshProfileIntersection.cpp 136 151 MeshProfileIntersection_python_la_CXXFLAGS = ${AM_CXXFLAGS} -
issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp
r21864 r22674 44 44 /*output: */ 45 45 *pscalar=dscalar; 46 } 47 /*}}}*/ 48 /*FUNCTION FetchData(float* pscalar,PyObject* py_float){{{*/ 49 void FetchData(float* pscalar,PyObject* py_float){ 50 51 float fscalar; 52 53 /*return internal value: */ 54 if (PyFloat_Check(py_float)) 55 fscalar=PyFloat_AsDouble(py_float); 56 else if (PyLong_Check(py_float)){ 57 #if _PYTHON_MAJOR_ == 3 58 fscalar=(float)PyLong_AsLong(py_float); 59 #else 60 fscalar=(float)PyLong_AsDouble(py_float); 61 #endif 62 } 63 else if (PyInt_Check(py_float)) 64 fscalar=(float)PyInt_AsLong(py_float); 65 else if (PyBool_Check(py_float)) 66 fscalar=(float)PyLong_AsLong(py_float); 67 else if (PyTuple_Check(py_float) && (int)PyTuple_Size(py_float)==1) 68 FetchData(&fscalar,PyTuple_GetItem(py_float,(Py_ssize_t)0)); 69 else if (PyList_Check(py_float) && (int)PyList_Size(py_float)==1) 70 FetchData(&fscalar,PyList_GetItem(py_float,(Py_ssize_t)0)); 71 else 72 _error_("unrecognized float type in input!"); 73 74 /*output: */ 75 *pscalar=fscalar; 46 76 } 47 77 /*}}}*/ … … 464 494 } 465 495 /*}}}*/ 496 /*FUNCTION FetchData(float** pvector,int* pM, PyObject* py_vector){{{*/ 497 void FetchData(float** pvector,int* pM,PyObject* py_vector){ 498 499 /*output: */ 500 float* vector=NULL; 501 int M; 502 int ndim; 503 npy_intp* dims=NULL; 504 505 /*intermediary:*/ 506 long* lvector=NULL; 507 bool* bvector=NULL; 508 double* dvector=NULL; 509 int i; 510 PyObject* py_vector2=NULL; 511 512 if (PyArray_Check((PyArrayObject*)py_vector)) { 513 /*retrieve dimensions: */ 514 ndim=PyArray_NDIM((const PyArrayObject*)py_vector); 515 if (ndim==1) { 516 dims=PyArray_DIMS((PyArrayObject*)py_vector); 517 M=dims[0]; 518 } 519 else if (ndim==2) { 520 dims=PyArray_DIMS((PyArrayObject*)py_vector); 521 if (dims[1]==1) 522 M=dims[0]; 523 else 524 _error_("expecting an Mx1 matrix or M vector in input!"); 525 } 526 else 527 _error_("expecting an Mx1 matrix or M vector in input!"); 528 529 if (M) { 530 if (!PyArray_ISCONTIGUOUS((PyArrayObject*)py_vector)) { 531 py_vector2=PyArray_ContiguousFromAny(py_vector,NPY_LONG,ndim,ndim); 532 py_vector=py_vector2; 533 } 534 535 if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_DOUBLE) { 536 /*retrieve internal value: */ 537 dvector=(double*)PyArray_DATA((PyArrayObject*)py_vector); 538 539 /*transform into int vector: */ 540 vector=xNew<float>(M); 541 for(i=0;i<M;i++)vector[i]=(float)lvector[i]; 542 } 543 544 else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_LONG) { 545 /*retrieve internal value: */ 546 lvector=(long*)PyArray_DATA((PyArrayObject*)py_vector); 547 548 /*transform into int vector: */ 549 vector=xNew<float>(M); 550 for(i=0;i<M;i++)vector[i]=(float)lvector[i]; 551 } 552 553 else if (PyArray_TYPE((PyArrayObject*)py_vector) == NPY_BOOL) { 554 /*retrieve internal value: */ 555 bvector=(bool*)PyArray_DATA((PyArrayObject*)py_vector); 556 557 /*transform into int vector: */ 558 vector=xNew<float>(M); 559 for(i=0;i<M;i++)vector[i]=(float)bvector[i]; 560 } 561 562 else 563 _error_("unrecognized int pyarray type in input!"); 564 565 if(py_vector2) delete(py_vector2); 566 } 567 else 568 vector=NULL; 569 } 570 else{ 571 M=1; 572 vector=xNew<float>(M); 573 FetchData(&(vector[0]),py_vector); 574 } 575 576 /*output: */ 577 if(pM)*pM=M; 578 if(pvector)*pvector=vector; 579 } 580 /*}}}*/ 466 581 /*FUNCTION FetchData(int** pvector,int* pM, PyObject* py_vector){{{*/ 467 582 void FetchData(int** pvector,int* pM,PyObject* py_vector){ … … 809 924 } 810 925 /*}}}*/ 926 void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN,PyObject* EWGTS_IN){ 927 _error_("Nathan... I need your help here"); 928 } 811 929 812 930 /*Python version dependent: */ -
issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
r21624 r22674 93 93 dim=(npy_intp)M; 94 94 array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,vector_python); 95 96 PyTuple_SetItem(py_tuple, index, array); 97 98 }/*}}}*/ 99 /*FUNCTION WriteData(PyObject* py_tuple,int index, short* vector, int M){{{*/ 100 void WriteData(PyObject* py_tuple, int index,short* vector, int M){ 101 102 long* lvector=NULL; 103 npy_intp dim=10; 104 PyObject* array=NULL; 105 106 /*transform into long matrix: */ 107 lvector=xNew<long>(M); 108 for(int i=0;i<M;i++)lvector[i]=(long)vector[i]; 109 110 dim=(npy_intp)M; 111 array=PyArray_SimpleNewFromData(1,&dim,NPY_INT64,lvector); 95 112 96 113 PyTuple_SetItem(py_tuple, index, array); -
issm/trunk-jpl/src/wrappers/python/io/pythonio.h
r15335 r22674 22 22 void WriteData(PyObject* py_tuple,int index, int integer); 23 23 void WriteData(PyObject* py_tuple,int index, double* vector, int M); 24 void WriteData(PyObject* py_tuple,int index, short* vector, int M); 24 25 void WriteData(PyObject* py_tuple,int index, int* vector, int M); 25 26 void WriteData(PyObject* py_tuple,int index, char* string); … … 35 36 void FetchData(bool** pmatrix,int* pM,int *pN,PyObject* py_matrix); 36 37 void FetchData(double** pvector,int* pM,PyObject* py_ref); 38 void FetchData(float** pvector,int* pM,PyObject* dataref); 37 39 void FetchData(int** pvector,int* pM,PyObject* py_ref); 38 40 void FetchData(bool** pvector,int* pM,PyObject* py_ref); 39 41 void FetchData(char** pstring,PyObject* py_unicode); 40 42 void FetchData(double* pscalar,PyObject* py_float); 43 void FetchData(short* pscalar,PyObject* py_float); 41 44 void FetchData(int* pscalar,PyObject* py_long); 42 45 void FetchData(bool* pbool,PyObject* py_boolean); … … 46 49 void FetchData(Options** poptions,int istart, int nrhs,PyObject* py_tuple); 47 50 void FetchData(Contours** pcontours,PyObject* py_list); 51 void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN,PyObject* EWGTS_IN); 48 52 49 53 int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));
Note:
See TracChangeset
for help on using the changeset viewer.