Changeset 27703


Ignore:
Timestamp:
04/24/23 08:10:27 (2 years ago)
Author:
Mathieu Morlighem
Message:

CHG: making input averaging work

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

Legend:

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

    r26468 r27703  
    227227}
    228228/*}}}*/
     229void ControlInput::AverageAndReplace(void){/*{{{*/
     230        this->values->AverageAndReplace();
     231}
     232/*}}}*/
    229233TriaInput* ControlInput::GetTriaInput(){/*{{{*/
    230234
  • issm/trunk-jpl/src/c/classes/Inputs/ControlInput.h

    r25508 r27703  
    4848                TriaInput* GetTriaInput();
    4949                PentaInput* GetPentaInput();
     50                void AverageAndReplace(void);
    5051};
    5152#endif  /* _CONTROLINPUT_H */
  • issm/trunk-jpl/src/c/classes/Inputs/TriaInput.cpp

    r27691 r27703  
    408408void TriaInput::AverageAndReplace(void){/*{{{*/
    409409
     410        if(this->M!=this->numberofelements_local) _error_("not implemented for P1");
     411
    410412        /*Get local sum and local size*/
    411413        IssmDouble sum  = 0.;
     414        int        weight;
    412415        for(int i=0;i<this->M*this->N;i++) sum += this->values[i];
    413         sum = sum/(this->M*this->N);
     416        weight = this->M*this->N;
    414417
    415418        /*Get sum across all procs*/
    416419        IssmDouble all_sum;
     420        int        all_weight;
    417421        ISSM_MPI_Allreduce((void*)&sum,(void*)&all_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     422        ISSM_MPI_Allreduce((void*)&weight,(void*)&all_weight,1,ISSM_MPI_INT,ISSM_MPI_SUM,IssmComm::GetComm());
    418423
    419424        /*Divide by number of procs*/
    420         int        num_procs = IssmComm::GetSize();
    421         IssmDouble newvalue = all_sum/num_procs;
     425        IssmDouble newvalue = all_sum/reCast<IssmPDouble>(all_weight);
    422426
    423427        /*Now replace existing input*/
Note: See TracChangeset for help on using the changeset viewer.