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 | //qmu statistics
|
---|
44 | bool statistics = false;
|
---|
45 | int numdirectories = 0;
|
---|
46 | int nfilesperdirectory = 0;
|
---|
47 |
|
---|
48 | /*recover parameters: */
|
---|
49 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
---|
50 |
|
---|
51 | if(dakota_analysis){
|
---|
52 |
|
---|
53 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.output",QmuOutputEnum));
|
---|
54 |
|
---|
55 | iomodel->FindConstant(&name,"md.miscellaneous.name");
|
---|
56 | iomodel->FindConstant(&numberofresponses,"md.qmu.numberofresponses");
|
---|
57 |
|
---|
58 | /*name of qmu input, error and output files*/
|
---|
59 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
---|
60 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
---|
61 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
---|
62 |
|
---|
63 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
---|
64 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
---|
65 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
---|
66 |
|
---|
67 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
---|
68 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
---|
69 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
---|
70 |
|
---|
71 | /*Fetch variable descriptors*/
|
---|
72 | iomodel->FindConstant(&variabledescriptors,&numvariabledescriptors,"md.qmu.variabledescriptors");
|
---|
73 |
|
---|
74 | /*Fetch response descriptors*/
|
---|
75 | iomodel->FindConstant(&responsedescriptors,&numresponsedescriptors,"md.qmu.responsedescriptors");
|
---|
76 |
|
---|
77 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
---|
78 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
---|
79 |
|
---|
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 |
|
---|
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));
|
---|
94 | iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_npart");
|
---|
95 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNpartEnum,intarray,M,N));
|
---|
96 | xDelete<int>(intarray); iomodel->FetchData(&intarray,&M,&N,"md.qmu.variablepartitions_nt");
|
---|
97 | parameters->AddObject(new IntMatParam(QmuVariablePartitionsNtEnum,intarray,M,N));
|
---|
98 |
|
---|
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 |
|
---|
127 | /*Deal with data needed because of qmu variables*/
|
---|
128 | DataSet* dataset_variable_descriptors = new DataSet(QmuVariableDescriptorsEnum);
|
---|
129 | for(i=0;i<numvariabledescriptors;i++){
|
---|
130 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
---|
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): */
|
---|
134 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
---|
135 |
|
---|
136 | /*Get field name and input enum from tag*/
|
---|
137 | char* fieldname = NULL;
|
---|
138 | int param_enum = -1;
|
---|
139 | FieldAndEnumFromCode(¶m_enum,&fieldname,tag);
|
---|
140 |
|
---|
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);
|
---|
153 | }
|
---|
154 | xDelete<char>(fieldname);
|
---|
155 | }
|
---|
156 | }
|
---|
157 | parameters->AddObject(new DataSetParam(QmuVariableDescriptorsEnum,dataset_variable_descriptors));
|
---|
158 | delete dataset_variable_descriptors;
|
---|
159 |
|
---|
160 | /*clean-up {{{*/
|
---|
161 | for(i=0;i<numresponsedescriptors;i++){
|
---|
162 | descriptor=responsedescriptors[i];
|
---|
163 | xDelete<char>(descriptor);
|
---|
164 | }
|
---|
165 | xDelete<char*>(responsedescriptors);
|
---|
166 | for(i=0;i<numvariabledescriptors;i++){
|
---|
167 | descriptor=variabledescriptors[i];
|
---|
168 | xDelete<char>(descriptor);
|
---|
169 | }
|
---|
170 | xDelete<char*>(variabledescriptors);
|
---|
171 | xDelete<char>(qmuinname);
|
---|
172 | xDelete<char>(qmuerrname);
|
---|
173 | xDelete<char>(qmuoutname);
|
---|
174 | xDelete<char>(name);
|
---|
175 | /*}}}*/
|
---|
176 | }
|
---|
177 |
|
---|
178 | }
|
---|