Changeset 11713


Ignore:
Timestamp:
03/14/12 15:37:29 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added lots of asserts to avoid nasty segmentation faults

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

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp

    r11695 r11713  
    183183void Matrix::Assemble(void){
    184184        #ifdef _HAVE_PETSC_
     185                _assert_(this->matrix);
    185186                MatAssemblyBegin(this->matrix,MAT_FINAL_ASSEMBLY);
    186187                MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
     
    199200        double norm=0;
    200201        #ifdef _HAVE_PETSC_
    201             MatNorm(this->matrix,ISSMToPetscNormMode(norm_type),&norm);
     202                _assert_(this->matrix);
     203                MatNorm(this->matrix,ISSMToPetscNormMode(norm_type),&norm);
    202204        #else
    203205                _error_("not implemented yet!");
     
    210212       
    211213        #ifdef _HAVE_PETSC_
    212             MatGetSize(this->matrix,pM,pN);
     214                _assert_(this->matrix);
     215                MatGetSize(this->matrix,pM,pN);
    213216        #else
    214217                _error_("not implemented yet!");
     
    220223       
    221224        #ifdef _HAVE_PETSC_
    222             MatGetLocalSize(this->matrix,pM,pN);
     225                _assert_(this->matrix);
     226                MatGetLocalSize(this->matrix,pM,pN);
    223227        #else
    224228                _error_("not implemented yet!");
     
    230234
    231235        #ifdef _HAVE_PETSC_
    232             MatMultPatch(this->matrix,X->vector,AX->vector);
     236                _assert_(this->matrix);
     237                _assert_(X->vector);
     238                MatMultPatch(this->matrix,X->vector,AX->vector);
    233239        #else
    234240                _error_("not implemented yet!");
     
    244250
    245251        #ifdef _HAVE_PETSC
     252                _assert_(this->matrix);
    246253                MatDuplicate(this->matrix,MAT_COPY_VALUES,&output->matrix);
    247254        #else
  • issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp

    r11704 r11713  
    150150               
    151151        #ifdef _HAVE_PETSC_
     152                _assert_(this->vector);
    152153                VecAssemblyBegin(this->vector);
    153154                VecAssemblyEnd(this->vector);
     
    163164               
    164165        #ifdef _HAVE_PETSC_
     166                _assert_(this->vector);
    165167                VecSetValues(this->vector,ssize,list,values,ISSMToPetscInsertMode(mode));
    166168        #else
     
    173175void Vector::SetValue(int dof, double value, InsMode mode){
    174176               
    175                
    176         #ifdef _HAVE_PETSC_
     177        #ifdef _HAVE_PETSC_
     178                _assert_(this->vector);
    177179                VecSetValues(this->vector,1,&dof,&value,ISSMToPetscInsertMode(mode));
    178180        #else
     
    185187void Vector::GetValue(double* pvalue,int dof){
    186188               
    187                
    188         #ifdef _HAVE_PETSC_
    189         VecGetValues(this->vector,1,&dof,pvalue);
    190         #else
    191                 _error_("not implemented yet!");
    192         #endif
    193 
    194 }
    195 /*}}}*/
    196                
     189        #ifdef _HAVE_PETSC_
     190                _assert_(this->vector);
     191                VecGetValues(this->vector,1,&dof,pvalue);
     192        #else
     193                _error_("not implemented yet!");
     194        #endif
     195}
     196/*}}}*/
    197197/*FUNCTION Vector::GetSize{{{1*/
    198198void Vector::GetSize(int* pM){
    199199               
    200200        #ifdef _HAVE_PETSC_
     201                _assert_(this->vector);
    201202                VecGetSize(this->vector,pM);
    202203        #else
     
    210211               
    211212        #ifdef _HAVE_PETSC_
     213                _assert_(this->vector);
    212214                VecGetLocalSize(this->vector,pM);
    213215        #else
     
    224226        #ifdef _HAVE_PETSC_
    225227                Vec vec_output=NULL;
     228                _assert_(this->vector);
    226229                VecDuplicate(this->vector,&vec_output);
    227230                output->vector=vec_output;
     
    238241       
    239242        #ifdef _HAVE_PETSC_
     243                _assert_(this->vector);
    240244                VecSet(this->vector,value);
    241245        #else
     
    249253       
    250254        #ifdef _HAVE_PETSC_
     255                _assert_(this->vector);
    251256                VecAXPY(this->vector,a,X->vector);
    252257        #else
     
    259264       
    260265        #ifdef _HAVE_PETSC_
     266                _assert_(this->vector);
    261267                VecAYPX(this->vector,a,X->vector);
    262268        #else
     
    297303        double norm=0;
    298304        #ifdef _HAVE_PETSC_
    299             VecNorm(this->vector,ISSMToPetscNormMode(norm_type),&norm);
     305                _assert_(this->vector);
     306                VecNorm(this->vector,ISSMToPetscNormMode(norm_type),&norm);
    300307        #else
    301308                _error_("not implemented yet!");
     
    308315       
    309316        #ifdef _HAVE_PETSC_
    310             VecScale(this->vector,scale_factor);
    311         #else
    312                 _error_("not implemented yet!");
    313         #endif
    314 }
    315 /*}}}*/
    316 /*FUNCTION Vector::Scale{{{1*/
     317                _assert_(this->vector);
     318                VecScale(this->vector,scale_factor);
     319        #else
     320                _error_("not implemented yet!");
     321        #endif
     322}
     323/*}}}*/
     324/*FUNCTION Vector::Dot{{{1*/
    317325double Vector::Dot(Vector* vector){
    318326
    319327        double dot;
    320328        #ifdef _HAVE_PETSC_
    321             VecDot(this->vector,vector->vector,&dot);
     329                _assert_(this->vector);
     330                VecDot(this->vector,vector->vector,&dot);
    322331        #else
    323332                _error_("not implemented yet!");
     
    330339
    331340        #ifdef _HAVE_PETSC_
     341                _assert_(this->vector);
    332342                VecPointwiseDivide(this->vector,x->vector,y->vector);
    333343        #else
Note: See TracChangeset for help on using the changeset viewer.