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 | int *part = NULL;
|
---|
16 | double *dpart = NULL;
|
---|
17 | char **responsedescriptors = NULL;
|
---|
18 | int numresponsedescriptors;
|
---|
19 | char **variabledescriptors = NULL;
|
---|
20 | int numvariabledescriptors;
|
---|
21 | char *descriptor = NULL;
|
---|
22 | double *dakota_parameter = NULL;
|
---|
23 |
|
---|
24 | //qmu files
|
---|
25 | char *qmuinname = NULL;
|
---|
26 | char *qmuerrname = NULL;
|
---|
27 | char *qmuoutname = NULL;
|
---|
28 |
|
---|
29 | //descriptors:
|
---|
30 | char tag[50];
|
---|
31 |
|
---|
32 | bool dakota_analysis = false;
|
---|
33 | char *name = NULL;
|
---|
34 | int numberofresponses;
|
---|
35 | int nrows,ncols;
|
---|
36 |
|
---|
37 | /*recover parameters: */
|
---|
38 | iomodel->FindConstant(&dakota_analysis,"md.qmu.isdakota");
|
---|
39 |
|
---|
40 | if(dakota_analysis){
|
---|
41 |
|
---|
42 | iomodel->FindConstant(&name,"md.miscellaneous.name");
|
---|
43 | iomodel->FindConstant(&numberofresponses,"md.qmu.numberofresponses");
|
---|
44 |
|
---|
45 | /*name of qmu input, error and output files*/
|
---|
46 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
---|
47 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
---|
48 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
---|
49 |
|
---|
50 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
---|
51 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
---|
52 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
---|
53 |
|
---|
54 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
---|
55 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
---|
56 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
---|
57 |
|
---|
58 | /*Fetch variable descriptors*/
|
---|
59 | iomodel->FetchData(&variabledescriptors,&numvariabledescriptors,"md.qmu.variabledescriptors");
|
---|
60 |
|
---|
61 | /*Ok, we have all the variable descriptors. Build a parameter with it: */
|
---|
62 | parameters->AddObject(new StringArrayParam(QmuVariabledescriptorsEnum,variabledescriptors,numvariabledescriptors));
|
---|
63 |
|
---|
64 | /*Fetch response descriptors*/
|
---|
65 | iomodel->FetchData(&responsedescriptors,&numresponsedescriptors,"md.qmu.responsedescriptors");
|
---|
66 |
|
---|
67 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
---|
68 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
---|
69 | parameters->AddObject(new IntParam(QmuNumberofresponsesEnum,numberofresponses));
|
---|
70 |
|
---|
71 | /*Deal with partitioning*/
|
---|
72 | /*partition vertices in iomodel->qmu_npart parts, unless a partition is already present: */
|
---|
73 | parameters->AddObject(iomodel->CopyConstantObject("md.qmu.numberofpartitions",QmuNumberofpartitionsEnum));
|
---|
74 | iomodel->FetchData(&dpart,NULL,NULL,"md.qmu.partition");
|
---|
75 | if(!dpart){
|
---|
76 | /*Partition elements and vertices and nodes: */
|
---|
77 | ElementsAndVerticesPartitioning(&iomodel->my_elements,&iomodel->my_vertices,iomodel);
|
---|
78 |
|
---|
79 | dpart=xNew<double>(iomodel->numberofvertices);
|
---|
80 | for(i=0;i<iomodel->numberofvertices;i++)dpart[i]=iomodel->my_vertices[i];
|
---|
81 | }
|
---|
82 | parameters->AddObject(new DoubleVecParam(QmuPartitionEnum,dpart,iomodel->numberofvertices));
|
---|
83 |
|
---|
84 | /*Deal with data needed because of qmu variables*/
|
---|
85 | for(i=0;i<numvariabledescriptors;i++){
|
---|
86 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
---|
87 | /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
|
---|
88 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
---|
89 |
|
---|
90 | /*Recover data: */
|
---|
91 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,StringToEnumx(tag));
|
---|
92 | if(nrows==iomodel->numberofvertices){
|
---|
93 | parameters->AddObject(new DoubleMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
---|
94 | }
|
---|
95 | else{
|
---|
96 | parameters->AddObject(new DoubleTransientMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
---|
97 | }
|
---|
98 | xDelete<double>(dakota_parameter);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | /*clean-up*/
|
---|
103 | for(i=0;i<numresponsedescriptors;i++){
|
---|
104 | descriptor=responsedescriptors[i];
|
---|
105 | xDelete<char>(descriptor);
|
---|
106 | }
|
---|
107 | xDelete<char*>(responsedescriptors);
|
---|
108 | for(i=0;i<numvariabledescriptors;i++){
|
---|
109 | descriptor=variabledescriptors[i];
|
---|
110 | xDelete<char>(descriptor);
|
---|
111 | }
|
---|
112 | xDelete<char*>(variabledescriptors);
|
---|
113 | xDelete<int>(part);
|
---|
114 | xDelete<double>(dpart);
|
---|
115 | xDelete<char>(qmuinname);
|
---|
116 | xDelete<char>(qmuerrname);
|
---|
117 | xDelete<char>(qmuoutname);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /*Free data*/
|
---|
121 | xDelete<char>(name);
|
---|
122 | }
|
---|