source: issm/trunk-jpl/src/c/modules/ModelProcessorx/Dakota/CreateParametersDakota.cpp@ 14999

Last change on this file since 14999 was 14999, checked in by Eric.Larour, 12 years ago

CHG: modules should include shared.h, and that's it.

File size: 4.7 KB
Line 
1/*!\file: CreateParametersDakota.cpp
2 * \brief general driver for creating parameters dataset
3 */
4
5#include "../../../toolkits/toolkits.h"
6#include "../../../classes/objects/objects.h"
7#include "../../../shared/shared.h"
8#include "../../MeshPartitionx/MeshPartitionx.h"
9#include "../ModelProcessorx.h"
10
11void CreateParametersDakota(Parameters** pparameters,IoModel* iomodel,char* rootpath,int solution_type,int analysis_type){
12
13 /*variable declarations: {{{*/
14 int i;
15 Parameters* parameters = NULL;
16
17 int* part=NULL;
18 double* dpart=NULL;
19
20 char** responsedescriptors=NULL;
21 int numresponsedescriptors;
22 char** variabledescriptors=NULL;
23 int numvariabledescriptors;
24 char* descriptor=NULL;
25 double* dakota_parameter=NULL;
26
27 //qmu files
28 char* qmuinname=NULL;
29 char* qmuerrname=NULL;
30 char* qmuoutname=NULL;
31
32 //descriptors:
33 char tag[50];
34
35 bool dakota_analysis=false;
36 char* name=NULL;
37 int numberofresponses;
38 int numberofvertices;
39 int nrows;
40 int ncols;
41
42 /*}}}*/
43
44 /*recover parameters : */
45 parameters=*pparameters;
46
47 /*recover parameters: */
48 iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
49
50 if(dakota_analysis){
51
52 iomodel->Constant(&name,MiscellaneousNameEnum);
53 iomodel->Constant(&numberofresponses,QmuNumberofresponsesEnum);
54 iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
55
56 /*name of qmu input, error and output files:{{{*/
57 qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
58 sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
59 parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
60
61 qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
62 sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
63 parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
64
65 qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
66 sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
67 parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
68 /*}}}*/
69 /*Fetch variable descriptors: {{{*/
70 iomodel->FetchData(&variabledescriptors,&numvariabledescriptors,QmuVariabledescriptorsEnum);
71
72 /*Ok, we have all the variable descriptors. Build a parameter with it: */
73 parameters->AddObject(new StringArrayParam(QmuVariabledescriptorsEnum,variabledescriptors,numvariabledescriptors));
74
75 /*}}}*/
76 /*Fetch response descriptors: {{{*/
77 iomodel->FetchData(&responsedescriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum);
78
79 /*Ok, we have all the response descriptors. Build a parameter with it: */
80 parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
81 parameters->AddObject(new IntParam(QmuNumberofresponsesEnum,numberofresponses));
82 /*}}}*/
83 /*Deal with partitioning: {{{*/
84 /*partition vertices in iomodel->qmu_npart parts, unless a partition is already present: */
85
86 parameters->AddObject(iomodel->CopyConstantObject(QmuNumberofpartitionsEnum));
87 iomodel->FetchData(&dpart,NULL,NULL,QmuPartitionEnum);
88
89 if(!dpart){
90
91 /*Partition elements and vertices and nodes: */
92 ElementsAndVerticesPartitioning(&iomodel->my_elements,&iomodel->my_vertices,iomodel);
93
94 dpart=xNew<double>(numberofvertices);
95 for(i=0;i<numberofvertices;i++)dpart[i]=iomodel->my_vertices[i];
96 }
97 parameters->AddObject(new DoubleVecParam(QmuPartitionEnum,dpart,numberofvertices));
98 /*}}}*/
99 /*Deal with data needed because of qmu variables: {{{*/
100
101 for(i=0;i<numvariabledescriptors;i++){
102
103 if (strncmp(variabledescriptors[i],"scaled_",7)==0){
104 /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
105 sscanf(variabledescriptors[i],"scaled_%s",tag);
106
107 /*Recover data: */
108 iomodel->FetchData(&dakota_parameter,&nrows,&ncols,StringToEnumx(tag));
109
110 /*Add to parameters: */
111 if(nrows==numberofvertices){
112 parameters->AddObject(new DoubleMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
113 }
114 else{
115 parameters->AddObject(new DoubleTransientMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
116 }
117
118 /*Free ressources:*/
119 xDelete<double>(dakota_parameter);
120 }
121 }
122 /*}}}*/
123 /*Free data: {{{*/
124 for(i=0;i<numresponsedescriptors;i++){
125 descriptor=responsedescriptors[i];
126 xDelete<char>(descriptor);
127 }
128 xDelete<char*>(responsedescriptors);
129
130 for(i=0;i<numvariabledescriptors;i++){
131 descriptor=variabledescriptors[i];
132 xDelete<char>(descriptor);
133 }
134 xDelete<char*>(variabledescriptors);
135 xDelete<int>(part);
136 xDelete<double>(dpart);
137 xDelete<char>(qmuinname);
138 xDelete<char>(qmuerrname);
139 xDelete<char>(qmuoutname);
140 /*}}}*/
141 } //if(dakota_analysis)
142
143 /*Free data*/
144 xDelete<char>(name);
145
146 /*Assign output pointer: */
147 *pparameters=parameters;
148}
Note: See TracBrowser for help on using the repository browser.