Changeset 13574


Ignore:
Timestamp:
10/09/12 21:05:46 (12 years ago)
Author:
Mathieu Morlighem
Message:

BUG: rewrote binary_search for double, there was a segfault in the previous implementation

Location:
issm/trunk-jpl/src/c/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r13554 r13574  
    187187        /*Now delete: */
    188188        delete profiler;
    189 
    190189}
    191190/*}}}*/
  • issm/trunk-jpl/src/c/classes/objects/Inputs/TransientInput.cpp

    r13569 r13574  
    429429        IssmDouble  alpha1,alpha2;
    430430       
    431         Input*  input=NULL;
    432         Input*  input1=NULL;
    433         Input*  input2=NULL;
     431        Input *input  = NULL;
     432        Input *input1 = NULL;
     433        Input *input2 = NULL;
    434434       
    435435        bool    found=false;
     
    440440         *fall within. Then interpolate the values on this interval: */
    441441        found_offset=binary_search(&offset,intime,this->timesteps,this->numtimesteps);
    442 
    443         if (found_offset==0){
    444                 if(intime<this->timesteps[0]){
    445                         /*get values for the first time: */
    446                         input=(Input*)((Input*)this->inputs->GetObjectByOffset(0))->copy();
    447                         found=true;
    448                 }
    449                 else if(intime>this->timesteps[this->numtimesteps-1]){
    450                         /*get values for the last time: */
    451                         input=(Input*)((Input*)this->inputs->GetObjectByOffset(numtimesteps-1))->copy();
    452                         found=true;
    453                 }
     442        if (found_offset==0) _error_("Input not found (is TransientInput sorted ?)");
     443
     444        if (found_offset==-1){
     445                /*get values for the first time: */
     446                _assert_(intime<this->timesteps[0]);
     447                input=(Input*)((Input*)this->inputs->GetObjectByOffset(0))->copy();
     448                found=true;
     449        }
     450        else if(found_offset==3){
     451                /*get values for the last time: */
     452                _assert_(intime>=this->timesteps[this->numtimesteps-1]);
     453                input=(Input*)((Input*)this->inputs->GetObjectByOffset(this->numtimesteps-1))->copy();
     454                found=true;
     455        }
     456        else if(found_offset==2){
     457                /*get values for this time: */
     458                _assert_(intime==this->timesteps[offset]);
     459                input=(Input*)((Input*)this->inputs->GetObjectByOffset(offset))->copy();
     460                found=true;
    454461        }
    455462        else{
    456                 if (found_offset==1){
    457                         /*intime is exactly equal to this->timesteps[offset]: */
    458                         input=(Input*)((Input*)this->inputs->GetObjectByOffset(offset))->copy();
    459                         found=true;
    460                 }
    461                 else if (found_offset==2){
    462                        
    463                         /*ok, we have the interval ]offset:offset+1[. Interpolate linearly for now: */
    464                         deltat=this->timesteps[offset+1]-this->timesteps[offset];
    465                         alpha2=(intime-this->timesteps[offset])/deltat;
    466                         alpha1=(1.0-alpha2);
    467 
    468                         input1=(Input*)this->inputs->GetObjectByOffset(offset);
    469                         input2=(Input*)this->inputs->GetObjectByOffset(offset+1);
    470 
    471                         input=(Input*)input1->copy();
    472                         input->Scale(alpha1);
    473                         input->AXPY(input2,alpha2);
    474 
    475                         found=true;
    476                 }
    477                 else _error_("binary_search returned the following value for found: " << found_offset<< "which is not supported yet!");
    478         }
    479 
    480         if(!found)_error_("did not find time interval on which to interpolate forcing values!");
     463                /*get values between two times ]offset:offset+1[, Interpolate linearly*/
     464                _assert_(intime>this->timesteps[offset] && intime<this->timesteps[offset+1]);
     465                deltat=this->timesteps[offset+1]-this->timesteps[offset];
     466                alpha2=(intime-this->timesteps[offset])/deltat;
     467                alpha1=(1.0-alpha2);
     468
     469                input1=(Input*)this->inputs->GetObjectByOffset(offset);
     470                input2=(Input*)this->inputs->GetObjectByOffset(offset+1);
     471
     472                input=(Input*)input1->copy();
     473                input->Scale(alpha1);
     474                input->AXPY(input2,alpha2);
     475
     476                found=true;
     477        }
    481478
    482479        /*Assign output pointer*/
Note: See TracChangeset for help on using the changeset viewer.