source: issm/trunk/src/c/parallel/ProcessResults.cpp@ 2722

Last change on this file since 2722 was 2722, checked in by Mathieu Morlighem, 15 years ago

Added balanced velocities new solution (not working yet, but who knows... one day??)

File size: 14.1 KB
Line 
1/*!\file: ProcessResults.cpp
2 * \brief: go through results dataset, and for each result, process it for easier retrieval
3 * by the Matlab side. This usually means splitting the velocities from the g-size nodeset
4 * to the grid set (ug->vx,vy,vz), same for pressure (p_g->pressure), etc ... It also implies
5 * departitioning of the results.
6 * This phase is necessary prior to outputting the results on disk.
7 */
8
9#ifdef HAVE_CONFIG_H
10 #include "config.h"
11#else
12#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
13#endif
14
15#undef __FUNCT__
16#define __FUNCT__ "ProcessResults"
17
18#include "../DataSet/DataSet.h"
19#include "../objects/objects.h"
20#include "../EnumDefinitions/EnumDefinitions.h"
21#include "../shared/shared.h"
22
23void ProcessResults(DataSet** pnewresults, DataSet* results,Model* model,int analysis_type){
24
25 int i,n;
26 Result* result=NULL;
27 Result* newresult=NULL;
28
29 /*output: */
30 DataSet* newresults=NULL;
31
32 /*fem diagnostic models: */
33 FemModel* fem_dh=NULL;
34 FemModel* fem_dv=NULL;
35 FemModel* fem_dhu=NULL;
36 FemModel* fem_ds=NULL;
37 FemModel* fem_sl=NULL;
38
39 /*fem thermal models: */
40 FemModel* fem_t=NULL;
41
42 /*fem prognostic models: */
43 FemModel* fem_p=NULL;
44
45 /*fem control models: */
46 FemModel* fem_c=NULL;
47
48 /*some parameters*/
49 int ishutter;
50 int ismacayealpattyn;
51 int isstokes;
52 int dim;
53
54 /*intermediary: */
55 Vec u_g=NULL;
56 double* u_g_serial=NULL;
57 double* vx=NULL;
58 double* vy=NULL;
59 double* vz=NULL;
60 double* vel=NULL;
61 Vec p_g=NULL;
62 double* p_g_serial=NULL;
63 double* pressure=NULL;
64 double* partition=NULL;
65 double yts;
66
67 double* param_g=NULL;
68 double* parameter=NULL;
69 Vec riftproperties=NULL;
70 double* riftproperties_serial=NULL;
71 int numrifts=0;
72
73 Vec s_g=NULL;
74 double* s_g_serial=NULL;
75 double* surface=NULL;
76
77 Vec b_g=NULL;
78 double* b_g_serial=NULL;
79 double* bed=NULL;
80
81 Vec h_g=NULL;
82 double* h_g_serial=NULL;
83 double* thickness=NULL;
84
85 Vec t_g=NULL;
86 double* t_g_serial=NULL;
87 double* temperature=NULL;
88
89 Vec m_g=NULL;
90 double* m_g_serial=NULL;
91 double* melting=NULL;
92
93 Vec v_g=NULL;
94 double* v_g_serial=NULL;
95
96 int numberofnodes;
97
98 /*Initialize new results: */
99 newresults=new DataSet(ResultsEnum());
100
101 /*some flags needed: */
102 model->FindParam(&dim,"dim");
103 model->FindParam(&ishutter,"ishutter");
104 model->FindParam(&isstokes,"isstokes");
105 model->FindParam(&ismacayealpattyn,"ismacayealpattyn");
106
107 /*Recover femmodels first: */
108 fem_dh=model->GetFormulation(DiagnosticAnalysisEnum(),HorizAnalysisEnum());
109 fem_c=fem_dh;
110 fem_dv=model->GetFormulation(DiagnosticAnalysisEnum(),VertAnalysisEnum());
111 fem_ds=model->GetFormulation(DiagnosticAnalysisEnum(),StokesAnalysisEnum());
112 fem_dhu=model->GetFormulation(DiagnosticAnalysisEnum(),HutterAnalysisEnum());
113 fem_sl=model->GetFormulation(SlopeComputeAnalysisEnum());
114 if(analysis_type==PrognosticAnalysisEnum()){
115 fem_p=model->GetFormulation(PrognosticAnalysisEnum());
116 }
117 if(analysis_type==TransientAnalysisEnum()){
118 fem_p=model->GetFormulation(PrognosticAnalysisEnum());
119 }
120 if(analysis_type==BalancedthicknessAnalysisEnum()){
121 fem_p=model->GetFormulation(BalancedthicknessAnalysisEnum());
122 }
123 if(analysis_type==BalancedvelocitiesAnalysisEnum()){
124 fem_p=model->GetFormulation(BalancedvelocitiesAnalysisEnum());
125 }
126 fem_t=model->GetFormulation(ThermalAnalysisEnum());
127
128 for(n=0;n<results->Size();n++){
129 result=(Result*)results->GetObjectByOffset(n);
130
131 if(strcmp(result->GetFieldName(),"u_g")==0){
132
133 /*Ok, are we dealing with velocities coming from MacAyeal, Pattyin, Hutter, on 2,3 dofs or
134 *Stokes on 4 dofs: */
135 result->GetField(&u_g);
136 VecToMPISerial(&u_g_serial,u_g);
137
138 //2d results -> 2 dofs per node
139 if (dim==2){
140 /*ok, 2 dofs, on number of nodes: */
141 if(ismacayealpattyn){
142 fem_dh->parameters->FindParam(&numberofnodes,"numberofnodes");
143 VecToMPISerial(&partition,fem_dh->partition->vector);
144 fem_dh->parameters->FindParam(&yts,"yts");
145 }
146 else{
147 fem_dhu->parameters->FindParam(&numberofnodes,"numberofnodes");
148 VecToMPISerial(&partition,fem_dhu->partition->vector);
149 fem_dhu->parameters->FindParam(&yts,"yts");
150 }
151 vx=(double*)xmalloc(numberofnodes*sizeof(double));
152 vy=(double*)xmalloc(numberofnodes*sizeof(double));
153 vz=(double*)xmalloc(numberofnodes*sizeof(double));
154 vel=(double*)xmalloc(numberofnodes*sizeof(double));
155
156 for(i=0;i<numberofnodes;i++){
157 vx[i]=u_g_serial[2*(int)partition[i]+0]*yts;
158 vy[i]=u_g_serial[2*(int)partition[i]+1]*yts;
159 vz[i]=0;
160 vel[i]=sqrt(pow(vx[i],2)+pow(vy[i],2)+pow(vz[i],2));
161 }
162 }
163 //3d results -> 3 or 4 (stokes) dofs per node
164 else{
165 if(!isstokes){
166 /*ok, 3 dofs, on number of nodes: */
167 if(ismacayealpattyn){
168 fem_dh->parameters->FindParam(&numberofnodes,"numberofnodes");
169 VecToMPISerial(&partition,fem_dh->partition->vector);
170 fem_dh->parameters->FindParam(&yts,"yts");
171 }
172 else{
173 fem_dhu->parameters->FindParam(&numberofnodes,"numberofnodes");
174 VecToMPISerial(&partition,fem_dhu->partition->vector);
175 fem_dhu->parameters->FindParam(&yts,"yts");
176 }
177 vx=(double*)xmalloc(numberofnodes*sizeof(double));
178 vy=(double*)xmalloc(numberofnodes*sizeof(double));
179 vz=(double*)xmalloc(numberofnodes*sizeof(double));
180 vel=(double*)xmalloc(numberofnodes*sizeof(double));
181
182 for(i=0;i<numberofnodes;i++){
183 vx[i]=u_g_serial[3*(int)partition[i]+0]*yts;
184 vy[i]=u_g_serial[3*(int)partition[i]+1]*yts;
185 vz[i]=u_g_serial[3*(int)partition[i]+2]*yts;
186 vel[i]=sqrt(pow(vx[i],2)+pow(vy[i],2)+pow(vz[i],2));
187 }
188 }
189 else{
190 /* 4 dofs on number of nodes. discard pressure: */
191 fem_ds->parameters->FindParam(&numberofnodes,"numberofnodes");
192 VecToMPISerial(&partition,fem_ds->partition->vector);
193 fem_ds->parameters->FindParam(&yts,"yts");
194 vx=(double*)xmalloc(numberofnodes*sizeof(double));
195 vy=(double*)xmalloc(numberofnodes*sizeof(double));
196 vz=(double*)xmalloc(numberofnodes*sizeof(double));
197 vel=(double*)xmalloc(numberofnodes*sizeof(double));
198 for(i=0;i<numberofnodes;i++){
199 vx[i]=u_g_serial[4*(int)partition[i]+0]*yts;
200 vy[i]=u_g_serial[4*(int)partition[i]+1]*yts;
201 vz[i]=u_g_serial[4*(int)partition[i]+2]*yts;
202 vel[i]=sqrt(pow(vx[i],2)+pow(vy[i],2)+pow(vz[i],2));
203 }
204 }
205 }
206
207 /*Ok, add vx,vy and vz to newresults: */
208 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vx",vx,numberofnodes);
209 newresults->AddObject(newresult);
210
211 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vy",vy,numberofnodes);
212 newresults->AddObject(newresult);
213
214 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vz",vz,numberofnodes);
215 newresults->AddObject(newresult);
216
217 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vel",vel,numberofnodes);
218 newresults->AddObject(newresult);
219
220 /*do some cleanup: */
221 xfree((void**)&u_g_serial);
222 xfree((void**)&partition);
223 xfree((void**)&vx);
224 xfree((void**)&vy);
225 xfree((void**)&vz);
226 xfree((void**)&vel);
227 VecFree(&u_g);
228 }
229 else if(strcmp(result->GetFieldName(),"p_g")==0){
230 /*easy, p_g is of size numberofnodes, on 1 dof, just repartition: */
231 result->GetField(&p_g);
232 VecToMPISerial(&p_g_serial,p_g);
233
234 if(!isstokes){
235 if(ismacayealpattyn){
236 fem_dh->parameters->FindParam(&numberofnodes,"numberofnodes");
237 VecToMPISerial(&partition,fem_dh->partition->vector);
238 }
239 else{
240 fem_dhu->parameters->FindParam(&numberofnodes,"numberofnodes");
241 VecToMPISerial(&partition,fem_dhu->partition->vector);
242 }
243 }
244 else{
245 fem_ds->parameters->FindParam(&numberofnodes,"numberofnodes");
246 VecToMPISerial(&partition,fem_ds->partition->vector);
247 }
248
249 pressure=(double*)xmalloc(numberofnodes*sizeof(double));
250
251 for(i=0;i<numberofnodes;i++){
252 pressure[i]=p_g_serial[(int)partition[i]];
253 }
254
255 /*Ok, add pressure,vy and vz to newresults: */
256 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"pressure",pressure,numberofnodes);
257 newresults->AddObject(newresult);
258
259 /*do some cleanup: */
260 xfree((void**)&p_g_serial);
261 xfree((void**)&partition);
262 xfree((void**)&pressure);
263 VecFree(&p_g);
264 }
265 else if(strcmp(result->GetFieldName(),"t_g")==0){
266 /*easy, t_g is of size numberofnodes, on 1 dof, just repartition: */
267 result->GetField(&t_g);
268 VecToMPISerial(&t_g_serial,t_g);
269 fem_t->parameters->FindParam(&numberofnodes,"numberofnodes");
270 VecToMPISerial(&partition,fem_t->partition->vector);
271
272 temperature=(double*)xmalloc(numberofnodes*sizeof(double));
273
274 for(i=0;i<numberofnodes;i++){
275 temperature[i]=t_g_serial[(int)partition[i]];
276 }
277
278 /*Ok, add pressure to newresults: */
279 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"temperature",temperature,numberofnodes);
280 newresults->AddObject(newresult);
281
282 /*do some cleanup: */
283 xfree((void**)&t_g_serial);
284 xfree((void**)&partition);
285 xfree((void**)&temperature);
286 VecFree(&t_g);
287 }
288 else if(strcmp(result->GetFieldName(),"m_g")==0){
289 /*easy, m_g is of size numberofnodes, on 1 dof, just repartition: */
290 result->GetField(&m_g);
291 VecToMPISerial(&m_g_serial,m_g);
292 fem_t->parameters->FindParam(&numberofnodes,"numberofnodes");
293 fem_t->parameters->FindParam(&yts,"yts");
294 VecToMPISerial(&partition,fem_t->partition->vector);
295
296 melting=(double*)xmalloc(numberofnodes*sizeof(double));
297
298 for(i=0;i<numberofnodes;i++){
299 melting[i]=m_g_serial[(int)partition[i]]*yts;
300 }
301
302 /*Ok, add pressure to newresults: */
303 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"melting",melting,numberofnodes);
304 newresults->AddObject(newresult);
305
306 /*do some cleanup: */
307 xfree((void**)&m_g_serial);
308 xfree((void**)&partition);
309 xfree((void**)&melting);
310 VecFree(&m_g);
311 }
312 else if(strcmp(result->GetFieldName(),"h_g")==0){
313 /*easy, h_g is of size numberofnodes, on 1 dof, just repartition: */
314 result->GetField(&h_g);
315 VecToMPISerial(&h_g_serial,h_g);
316 fem_p->parameters->FindParam(&numberofnodes,"numberofnodes");
317 VecToMPISerial(&partition,fem_p->partition->vector);
318
319 thickness=(double*)xmalloc(numberofnodes*sizeof(double));
320
321 for(i=0;i<numberofnodes;i++){
322 thickness[i]=h_g_serial[(int)partition[i]];
323 }
324
325 /*Ok, add pressure to newresults: */
326 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"thickness",thickness,numberofnodes);
327 newresults->AddObject(newresult);
328
329 /*do some cleanup: */
330 xfree((void**)&h_g_serial);
331 xfree((void**)&thickness);
332 xfree((void**)&partition);
333 VecFree(&h_g);
334 }
335 else if(strcmp(result->GetFieldName(),"v_g")==0){
336 /*easy, v_g is of size numberofnodes, on 1 dof, just repartition: */
337 result->GetField(&v_g);
338 VecToMPISerial(&v_g_serial,v_g);
339 fem_p->parameters->FindParam(&numberofnodes,"numberofnodes");
340 VecToMPISerial(&partition,fem_p->partition->vector);
341
342 vel=(double*)xmalloc(numberofnodes*sizeof(double));
343
344 for(i=0;i<numberofnodes;i++){
345 vel[i]=v_g_serial[(int)partition[i]];
346 }
347
348 /*Ok, add pressure to newresults: */
349 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vel",vel,numberofnodes);
350 newresults->AddObject(newresult);
351
352 /*do some cleanup: */
353 xfree((void**)&v_g_serial);
354 xfree((void**)&vel);
355 xfree((void**)&partition);
356 VecFree(&v_g);
357 }
358 else if(strcmp(result->GetFieldName(),"s_g")==0){
359 /*easy, s_g is of size numberofnodes, on 1 dof, just repartition: */
360 result->GetField(&s_g);
361 VecToMPISerial(&s_g_serial,s_g);
362 fem_p->parameters->FindParam(&numberofnodes,"numberofnodes");
363 VecToMPISerial(&partition,fem_p->partition->vector);
364
365 surface=(double*)xmalloc(numberofnodes*sizeof(double));
366
367 for(i=0;i<numberofnodes;i++){
368 surface[i]=s_g_serial[(int)partition[i]];
369 }
370
371 /*Ok, add pressure to newresults: */
372 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"surface",surface,numberofnodes);
373 newresults->AddObject(newresult);
374
375 /*do some cleanup: */
376 xfree((void**)&s_g_serial);
377 xfree((void**)&partition);
378 xfree((void**)&surface);
379 VecFree(&s_g);
380 }
381 else if(strcmp(result->GetFieldName(),"b_g")==0){
382 /*easy, b_g is of size numberofnodes, on 1 dof, just repartition: */
383 result->GetField(&b_g);
384 VecToMPISerial(&b_g_serial,b_g);
385 fem_p->parameters->FindParam(&numberofnodes,"numberofnodes");
386 VecToMPISerial(&partition,fem_p->partition->vector);
387
388 bed=(double*)xmalloc(numberofnodes*sizeof(double));
389
390 for(i=0;i<numberofnodes;i++){
391 bed[i]=b_g_serial[(int)partition[i]];
392 }
393
394 /*Ok, add pressure to newresults: */
395 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"bed",bed,numberofnodes);
396 newresults->AddObject(newresult);
397
398 /*do some cleanup: */
399 xfree((void**)&b_g_serial);
400 xfree((void**)&partition);
401 xfree((void**)&bed);
402 VecFree(&b_g);
403 }
404 else if(strcmp(result->GetFieldName(),"param_g")==0){
405 /*easy, param_g is of size numberofnodes, on 1 dof, just repartition: */
406 result->GetField(&param_g);
407 fem_dh->parameters->FindParam(&numberofnodes,"numberofnodes");
408 VecToMPISerial(&partition,fem_dh->partition->vector);
409
410 parameter=(double*)xmalloc(numberofnodes*sizeof(double));
411
412 for(i=0;i<numberofnodes;i++){
413 parameter[i]=param_g[(int)partition[i]];
414 }
415
416 /*Ok, add parameter to newresults: */
417 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"parameter",parameter,numberofnodes);
418 newresults->AddObject(newresult);
419
420 /*do some cleanup: */
421 xfree((void**)&partition);
422 xfree((void**)&param_g);
423 xfree((void**)&parameter);
424 }
425 else if(strcmp(result->GetFieldName(),"riftproperties")==0){
426 result->GetField(&riftproperties);
427 fem_dh->parameters->FindParam(&numrifts,"numrifts");
428 VecToMPISerial(&riftproperties_serial,riftproperties);
429
430 /*Ok, add parameter to newresults: */
431 newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"riftproperties",riftproperties_serial,numrifts);
432 newresults->AddObject(newresult);
433 xfree((void**)&riftproperties);
434
435 }
436 else{
437 /*Just copy the result into the new results dataset: */
438 newresults->AddObject(result->copy());
439 }
440 }
441
442 /*Assign output pointers:*/
443 *pnewresults=newresults;
444}
Note: See TracBrowser for help on using the repository browser.