| 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 | char **responsedescriptors = NULL;
|
|---|
| 16 | int numresponsedescriptors;
|
|---|
| 17 | char **variabledescriptors = NULL;
|
|---|
| 18 | int numvariabledescriptors;
|
|---|
| 19 | char *descriptor = NULL;
|
|---|
| 20 | double *dakota_parameter = NULL;
|
|---|
| 21 |
|
|---|
| 22 | //qmu files
|
|---|
| 23 | char *qmuinname = NULL;
|
|---|
| 24 | char *qmuerrname = NULL;
|
|---|
| 25 | char *qmuoutname = NULL;
|
|---|
| 26 |
|
|---|
| 27 | //descriptors:
|
|---|
| 28 | char tag[50];
|
|---|
| 29 |
|
|---|
| 30 | bool dakota_analysis = false;
|
|---|
| 31 | char *name = NULL;
|
|---|
| 32 | int numberofresponses;
|
|---|
| 33 | int nrows,ncols;
|
|---|
| 34 |
|
|---|
| 35 | //variable partitions:
|
|---|
| 36 | IssmDouble **array = NULL;
|
|---|
| 37 | int *mdims_array = NULL;
|
|---|
| 38 | int *ndims_array = NULL;
|
|---|
| 39 | int num_partitions;
|
|---|
| 40 | int* intarray = NULL;
|
|---|
| 41 | int M,N;
|
|---|
| 42 |
|
|---|
| 43 | /*recover parameters: */
|
|---|
| 44 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
|---|
| 45 |
|
|---|
| 46 | if(dakota_analysis){
|
|---|
| 47 |
|
|---|
| 48 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.output",QmuOutputEnum));
|
|---|
| 49 |
|
|---|
| 50 | iomodel->FindConstant(&name,"md.miscellaneous.name");
|
|---|
| 51 | iomodel->FindConstant(&numberofresponses,"md.qmu.numberofresponses");
|
|---|
| 52 |
|
|---|
| 53 | /*name of qmu input, error and output files*/
|
|---|
| 54 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
|---|
| 55 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
|---|
| 56 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
|---|
| 57 |
|
|---|
| 58 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
|---|
| 59 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
|---|
| 60 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
|---|
| 61 |
|
|---|
| 62 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
|---|
| 63 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
|---|
| 64 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
|---|
| 65 |
|
|---|
| 66 | /*Fetch variable descriptors*/
|
|---|
| 67 | iomodel->FindConstant(&variabledescriptors,&numvariabledescriptors,"md.qmu.variabledescriptors");
|
|---|
| 68 |
|
|---|
| 69 | /*Fetch response descriptors*/
|
|---|
| 70 | iomodel->FindConstant(&responsedescriptors,&numresponsedescriptors,"md.qmu.responsedescriptors");
|
|---|
| 71 |
|
|---|
| 72 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
|---|
| 73 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
|---|
| 74 |
|
|---|
| 75 | /*Load partitioning vectors specific to variables:*/
|
|---|
| 76 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.variablepartitions");
|
|---|
| 77 | parameters->AddObject(new DoubleMatArrayParam(QmuVariablePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
|
|---|
| 78 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_npart");
|
|---|
| 79 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNpartEnum,intarray,M,N));
|
|---|
| 80 | xDelete<int>(intarray); iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_nt");
|
|---|
| 81 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNtEnum,intarray,M,N));
|
|---|
| 82 |
|
|---|
| 83 | /*free arrays: {{{*/
|
|---|
| 84 | for(i=0;i<num_partitions;i++){
|
|---|
| 85 | IssmDouble* matrix=array[i];
|
|---|
| 86 | xDelete<IssmDouble>(matrix);
|
|---|
| 87 | }
|
|---|
| 88 | xDelete<int>(mdims_array);
|
|---|
| 89 | xDelete<int>(ndims_array);
|
|---|
| 90 | xDelete<IssmDouble*>(array);
|
|---|
| 91 | xDelete<int>(intarray);
|
|---|
| 92 | /*}}}*/
|
|---|
| 93 |
|
|---|
| 94 | /*Load partitioning vectors specific to responses:*/
|
|---|
| 95 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.responsepartitions");
|
|---|
| 96 | parameters->AddObject(new DoubleMatArrayParam(QmuResponsePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
|
|---|
| 97 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.responsepartitions_npart");
|
|---|
| 98 | parameters->AddObject(new IntMatParam(QmuResponsePartitionsNpartEnum,intarray,M,N));
|
|---|
| 99 |
|
|---|
| 100 | /*free arrays: {{{*/
|
|---|
| 101 | for(i=0;i<num_partitions;i++){
|
|---|
| 102 | IssmDouble* matrix=array[i];
|
|---|
| 103 | xDelete<IssmDouble>(matrix);
|
|---|
| 104 | }
|
|---|
| 105 | xDelete<int>(mdims_array);
|
|---|
| 106 | xDelete<int>(ndims_array);
|
|---|
| 107 | xDelete<IssmDouble*>(array);
|
|---|
| 108 | xDelete<int>(intarray);
|
|---|
| 109 | /*}}}*/
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | /*Deal with data needed because of qmu variables*/
|
|---|
| 113 | DataSet* dataset_variable_descriptors = new DataSet(QmuVariableDescriptorsEnum);
|
|---|
| 114 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 115 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
|---|
| 116 | int code;
|
|---|
| 117 |
|
|---|
| 118 | /*Ok, we are dealing with a variable that is distributed over nodes or elements. Recover the name of the variable (ex: scaled_Thickness): */
|
|---|
| 119 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
|---|
| 120 |
|
|---|
| 121 | /*Get field name and input enum from tag*/
|
|---|
| 122 | char* fieldname = NULL;
|
|---|
| 123 | int param_enum = -1;
|
|---|
| 124 | FieldAndEnumFromCode(¶m_enum,&fieldname,tag);
|
|---|
| 125 |
|
|---|
| 126 | iomodel->SetFilePointerToData(&code,NULL,fieldname);
|
|---|
| 127 | if(code==8) dataset_variable_descriptors->AddObject(new DoubleParam(param_enum,8)); //skip MatArray inputs, as we don't know which input will be scaled yet!
|
|---|
| 128 | else{
|
|---|
| 129 | /*recover more classic data, arrays and scalar mainly:*/
|
|---|
| 130 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,fieldname);
|
|---|
| 131 | if(nrows==iomodel->numberofvertices || nrows==iomodel->numberofelements){
|
|---|
| 132 | dataset_variable_descriptors->AddObject(new DoubleMatParam(param_enum,dakota_parameter,nrows,ncols));
|
|---|
| 133 | }
|
|---|
| 134 | else{
|
|---|
| 135 | dataset_variable_descriptors->AddObject(new DoubleTransientMatParam(param_enum,dakota_parameter,nrows,ncols));
|
|---|
| 136 | }
|
|---|
| 137 | xDelete<double>(dakota_parameter);
|
|---|
| 138 | }
|
|---|
| 139 | xDelete<char>(fieldname);
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | parameters->AddObject(new DataSetParam(QmuVariableDescriptorsEnum,dataset_variable_descriptors));
|
|---|
| 143 | delete dataset_variable_descriptors;
|
|---|
| 144 |
|
|---|
| 145 | /*clean-up*/
|
|---|
| 146 | for(i=0;i<numresponsedescriptors;i++){
|
|---|
| 147 | descriptor=responsedescriptors[i];
|
|---|
| 148 | xDelete<char>(descriptor);
|
|---|
| 149 | }
|
|---|
| 150 | xDelete<char*>(responsedescriptors);
|
|---|
| 151 | for(i=0;i<numvariabledescriptors;i++){
|
|---|
| 152 | descriptor=variabledescriptors[i];
|
|---|
| 153 | xDelete<char>(descriptor);
|
|---|
| 154 | }
|
|---|
| 155 | xDelete<char*>(variabledescriptors);
|
|---|
| 156 | xDelete<char>(qmuinname);
|
|---|
| 157 | xDelete<char>(qmuerrname);
|
|---|
| 158 | xDelete<char>(qmuoutname);
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /*Free data*/
|
|---|
| 165 | xDelete<char>(name);
|
|---|
| 166 | }
|
|---|