Changeset 8263 for issm/trunk


Ignore:
Timestamp:
05/11/11 11:56:19 (14 years ago)
Author:
Mathieu Morlighem
Message:

Error out when parameter is not found (use Exist to check wether it exist or not)

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

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/Container/Parameters.cpp

    r6213 r8263  
    4343
    4444/*Object management*/
     45/*FUNCTION Parameters::Exist{{{1*/
     46bool Parameters::Exist(int enum_type){
     47
     48        vector<Object*>::iterator object;
     49        Param* param=NULL;
     50
     51        for ( object=objects.begin() ; object < objects.end(); object++ ){
     52                param=(Param*)(*object);
     53                if(param->EnumType()==enum_type) return true;
     54        }
     55        return false;
     56}
     57/*}}}*/
    4558/*FUNCTION Parameters::FindParam(bool* pbool,int enum_type){{{1*/
    46 int   Parameters::FindParam(bool* pbool,int enum_type){
    47        
    48         /*Go through a dataset, and find a Param* object
    49          *which parameter name is "name" : */
    50        
    51         vector<Object*>::iterator object;
    52         Param* param=NULL;
    53 
    54         int found=0;
    55 
    56         for ( object=objects.begin() ; object < objects.end(); object++ ){
    57 
    58                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    59                 param=(Param*)(*object);
    60 
    61                 if(param->EnumType()==enum_type){
    62                         /*Ok, this is the one! Recover the value of this parameter: */
     59void Parameters::FindParam(bool* pbool,int enum_type){
     60       
     61        vector<Object*>::iterator object;
     62        Param* param=NULL;
     63
     64        for ( object=objects.begin() ; object < objects.end(); object++ ){
     65
     66                param=(Param*)(*object);
     67                if(param->EnumType()==enum_type){
    6368                        param->GetParameterValue(pbool);
    64                         found=1;
    65                         break;
    66                 }
    67         }
    68         return found;
     69                        return;
     70                }
     71        }
     72        _error_("could not find parameter %s",EnumToStringx(enum_type));
    6973}
    7074/*}}}*/
    7175/*FUNCTION Parameters::FindParam(int* pinteger,int enum_type){{{1*/
    72 int   Parameters::FindParam(int* pinteger,int enum_type){
    73        
    74         /*Go through a dataset, and find a Param* object
    75          *which parameter name is "name" : */
    76        
    77         vector<Object*>::iterator object;
    78         Param* param=NULL;
    79 
    80         int found=0;
    81 
    82         for ( object=objects.begin() ; object < objects.end(); object++ ){
    83 
    84                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    85                 param=(Param*)(*object);
    86 
    87                 if(param->EnumType()==enum_type){
    88                         /*Ok, this is the one! Recover the value of this parameter: */
     76void Parameters::FindParam(int* pinteger,int enum_type){
     77       
     78        vector<Object*>::iterator object;
     79        Param* param=NULL;
     80
     81        for ( object=objects.begin() ; object < objects.end(); object++ ){
     82
     83                param=(Param*)(*object);
     84                if(param->EnumType()==enum_type){
    8985                        param->GetParameterValue(pinteger);
    90                         found=1;
    91                         break;
    92                 }
    93         }
    94         return found;
     86                        return;
     87                }
     88        }
     89        _error_("could not find parameter %s",EnumToStringx(enum_type));
    9590}
    9691/*}}}*/
    9792/*FUNCTION Parameters::FindParam(double* pscalar, int enum_type){{{1*/
    98 int   Parameters::FindParam(double* pscalar, int enum_type){
    99        
    100         /*Go through a dataset, and find a Param* object
    101          *which parameter name is "name" : */
    102        
    103         vector<Object*>::iterator object;
    104         Param* param=NULL;
    105 
    106         int found=0;
    107 
    108         for ( object=objects.begin() ; object < objects.end(); object++ ){
    109 
    110                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    111                 param=(Param*)(*object);
    112 
    113                 if(param->EnumType()==enum_type){
    114                         /*Ok, this is the one! Recover the value of this parameter: */
     93void Parameters::FindParam(double* pscalar, int enum_type){
     94       
     95        vector<Object*>::iterator object;
     96        Param* param=NULL;
     97
     98        for ( object=objects.begin() ; object < objects.end(); object++ ){
     99
     100                param=(Param*)(*object);
     101                if(param->EnumType()==enum_type){
    115102                        param->GetParameterValue(pscalar);
    116                         found=1;
    117                         break;
    118                 }
    119         }
    120         return found;
     103                        return;
     104                }
     105        }
     106        _error_("could not find parameter %s",EnumToStringx(enum_type));
    121107}
    122108/*}}}*/
    123109/*FUNCTION Parameters::FindParam(char** pstring,int enum_type){{{1*/
    124 int   Parameters::FindParam(char** pstring,int enum_type){
    125        
    126         /*Go through a dataset, and find a Param* object
    127          *which parameter name is "name" : */
    128        
    129         vector<Object*>::iterator object;
    130         Param* param=NULL;
    131 
    132         int found=0;
    133 
    134         for ( object=objects.begin() ; object < objects.end(); object++ ){
    135 
    136                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    137                 param=(Param*)(*object);
    138 
    139                 if(param->EnumType()==enum_type){
    140                         /*Ok, this is the one! Recover the value of this parameter: */
     110void Parameters::FindParam(char** pstring,int enum_type){
     111       
     112        vector<Object*>::iterator object;
     113        Param* param=NULL;
     114
     115        for ( object=objects.begin() ; object < objects.end(); object++ ){
     116
     117                param=(Param*)(*object);
     118                if(param->EnumType()==enum_type){
    141119                        param->GetParameterValue(pstring);
    142                         found=1;
    143                         break;
    144                 }
    145         }
    146         return found;
     120                        return;
     121                }
     122        }
     123        _error_("could not find parameter %s",EnumToStringx(enum_type));
    147124
    148125}
    149126/*}}}*/
    150127/*FUNCTION Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){{{1*/
    151 int   Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){
    152        
    153         /*Go through a dataset, and find a Param* object
    154          *which parameter name is "name" : */
    155        
    156         vector<Object*>::iterator object;
    157         Param* param=NULL;
    158 
    159         int found=0;
    160 
    161         for ( object=objects.begin() ; object < objects.end(); object++ ){
    162 
    163                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    164                 param=(Param*)(*object);
    165 
    166                 if(param->EnumType()==enum_type){
    167                         /*Ok, this is the one! Recover the value of this parameter: */
     128void Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){
     129       
     130        vector<Object*>::iterator object;
     131        Param* param=NULL;
     132
     133        for ( object=objects.begin() ; object < objects.end(); object++ ){
     134
     135                param=(Param*)(*object);
     136                if(param->EnumType()==enum_type){
    168137                        param->GetParameterValue(pstringarray,pM);
    169                         found=1;
    170                         break;
    171                 }
    172         }
    173         return found;
     138                        return;
     139                }
     140        }
     141        _error_("could not find parameter %s",EnumToStringx(enum_type));
    174142
    175143}
    176144/*}}}*/
    177145/*FUNCTION Parameters::FindParam(int** pintarray,int* pM,int enum_type){{{1*/
    178 int   Parameters::FindParam(int** pintarray,int* pM, int enum_type){
    179 
    180         /*Go through a dataset, and find a Param* object
    181          *which parameter name is "name" : */
    182 
    183         vector<Object*>::iterator object;
    184         Param* param=NULL;
    185 
    186         int found=0;
    187 
    188         for ( object=objects.begin() ; object < objects.end(); object++ ){
    189 
    190                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    191                 param=(Param*)(*object);
    192 
    193                 if(param->EnumType()==enum_type){
    194                         /*Ok, this is the one! Recover the value of this parameter: */
     146void Parameters::FindParam(int** pintarray,int* pM, int enum_type){
     147
     148        vector<Object*>::iterator object;
     149        Param* param=NULL;
     150
     151        for ( object=objects.begin() ; object < objects.end(); object++ ){
     152
     153                param=(Param*)(*object);
     154                if(param->EnumType()==enum_type){
    195155                        param->GetParameterValue(pintarray,pM);
    196                         found=1;
    197                         break;
    198                 }
    199         }
    200         return found;
     156                        return;
     157                }
     158        }
     159        _error_("could not find parameter %s",EnumToStringx(enum_type));
    201160
    202161}
    203162/*}}}*/
    204163/*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM,int enum_type){{{1*/
    205 int   Parameters::FindParam(double** pdoublearray,int* pM, int enum_type){
    206        
    207         /*Go through a dataset, and find a Param* object
    208          *which parameter name is "name" : */
    209        
    210         vector<Object*>::iterator object;
    211         Param* param=NULL;
    212 
    213         int found=0;
    214 
    215         for ( object=objects.begin() ; object < objects.end(); object++ ){
    216 
    217                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    218                 param=(Param*)(*object);
    219 
    220                 if(param->EnumType()==enum_type){
    221                         /*Ok, this is the one! Recover the value of this parameter: */
     164void Parameters::FindParam(double** pdoublearray,int* pM, int enum_type){
     165
     166        vector<Object*>::iterator object;
     167        Param* param=NULL;
     168
     169        for ( object=objects.begin() ; object < objects.end(); object++ ){
     170
     171                param=(Param*)(*object);
     172                if(param->EnumType()==enum_type){
    222173                        param->GetParameterValue(pdoublearray,pM);
    223                         found=1;
    224                         break;
    225                 }
    226         }
    227         return found;
     174                        return;
     175                }
     176        }
     177        _error_("could not find parameter %s",EnumToStringx(enum_type));
    228178
    229179}
    230180/*}}}*/
    231181/*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){{{1*/
    232 int   Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){
    233        
    234         /*Go through a dataset, and find a Param* object
    235          *which parameter name is "name" : */
    236        
    237         vector<Object*>::iterator object;
    238         Param* param=NULL;
    239 
    240         int found=0;
    241 
    242         for ( object=objects.begin() ; object < objects.end(); object++ ){
    243 
    244                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    245                 param=(Param*)(*object);
    246 
    247                 if(param->EnumType()==enum_type){
    248                         /*Ok, this is the one! Recover the value of this parameter: */
     182void Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){
     183
     184        vector<Object*>::iterator object;
     185        Param* param=NULL;
     186
     187        for ( object=objects.begin() ; object < objects.end(); object++ ){
     188
     189                param=(Param*)(*object);
     190                if(param->EnumType()==enum_type){
    249191                        param->GetParameterValue(pdoublearray,pM,pN);
    250                         found=1;
    251                         break;
    252                 }
    253         }
    254         return found;
     192                        return;
     193                }
     194        }
     195        _error_("could not find parameter %s",EnumToStringx(enum_type));
    255196
    256197}
    257198/*}}}*/
    258199/*FUNCTION Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){{{1*/
    259 int   Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){
    260        
    261         /*Go through a dataset, and find a Param* object
    262          *which parameter name is "name" : */
    263        
    264         vector<Object*>::iterator object;
    265         Param* param=NULL;
    266 
    267         int found=0;
    268 
    269         for ( object=objects.begin() ; object < objects.end(); object++ ){
    270 
    271                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    272                 param=(Param*)(*object);
    273 
    274                 if(param->EnumType()==enum_type){
    275                         /*Ok, this is the one! Recover the value of this parameter: */
     200void Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){
     201       
     202        vector<Object*>::iterator object;
     203        Param* param=NULL;
     204
     205        for ( object=objects.begin() ; object < objects.end(); object++ ){
     206
     207                param=(Param*)(*object);
     208                if(param->EnumType()==enum_type){
    276209                        param->GetParameterValue(parray,pM,pmdims_array,pndims_array);
    277                         found=1;
    278                         break;
    279                 }
    280         }
    281         return found;
     210                        return;
     211                }
     212        }
     213        _error_("could not find parameter %s",EnumToStringx(enum_type));
    282214}
    283215/*}}}*/
    284216/*FUNCTION Parameters::FindParam(Vec* pvec,int enum_type){{{1*/
    285 int   Parameters::FindParam(Vec* pvec,int enum_type){
    286        
    287         /*Go through a dataset, and find a Param* object
    288          *which parameter name is "name" : */
    289        
    290         vector<Object*>::iterator object;
    291         Param* param=NULL;
    292 
    293         int found=0;
    294 
    295         for ( object=objects.begin() ; object < objects.end(); object++ ){
    296 
    297                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    298                 param=(Param*)(*object);
    299 
    300                 if(param->EnumType()==enum_type){
    301                         /*Ok, this is the one! Recover the value of this parameter: */
     217void Parameters::FindParam(Vec* pvec,int enum_type){
     218       
     219        vector<Object*>::iterator object;
     220        Param* param=NULL;
     221
     222        for ( object=objects.begin() ; object < objects.end(); object++ ){
     223
     224                param=(Param*)(*object);
     225                if(param->EnumType()==enum_type){
    302226                        param->GetParameterValue(pvec);
    303                         found=1;
    304                         break;
    305                 }
    306         }
    307         return found;
     227                        return;
     228                }
     229        }
     230        _error_("could not find parameter %s",EnumToStringx(enum_type));
    308231
    309232}
    310233/*}}}*/
    311234/*FUNCTION Parameters::FindParam(Mat* pmat,int enum_type){{{1*/
    312 int   Parameters::FindParam(Mat* pmat,int enum_type){
    313        
    314         /*Go through a dataset, and find a Param* object
    315          *which parameter name is "name" : */
    316        
    317         vector<Object*>::iterator object;
    318         Param* param=NULL;
    319 
    320         int found=0;
    321 
    322         for ( object=objects.begin() ; object < objects.end(); object++ ){
    323 
    324                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    325                 param=(Param*)(*object);
    326 
    327                 if(param->EnumType()==enum_type){
    328                         /*Ok, this is the one! Recover the value of this parameter: */
     235void Parameters::FindParam(Mat* pmat,int enum_type){
     236       
     237        vector<Object*>::iterator object;
     238        Param* param=NULL;
     239
     240        for ( object=objects.begin() ; object < objects.end(); object++ ){
     241
     242                param=(Param*)(*object);
     243                if(param->EnumType()==enum_type){
    329244                        param->GetParameterValue(pmat);
    330                         found=1;
    331                         break;
    332                 }
    333         }
    334         return found;
     245                        return;
     246                }
     247        }
     248        _error_("could not find parameter %s",EnumToStringx(enum_type));
    335249
    336250}
    337251/*}}}*/
    338252/*FUNCTION Parameters::FindParam(FILE** pfid,int enum_type){{{1*/
    339 int   Parameters::FindParam(FILE** pfid,int enum_type){
    340 
    341         /*Go through a dataset, and find a Param* object
    342          *which parameter name is "name" : */
    343 
    344         vector<Object*>::iterator object;
    345         Param* param=NULL;
    346 
    347         int found=0;
    348 
    349         for ( object=objects.begin() ; object < objects.end(); object++ ){
    350 
    351                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    352                 param=(Param*)(*object);
    353 
    354                 if(param->EnumType()==enum_type){
    355                         /*Ok, this is the one! Recover the value of this parameter: */
     253void Parameters::FindParam(FILE** pfid,int enum_type){
     254
     255        vector<Object*>::iterator object;
     256        Param* param=NULL;
     257
     258        for ( object=objects.begin() ; object < objects.end(); object++ ){
     259
     260                param=(Param*)(*object);
     261                if(param->EnumType()==enum_type){
    356262                        param->GetParameterValue(pfid);
    357                         found=1;
    358                         break;
    359                 }
    360         }
    361         return found;
     263                        return;
     264                }
     265        }
     266        _error_("could not find parameter %s",EnumToStringx(enum_type));
    362267}
    363268/*}}}*/
     
    487392Object* Parameters::FindParamObject(int enum_type){
    488393
    489         /*Go through a dataset, and find a Param* object
    490          *which parameter name is "name" : */
    491 
    492         vector<Object*>::iterator object;
    493         Param* param=NULL;
    494 
    495         for ( object=objects.begin() ; object < objects.end(); object++ ){
    496 
    497                 /*Ok, this object is a parameter, recover it and ask which name it has: */
    498                 param=(Param*)(*object);
    499 
    500                 if(param->EnumType()==enum_type){
    501                         /*Ok, this is the one! Return the object: */
     394        vector<Object*>::iterator object;
     395        Param* param=NULL;
     396
     397        for ( object=objects.begin() ; object < objects.end(); object++ ){
     398
     399                param=(Param*)(*object);
     400                if(param->EnumType()==enum_type){
    502401                        return (*object);
    503402                }
  • issm/trunk/src/c/Container/Parameters.h

    r6213 r8263  
    2626                /*}}}*/
    2727                /*numerics: {{{1*/
    28                 int   FindParam(bool* pinteger,int enum_type);
    29                 int   FindParam(int* pinteger,int enum_type);
    30                 int   FindParam(double* pscalar, int enum_type);
    31                 int   FindParam(char** pstring,int enum_type);
    32                 int   FindParam(char*** pstringarray,int* pM,int enum_type);
    33                 int   FindParam(int** pintarray,int* pM,int enum_type);
    34                 int   FindParam(double** pdoublearray,int* pM,int enum_type);
    35                 int   FindParam(double** pdoublearray,int* pM,int* pN,int enum_type);
    36                 int   FindParam(double*** parray,int* pM, int** pmdims_array,int** pndims_array,int enum_type);
    37                 int   FindParam(Vec* pvec,int enum_type);
    38                 int   FindParam(Mat* pmat,int enum_type);
    39                 int   FindParam(FILE** pfid,int enum_type);
     28                bool  Exist(int enum_type);
     29
     30                void  FindParam(bool* pinteger,int enum_type);
     31                void  FindParam(int* pinteger,int enum_type);
     32                void  FindParam(double* pscalar, int enum_type);
     33                void  FindParam(char** pstring,int enum_type);
     34                void  FindParam(char*** pstringarray,int* pM,int enum_type);
     35                void  FindParam(int** pintarray,int* pM,int enum_type);
     36                void  FindParam(double** pdoublearray,int* pM,int enum_type);
     37                void  FindParam(double** pdoublearray,int* pM,int* pN,int enum_type);
     38                void  FindParam(double*** parray,int* pM, int** pmdims_array,int** pndims_array,int enum_type);
     39                void  FindParam(Vec* pvec,int enum_type);
     40                void  FindParam(Mat* pmat,int enum_type);
     41                void  FindParam(FILE** pfid,int enum_type);
    4042               
    4143                void  SetParam(bool boolean,int enum_type);
     
    5557};
    5658
    57 
    58 
    5959#endif //ifndef _PARAMETERS_H_
    60 
  • issm/trunk/src/c/modules/AverageOntoPartitionx/AverageOntoPartitionx.cpp

    r6412 r8263  
    3535
    3636        /*First, recover qmu partition of vertices: */
    37         if(!parameters->FindParam(&qmu_part,&dummy,QmuPartEnum))_error_(" could not find qmu partition vector");
     37        parameters->FindParam(&qmu_part,&dummy,QmuPartEnum);
    3838
    3939        /*Some parameters: */
  • issm/trunk/src/c/modules/ComputeBasalStressx/ComputeBasalStressx.cpp

    r6412 r8263  
    2222
    2323        /*Recover numberofelements: */
    24         found= parameters->FindParam(&numberofelements,NumberOfElementsEnum);
    25         if (!found) _error_("numberofelements not provided in parameters");
     24        parameters->FindParam(&numberofelements,NumberOfElementsEnum);
    2625
    2726        /*Allocate sigma on numberofelements: */
  • issm/trunk/src/c/modules/InputUpdateFromDakotax/InputUpdateFromDakotax.cpp

    r8224 r8263  
    5050
    5151                        /*Now, pick up the parameter corresponding to root: */
    52                         if(!parameters->FindParam(&parameter,NULL,StringToEnumx(root))){
    53                                 _error_("%s%s"," could not find Qmu parameter: ",root);
    54                         }
     52                        parameters->FindParam(&parameter,NULL,StringToEnumx(root));
    5553
    5654                        /*We've got the parameter, we need to update it using qmu_part (a partitioning vector), and the distributed_values: */
  • issm/trunk/src/c/modules/MassFluxx/MassFluxx.cpp

    r6684 r8263  
    3636
    3737        /*First, figure out which segment to compute our mass flux on. Start with retrieving qmu_mass_flux_segments: */
    38         if(!parameters->FindParam(&array,&M,&mdims_array,&ndims_array,QmuMassFluxSegmentsEnum))_error_(" could not find QmuMassFluxSegmentsEnum");
     38        parameters->FindParam(&array,&M,&mdims_array,&ndims_array,QmuMassFluxSegmentsEnum);
    3939
    4040        /*Retrieve index of segments being used for MassFlux computation: */
    41         if(!parameters->FindParam(&counter,IndexEnum))_error_(" could not find IndexEnum");
     41        parameters->FindParam(&counter,IndexEnum);
    4242
    4343        /*retrieve segments from array: */
  • issm/trunk/src/c/modules/OutputResultsx/OutputResultsx.cpp

    r8224 r8263  
    5050
    5151        /*Now, open file for writing, if not already done: */
    52         if(!parameters->FindParam(&fid,OutputFilePointerEnum)){
     52        if(!parameters->Exist(OutputFilePointerEnum)){
    5353               
    5454                /*We don't have a file pointer. Retrieve the output file name and open it for writing:*/
     
    6464                else{
    6565                        /*We are opening different  files for output on all cpus. Append the  rank to the filename, and open: */
     66                        parameters->FindParam(&fid,OutputFilePointerEnum);
    6667                        sprintf(cpu_outputfilename,"%s.%i",outputfilename,my_rank);
    6768                        fid=pfopen(cpu_outputfilename ,"wb");
     
    7273                parameters->SetParam(fid,OutputFilePointerEnum);
    7374        }
    74 
    7575        #endif
    7676
  • issm/trunk/src/c/objects/FemModel.cpp

    r8224 r8263  
    168168        this->loads->SetCurrentConfiguration(elements, loads, nodes,vertices, materials,parameters);
    169169
    170         /*take care of petsc options, that depend on this analysis type: */
    171         PetscOptionsFromAnalysis(this->parameters,analysis_type);
    172         _printf_(VerboseSolver(),"      petsc Options set for analysis type: %s\n",EnumToStringx(analysis_type));
     170        /*take care of petsc options, that depend on this analysis type (present only after model processor)*/
     171        if(this->parameters->Exist(PetscOptionsStringsEnum)){
     172                PetscOptionsFromAnalysis(this->parameters,analysis_type);
     173                _printf_(VerboseSolver(),"      petsc Options set for analysis type: %s\n",EnumToStringx(analysis_type));
     174        }
    173175
    174176}
Note: See TracChangeset for help on using the changeset viewer.