[10566] | 1 | /*!\file: CreateParametersDakota.cpp
|
---|
[765] | 2 | * \brief general driver for creating parameters dataset
|
---|
| 3 | */
|
---|
| 4 |
|
---|
[3913] | 5 | #include "../../../toolkits/toolkits.h"
|
---|
[15000] | 6 | #include "../../../classes/classes.h"
|
---|
[3913] | 7 | #include "../../../shared/shared.h"
|
---|
[765] | 8 | #include "../../MeshPartitionx/MeshPartitionx.h"
|
---|
[3633] | 9 | #include "../ModelProcessorx.h"
|
---|
[765] | 10 |
|
---|
[16543] | 11 | void CreateParametersDakota(Parameters* parameters,IoModel* iomodel,char* rootpath){
|
---|
[4852] | 12 |
|
---|
[16240] | 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;
|
---|
[13622] | 21 |
|
---|
[962] | 22 | //qmu files
|
---|
[16240] | 23 | char *qmuinname = NULL;
|
---|
| 24 | char *qmuerrname = NULL;
|
---|
| 25 | char *qmuoutname = NULL;
|
---|
[13622] | 26 |
|
---|
[5477] | 27 | //descriptors:
|
---|
| 28 | char tag[50];
|
---|
[13622] | 29 |
|
---|
[16240] | 30 | bool dakota_analysis = false;
|
---|
| 31 | char *name = NULL;
|
---|
| 32 | int numberofresponses;
|
---|
| 33 | int nrows,ncols;
|
---|
[962] | 34 |
|
---|
[24988] | 35 | //variable partitions:
|
---|
| 36 | IssmDouble **array = NULL;
|
---|
| 37 | int *mdims_array = NULL;
|
---|
| 38 | int *ndims_array = NULL;
|
---|
| 39 | int num_partitions;
|
---|
[24989] | 40 | int* intarray = NULL;
|
---|
| 41 | int M,N;
|
---|
[24988] | 42 |
|
---|
[25627] | 43 | //qmu statistics
|
---|
| 44 | bool statistics = false;
|
---|
| 45 | int numdirectories = 0;
|
---|
| 46 | int nfilesperdirectory = 0;
|
---|
| 47 |
|
---|
[9356] | 48 | /*recover parameters: */
|
---|
[20690] | 49 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
---|
[9476] | 50 |
|
---|
[9571] | 51 | if(dakota_analysis){
|
---|
[2110] | 52 |
|
---|
[24450] | 53 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.output",QmuOutputEnum));
|
---|
| 54 |
|
---|
[20690] | 55 | iomodel->FindConstant(&name,"md.miscellaneous.name");
|
---|
| 56 | iomodel->FindConstant(&numberofresponses,"md.qmu.numberofresponses");
|
---|
[9476] | 57 |
|
---|
[16240] | 58 | /*name of qmu input, error and output files*/
|
---|
[13277] | 59 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
---|
| 60 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
---|
[3697] | 61 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
---|
[765] | 62 |
|
---|
[13277] | 63 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
---|
| 64 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
---|
[3697] | 65 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
---|
[765] | 66 |
|
---|
[13277] | 67 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
---|
| 68 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
---|
[3697] | 69 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
---|
[16240] | 70 |
|
---|
| 71 | /*Fetch variable descriptors*/
|
---|
[20693] | 72 | iomodel->FindConstant(&variabledescriptors,&numvariabledescriptors,"md.qmu.variabledescriptors");
|
---|
[765] | 73 |
|
---|
[16240] | 74 | /*Fetch response descriptors*/
|
---|
[20693] | 75 | iomodel->FindConstant(&responsedescriptors,&numresponsedescriptors,"md.qmu.responsedescriptors");
|
---|
[765] | 76 |
|
---|
[962] | 77 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
---|
[9650] | 78 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
---|
[16240] | 79 |
|
---|
[25627] | 80 | /*Deal with statistics: */
|
---|
| 81 | iomodel->FindConstant(&statistics,"md.qmu.statistics");
|
---|
| 82 | parameters->AddObject(new BoolParam(QmuStatisticsEnum,statistics));
|
---|
| 83 | if(statistics){
|
---|
| 84 | iomodel->FindConstant(&numdirectories,"md.qmu.statistics.ndirectories");
|
---|
| 85 | parameters->AddObject(new IntParam(QmuNdirectoriesEnum,numdirectories));
|
---|
| 86 |
|
---|
| 87 | iomodel->FindConstant(&nfilesperdirectory,"md.qmu.statistics.nfiles_per_directory");
|
---|
| 88 | parameters->AddObject(new IntParam(QmuNfilesPerDirectoryEnum,nfilesperdirectory));
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[24988] | 91 | /*Load partitioning vectors specific to variables:*/
|
---|
| 92 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.variablepartitions");
|
---|
| 93 | parameters->AddObject(new DoubleMatArrayParam(QmuVariablePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
|
---|
[24989] | 94 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_npart");
|
---|
| 95 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNpartEnum,intarray,M,N));
|
---|
[25019] | 96 | xDelete<int>(intarray); iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_nt");
|
---|
| 97 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNtEnum,intarray,M,N));
|
---|
[13622] | 98 |
|
---|
[24998] | 99 | /*free arrays: {{{*/
|
---|
| 100 | for(i=0;i<num_partitions;i++){
|
---|
| 101 | IssmDouble* matrix=array[i];
|
---|
| 102 | xDelete<IssmDouble>(matrix);
|
---|
| 103 | }
|
---|
| 104 | xDelete<int>(mdims_array);
|
---|
| 105 | xDelete<int>(ndims_array);
|
---|
| 106 | xDelete<IssmDouble*>(array);
|
---|
| 107 | xDelete<int>(intarray);
|
---|
| 108 | /*}}}*/
|
---|
| 109 |
|
---|
| 110 | /*Load partitioning vectors specific to responses:*/
|
---|
| 111 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.responsepartitions");
|
---|
| 112 | parameters->AddObject(new DoubleMatArrayParam(QmuResponsePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
|
---|
| 113 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.responsepartitions_npart");
|
---|
| 114 | parameters->AddObject(new IntMatParam(QmuResponsePartitionsNpartEnum,intarray,M,N));
|
---|
| 115 |
|
---|
| 116 | /*free arrays: {{{*/
|
---|
| 117 | for(i=0;i<num_partitions;i++){
|
---|
| 118 | IssmDouble* matrix=array[i];
|
---|
| 119 | xDelete<IssmDouble>(matrix);
|
---|
| 120 | }
|
---|
| 121 | xDelete<int>(mdims_array);
|
---|
| 122 | xDelete<int>(ndims_array);
|
---|
| 123 | xDelete<IssmDouble*>(array);
|
---|
| 124 | xDelete<int>(intarray);
|
---|
| 125 | /*}}}*/
|
---|
| 126 |
|
---|
[16240] | 127 | /*Deal with data needed because of qmu variables*/
|
---|
[22617] | 128 | DataSet* dataset_variable_descriptors = new DataSet(QmuVariableDescriptorsEnum);
|
---|
[8936] | 129 | for(i=0;i<numvariabledescriptors;i++){
|
---|
[5477] | 130 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
---|
[25257] | 131 | int code;
|
---|
| 132 |
|
---|
| 133 | /*Ok, we are dealing with a variable that is distributed over nodes or elements. Recover the name of the variable (ex: scaled_Thickness): */
|
---|
[5477] | 134 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
---|
[13622] | 135 |
|
---|
[20888] | 136 | /*Get field name and input enum from tag*/
|
---|
| 137 | char* fieldname = NULL;
|
---|
[20692] | 138 | int param_enum = -1;
|
---|
[20888] | 139 | FieldAndEnumFromCode(¶m_enum,&fieldname,tag);
|
---|
[20692] | 140 |
|
---|
[25257] | 141 | iomodel->SetFilePointerToData(&code,NULL,fieldname);
|
---|
| 142 | 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!
|
---|
| 143 | else{
|
---|
| 144 | /*recover more classic data, arrays and scalar mainly:*/
|
---|
| 145 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,fieldname);
|
---|
| 146 | if(nrows==iomodel->numberofvertices || nrows==iomodel->numberofelements){
|
---|
| 147 | dataset_variable_descriptors->AddObject(new DoubleMatParam(param_enum,dakota_parameter,nrows,ncols));
|
---|
| 148 | }
|
---|
| 149 | else{
|
---|
| 150 | dataset_variable_descriptors->AddObject(new DoubleTransientMatParam(param_enum,dakota_parameter,nrows,ncols));
|
---|
| 151 | }
|
---|
| 152 | xDelete<double>(dakota_parameter);
|
---|
[10660] | 153 | }
|
---|
[20692] | 154 | xDelete<char>(fieldname);
|
---|
[962] | 155 | }
|
---|
[765] | 156 | }
|
---|
[22617] | 157 | parameters->AddObject(new DataSetParam(QmuVariableDescriptorsEnum,dataset_variable_descriptors));
|
---|
| 158 | delete dataset_variable_descriptors;
|
---|
[16240] | 159 |
|
---|
[25627] | 160 | /*clean-up {{{*/
|
---|
[8936] | 161 | for(i=0;i<numresponsedescriptors;i++){
|
---|
[5477] | 162 | descriptor=responsedescriptors[i];
|
---|
[12450] | 163 | xDelete<char>(descriptor);
|
---|
[962] | 164 | }
|
---|
[12450] | 165 | xDelete<char*>(responsedescriptors);
|
---|
[8936] | 166 | for(i=0;i<numvariabledescriptors;i++){
|
---|
[5477] | 167 | descriptor=variabledescriptors[i];
|
---|
[12450] | 168 | xDelete<char>(descriptor);
|
---|
[962] | 169 | }
|
---|
[12450] | 170 | xDelete<char*>(variabledescriptors);
|
---|
| 171 | xDelete<char>(qmuinname);
|
---|
| 172 | xDelete<char>(qmuerrname);
|
---|
| 173 | xDelete<char>(qmuoutname);
|
---|
[25627] | 174 | xDelete<char>(name);
|
---|
| 175 | /*}}}*/
|
---|
[16240] | 176 | }
|
---|
[765] | 177 |
|
---|
| 178 | }
|
---|