| 1 | /*!\file: CreateParametersDakota.cpp
|
|---|
| 2 | * \brief general driver for creating parameters dataset
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include "../../../Container/Container.h"
|
|---|
| 6 | #include "../../../toolkits/toolkits.h"
|
|---|
| 7 | #include "../../../EnumDefinitions/EnumDefinitions.h"
|
|---|
| 8 | #include "../../../classes/objects/objects.h"
|
|---|
| 9 | #include "../../../shared/shared.h"
|
|---|
| 10 | #include "../../../io/io.h"
|
|---|
| 11 | #include "../../../include/include.h"
|
|---|
| 12 | #include "../../MeshPartitionx/MeshPartitionx.h"
|
|---|
| 13 | #include "../ModelProcessorx.h"
|
|---|
| 14 |
|
|---|
| 15 | void CreateParametersDakota(Parameters** pparameters,IoModel* iomodel,char* rootpath,int solution_type,int analysis_type){
|
|---|
| 16 |
|
|---|
| 17 | /*variable declarations: {{{*/
|
|---|
| 18 | int i,j,k;
|
|---|
| 19 |
|
|---|
| 20 | Parameters* parameters = NULL;
|
|---|
| 21 | int second_count;
|
|---|
| 22 |
|
|---|
| 23 | int* part=NULL;
|
|---|
| 24 | double* dpart=NULL;
|
|---|
| 25 |
|
|---|
| 26 | char** responsedescriptors=NULL;
|
|---|
| 27 | int numresponsedescriptors;
|
|---|
| 28 | char** variabledescriptors=NULL;
|
|---|
| 29 | int numvariabledescriptors;
|
|---|
| 30 | char* descriptor=NULL;
|
|---|
| 31 | double* dakota_parameter=NULL;
|
|---|
| 32 |
|
|---|
| 33 | //qmu files
|
|---|
| 34 | char* qmuinname=NULL;
|
|---|
| 35 | char* qmuerrname=NULL;
|
|---|
| 36 | char* qmuoutname=NULL;
|
|---|
| 37 |
|
|---|
| 38 | //descriptors:
|
|---|
| 39 | char tag[50];
|
|---|
| 40 |
|
|---|
| 41 | int M;
|
|---|
| 42 | int m,n;
|
|---|
| 43 | bool dakota_analysis=false;
|
|---|
| 44 | char* name=NULL;
|
|---|
| 45 | int numberofresponses;
|
|---|
| 46 | int numberofvertices;
|
|---|
| 47 | int nrows;
|
|---|
| 48 | int ncols;
|
|---|
| 49 |
|
|---|
| 50 | /*}}}*/
|
|---|
| 51 |
|
|---|
| 52 | /*recover parameters : */
|
|---|
| 53 | parameters=*pparameters;
|
|---|
| 54 |
|
|---|
| 55 | /*recover parameters: */
|
|---|
| 56 | iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
|
|---|
| 57 |
|
|---|
| 58 | if(dakota_analysis){
|
|---|
| 59 |
|
|---|
| 60 | iomodel->Constant(&name,MiscellaneousNameEnum);
|
|---|
| 61 | iomodel->Constant(&numberofresponses,QmuNumberofresponsesEnum);
|
|---|
| 62 | iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
|
|---|
| 63 |
|
|---|
| 64 | /*name of qmu input, error and output files:{{{*/
|
|---|
| 65 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
|---|
| 66 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
|---|
| 67 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
|---|
| 68 |
|
|---|
| 69 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
|---|
| 70 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
|---|
| 71 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
|---|
| 72 |
|
|---|
| 73 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
|---|
| 74 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
|---|
| 75 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
|---|
| 76 | /*}}}*/
|
|---|
| 77 | /*Fetch variable descriptors: {{{*/
|
|---|
| 78 | iomodel->FetchData(&variabledescriptors,&numvariabledescriptors,QmuVariabledescriptorsEnum);
|
|---|
| 79 |
|
|---|
| 80 | /*Ok, we have all the variable descriptors. Build a parameter with it: */
|
|---|
| 81 | parameters->AddObject(new StringArrayParam(QmuVariabledescriptorsEnum,variabledescriptors,numvariabledescriptors));
|
|---|
| 82 |
|
|---|
| 83 | /*}}}*/
|
|---|
| 84 | /*Fetch response descriptors: {{{*/
|
|---|
| 85 | iomodel->FetchData(&responsedescriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum);
|
|---|
| 86 |
|
|---|
| 87 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
|---|
| 88 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
|---|
| 89 | parameters->AddObject(new IntParam(QmuNumberofresponsesEnum,numberofresponses));
|
|---|
| 90 | /*}}}*/
|
|---|
| 91 | /*Deal with partitioning: {{{*/
|
|---|
| 92 | /*partition vertices in iomodel->qmu_npart parts, unless a partition is already present: */
|
|---|
| 93 |
|
|---|
| 94 | parameters->AddObject(iomodel->CopyConstantObject(QmuNumberofpartitionsEnum));
|
|---|
| 95 | iomodel->FetchData(&dpart,NULL,NULL,QmuPartitionEnum);
|
|---|
| 96 |
|
|---|
| 97 | if(!dpart){
|
|---|
| 98 |
|
|---|
| 99 | /*Partition elements and vertices and nodes: */
|
|---|
| 100 | ElementsAndVerticesPartitioning(&iomodel->my_elements,&iomodel->my_vertices,iomodel);
|
|---|
| 101 |
|
|---|
| 102 | dpart=xNew<double>(numberofvertices);
|
|---|
| 103 | for(i=0;i<numberofvertices;i++)dpart[i]=iomodel->my_vertices[i];
|
|---|
| 104 | }
|
|---|
| 105 | parameters->AddObject(new DoubleVecParam(QmuPartitionEnum,dpart,numberofvertices));
|
|---|
| 106 | /*}}}*/
|
|---|
| 107 | /*Deal with data needed because of qmu variables: {{{*/
|
|---|
| 108 |
|
|---|
| 109 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 110 |
|
|---|
| 111 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
|---|
| 112 | /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
|
|---|
| 113 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
|---|
| 114 |
|
|---|
| 115 | /*Recover data: */
|
|---|
| 116 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,StringToEnumx(tag));
|
|---|
| 117 |
|
|---|
| 118 | /*Add to parameters: */
|
|---|
| 119 | if(nrows==numberofvertices){
|
|---|
| 120 | parameters->AddObject(new DoubleMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
|---|
| 121 | }
|
|---|
| 122 | else{
|
|---|
| 123 | parameters->AddObject(new DoubleTransientMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /*Free ressources:*/
|
|---|
| 127 | xDelete<double>(dakota_parameter);
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | /*}}}*/
|
|---|
| 131 | /*Free data: {{{*/
|
|---|
| 132 | for(i=0;i<numresponsedescriptors;i++){
|
|---|
| 133 | descriptor=responsedescriptors[i];
|
|---|
| 134 | xDelete<char>(descriptor);
|
|---|
| 135 | }
|
|---|
| 136 | xDelete<char*>(responsedescriptors);
|
|---|
| 137 |
|
|---|
| 138 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 139 | descriptor=variabledescriptors[i];
|
|---|
| 140 | xDelete<char>(descriptor);
|
|---|
| 141 | }
|
|---|
| 142 | xDelete<char*>(variabledescriptors);
|
|---|
| 143 | xDelete<int>(part);
|
|---|
| 144 | xDelete<double>(dpart);
|
|---|
| 145 | xDelete<char>(qmuinname);
|
|---|
| 146 | xDelete<char>(qmuerrname);
|
|---|
| 147 | xDelete<char>(qmuoutname);
|
|---|
| 148 | /*}}}*/
|
|---|
| 149 | } //if(dakota_analysis)
|
|---|
| 150 |
|
|---|
| 151 | /*Free data*/
|
|---|
| 152 | xDelete<char>(name);
|
|---|
| 153 |
|
|---|
| 154 | /*Assign output pointer: */
|
|---|
| 155 | *pparameters=parameters;
|
|---|
| 156 | }
|
|---|