Changeset 13616


Ignore:
Timestamp:
10/11/12 09:07:12 (13 years ago)
Author:
Mathieu Morlighem
Message:

CHG: cosmetics

File:
1 edited

Legend:

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

    r13612 r13616  
    7575}
    7676/*}}}*/
    77 /*FUNCTION FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){{{*/
    78 void FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){
    79        
    80         /*intermediary*/
    81         int         i;
    82         int         analysis_type;
    83         FILE       *IOMODEL = NULL;
    84         FILE       *petscoptionsfid = NULL;
    85         FILE       *output_fid = NULL;
    86         int         my_rank;
    87        
    88         /*recover my_rank:*/
    89         my_rank=IssmComm::GetRank();
    90 
    91         /*Open input file on cpu 0: */
    92         if(my_rank==0) IOMODEL = pfopen(inputfilename ,"rb");
    93 
    94         /*Initialize internal data: */
    95         this->nummodels        = nummodels;
    96         this->solution_type    = in_solution_type;
    97         this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
    98         this->results          = new Results(); //not initialized by CreateDataSets
    99        
    100         /*Dynamically allocate whatever is a list of length nummodels: */
    101         analysis_type_list=xNew<int>(nummodels);
    102 
    103         /*Initialize: */
    104         for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
    105 
    106         /*create datasets for all analyses*/
    107         ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,rootpath,this->solution_type,nummodels,analyses);
    108 
    109         /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
    110         for(i=0;i<nummodels;i++){
    111 
    112                 if(VerboseMProcessor()) _pprintLine_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":");
    113                 analysis_type=analysis_type_list[i];
    114                 this->SetCurrentConfiguration(analysis_type);
    115        
    116                 if(i==0){
    117                         if(VerboseMProcessor()) _pprintLine_("      creating vertex degrees of freedom");
    118                         VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
    119                 }
    120 
    121                 if(VerboseMProcessor()) _pprintLine_("      resolving node constraints");
    122                 SpcNodesx(nodes,constraints,parameters,analysis_type);
    123 
    124                 if(VerboseMProcessor()) _pprintLine_("      creating nodal degrees of freedom");
    125                 NodesDofx(nodes,parameters,analysis_type);
    126        
    127                 if(VerboseMProcessor()) _pprintLine_("      configuring element and loads");
    128                 ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
    129         }
    130        
    131         /*Close input file descriptors: */
    132         if(my_rank==0) pfclose(IOMODEL,inputfilename);
    133 
    134         /*Open output file once for all and add output file name and file descriptor to parameters*/
    135         output_fid=pfopen(outputfilename,"wb");
    136         this->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
    137         this->parameters->SetParam(output_fid,OutputFilePointerEnum);
    138        
    139         /*Save lock file name for later: */
    140         this->parameters->AddObject(new StringParam(LockFileNameEnum,lockfilename));
    141 
    142         /*Now, deal with petsc options, which need to be put into the parameters dataset: */
    143         petscoptionsfid=pfopen(petscfilename,"r");
    144         ParsePetscOptionsx(this->parameters,petscoptionsfid);
    145         pfclose(petscoptionsfid,petscfilename);
    146 }
    147 /*}}}*/
    148 /*FUNCTION FemModel::destructor {{{*/
     77/*FUNCTION FemModel::~FemModel{{{*/
    14978FemModel::~FemModel(){
    15079
    15180        /*Intermediary*/
    152         int i;
    153         FILE* output_fid;
    154         char* outbinfilename=NULL;
    155         char* lockfilename=NULL;
    156         bool   waitonlock=false;
     81        FILE *output_fid;
     82        char *outbinfilename = NULL;
     83        char *lockfilename   = NULL;
     84        bool  waitonlock     = false;
    15785
    15886        /*Close output file: */
     
    201129
    202130/*Object management*/
    203 /*FUNCTION FemModel::OutputResults {{{*/
    204 void FemModel::OutputResults(void){
    205        
    206         _pprintLine_("write results to disk:");
    207 
    208         /*Just call the OutputResultsx module: */
    209         OutputResultsx(this->elements, this->nodes, this->vertices, this->loads, this->materials, this->parameters,this->results);
    210 
    211 }
    212 /*}}}*/
    213 /*FUNCTION FemModel::Solve {{{*/
    214 void FemModel::Solve(void){
    215 
    216         /*profiling: */
    217         bool profiling = false;
    218         IssmDouble solution_time;
    219         IssmDouble solution_flops;
    220         IssmDouble solution_memory;
    221 
    222         /*solution: */
    223         int solution_type;
    224         void (*solutioncore)(FemModel*)=NULL; //core solution function pointer
    225        
    226         _pprintLine_("call computational core:");
    227 
    228         /*Retrieve solution_type from parameters: */
    229         parameters->FindParam(&solution_type,SolutionTypeEnum);
    230 
    231         /*Figure out which solution core we are going to run with the current solution type: */
    232         CorePointerFromSolutionEnum(&solutioncore,this->parameters,solution_type);
    233 
    234         /*run solutoin core: */
    235         profiler->Tag(StartCore);   
    236         solutioncore(this);
    237         profiler->Tag(FinishCore);
    238 
    239         /*run AD core if needed: */
    240         profiler->Tag(StartAdCore);
    241         ad_core(this);     
    242         profiler->Tag(FinishAdCore);
    243 
    244         /*some profiling results for the core: */
    245         parameters->FindParam(&profiling,DebugProfilingEnum);
    246         if(profiling){
    247 
    248                 solution_time=profiler->DeltaTime(StartCore,FinishCore);
    249                 solution_flops=profiler->DeltaFlops(StartCore,FinishCore);
    250                 solution_memory=profiler->Memory(FinishCore);
    251 
    252                 _pprintLine_("Solution elapsed time  : " << solution_time << "  Seconds");
    253                 _pprintLine_("Solution elapsed flops : " << solution_flops << "  Flops");
    254                 _pprintLine_("Solution memory used   : " << solution_memory << "  Bytes");
    255 
    256                 /*Add to results: */
    257                 results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingSolutionTimeEnum, solution_time, 1, 0));
    258                 results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingCurrentMemEnum, solution_memory, 1, 0));
    259                 results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingCurrentFlopsEnum, solution_flops, 1, 0));
    260         }
    261 
    262 }
    263 /*}}}*/
    264131/*FUNCTION FemModel::Echo {{{*/
    265132void FemModel::Echo(void){
     
    274141}
    275142/*}}}*/
     143/*FUNCTION FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){{{*/
     144void FemModel::InitFromFiles(char* rootpath, char* inputfilename, char* outputfilename, char* petscfilename, char* lockfilename, const int in_solution_type,const int* analyses,const int nummodels){
     145
     146        /*intermediary*/
     147        int         i;
     148        int         analysis_type;
     149        FILE       *IOMODEL = NULL;
     150        FILE       *petscoptionsfid = NULL;
     151        FILE       *output_fid = NULL;
     152        int         my_rank;
     153
     154        /*recover my_rank:*/
     155        my_rank=IssmComm::GetRank();
     156
     157        /*Open input file on cpu 0: */
     158        if(my_rank==0) IOMODEL = pfopen(inputfilename ,"rb");
     159
     160        /*Initialize internal data: */
     161        this->nummodels        = nummodels;
     162        this->solution_type    = in_solution_type;
     163        this->analysis_counter = nummodels-1;   //point to last analysis_type carried out.
     164        this->results          = new Results(); //not initialized by CreateDataSets
     165
     166        /*Dynamically allocate whatever is a list of length nummodels: */
     167        analysis_type_list=xNew<int>(nummodels);
     168
     169        /*Initialize: */
     170        for(i=0;i<nummodels;i++)analysis_type_list[i]=analyses[i];
     171
     172        /*create datasets for all analyses*/
     173        ModelProcessorx(&this->elements,&this->nodes,&this->vertices,&this->materials,&this->constraints,&this->loads,&this->parameters,IOMODEL,rootpath,this->solution_type,nummodels,analyses);
     174
     175        /*do the post-processing of the datasets to get an FemModel that can actually run analyses: */
     176        for(i=0;i<nummodels;i++){
     177
     178                if(VerboseMProcessor()) _pprintLine_("   Processing finite element model of analysis " << EnumToStringx(analysis_type_list[i]) << ":");
     179                analysis_type=analysis_type_list[i];
     180                this->SetCurrentConfiguration(analysis_type);
     181
     182                if(i==0){
     183                        if(VerboseMProcessor()) _pprintLine_("      creating vertex degrees of freedom");
     184                        VerticesDofx(vertices,parameters); //only call once, we only have one set of vertices
     185                }
     186
     187                if(VerboseMProcessor()) _pprintLine_("      resolving node constraints");
     188                SpcNodesx(nodes,constraints,parameters,analysis_type);
     189
     190                if(VerboseMProcessor()) _pprintLine_("      creating nodal degrees of freedom");
     191                NodesDofx(nodes,parameters,analysis_type);
     192
     193                if(VerboseMProcessor()) _pprintLine_("      configuring element and loads");
     194                ConfigureObjectsx(elements, loads, nodes, vertices, materials,parameters);
     195        }
     196
     197        /*Close input file descriptors: */
     198        if(my_rank==0) pfclose(IOMODEL,inputfilename);
     199
     200        /*Open output file once for all and add output file name and file descriptor to parameters*/
     201        output_fid=pfopen(outputfilename,"wb");
     202        this->parameters->AddObject(new StringParam(OutputFileNameEnum,outputfilename));
     203        this->parameters->SetParam(output_fid,OutputFilePointerEnum);
     204
     205        /*Save lock file name for later: */
     206        this->parameters->AddObject(new StringParam(LockFileNameEnum,lockfilename));
     207
     208        /*Now, deal with petsc options, which need to be put into the parameters dataset: */
     209        petscoptionsfid=pfopen(petscfilename,"r");
     210        ParsePetscOptionsx(this->parameters,petscoptionsfid);
     211        pfclose(petscoptionsfid,petscfilename);
     212}
     213/*}}}*/
     214/*FUNCTION FemModel::OutputResults {{{*/
     215void FemModel::OutputResults(void){
     216       
     217        _pprintLine_("write results to disk:");
     218
     219        /*Just call the OutputResultsx module: */
     220        OutputResultsx(this->elements, this->nodes, this->vertices, this->loads, this->materials, this->parameters,this->results);
     221
     222}
     223/*}}}*/
     224/*FUNCTION FemModel::PrintBanner {{{*/
     225void FemModel::PrintBanner(void){
     226
     227        _pprintLine_("");
     228        _pprintLine_("Ice Sheet System Model (" << PACKAGE_NAME << ") version " << PACKAGE_VERSION);
     229        _pprintLine_("(website: " << PACKAGE_URL << " contact: " << PACKAGE_BUGREPORT << ")");
     230        _pprintLine_("");
     231
     232}
     233/*}}}*/
    276234/*FUNCTION FemModel::SetStaticComm {{{*/
    277235void FemModel::SetStaticComm(void){
     
    283241}
    284242/*}}}*/
    285 /*FUNCTION FemModel::PrintBanner {{{*/
    286 void FemModel::PrintBanner(void){
    287 
    288         _pprintLine_("");
    289         _pprintLine_("Ice Sheet System Model (" << PACKAGE_NAME << ") version " << PACKAGE_VERSION);
    290         _pprintLine_("(website: " << PACKAGE_URL << " contact: " << PACKAGE_BUGREPORT << ")");
    291         _pprintLine_("");
     243/*FUNCTION FemModel::Solve {{{*/
     244void FemModel::Solve(void){
     245
     246        /*profiling: */
     247        bool profiling = false;
     248        IssmDouble solution_time;
     249        IssmDouble solution_flops;
     250        IssmDouble solution_memory;
     251
     252        /*solution: */
     253        int solution_type;
     254        void (*solutioncore)(FemModel*)=NULL; //core solution function pointer
     255       
     256        _pprintLine_("call computational core:");
     257
     258        /*Retrieve solution_type from parameters: */
     259        parameters->FindParam(&solution_type,SolutionTypeEnum);
     260
     261        /*Figure out which solution core we are going to run with the current solution type: */
     262        CorePointerFromSolutionEnum(&solutioncore,this->parameters,solution_type);
     263
     264        /*run solutoin core: */
     265        profiler->Tag(StartCore);   
     266        solutioncore(this);
     267        profiler->Tag(FinishCore);
     268
     269        /*run AD core if needed: */
     270        profiler->Tag(StartAdCore);
     271        ad_core(this);     
     272        profiler->Tag(FinishAdCore);
     273
     274        /*some profiling results for the core: */
     275        parameters->FindParam(&profiling,DebugProfilingEnum);
     276        if(profiling){
     277
     278                solution_time=profiler->DeltaTime(StartCore,FinishCore);
     279                solution_flops=profiler->DeltaFlops(StartCore,FinishCore);
     280                solution_memory=profiler->Memory(FinishCore);
     281
     282                _pprintLine_("Solution elapsed time  : " << solution_time << "  Seconds");
     283                _pprintLine_("Solution elapsed flops : " << solution_flops << "  Flops");
     284                _pprintLine_("Solution memory used   : " << solution_memory << "  Bytes");
     285
     286                /*Add to results: */
     287                results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingSolutionTimeEnum, solution_time, 1, 0));
     288                results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingCurrentMemEnum, solution_memory, 1, 0));
     289                results->AddObject(new GenericExternalResult<IssmDouble>(results->Size()+1, ProfilingCurrentFlopsEnum, solution_flops, 1, 0));
     290        }
    292291
    293292}
Note: See TracChangeset for help on using the changeset viewer.