Ignore:
Timestamp:
08/25/22 16:50:29 (3 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 27230

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/c/classes/Inputs/TransientInput.cpp

    r27035 r27232  
    99#endif
    1010
     11#include <numeric>
    1112#include "./TransientInput.h"
    1213#include "./TriaInput.h"
     
    208209
    209210        /*This is a new time step! we need to add it to the list*/
    210         if(this->numtimesteps>0 && time<this->timesteps[this->numtimesteps-1]) _error_("timestep values must increase sequentially");
     211        if(this->numtimesteps>0 && time<this->timesteps[this->numtimesteps-1]) _error_("timestep values must increase sequentially, here " << this->timesteps[this->numtimesteps-1] <<" is the last step but smaller than the preceding "<< time<<"\n");
    211212
    212213        IssmDouble *old_timesteps = NULL;
     
    433434
    434435        /*First, recover current time from parameters: */
    435         bool linear_interp,cycle;
     436        bool linear_interp,average,cycle;
    436437        IssmDouble dt;
    437438        this->parameters->FindParam(&linear_interp,TimesteppingInterpForcingEnum);
     439        this->parameters->FindParam(&average,TimesteppingAverageForcingEnum);
    438440        this->parameters->FindParam(&cycle,TimesteppingCycleForcingEnum);
    439441        this->parameters->FindParam(&dt,TimesteppingTimeStepEnum);          /*transient core time step*/
     
    471473
    472474        /*Figure step out*/
    473         int offset;
     475        int offset, prevoffset;
    474476        if(!binary_search(&offset,time,this->timesteps,this->numtimesteps)){
     477                _error_("Input not found (is TransientInput sorted ?)");
     478        }
     479        if(!binary_search(&prevoffset,reCast<IssmDouble>(time-dt),this->timesteps,this->numtimesteps)){
    475480                _error_("Input not found (is TransientInput sorted ?)");
    476481        }
     
    488493                this->current_step = 0.;
    489494                this->current_input = this->inputs[0]->copy();
     495
     496        }
     497        else if(offset-prevoffset>1 && prevoffset >=0 && average){
     498                /*get values for the last time: */
     499                _assert_(time>=this->timesteps[offset]);
     500
     501                /*If already processed return*/
     502                if(this->current_step==reCast<IssmDouble>(offset)) return;
     503
     504                /*Prepare input*/
     505                if(this->current_input) delete this->current_input;
     506                this->current_step  = reCast<IssmDouble>(offset);
     507
     508                this->current_input = this->inputs[prevoffset]->copy();
     509                for(int i=prevoffset+1;i<offset;i++) {
     510                        this->current_input->AXPY(this->inputs[i],+1.0);
     511                }
     512                this->current_input->Scale(1./(offset-prevoffset));
    490513
    491514        }
     
    535558        IssmDouble  timespan,mid_step;
    536559        int         found,start_offset,end_offset,input_offset;
     560
    537561
    538562        /*go through the timesteps, and grab offset for start and end*/
     
    573597                        _assert_(dt>0.);
    574598                }
    575                 Input* stepinput=this->inputs[offset+1];
    576 
     599                Input* stepinput=this->inputs[offset+1]->copy();
    577600                switch(averaging_method){
    578601                        case 0: /*Arithmetic mean*/
     
    608631                                _error_("averaging method is not recognised");
    609632                }
     633                delete stepinput;
    610634                dtsum+=dt;
    611635                offset+=1;
Note: See TracChangeset for help on using the changeset viewer.