| 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 |
|
|---|
| 23 | void ProcessResults(DataSet** pnewresults,DataSet* results,FemModel* fems,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 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 | int ishutter;
|
|---|
| 40 | int ismacayealpattyn;
|
|---|
| 41 | int isstokes;
|
|---|
| 42 |
|
|---|
| 43 | /*intermediary: */
|
|---|
| 44 | Vec u_g=NULL;
|
|---|
| 45 | double* u_g_serial=NULL;
|
|---|
| 46 | double* vx=NULL;
|
|---|
| 47 | double* vy=NULL;
|
|---|
| 48 | double* vz=NULL;
|
|---|
| 49 | Vec p_g=NULL;
|
|---|
| 50 | double* p_g_serial=NULL;
|
|---|
| 51 | double* pressure=NULL;
|
|---|
| 52 | double* partition=NULL;
|
|---|
| 53 | double yts;
|
|---|
| 54 |
|
|---|
| 55 | int numberofnodes;
|
|---|
| 56 |
|
|---|
| 57 | /*Initialize new results: */
|
|---|
| 58 | newresults=new DataSet(ResultsEnum());
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | /*Recover femmodels first: */
|
|---|
| 62 | if(analysis_type==DiagnosticAnalysisEnum()){
|
|---|
| 63 |
|
|---|
| 64 | fem_dh=fems+0;
|
|---|
| 65 | fem_dv=fems+1;
|
|---|
| 66 | fem_ds=fems+2;
|
|---|
| 67 | fem_dhu=fems+3;
|
|---|
| 68 | fem_sl=fems+4;
|
|---|
| 69 |
|
|---|
| 70 | /*some flags needed: */
|
|---|
| 71 | fem_dhu->parameters->FindParam((void*)&ishutter,"ishutter");
|
|---|
| 72 | fem_ds->parameters->FindParam((void*)&isstokes,"isstokes");
|
|---|
| 73 | fem_dh->parameters->FindParam((void*)&ismacayealpattyn,"ismacayealpattyn");
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | for(n=0;n<results->Size();n++){
|
|---|
| 79 |
|
|---|
| 80 | result=(Result*)results->GetObjectByOffset(n);
|
|---|
| 81 |
|
|---|
| 82 | if(strcmp(result->GetFieldName(),"u_g")==0){
|
|---|
| 83 | /*Ok, are we dealing with velocities coming from MacAyeal, Pattyin, Hutter, on 2 dofs? or from
|
|---|
| 84 | *Stokes on 4 dofs: */
|
|---|
| 85 | result->GetField(&u_g);
|
|---|
| 86 | VecToMPISerial(&u_g_serial,u_g);
|
|---|
| 87 |
|
|---|
| 88 | if(!isstokes){
|
|---|
| 89 | /*ok, 2 dofs, on number of nodes: */
|
|---|
| 90 | if(ismacayealpattyn){
|
|---|
| 91 | fem_dh->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 92 | VecToMPISerial(&partition,fem_dh->partition);
|
|---|
| 93 | fem_dh->parameters->FindParam((void*)&yts,"yts");
|
|---|
| 94 | }
|
|---|
| 95 | else{
|
|---|
| 96 | fem_dhu->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 97 | VecToMPISerial(&partition,fem_dhu->partition);
|
|---|
| 98 | fem_dhu->parameters->FindParam((void*)&yts,"yts");
|
|---|
| 99 | }
|
|---|
| 100 | vx=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 101 | vy=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 102 | vz=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 103 |
|
|---|
| 104 | for(i=0;i<numberofnodes;i++){
|
|---|
| 105 | vx[i]=u_g_serial[2*(int)partition[i]+0]*yts;
|
|---|
| 106 | vy[i]=u_g_serial[2*(int)partition[i]+1]*yts;
|
|---|
| 107 | vz[i]=0;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | else{
|
|---|
| 111 | /* 4 dofs on number of nodes. discard pressure: */
|
|---|
| 112 | fem_ds->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 113 | VecToMPISerial(&partition,fem_ds->partition);
|
|---|
| 114 | fem_ds->parameters->FindParam((void*)&yts,"yts");
|
|---|
| 115 | vx=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 116 | vy=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 117 | vz=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 118 | for(i=0;i<numberofnodes;i++){
|
|---|
| 119 | vx[i]=u_g_serial[4*(int)partition[i]+0]*yts;
|
|---|
| 120 | vy[i]=u_g_serial[4*(int)partition[i]+1]*yts;
|
|---|
| 121 | vz[i]=u_g_serial[4*(int)partition[i]+2]*yts;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | /*Ok, add vx,vy and vz to newresults: */
|
|---|
| 126 | newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vx",vx,numberofnodes);
|
|---|
| 127 | newresults->AddObject(newresult);
|
|---|
| 128 |
|
|---|
| 129 | newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vy",vy,numberofnodes);
|
|---|
| 130 | newresults->AddObject(newresult);
|
|---|
| 131 |
|
|---|
| 132 | newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"vz",vz,numberofnodes);
|
|---|
| 133 | newresults->AddObject(newresult);
|
|---|
| 134 |
|
|---|
| 135 | /*do some cleanup: */
|
|---|
| 136 | xfree((void**)&u_g_serial);
|
|---|
| 137 | xfree((void**)&partition);
|
|---|
| 138 | }
|
|---|
| 139 | else if(strcmp(result->GetFieldName(),"p_g")==0){
|
|---|
| 140 |
|
|---|
| 141 | /*easy, p_g is of size numberofnodes, on 1 dof, just repartition: */
|
|---|
| 142 | result->GetField(&p_g);
|
|---|
| 143 | VecToMPISerial(&p_g_serial,p_g);
|
|---|
| 144 |
|
|---|
| 145 | if(!isstokes){
|
|---|
| 146 | if(ismacayealpattyn){
|
|---|
| 147 | fem_dh->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 148 | VecToMPISerial(&partition,fem_dh->partition);
|
|---|
| 149 | }
|
|---|
| 150 | else{
|
|---|
| 151 | fem_dhu->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 152 | VecToMPISerial(&partition,fem_dhu->partition);
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | else{
|
|---|
| 156 | fem_ds->parameters->FindParam((void*)&numberofnodes,"numberofnodes");
|
|---|
| 157 | VecToMPISerial(&partition,fem_ds->partition);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | pressure=(double*)xmalloc(numberofnodes*sizeof(double));
|
|---|
| 161 |
|
|---|
| 162 | for(i=0;i<numberofnodes;i++){
|
|---|
| 163 | pressure[i]=p_g_serial[(int)partition[i]];
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /*Ok, add pressure,vy and vz to newresults: */
|
|---|
| 167 | newresult=new Result(newresults->Size()+1,result->GetTime(),result->GetStep(),"pressure",pressure,numberofnodes);
|
|---|
| 168 | newresults->AddObject(newresult);
|
|---|
| 169 |
|
|---|
| 170 | /*do some cleanup: */
|
|---|
| 171 | xfree((void**)&p_g_serial);
|
|---|
| 172 | xfree((void**)&partition);
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | /*Assign output pointers:*/
|
|---|
| 177 | *pnewresults=newresults;
|
|---|
| 178 |
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|