1 | /*!\file: transient.cpp
|
---|
2 | * \brief: transient solution
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "../issm.h"
|
---|
6 | #include "./parallel.h"
|
---|
7 |
|
---|
8 | #undef __FUNCT__
|
---|
9 | #define __FUNCT__ "transient"
|
---|
10 |
|
---|
11 | #ifdef HAVE_CONFIG_H
|
---|
12 | #include "config.h"
|
---|
13 | #else
|
---|
14 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
15 | #endif
|
---|
16 |
|
---|
17 |
|
---|
18 | int main(int argc,char* *argv){
|
---|
19 |
|
---|
20 | /*I/O: */
|
---|
21 | FILE* fid=NULL;
|
---|
22 | char* inputfilename=NULL;
|
---|
23 | char* outputfilename=NULL;
|
---|
24 | char* lockname=NULL;
|
---|
25 | int numberofnodes;
|
---|
26 | int qmu_analysis=0;
|
---|
27 |
|
---|
28 | /*Model: */
|
---|
29 | Model* model=NULL;
|
---|
30 | int dim=-1;
|
---|
31 |
|
---|
32 | /*Results: */
|
---|
33 | DataSet* results=NULL;
|
---|
34 | DataSet* processed_results=NULL;
|
---|
35 | Result* result=NULL;
|
---|
36 |
|
---|
37 | ParameterInputs* inputs=NULL;
|
---|
38 | int waitonlock=0;
|
---|
39 |
|
---|
40 | /*inputs: */
|
---|
41 | double* u_g=NULL;
|
---|
42 | double* m_g=NULL;
|
---|
43 | double* a_g=NULL;
|
---|
44 | double dt;
|
---|
45 | double yts;
|
---|
46 | Param* param=NULL;
|
---|
47 |
|
---|
48 | MODULEBOOT();
|
---|
49 |
|
---|
50 | #if !defined(_PARALLEL_) || (defined(_PARALLEL_) && !defined(_HAVE_PETSC_))
|
---|
51 | throw ErrorException(__FUNCT__," parallel executable was compiled without support of parallel libraries!");
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | PetscInitialize(&argc,&argv,(char *)0,"");
|
---|
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 | model=new Model();
|
---|
70 |
|
---|
71 | _printf_("read and create finite element model:\n");
|
---|
72 | _printf_("\n reading diagnostic horiz model data:\n");
|
---|
73 | model->AddFormulation(fid,DiagnosticAnalysisEnum(),HorizAnalysisEnum());
|
---|
74 |
|
---|
75 | _printf_("\n reading diagnostic vert model data:\n");
|
---|
76 | model->AddFormulation(fid,DiagnosticAnalysisEnum(),VertAnalysisEnum());
|
---|
77 |
|
---|
78 | _printf_("\n reading diagnostic stokes model data:\n");
|
---|
79 | model->AddFormulation(fid,DiagnosticAnalysisEnum(),StokesAnalysisEnum());
|
---|
80 |
|
---|
81 | _printf_("\n reading diagnostic hutter model data:\n");
|
---|
82 | model->AddFormulation(fid,DiagnosticAnalysisEnum(),HutterAnalysisEnum());
|
---|
83 |
|
---|
84 | _printf_("\n reading surface and bed slope computation model data:\n");
|
---|
85 | model->AddFormulation(fid,SlopeComputeAnalysisEnum());
|
---|
86 |
|
---|
87 | _printf_("\n reading prognositc model data:\n");
|
---|
88 | model->AddFormulation(fid,PrognosticAnalysisEnum());
|
---|
89 |
|
---|
90 | /*Do we run in 3d?, in which case we need thermal and melting also:*/
|
---|
91 | model->FindParam(&dim,"dim");
|
---|
92 | if(dim==3){
|
---|
93 | _printf_("read and create thermal finite element model:\n");
|
---|
94 | model->AddFormulation(fid,ThermalAnalysisEnum(),TransientAnalysisEnum());
|
---|
95 | _printf_("read and create melting finite element model:\n");
|
---|
96 | model->AddFormulation(fid,MeltingAnalysisEnum(),TransientAnalysisEnum());
|
---|
97 | }
|
---|
98 |
|
---|
99 | /*recover parameters: */
|
---|
100 | model->FindParam(&waitonlock,"waitonlock");
|
---|
101 | model->FindParam(&qmu_analysis,"qmu_analysis");
|
---|
102 |
|
---|
103 | _printf_("initialize inputs:\n");
|
---|
104 | model->FindParam(&u_g,NULL,NULL,"u_g",PrognosticAnalysisEnum());
|
---|
105 | model->FindParam(&m_g,NULL,NULL,"m_g",PrognosticAnalysisEnum());
|
---|
106 | model->FindParam(&a_g,NULL,NULL,"a_g",PrognosticAnalysisEnum());
|
---|
107 | model->FindParam(&numberofnodes,"numberofnodes");
|
---|
108 | model->FindParam(&dt,"dt");
|
---|
109 | model->FindParam(&yts,"yts");
|
---|
110 |
|
---|
111 |
|
---|
112 | inputs=new ParameterInputs;
|
---|
113 | inputs->Add("velocity",u_g,3,numberofnodes);
|
---|
114 | inputs->Add("melting",m_g,1,numberofnodes);
|
---|
115 | inputs->Add("accumulation",a_g,1,numberofnodes);
|
---|
116 | inputs->Add("dt",dt*yts);
|
---|
117 |
|
---|
118 | _printf_("initialize results:\n");
|
---|
119 | results=new DataSet(ResultsEnum());
|
---|
120 |
|
---|
121 | /*are we running the solution sequence, or a qmu wrapper around it? : */
|
---|
122 | if(!qmu_analysis){
|
---|
123 |
|
---|
124 | /*run diagnostic analysis: */
|
---|
125 | _printf_("call computational core:\n");
|
---|
126 | transient_core(results,model,inputs);
|
---|
127 |
|
---|
128 | /*Add analysis_type to results: */
|
---|
129 | result=new Result(results->Size()+1,0,1,"analysis_type","transient");
|
---|
130 | results->AddObject(result);
|
---|
131 |
|
---|
132 | _printf_("process results:\n");
|
---|
133 | ProcessResults(&processed_results,results,model,TransientAnalysisEnum());
|
---|
134 |
|
---|
135 | _printf_("write results to disk:\n");
|
---|
136 | OutputResults(processed_results,outputfilename);
|
---|
137 | }
|
---|
138 | else{
|
---|
139 | /*run qmu analysis: */
|
---|
140 | _printf_("calling qmu analysis on transient core:\n");
|
---|
141 |
|
---|
142 | #ifdef _HAVE_DAKOTA_
|
---|
143 | Qmux(model,inputs,TransientAnalysisEnum(),NoneAnalysisEnum());
|
---|
144 | #else
|
---|
145 | throw ErrorException(__FUNCT__," Dakota not present, cannot do qmu!");
|
---|
146 | #endif
|
---|
147 | }
|
---|
148 | _printf_("write lock file:\n");
|
---|
149 | if (waitonlock){
|
---|
150 | WriteLockFile(lockname);
|
---|
151 | }
|
---|
152 | /*Free ressources:*/
|
---|
153 | delete results;
|
---|
154 | delete processed_results;
|
---|
155 | delete model;
|
---|
156 | delete inputs;
|
---|
157 | xfree((void**)&u_g);
|
---|
158 | xfree((void**)&m_g);
|
---|
159 | xfree((void**)&a_g);
|
---|
160 |
|
---|
161 | _printf_("closing MPI and Petsc\n");
|
---|
162 | PetscFinalize();
|
---|
163 |
|
---|
164 | /*end module: */
|
---|
165 | MODULEEND();
|
---|
166 |
|
---|
167 | return 0; //unix success return;
|
---|
168 | }
|
---|