[1] | 1 | /*!\file: diagnostic.cpp
|
---|
| 2 | * \brief: diagnostic solution
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | #ifdef HAVE_CONFIG_H
|
---|
| 6 | #include "config.h"
|
---|
| 7 | #else
|
---|
| 8 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 9 | #endif
|
---|
| 10 |
|
---|
[3751] | 11 | #include "../objects/objects.h"
|
---|
| 12 | #include "../shared/shared.h"
|
---|
| 13 | #include "../DataSet/DataSet.h"
|
---|
| 14 | #include "../EnumDefinitions/EnumDefinitions.h"
|
---|
[3775] | 15 | #include "../include/include.h"
|
---|
[3913] | 16 | #include "../modules/modules.h"
|
---|
[3895] | 17 | #include "./solutions.h"
|
---|
[643] | 18 |
|
---|
[1] | 19 | int main(int argc,char* *argv){
|
---|
| 20 |
|
---|
| 21 | /*I/O: */
|
---|
| 22 | FILE* fid=NULL;
|
---|
| 23 | char* inputfilename=NULL;
|
---|
| 24 | char* outputfilename=NULL;
|
---|
| 25 | char* lockname=NULL;
|
---|
[3767] | 26 | bool qmu_analysis=false;
|
---|
| 27 | bool control_analysis=false;
|
---|
[1] | 28 |
|
---|
[1826] | 29 | /*Model: */
|
---|
| 30 | Model* model=NULL;
|
---|
[643] | 31 |
|
---|
| 32 | /*Results: */
|
---|
| 33 | DataSet* results=NULL;
|
---|
[2112] | 34 | DataSet* processed_results=NULL;
|
---|
[2268] | 35 | Result* result=NULL;
|
---|
[434] | 36 |
|
---|
[3767] | 37 | bool waitonlock=false;
|
---|
[210] | 38 |
|
---|
[2489] | 39 | /*time*/
|
---|
| 40 | double start, finish;
|
---|
| 41 | double start_core, finish_core;
|
---|
| 42 | double start_init, finish_init;
|
---|
| 43 |
|
---|
[1] | 44 | MODULEBOOT();
|
---|
| 45 |
|
---|
| 46 | #if !defined(_PARALLEL_) || (defined(_PARALLEL_) && !defined(_HAVE_PETSC_))
|
---|
[3332] | 47 | ISSMERROR(" parallel executable was compiled without support of parallel libraries!");
|
---|
[1] | 48 | #endif
|
---|
| 49 |
|
---|
[2489] | 50 | /*Initialize Petsc and get start time*/
|
---|
[1] | 51 | PetscInitialize(&argc,&argv,(char *)0,"");
|
---|
[2489] | 52 | MPI_Barrier(MPI_COMM_WORLD); start=MPI_Wtime();
|
---|
[1] | 53 |
|
---|
| 54 | /*Size and rank: */
|
---|
| 55 | MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
|
---|
| 56 | MPI_Comm_size(MPI_COMM_WORLD,&num_procs);
|
---|
| 57 |
|
---|
| 58 | _printf_("recover , input file name and output file name:\n");
|
---|
| 59 | inputfilename=argv[2];
|
---|
| 60 | outputfilename=argv[3];
|
---|
| 61 | lockname=argv[4];
|
---|
| 62 |
|
---|
[1826] | 63 | /*Initialize model structure: */
|
---|
[2489] | 64 | MPI_Barrier(MPI_COMM_WORLD); start_init=MPI_Wtime();
|
---|
[1826] | 65 | model=new Model();
|
---|
| 66 |
|
---|
[1] | 67 | /*Open handle to data on disk: */
|
---|
[472] | 68 | fid=pfopen(inputfilename,"rb");
|
---|
[358] | 69 |
|
---|
[1] | 70 | _printf_("read and create finite element model:\n");
|
---|
[458] | 71 | _printf_("\n reading diagnostic horiz model data:\n");
|
---|
[3567] | 72 | model->AddFormulation(fid,DiagnosticAnalysisEnum,HorizAnalysisEnum);
|
---|
[1881] | 73 |
|
---|
[458] | 74 | _printf_("\n reading diagnostic vert model data:\n");
|
---|
[3567] | 75 | model->AddFormulation(fid,DiagnosticAnalysisEnum,VertAnalysisEnum);
|
---|
[1881] | 76 |
|
---|
[458] | 77 | _printf_("\n reading diagnostic stokes model data:\n");
|
---|
[3567] | 78 | model->AddFormulation(fid,DiagnosticAnalysisEnum,StokesAnalysisEnum);
|
---|
[1881] | 79 |
|
---|
[458] | 80 | _printf_("\n reading diagnostic hutter model data:\n");
|
---|
[3567] | 81 | model->AddFormulation(fid,DiagnosticAnalysisEnum,HutterAnalysisEnum);
|
---|
[1881] | 82 |
|
---|
[458] | 83 | _printf_("\n reading surface and bed slope computation model data:\n");
|
---|
[3567] | 84 | model->AddFormulation(fid,SlopecomputeAnalysisEnum);
|
---|
[1942] | 85 |
|
---|
[1887] | 86 | /*get parameters: */
|
---|
[3699] | 87 | model->FindParam(&qmu_analysis,QmuAnalysisEnum);
|
---|
| 88 | model->FindParam(&control_analysis,ControlAnalysisEnum);
|
---|
| 89 | model->FindParam(&waitonlock,WaitOnLockEnum);
|
---|
[1] | 90 |
|
---|
[2489] | 91 | MPI_Barrier(MPI_COMM_WORLD); finish_init=MPI_Wtime();
|
---|
| 92 |
|
---|
[732] | 93 | /*are we running the solution sequence, or a qmu wrapper around it? : */
|
---|
[586] | 94 | if(!qmu_analysis){
|
---|
[1911] | 95 | if(!control_analysis){
|
---|
[3887] | 96 |
|
---|
[1911] | 97 | _printf_("call computational core:\n");
|
---|
[2489] | 98 | MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
|
---|
[3887] | 99 | results=diagnostic_core(model);
|
---|
[2489] | 100 | MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
|
---|
[2234] | 101 |
|
---|
[2048] | 102 | _printf_("process results:\n");
|
---|
[3567] | 103 | ProcessResults(&processed_results,results,model,DiagnosticAnalysisEnum);
|
---|
[2048] | 104 | }
|
---|
| 105 | else{
|
---|
[2234] | 106 | /*run control analysis: */
|
---|
| 107 | _printf_("call computational core:\n");
|
---|
[2489] | 108 | MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
|
---|
[3887] | 109 | results=control_core(model);
|
---|
[2489] | 110 | MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
|
---|
[2234] | 111 |
|
---|
[2048] | 112 | _printf_("process results:\n");
|
---|
[3567] | 113 | ProcessResults(&processed_results,results,model,ControlAnalysisEnum);
|
---|
[2048] | 114 | }
|
---|
| 115 |
|
---|
| 116 | _printf_("write results to disk:\n");
|
---|
[2113] | 117 | OutputResults(processed_results,outputfilename);
|
---|
[586] | 118 | }
|
---|
| 119 | else{
|
---|
| 120 | /*run qmu analysis: */
|
---|
| 121 | _printf_("calling qmu analysis on diagnostic core:\n");
|
---|
[804] | 122 |
|
---|
[662] | 123 | #ifdef _HAVE_DAKOTA_
|
---|
[2489] | 124 | MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
|
---|
[3699] | 125 | Qmux(model,DiagnosticAnalysisEnum,NoneAnalysisEnum);
|
---|
[2489] | 126 | MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
|
---|
[662] | 127 | #else
|
---|
[3332] | 128 | ISSMERROR(" Dakota not present, cannot do qmu!");
|
---|
[662] | 129 | #endif
|
---|
[586] | 130 | }
|
---|
[1] | 131 |
|
---|
[2629] | 132 | if (waitonlock>0){
|
---|
| 133 | _printf_("write lock file:\n");
|
---|
[1] | 134 | WriteLockFile(lockname);
|
---|
| 135 | }
|
---|
[2048] | 136 |
|
---|
[1911] | 137 | /*Free ressources */
|
---|
[1942] | 138 | delete model;
|
---|
| 139 | delete results;
|
---|
[2112] | 140 | delete processed_results;
|
---|
[1911] | 141 |
|
---|
[2489] | 142 | /*Get finish time and close*/
|
---|
| 143 | MPI_Barrier(MPI_COMM_WORLD); finish = MPI_Wtime( );
|
---|
| 144 | _printf_("\n %-34s %f seconds \n","Model initialization elapsed time:",finish_init-start_init);
|
---|
| 145 | _printf_(" %-34s %f seconds \n","Core solution elapsed time:",finish_core-start_core);
|
---|
[3097] | 146 | _printf_("\n %s %i hrs %i min %i sec\n\n","Total elapsed time:",int((finish-start)/3600),int(int(finish-start)%3600/60),int(finish-start)%60);
|
---|
[2397] | 147 | _printf_("closing MPI and Petsc\n");
|
---|
| 148 | PetscFinalize();
|
---|
| 149 |
|
---|
| 150 | /*end module: */
|
---|
| 151 | MODULEEND();
|
---|
| 152 |
|
---|
[1] | 153 | return 0; //unix success return;
|
---|
| 154 | }
|
---|