Changeset 24679


Ignore:
Timestamp:
04/01/20 00:38:51 (5 years ago)
Author:
yfischler
Message:

NEW: reusing allocated matrices in solutionsequence_nonlinear

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/modules/SystemMatricesx/SystemMatricesx.cpp

    r24433 r24679  
    88#include "../AllocateSystemMatricesx/AllocateSystemMatricesx.h"
    99
    10 void SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax,FemModel* femmodel){
     10void SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax,FemModel* femmodel, bool isAllocated){
    1111
    1212        /*intermediary: */
     
    6464
    6565        /*Allocate stiffness matrices and load vector*/
    66         AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
     66        if(isAllocated) {
     67                Kff  = *pKff;
     68                Kfs  = *pKfs;
     69                pf   = *ppf;
     70                df   = *pdf;
     71        }
     72        else {
     73                AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
     74        }
    6775
    6876        /*Display size*/
  • issm/trunk-jpl/src/c/modules/SystemMatricesx/SystemMatricesx.h

    r16789 r24679  
    99
    1010/* local prototypes: */
    11 void SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax,FemModel* femmodel);
     11void SystemMatricesx(Matrix<IssmDouble>** pKff, Matrix<IssmDouble>** pKfs, Vector<IssmDouble>** ppf, Vector<IssmDouble>** pdf, IssmDouble* pkmax,FemModel* femmodel, bool isAllocated=false);
    1212
    1313#endif  /* _SYSTEMMATRICESX_H */
  • issm/trunk-jpl/src/c/solutionsequences/solutionsequence_nonlinear.cpp

    r23587 r24679  
    5858        InputUpdateFromSolutionx(femmodel,ug);
    5959
     60        // allocate the matrices once and reuce them per iteration
     61        AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
     62
    6063        for(;;){
    6164
     
    6467                delete ug;
    6568
    66                 SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
     69                SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel, true);
    6770                CreateNodalConstraintsx(&ys,femmodel->nodes);
    68                 Reduceloadx(pf, Kfs, ys); delete Kfs;
     71                Reduceloadx(pf, Kfs, ys);
    6972                femmodel->profiler->Start(SOLVER);
    7073                Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
     
    7376                Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
    7477
    75                 convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs); delete Kff; delete pf; delete df;
     78                convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs);
    7679                InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
    7780                InputUpdateFromSolutionx(femmodel,ug);
     
    102105                        break;
    103106                }
     107
     108                // Set the matrix entries to zero if we do an other iteration
     109                Kff->SetZero();
     110                Kfs->SetZero();
     111                df->Set(0);
     112                pf->Set(0);
    104113        }
     114
     115        // delete matrices after the iteration loop
     116        delete Kff; delete pf; delete df;
     117        delete Kfs;
    105118
    106119        if(VerboseConvergence()) _printf0_("\n   total number of iterations: " << count << "\n");
  • issm/trunk-jpl/src/c/toolkits/issm/IssmAbsMat.h

    r15777 r24679  
    4343                virtual void SetValues(int m,int* idxm,int n,int* idxn,doubletype* values,InsMode mode)=0;
    4444                virtual void Convert(MatrixType type)=0;
     45                virtual void SetZero(void){};
    4546                #ifndef _HAVE_WRAPPERS_
    4647                virtual IssmAbsVec<IssmDouble>* Solve(IssmAbsVec<IssmDouble>* pf, Parameters* parameters)=0;
  • issm/trunk-jpl/src/c/toolkits/issm/IssmMat.h

    r23044 r24679  
    239239                        matrix->convert(type);
    240240                }/*}}}*/
     241                void SetZero(void){/*{{{*/
     242                        matrix->SetZero();
     243                }/*}}}*/
    241244                #ifndef _HAVE_WRAPPERS_
    242245                IssmVec<doubletype>* Solve(IssmVec<doubletype>* pf, Parameters* parameters){ /*{{{*/
  • issm/trunk-jpl/src/c/toolkits/objects/Matrix.h

    r22558 r24679  
    307307                }
    308308                /*}}}*/
    309 
     309                /*
     310                * sets all values to 0 but keeps the structure of a sparse matrix
     311                */
     312                void SetZero(void) {/*{{{*/
     313                        if(type==PetscMatType){
     314                                #ifdef _HAVE_PETSC_
     315                                this->pmatrix->SetZero();
     316                                #endif
     317                        }
     318                        else{
     319                                this->imatrix->SetZero();
     320                        }
     321                }
     322                /*}}}*/
    310323};
    311324
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscMat.cpp

    r23255 r24679  
    193193}
    194194/*}}}*/
     195void PetscMat::SetZero(void){/*{{{*/
     196        MatZeroEntries(this->matrix);
     197}
     198/*}}}*/
  • issm/trunk-jpl/src/c/toolkits/petsc/objects/PetscMat.h

    r23255 r24679  
    5252                void SetValues(int m,int* idxm,int n,int* idxn,IssmDouble* values,InsMode mode);
    5353                void Convert(MatrixType type);
     54                void SetZero(void);
    5455};
    5556
Note: See TracChangeset for help on using the changeset viewer.