Changeset 23231


Ignore:
Timestamp:
09/08/18 13:03:10 (7 years ago)
Author:
kruegern
Message:

NEW: added Dakota/QMU Chaco tests (234,235,413,414,417,444), minor bug fixes, left out 418 due to unresolved memory issues

Location:
issm/trunk-jpl
Files:
6 added
9 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/modules/Chaco.py

    r23095 r23231  
    55
    66   Usage:
    7       [assgn] = Chaco(A,vwgts,ewgts,x,y,z,options,nparts,goal);
     7      assgn = Chaco(A,vwgts,ewgts,x,y,z,options,nparts,goal);
    88
    99   A:                   Input adjacency matrix
  • issm/trunk-jpl/src/m/modules/Scotch.py

    r23095 r23231  
    22
    33def Scotch(*varargin):
    4 '''SCOTCH - Scotch partitioner
     4        '''SCOTCH - Scotch partitioner
    55
    66   Usage:
  • issm/trunk-jpl/src/m/partition/partitioner.py

    r23095 r23231  
    33import MatlabFuncs as m
    44from adjacency import *
    5 #from Chaco import *
     5from Chaco import *
    66#from Scotch import *
    7 #from MeshPartition import *
     7from MeshPartition import *
    88from project3d import *
     9from mesh2d import *
    910
    1011def partitioner(md,*varargin):
     
    6061
    6162        if m.strcmpi(package,'chaco'):
    62                 raise RuntimeError('Chaco is not currently supported for this function')
     63                #raise RuntimeError('Chaco is not currently supported for this function')
    6364
    6465                #  default method (from chaco.m)
    65                 #method=np.array([1,1,0,0,1,1,50,0,.001,7654321]).reshape(-1,1)
    66                 #method[0]=3    #  global method (3=inertial (geometric))
    67                 #method[2]=0    #  vertex weights (0=off, 1=on)
     66                method=np.array([1,1,0,0,1,1,50,0,.001,7654321])
     67                method[0]=3    #  global method (3=inertial (geometric))
     68                method[2]=0    #  vertex weights (0=off, 1=on)
    6869
    6970                #specify bisection
    70                 #method[5]=options.getfieldvalue('section')#  ndims (1=bisection, 2=quadrisection, 3=octasection)
     71                method[5]=options.getfieldvalue('section')#  ndims (1=bisection, 2=quadrisection, 3=octasection)
    7172
    7273                #are we using weights?
    73                 #if m.strcmpi(options.getfieldvalue('weighting'),'on'):
    74                         #weights=np.floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight))
    75                         #method[2]=1
    76                 #else:
    77                         #weights=[]
     74                if m.strcmpi(options.getfieldvalue('weighting'),'on'):
     75                        weights=np.floor(md.qmu.vertex_weight/min(md.qmu.vertex_weight))
     76                        method[2]=1
     77                else:
     78                        weights=[]
    7879       
     80                method = method.reshape(-1,1)   # transpose to 1x10 instead of 10
     81
    7982                #  partition into nparts
    80                 #if isinstance(md.mesh,mesh2d):
    81                         #part=Chaco(md.qmu.adjacency,weights,[],md.mesh.x, md.mesh.y,np.zeros((md.mesh.numberofvertices,)),method,npart,[]).T+1 #index partitions from 1 up. like metis.
    82                 #else:
    83                         #part=Chaco(md.qmu.adjacency,weights,[],md.mesh.x, md.mesh.y,md.mesh.z,method,npart,[]).T+1 #index partitions from 1 up. like metis.
    84        
     83                if isinstance(md.mesh,mesh2d):
     84                        part=np.array(Chaco(md.qmu.adjacency,weights,np.array([]),md.mesh.x, md.mesh.y,np.zeros((md.mesh.numberofvertices,)),method,npart,np.array([]))).T+1 #index partitions from 1 up. like metis.
     85                else:
     86                        part=np.array(Chaco(md.qmu.adjacency,weights,np.array([]),md.mesh.x, md.mesh.y,md.mesh.z,method,npart,np.array([]))).T+1 #index partitions from 1 up. like metis.
    8587       
    8688        elif m.strcmpi(package,'scotch'):
  • issm/trunk-jpl/src/m/qmu/dakota_in_write.py

    r23095 r23231  
    6262        filei2=fullfile(pathstr,name+ext)
    6363
    64         print 'Opening Dakota input file \''+filei2 + '\''
     64        print 'Opening Dakota input file \''+filei2 + '\'.'
    6565        try:
    6666                with open(filei2,'w+') as fidi:
  • issm/trunk-jpl/src/m/qmu/dakota_out_parse.py

    r23095 r23231  
    241241        dmax95 =prctile_issm(data,95,0)
    242242
     243        # Note: the following line may cause the following warning
     244        #       (should not crash or invalidate results) when one of
     245        #       the inputs does not change with respect to the
     246        #       other/s causing an internal divide-by-zero error
     247
     248        #/usr/local/lib/python2.7/dist-packages/numpy/lib/function_base.py:3163:
     249        #       RuntimeWarning: invalid value encountered in true_divide
     250        #       c /= stddev[:,None]
     251
     252        #       (and/or the same but with "c /= stddev[None, :]")
     253
    243254        dcorrel=np.corrcoef(data.T)
    244255
  • issm/trunk-jpl/src/m/qmu/process_qmu_response_data.m

    r23095 r23231  
    4343        %ok, process the domains named in qmu_mass_flux_profiles,  to build a list of segments (MatArray)
    4444        md.qmu.mass_flux_segments=cell(num_mass_flux,1);
    45         md.qmu.mass_flux_segments
    4645        for i=1:num_mass_flux,
    4746                md.qmu.mass_flux_segments{i}=MeshProfileIntersection(md.mesh.elements,md.mesh.x,md.mesh.y,[md.qmu.mass_flux_profile_directory '/' md.qmu.mass_flux_profiles{i}]);
    4847        end
    49         md.qmu.mass_flux_segments
    5048end
  • issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp

    r22671 r23231  
    4747        /*Fetch Data*/
    4848        FetchChacoData(&nvtxs,&adjacency,&start,&ewgts,A_IN,EWGTS_IN);
    49         FetchData(&vwgts,&nterms,VWGTS_IN); 
    50         FetchData(&x,&nterms,X_IN); 
    51         FetchData(&y,&nterms,Y_IN); 
    52         FetchData(&z,&nterms,Z_IN); 
    53         FetchData(&in_options,&nterms,OPTNS_IN); 
     49        FetchData(&vwgts,&nterms,VWGTS_IN);
     50        FetchData(&x,&nterms,X_IN);
     51        FetchData(&y,&nterms,Y_IN);
     52        FetchData(&z,&nterms,Z_IN);
     53        FetchData(&in_options,&nterms,OPTNS_IN);
    5454        for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
    55         FetchData(&npart,NPARTS_IN); 
     55        FetchData(&npart,NPARTS_IN);
    5656        //int * nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
    57         FetchData(&goal,&nterms,GOAL_IN); 
     57        FetchData(&goal,&nterms,GOAL_IN);
    5858
    5959        /*Allocate output: */
  • issm/trunk-jpl/src/wrappers/python/io/FetchPythonData.cpp

    r22674 r23231  
    3232        }
    3333        else if (PyInt_Check(py_float))
    34          dscalar=(double)PyInt_AsLong(py_float);
     34                dscalar=(double)PyInt_AsLong(py_float);
    3535        else if (PyBool_Check(py_float))
    3636                dscalar=(double)PyLong_AsLong(py_float);
     
    132132        double* dmatrix=NULL;
    133133        double* matrix=NULL;
    134         int M,N;
     134        int M=0;
     135        int N=0;
    135136        int ndim;
    136137        npy_intp*  dims=NULL;
     
    236237        /*output: */
    237238        int* matrix=NULL;
    238         int M,N;
     239        int M=0;
     240        int N=0;
    239241        int ndim;
    240242        npy_intp*  dims=NULL;
     
    325327        bool* bmatrix=NULL;
    326328        bool* matrix=NULL;
    327         int M,N;
     329        int M=0;
     330        int N=0;
    328331        int ndim;
    329332        npy_intp*  dims=NULL;
     
    411414        double* dvector=NULL;
    412415        double* vector=NULL;
    413         int M;
     416        int M=0;
    414417        int ndim;
    415418        npy_intp*  dims=NULL;
     
    499502        /*output: */
    500503        float* vector=NULL;
    501         int M;
     504        int M=0;
    502505        int ndim;
    503506        npy_intp*  dims=NULL;
     
    539542                                /*transform into int vector: */
    540543                                vector=xNew<float>(M);
    541                                 for(i=0;i<M;i++)vector[i]=(float)lvector[i];
     544                                for(i=0;i<M;i++)vector[i]=(float)dvector[i];
    542545                        }
    543546
     
    566569                }
    567570                else
    568                  vector=NULL;
     571                        vector=NULL;
    569572        }
    570573        else{
     
    584587        /*output: */
    585588        int* vector=NULL;
    586         int M;
     589        int M=0;
    587590        int ndim;
    588591        npy_intp*  dims=NULL;
     
    624627                                /*transform into int vector: */
    625628                                vector=xNew<int>(M);
    626                                 for(i=0;i<M;i++)vector[i]=(int)lvector[i];
     629                                for(i=0;i<M;i++)vector[i]=(int)dvector[i];
    627630                        }
    628631
     
    672675        bool* bvector=NULL;
    673676        bool* vector=NULL;
    674         int M;
     677        int M=0;
    675678        int ndim;
    676679        npy_intp*  dims=NULL;
     
    923926        *pcontours=contours;
    924927}
    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 }
     928
     929void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN, PyObject* EWGTS_IN){/*{{{*/
     930
     931        double* a = ((double*)PyArray_DATA((PyArrayObject*)A_IN));
     932        int ndim  = PyArray_NDIM((PyArrayObject*)A_IN);
     933        int nzmax = PyArray_CountNonzero((PyArrayObject*)A_IN);
     934
     935        /*Fetch adjacency matrix:*/
     936        int      nvtxs       = PyArray_DIMS((PyArrayObject*)A_IN)[1];
     937
     938        int* mwstart = xNewZeroInit<int>(nvtxs+1);
     939        pyGetJc(a,nvtxs,mwstart);
     940
     941        int* mwadjacency = xNewZeroInit<int>(nzmax);
     942        pyGetIr(a,nvtxs,nzmax,mwadjacency);
     943       
     944        int* start = xNew<int>(nvtxs+1);
     945        for(int i=0;i<nvtxs+1;i++) start[i]=(int)mwstart[i];
     946        int* adjacency = xNew<int>(nzmax);
     947        for(int i=0; i<nzmax; i++) adjacency[i]=(int)mwadjacency[i];
     948
     949        /*Get edges weights*/
     950        int nedges = start[nvtxs];
     951        float* ewgts = NULL;
     952        int size = PyArray_SIZE((PyArrayObject*)EWGTS_IN);
     953        //size may be 1 and still be empty;
     954        //presumably size of edge_weights input will never be exactly 1
     955        if(size != 1 && size != 0){
     956                ewgts = xNewZeroInit<float>(nedges);
     957                for(int i = 0; i<nedges;i++){
     958                        ewgts[i] = (float)a[i];
     959                }
     960        }
     961
     962        /*Assign output pointers*/
     963        *pnvtxs     = nvtxs;
     964        *padjacency = adjacency;
     965        *pstart     = start;
     966        *pewgts     = ewgts;
     967}
     968/*}}}*/
     969
     970void pyGetJc(double* a, int nvtxs, int* Jc){
     971/*{{{*/
     972        //get the number of non-zero elements in each row, adding to the prior number;
     973        //always starts with 0 and has length: number_of_rows_in(a)+1 == nvtxs+1
     974        // eg: 0, 1, 3, 6, 8, 13, ...
     975        // for: 1 in the first row, 2 in the second, 3 in the third, etc.
     976        int c = 0;
     977        Jc[c++] = 0;
     978
     979        for(int i=0;i<nvtxs;i++){
     980                for(int j=0;j<nvtxs;j++){
     981                        if ((int)a[i+(j*nvtxs)] != 0){
     982                                Jc[c] += 1;
     983                        }
     984                }
     985                c++;
     986                Jc[c] = Jc[c-1];
     987        }
     988        return;
     989}
     990/*}}}*/
     991
     992void pyGetIr(double* a, int nvtxs, int nzmax, int* Ir){
     993/*{{{*/
     994        //get the row-wise position of each non-zero element;
     995        //has length: number_of_non_zero_elements_in(a) == nzmax
     996        // eg: 10, 24, 25, 4, ...
     997        // the 10th, 24th, and 25th elements in the first row, the 4th in the second row
     998        // using pyGetJc to determine which indices correspond to which row
     999        int r = 0;
     1000
     1001        for(int i=0;i<nvtxs;i++){
     1002                for(int j=0;j<nvtxs;j++){
     1003                        if ((int)a[i+(j*nvtxs)] != 0){
     1004                                Ir[r] = j;
     1005                                r++;
     1006                        }
     1007                }
     1008        }
     1009        return;
     1010}
     1011/*}}}*/
    9291012
    9301013/*Python version dependent: */
  • issm/trunk-jpl/src/wrappers/python/io/pythonio.h

    r22674 r23231  
    5151void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,PyObject* A_IN,PyObject* EWGTS_IN);
    5252
     53void pyGetJc(double* a, int nvtxs, int* Jc);
     54void pyGetIr(double* a, int nvtxs, int nzmax, int* Ir);
     55
    5356int CheckNumPythonArguments(PyObject* inputs,int NRHS, void (*function)( void ));
    5457
Note: See TracChangeset for help on using the changeset viewer.