| 1 | /*!\file: CreateParametersDakota.cpp
|
|---|
| 2 | * \brief general driver for creating parameters dataset
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include "../../../toolkits/toolkits.h"
|
|---|
| 6 | #include "../../../classes/classes.h"
|
|---|
| 7 | #include "../../../shared/shared.h"
|
|---|
| 8 | #include "../../MeshPartitionx/MeshPartitionx.h"
|
|---|
| 9 | #include "../ModelProcessorx.h"
|
|---|
| 10 |
|
|---|
| 11 | void CreateParametersDakota(Parameters* parameters,IoModel* iomodel,char* rootpath){
|
|---|
| 12 |
|
|---|
| 13 | /*variable declarations*/
|
|---|
| 14 | int i;
|
|---|
| 15 | double *vpart = NULL;
|
|---|
| 16 | double *epart = NULL;
|
|---|
| 17 | int npart;
|
|---|
| 18 | char **responsedescriptors = NULL;
|
|---|
| 19 | int numresponsedescriptors;
|
|---|
| 20 | char **variabledescriptors = NULL;
|
|---|
| 21 | int numvariabledescriptors;
|
|---|
| 22 | char *descriptor = NULL;
|
|---|
| 23 | double *dakota_parameter = NULL;
|
|---|
| 24 |
|
|---|
| 25 | //qmu files
|
|---|
| 26 | char *qmuinname = NULL;
|
|---|
| 27 | char *qmuerrname = NULL;
|
|---|
| 28 | char *qmuoutname = NULL;
|
|---|
| 29 |
|
|---|
| 30 | //descriptors:
|
|---|
| 31 | char tag[50];
|
|---|
| 32 |
|
|---|
| 33 | bool dakota_analysis = false;
|
|---|
| 34 | char *name = NULL;
|
|---|
| 35 | int numberofresponses;
|
|---|
| 36 | int nrows,ncols;
|
|---|
| 37 |
|
|---|
| 38 | /*recover parameters: */
|
|---|
| 39 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
|---|
| 40 |
|
|---|
| 41 | if(dakota_analysis){
|
|---|
| 42 |
|
|---|
| 43 | iomodel->FindConstant(&name,"md.miscellaneous.name");
|
|---|
| 44 | iomodel->FindConstant(&numberofresponses,"md.qmu.numberofresponses");
|
|---|
| 45 |
|
|---|
| 46 | /*name of qmu input, error and output files*/
|
|---|
| 47 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
|---|
| 48 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
|---|
| 49 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
|---|
| 50 |
|
|---|
| 51 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
|---|
| 52 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
|---|
| 53 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
|---|
| 54 |
|
|---|
| 55 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
|---|
| 56 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
|---|
| 57 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
|---|
| 58 |
|
|---|
| 59 | /*Fetch variable descriptors*/
|
|---|
| 60 | iomodel->FindConstant(&variabledescriptors,&numvariabledescriptors,"md.qmu.variabledescriptors");
|
|---|
| 61 |
|
|---|
| 62 | /*Fetch response descriptors*/
|
|---|
| 63 | iomodel->FindConstant(&responsedescriptors,&numresponsedescriptors,"md.qmu.responsedescriptors");
|
|---|
| 64 |
|
|---|
| 65 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
|---|
| 66 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
|---|
| 67 |
|
|---|
| 68 | /*Load partitioning vectors (both vertex and element based: */
|
|---|
| 69 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.numberofpartitions",QmuNumberofpartitionsEnum));
|
|---|
| 70 | iomodel->FetchData(&vpart,&npart,NULL,"md.qmu.vpartition"); if(!vpart) _error_("md.qmu.vpartition is empty");
|
|---|
| 71 | parameters->AddObject(new DoubleVecParam(QmuVpartitionEnum,vpart,npart));
|
|---|
| 72 |
|
|---|
| 73 | iomodel->FetchData(&epart,&npart,NULL,"md.qmu.epartition"); if(!epart) _error_("md.qmu.epartition is empty");
|
|---|
| 74 | parameters->AddObject(new DoubleVecParam(QmuEpartitionEnum,epart,npart));
|
|---|
| 75 |
|
|---|
| 76 | /*Deal with data needed because of qmu variables*/
|
|---|
| 77 | DataSet* dataset_variable_descriptors = new DataSet(QmuVariableDescriptorsEnum);
|
|---|
| 78 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 79 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
|---|
| 80 | /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
|
|---|
| 81 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
|---|
| 82 |
|
|---|
| 83 | /*Get field name and input enum from tag*/
|
|---|
| 84 | char* fieldname = NULL;
|
|---|
| 85 | int param_enum = -1;
|
|---|
| 86 | FieldAndEnumFromCode(¶m_enum,&fieldname,tag);
|
|---|
| 87 |
|
|---|
| 88 | /*Recover data: */
|
|---|
| 89 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,fieldname);
|
|---|
| 90 | if(nrows==iomodel->numberofvertices){
|
|---|
| 91 | dataset_variable_descriptors->AddObject(new DoubleMatParam(param_enum,dakota_parameter,nrows,ncols));
|
|---|
| 92 | }
|
|---|
| 93 | else{
|
|---|
| 94 | dataset_variable_descriptors->AddObject(new DoubleTransientMatParam(param_enum,dakota_parameter,nrows,ncols));
|
|---|
| 95 | }
|
|---|
| 96 | xDelete<double>(dakota_parameter);
|
|---|
| 97 | xDelete<char>(fieldname);
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | parameters->AddObject(new DataSetParam(QmuVariableDescriptorsEnum,dataset_variable_descriptors));
|
|---|
| 101 | delete dataset_variable_descriptors;
|
|---|
| 102 |
|
|---|
| 103 | /*clean-up*/
|
|---|
| 104 | for(i=0;i<numresponsedescriptors;i++){
|
|---|
| 105 | descriptor=responsedescriptors[i];
|
|---|
| 106 | xDelete<char>(descriptor);
|
|---|
| 107 | }
|
|---|
| 108 | xDelete<char*>(responsedescriptors);
|
|---|
| 109 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 110 | descriptor=variabledescriptors[i];
|
|---|
| 111 | xDelete<char>(descriptor);
|
|---|
| 112 | }
|
|---|
| 113 | xDelete<char*>(variabledescriptors);
|
|---|
| 114 | xDelete<double>(vpart);
|
|---|
| 115 | xDelete<double>(epart);
|
|---|
| 116 | xDelete<char>(qmuinname);
|
|---|
| 117 | xDelete<char>(qmuerrname);
|
|---|
| 118 | xDelete<char>(qmuoutname);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /*Free data*/
|
|---|
| 122 | xDelete<char>(name);
|
|---|
| 123 | }
|
|---|