1 | /*!\file: transient.cpp
|
---|
2 | * \brief: transient 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 |
|
---|
11 | #include "../objects/objects.h"
|
---|
12 | #include "../shared/shared.h"
|
---|
13 | #include "../DataSet/DataSet.h"
|
---|
14 | #include "../EnumDefinitions/EnumDefinitions.h"
|
---|
15 | #include "../include/include.h"
|
---|
16 | #include "../modules.h"
|
---|
17 | #include "./parallel.h"
|
---|
18 |
|
---|
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;
|
---|
26 | int numberofnodes;
|
---|
27 | bool qmu_analysis=false;
|
---|
28 | bool waitonlock=false;
|
---|
29 |
|
---|
30 | /*Model: */
|
---|
31 | Model* model=NULL;
|
---|
32 | int dim=-1;
|
---|
33 |
|
---|
34 | /*Results: */
|
---|
35 | DataSet* results=NULL;
|
---|
36 | DataSet* processed_results=NULL;
|
---|
37 | Result* result=NULL;
|
---|
38 |
|
---|
39 | Param* param=NULL;
|
---|
40 |
|
---|
41 | /*time*/
|
---|
42 | double start, finish;
|
---|
43 | double start_core, finish_core;
|
---|
44 | double start_init, finish_init;
|
---|
45 |
|
---|
46 | MODULEBOOT();
|
---|
47 |
|
---|
48 | #if !defined(_PARALLEL_) || (defined(_PARALLEL_) && !defined(_HAVE_PETSC_))
|
---|
49 | ISSMERROR(" parallel executable was compiled without support of parallel libraries!");
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | /*Initialize Petsc and get start time*/
|
---|
53 | PetscInitialize(&argc,&argv,(char *)0,"");
|
---|
54 | MPI_Barrier(MPI_COMM_WORLD); start=MPI_Wtime();
|
---|
55 |
|
---|
56 | /*Size and rank: */
|
---|
57 | MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
|
---|
58 | MPI_Comm_size(MPI_COMM_WORLD,&num_procs);
|
---|
59 |
|
---|
60 | _printf_("recover , input file name and output file name:\n");
|
---|
61 | inputfilename=argv[2];
|
---|
62 | outputfilename=argv[3];
|
---|
63 | lockname=argv[4];
|
---|
64 |
|
---|
65 | /*Open handle to data on disk: */
|
---|
66 | fid=pfopen(inputfilename,"rb");
|
---|
67 |
|
---|
68 | /*Initialize model structure: */
|
---|
69 | MPI_Barrier(MPI_COMM_WORLD); start_init=MPI_Wtime();
|
---|
70 | model=new Model();
|
---|
71 |
|
---|
72 | _printf_("read and create finite element model:\n");
|
---|
73 | _printf_("\n reading diagnostic horiz model data:\n");
|
---|
74 | model->AddFormulation(fid,DiagnosticAnalysisEnum,HorizAnalysisEnum);
|
---|
75 |
|
---|
76 | _printf_("\n reading diagnostic vert model data:\n");
|
---|
77 | model->AddFormulation(fid,DiagnosticAnalysisEnum,VertAnalysisEnum);
|
---|
78 |
|
---|
79 | _printf_("\n reading diagnostic stokes model data:\n");
|
---|
80 | model->AddFormulation(fid,DiagnosticAnalysisEnum,StokesAnalysisEnum);
|
---|
81 |
|
---|
82 | _printf_("\n reading diagnostic hutter model data:\n");
|
---|
83 | model->AddFormulation(fid,DiagnosticAnalysisEnum,HutterAnalysisEnum);
|
---|
84 |
|
---|
85 | _printf_("\n reading surface and bed slope computation model data:\n");
|
---|
86 | model->AddFormulation(fid,SlopecomputeAnalysisEnum);
|
---|
87 |
|
---|
88 | _printf_("\n reading prognositc model data:\n");
|
---|
89 | model->AddFormulation(fid,PrognosticAnalysisEnum);
|
---|
90 |
|
---|
91 | /*Do we run in 3d?, in which case we need thermal and melting also:*/
|
---|
92 | model->FindParam(&dim,DimEnum);
|
---|
93 | if(dim==3){
|
---|
94 | _printf_("read and create thermal finite element model:\n");
|
---|
95 | model->AddFormulation(fid,ThermalAnalysisEnum,TransientAnalysisEnum);
|
---|
96 | _printf_("read and create melting finite element model:\n");
|
---|
97 | model->AddFormulation(fid,MeltingAnalysisEnum,TransientAnalysisEnum);
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*recover parameters: */
|
---|
101 | model->FindParam(&waitonlock,WaitOnLockEnum);
|
---|
102 | model->FindParam(&qmu_analysis,QmuAnalysisEnum);
|
---|
103 |
|
---|
104 | MPI_Barrier(MPI_COMM_WORLD); finish_init=MPI_Wtime();
|
---|
105 |
|
---|
106 | /*are we running the solution sequence, or a qmu wrapper around it? : */
|
---|
107 | if(!qmu_analysis){
|
---|
108 |
|
---|
109 | /*run diagnostic analysis: */
|
---|
110 | _printf_("call computational core:\n");
|
---|
111 | MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
|
---|
112 | results=transient_core(model);
|
---|
113 | MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
|
---|
114 |
|
---|
115 | _printf_("process results:\n");
|
---|
116 | ProcessResults(&processed_results,results,model,TransientAnalysisEnum);
|
---|
117 |
|
---|
118 | _printf_("write results to disk:\n");
|
---|
119 | OutputResults(processed_results,outputfilename);
|
---|
120 | }
|
---|
121 | else{
|
---|
122 | /*run qmu analysis: */
|
---|
123 | _printf_("calling qmu analysis on transient core:\n");
|
---|
124 |
|
---|
125 | #ifdef _HAVE_DAKOTA_
|
---|
126 | MPI_Barrier(MPI_COMM_WORLD); start_core=MPI_Wtime( );
|
---|
127 | Qmux(model,TransientAnalysisEnum,NoneAnalysisEnum);
|
---|
128 | MPI_Barrier(MPI_COMM_WORLD); finish_core=MPI_Wtime( );
|
---|
129 | #else
|
---|
130 | ISSMERROR(" Dakota not present, cannot do qmu!");
|
---|
131 | #endif
|
---|
132 | }
|
---|
133 |
|
---|
134 | if (waitonlock>0){
|
---|
135 | _printf_("write lock file:\n");
|
---|
136 | WriteLockFile(lockname);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /*Free ressources:*/
|
---|
140 | delete results;
|
---|
141 | delete processed_results;
|
---|
142 | delete model;
|
---|
143 |
|
---|
144 | /*Get finish time and close*/
|
---|
145 | MPI_Barrier(MPI_COMM_WORLD); finish = MPI_Wtime( );
|
---|
146 | _printf_("\n %-34s %f seconds \n","Model initialization elapsed time:",finish_init-start_init);
|
---|
147 | _printf_(" %-34s %f seconds \n","Core solution elapsed time:",finish_core-start_core);
|
---|
148 | _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);
|
---|
149 | _printf_("closing MPI and Petsc\n");
|
---|
150 | PetscFinalize();
|
---|
151 |
|
---|
152 | /*end module: */
|
---|
153 | MODULEEND();
|
---|
154 |
|
---|
155 | return 0; //unix success return;
|
---|
156 | }
|
---|