Changeset 14048


Ignore:
Timestamp:
11/28/12 21:04:08 (12 years ago)
Author:
Mathieu Morlighem
Message:

NEW: working on minimum curvature interpolation module

Location:
issm/trunk-jpl/src/c
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/Container/Observations.cpp

    r13797 r14048  
    424424        *pprediction = obs;
    425425}/*}}}*/
     426/*FUNCTION Observations::InterpolationV4{{{*/
     427void Observations::InterpolationV4(IssmPDouble *pprediction,IssmPDouble x_interp,IssmPDouble y_interp,IssmPDouble radius,int mindata,int maxdata){
     428
     429        /*Intermediaries*/
     430        int         i,j,n_obs;
     431        IssmPDouble prediction,h;
     432        IssmPDouble *x       = NULL;
     433        IssmPDouble *y       = NULL;
     434        IssmPDouble *obs     = NULL;
     435        IssmPDouble *Green   = NULL;
     436        IssmPDouble *weights = NULL;
     437        IssmPDouble *d       = NULL;
     438
     439        /*Some checks*/
     440        _assert_(maxdata>0);
     441        _assert_(pprediction);
     442
     443        /*If radius is not provided or is 0, return all observations*/
     444        if(radius==0) radius=this->quadtree->root->length;
     445
     446        /*Get list of observations for current point*/
     447        this->ObservationList(&x,&y,&obs,&n_obs,x_interp,y_interp,radius,maxdata);
     448
     449        /*If we have less observations than mindata, return UNDEF*/
     450        if(n_obs<mindata){
     451                prediction = UNDEF;
     452        }
     453        else{
     454
     455                /*Allocate intermediary matrix and vectors*/
     456                Green = xNew<IssmPDouble>(n_obs*n_obs);
     457                d     = xNew<IssmPDouble>(n_obs);
     458
     459                /*First: distance vector*/
     460                for(i=0;i<n_obs;i++){
     461                        d[i] = sqrt( (x[i]-x_interp)*(x[i]-x_interp) + (y[i]-y_interp)*(y[i]-y_interp) );
     462                }
     463
     464                /*Build Green function matrix*/
     465                for(i=0;i<n_obs;i++){
     466                        for(j=0;j<=i;j++){
     467                                h = sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
     468                                if(h>0){
     469                                        Green[j*n_obs+i] = h*h*(log(h)-1.);
     470                                }
     471                                else{
     472                                        Green[j*n_obs+i] = 0.;
     473                                }
     474                                Green[i*n_obs+j] = Green[j*n_obs+i];
     475                        }
     476                }
     477
     478                /*Compute weights*/
     479#if _HAVE_GSL_
     480                SolverxSeq(&weights,Green,obs,n_obs); // Green^-1 obs
     481#else
     482                _error_("GSL is required");
     483#endif
     484
     485                /*ok now we can interpolate with these weights*/
     486
     487                _error_("Not implemented yet");
     488        }
     489
     490        /*clean-up*/
     491        *pprediction = prediction;
     492        xDelete<IssmPDouble>(x);
     493        xDelete<IssmPDouble>(y);
     494        xDelete<IssmPDouble>(obs);
     495}/*}}}*/
    426496/*FUNCTION Observations::QuadtreeColoring{{{*/
    427497void Observations::QuadtreeColoring(IssmPDouble* A,IssmPDouble *x,IssmPDouble *y,int n){
  • issm/trunk-jpl/src/c/Container/Observations.h

    r13623 r14048  
    2828                void ClosestObservation(IssmDouble *px,IssmDouble *py,IssmDouble *pobs,IssmDouble x_interp,IssmDouble y_interp,IssmDouble radius);
    2929                void InterpolationIDW(IssmDouble *pprediction,IssmDouble x_interp,IssmDouble y_interp,IssmDouble radius,int mindata,int maxdata,IssmDouble power);
     30                void InterpolationV4(IssmDouble *pprediction,IssmDouble x_interp,IssmDouble y_interp,IssmDouble radius,int mindata,int maxdata);
    3031                void InterpolationKriging(IssmDouble *pprediction,IssmDouble *perror,IssmDouble x_interp,IssmDouble y_interp,IssmDouble radius,int mindata,int maxdata,Variogram* variogram);
    3132                void InterpolationNearestNeighbor(IssmDouble *pprediction,IssmDouble x_interp,IssmDouble y_interp,IssmDouble radius);
  • issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp

    r13216 r14048  
    117117                xDelete<double>(gate.percent);
    118118        }
     119        else if(strcmp(output,"v4")==0){ //Inverse distance weighting
     120                /*initialize thread parameters: */
     121                gate.n_interp     = n_interp;
     122                gate.x_interp     = x_interp;
     123                gate.y_interp     = y_interp;
     124                gate.radius       = radius;
     125                gate.mindata      = mindata;
     126                gate.maxdata      = maxdata;
     127                gate.variogram    = variogram;
     128                gate.observations = observations;
     129                gate.predictions  = predictions;
     130                gate.error        = error;
     131                gate.percent      = xNewZeroInit<double>(num);
     132
     133                /*launch the thread manager with Krigingxt as a core: */
     134                LaunchThread(v4t,(void*)&gate,num);
     135                _printLine_("\r      interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"%");
     136                xDelete<double>(gate.percent);
     137        }
    119138        else if(strcmp(output,"prediction")==0){
    120139
     
    292311        return NULL;
    293312}/*}}}*/
     313/*FUNCTION v4t{{{*/
     314void* v4t(void* vpthread_handle){
     315
     316        /*gate variables :*/
     317        KrigingxThreadStruct *gate        = NULL;
     318        pthread_handle       *handle      = NULL;
     319        int my_thread;
     320        int num_threads;
     321        int i0,i1;
     322
     323        /*recover handle and gate: */
     324        handle      = (pthread_handle*)vpthread_handle;
     325        gate        = (KrigingxThreadStruct*)handle->gate;
     326        my_thread   = handle->id;
     327        num_threads = handle->num;
     328
     329        /*recover parameters :*/
     330        int           n_interp     = gate->n_interp;
     331        double       *x_interp     = gate->x_interp;
     332        double       *y_interp     = gate->y_interp;
     333        double        radius       = gate->radius;
     334        int           mindata      = gate->mindata;
     335        int           maxdata      = gate->maxdata;
     336        Variogram    *variogram    = gate->variogram;
     337        Observations *observations = gate->observations;
     338        double       *predictions  = gate->predictions;
     339        double       *error        = gate->error;
     340        double       *percent      = gate->percent;
     341
     342        /*Intermediaries*/
     343        double localpercent;
     344
     345        /*partition loop across threads: */
     346        PartitionRange(&i0,&i1,n_interp,num_threads,my_thread);
     347        for(int idx=i0;idx<i1;idx++){
     348
     349                /*Print info*/
     350                percent[my_thread]=double(idx-i0)/double(i1-i0)*100.;
     351                localpercent=percent[0];
     352                for(int i=1;i<num_threads;i++) localpercent=min(localpercent,percent[i]);
     353                if(my_thread==0) _printString_("\r      interpolation progress: "<<setw(6)<<setprecision(2)<<localpercent<<"%");
     354
     355                observations->InterpolationV4(&predictions[idx],x_interp[idx],y_interp[idx],radius,mindata,maxdata);
     356        }
     357        return NULL;
     358}/*}}}*/
    294359
    295360void ProcessVariogram(Variogram **pvariogram,Options* options){/*{{{*/
  • issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.h

    r12832 r14048  
    3535void* NearestNeighbort(void*);
    3636void* idwt(void*);
     37void* v4t(void*);
    3738#endif /* _KRIGINGX_H */
Note: See TracChangeset for help on using the changeset viewer.