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 (both vertex and element based: */
|
---|
76 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.numberofpartitions",QmuNumberofpartitionsEnum));
|
---|
77 |
|
---|
78 | /*Load partitioning vectors specific to variables:*/
|
---|
79 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&num_partitions,"md.qmu.variablepartitions");
|
---|
80 | parameters->AddObject(new DoubleMatArrayParam(QmuVariablePartitionsEnum,array,num_partitions,mdims_array,ndims_array));
|
---|
81 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_npart");
|
---|
82 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNpartEnum,intarray,M,N));
|
---|
83 |
|
---|
84 | /*Deal with data needed because of qmu variables*/
|
---|
85 | DataSet* dataset_variable_descriptors = new DataSet(QmuVariableDescriptorsEnum);
|
---|
86 | for(i=0;i<numvariabledescriptors;i++){
|
---|
87 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
---|
88 | /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
|
---|
89 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
---|
90 |
|
---|
91 | /*Get field name and input enum from tag*/
|
---|
92 | char* fieldname = NULL;
|
---|
93 | int param_enum = -1;
|
---|
94 | FieldAndEnumFromCode(¶m_enum,&fieldname,tag);
|
---|
95 |
|
---|
96 | /*Recover data: */
|
---|
97 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,fieldname);
|
---|
98 | if(nrows==iomodel->numberofvertices){
|
---|
99 | dataset_variable_descriptors->AddObject(new DoubleMatParam(param_enum,dakota_parameter,nrows,ncols));
|
---|
100 | }
|
---|
101 | else{
|
---|
102 | dataset_variable_descriptors->AddObject(new DoubleTransientMatParam(param_enum,dakota_parameter,nrows,ncols));
|
---|
103 | }
|
---|
104 | xDelete<double>(dakota_parameter);
|
---|
105 | xDelete<char>(fieldname);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | parameters->AddObject(new DataSetParam(QmuVariableDescriptorsEnum,dataset_variable_descriptors));
|
---|
109 | delete dataset_variable_descriptors;
|
---|
110 |
|
---|
111 | /*clean-up*/
|
---|
112 | for(i=0;i<numresponsedescriptors;i++){
|
---|
113 | descriptor=responsedescriptors[i];
|
---|
114 | xDelete<char>(descriptor);
|
---|
115 | }
|
---|
116 | xDelete<char*>(responsedescriptors);
|
---|
117 | for(i=0;i<numvariabledescriptors;i++){
|
---|
118 | descriptor=variabledescriptors[i];
|
---|
119 | xDelete<char>(descriptor);
|
---|
120 | }
|
---|
121 | xDelete<char*>(variabledescriptors);
|
---|
122 | xDelete<char>(qmuinname);
|
---|
123 | xDelete<char>(qmuerrname);
|
---|
124 | xDelete<char>(qmuoutname);
|
---|
125 |
|
---|
126 | for(i=0;i<num_partitions;i++){
|
---|
127 | IssmDouble* matrix=array[i];
|
---|
128 | xDelete<IssmDouble>(matrix);
|
---|
129 | }
|
---|
130 | xDelete<int>(mdims_array);
|
---|
131 | xDelete<int>(ndims_array);
|
---|
132 | xDelete<IssmDouble*>(array);
|
---|
133 | xDelete<int>(intarray);
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 | /*Free data*/
|
---|
138 | xDelete<char>(name);
|
---|
139 | }
|
---|