1 | /*!\file: CreateParametersDakota.cpp
|
---|
2 | * \brief general driver for creating parameters dataset
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "../../../Container/Container.h"
|
---|
6 | #include "../../../toolkits/toolkits.h"
|
---|
7 | #include "../../../EnumDefinitions/EnumDefinitions.h"
|
---|
8 | #include "../../../classes/objects/objects.h"
|
---|
9 | #include "../../../shared/shared.h"
|
---|
10 | #include "../../../io/io.h"
|
---|
11 | #include "../../../include/include.h"
|
---|
12 | #include "../../MeshPartitionx/MeshPartitionx.h"
|
---|
13 | #include "../ModelProcessorx.h"
|
---|
14 |
|
---|
15 | void CreateParametersDakota(Parameters** pparameters,IoModel* iomodel,char* rootpath,int solution_type,int analysis_type){
|
---|
16 |
|
---|
17 | /*variable declarations: {{{*/
|
---|
18 | int i,j,k;
|
---|
19 |
|
---|
20 | Parameters* parameters = NULL;
|
---|
21 | int second_count;
|
---|
22 |
|
---|
23 | int* part=NULL;
|
---|
24 | double* dpart=NULL;
|
---|
25 |
|
---|
26 | char** responsedescriptors=NULL;
|
---|
27 | int numresponsedescriptors;
|
---|
28 | char** variabledescriptors=NULL;
|
---|
29 | int numvariabledescriptors;
|
---|
30 | char* descriptor=NULL;
|
---|
31 | double* dakota_parameter=NULL;
|
---|
32 |
|
---|
33 | //qmu files
|
---|
34 | char* qmuinname=NULL;
|
---|
35 | char* qmuerrname=NULL;
|
---|
36 | char* qmuoutname=NULL;
|
---|
37 |
|
---|
38 | //descriptors:
|
---|
39 | char tag[50];
|
---|
40 |
|
---|
41 | /*parameters for mass flux: */
|
---|
42 | bool qmu_mass_flux_present=false;
|
---|
43 | int qmu_mass_flux_num_profiles=0;
|
---|
44 | double** array=NULL;
|
---|
45 | int* mdims_array=NULL;
|
---|
46 | int* ndims_array=NULL;
|
---|
47 |
|
---|
48 | double* matrix=NULL;
|
---|
49 | double* temp_matrix=NULL;
|
---|
50 | int M;
|
---|
51 | int temp_m,temp_n;
|
---|
52 | int m,n;
|
---|
53 | int count;
|
---|
54 | bool dakota_analysis=false;
|
---|
55 | char* name=NULL;
|
---|
56 | int numberofresponses;
|
---|
57 | int numberofvertices;
|
---|
58 | int nrows;
|
---|
59 | int ncols;
|
---|
60 |
|
---|
61 | /*}}}*/
|
---|
62 |
|
---|
63 | /*recover parameters : */
|
---|
64 | parameters=*pparameters;
|
---|
65 |
|
---|
66 | /*recover parameters: */
|
---|
67 | iomodel->Constant(&dakota_analysis,QmuIsdakotaEnum);
|
---|
68 |
|
---|
69 | if(dakota_analysis){
|
---|
70 |
|
---|
71 | iomodel->Constant(&name,MiscellaneousNameEnum);
|
---|
72 | iomodel->Constant(&numberofresponses,QmuNumberofresponsesEnum);
|
---|
73 | iomodel->Constant(&numberofvertices,MeshNumberofverticesEnum);
|
---|
74 |
|
---|
75 | /*name of qmu input, error and output files:{{{*/
|
---|
76 | qmuinname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.in")+1));
|
---|
77 | sprintf(qmuinname,"%s%s%s",rootpath,name,".qmu.in");
|
---|
78 | parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
|
---|
79 |
|
---|
80 | qmuoutname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.out")+1));
|
---|
81 | sprintf(qmuoutname,"%s%s%s",rootpath,name,".qmu.out");
|
---|
82 | parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
|
---|
83 |
|
---|
84 | qmuerrname=xNew<char>((strlen(rootpath)+strlen(name)+strlen(".qmu.err")+1));
|
---|
85 | sprintf(qmuerrname,"%s%s%s",rootpath,name,".qmu.err");
|
---|
86 | parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
|
---|
87 | /*}}}*/
|
---|
88 | /*Fetch variable descriptors: {{{*/
|
---|
89 | iomodel->FetchData(&variabledescriptors,&numvariabledescriptors,QmuVariabledescriptorsEnum);
|
---|
90 |
|
---|
91 | /*Ok, we have all the variable descriptors. Build a parameter with it: */
|
---|
92 | parameters->AddObject(new StringArrayParam(QmuVariabledescriptorsEnum,variabledescriptors,numvariabledescriptors));
|
---|
93 |
|
---|
94 | /*}}}*/
|
---|
95 | /*Fetch response descriptors: {{{*/
|
---|
96 | iomodel->FetchData(&responsedescriptors,&numresponsedescriptors,QmuResponsedescriptorsEnum);
|
---|
97 |
|
---|
98 | /*Ok, we have all the response descriptors. Build a parameter with it: */
|
---|
99 | parameters->AddObject(new StringArrayParam(QmuResponsedescriptorsEnum,responsedescriptors,numresponsedescriptors));
|
---|
100 | parameters->AddObject(new IntParam(QmuNumberofresponsesEnum,numberofresponses));
|
---|
101 | /*}}}*/
|
---|
102 | /*Deal with partitioning: {{{*/
|
---|
103 | /*partition vertices in iomodel->qmu_npart parts, unless a partition is already present: */
|
---|
104 |
|
---|
105 | parameters->AddObject(iomodel->CopyConstantObject(QmuNumberofpartitionsEnum));
|
---|
106 | iomodel->FetchData(&dpart,NULL,NULL,QmuPartitionEnum);
|
---|
107 |
|
---|
108 | if(!dpart){
|
---|
109 |
|
---|
110 | /*Partition elements and vertices and nodes: */
|
---|
111 | ElementsAndVerticesPartitioning(&iomodel->my_elements,&iomodel->my_vertices,iomodel);
|
---|
112 |
|
---|
113 | dpart=xNew<double>(numberofvertices);
|
---|
114 | for(i=0;i<numberofvertices;i++)dpart[i]=iomodel->my_vertices[i];
|
---|
115 | }
|
---|
116 | parameters->AddObject(new DoubleVecParam(QmuPartitionEnum,dpart,numberofvertices));
|
---|
117 | /*}}}*/
|
---|
118 | /*Deal with data needed because of qmu variables: {{{*/
|
---|
119 |
|
---|
120 | for(i=0;i<numvariabledescriptors;i++){
|
---|
121 |
|
---|
122 | if (strncmp(variabledescriptors[i],"scaled_",7)==0){
|
---|
123 | /*Ok, we are dealing with a variable that is distributed over nodes. Recover the name of the variable (ex: scaled_Thickness): */
|
---|
124 | sscanf(variabledescriptors[i],"scaled_%s",tag);
|
---|
125 |
|
---|
126 | /*Recover data: */
|
---|
127 | iomodel->FetchData(&dakota_parameter,&nrows,&ncols,StringToEnumx(tag));
|
---|
128 |
|
---|
129 | /*Add to parameters: */
|
---|
130 | if(nrows==numberofvertices){
|
---|
131 | parameters->AddObject(new DoubleMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
---|
132 | }
|
---|
133 | else{
|
---|
134 | parameters->AddObject(new DoubleTransientMatParam(StringToEnumx(tag),dakota_parameter,nrows,ncols));
|
---|
135 | }
|
---|
136 |
|
---|
137 | /*Free ressources:*/
|
---|
138 | xDelete<double>(dakota_parameter);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | /*}}}*/
|
---|
142 | /*Deal with data needed to compute qmu responses: {{{*/
|
---|
143 | for(i=0;i<numresponsedescriptors;i++){
|
---|
144 |
|
---|
145 | if(strncmp(responsedescriptors[i],"indexed_MassFlux",16)==0){
|
---|
146 | qmu_mass_flux_present=true;
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | if(qmu_mass_flux_present){
|
---|
152 |
|
---|
153 | /*Fetch the mass flux segments necessary to compute the mass fluxes. Build a DoubleMatArrayParam object out of them: */
|
---|
154 | iomodel->FetchData(&array,&mdims_array,&ndims_array,&qmu_mass_flux_num_profiles,QmuMassFluxSegmentsEnum);
|
---|
155 | if(qmu_mass_flux_num_profiles==0)_error_("qmu_mass_flux_num_profiles is 0, when MassFlux computations were requested!");
|
---|
156 |
|
---|
157 | /*Go through segments, and extract those that belong to this cpu: */
|
---|
158 | for(i=0;i<qmu_mass_flux_num_profiles;i++){
|
---|
159 | temp_matrix=array[i];
|
---|
160 | temp_m=mdims_array[i];
|
---|
161 | temp_n=ndims_array[i];
|
---|
162 |
|
---|
163 | m=0;
|
---|
164 | for(j=0;j<temp_m;j++){
|
---|
165 | if ( iomodel->my_elements[(int)(*(temp_matrix+5*j+4))-1])m++;
|
---|
166 | }
|
---|
167 | if(m){
|
---|
168 | matrix=xNewZeroInit<double>(5*m);
|
---|
169 | count=0;
|
---|
170 | for(j=0;j<temp_m;j++){
|
---|
171 | if (iomodel->my_elements[(int)*(temp_matrix+5*j+4)-1]){
|
---|
172 | for(k=0;k<5;k++)*(matrix+5*count+k)=*(temp_matrix+5*j+k);
|
---|
173 | count++;
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 | else{
|
---|
178 | matrix=NULL;
|
---|
179 | }
|
---|
180 |
|
---|
181 | /*Assign: */
|
---|
182 | array[i]=matrix;
|
---|
183 | mdims_array[i]=m;
|
---|
184 | ndims_array[i]=5;
|
---|
185 |
|
---|
186 | /*Free temporary matrix: */
|
---|
187 | xDelete<double>(temp_matrix);
|
---|
188 | }
|
---|
189 |
|
---|
190 | /*Ok, we have an array of segments, different on every cpu. Create a DoubleMatArrayParam object with it: */
|
---|
191 | parameters->AddObject(new DoubleMatArrayParam(QmuMassFluxSegmentsEnum,array,qmu_mass_flux_num_profiles,mdims_array,ndims_array));
|
---|
192 |
|
---|
193 | /*Free data: */
|
---|
194 | for(i=0;i<qmu_mass_flux_num_profiles;i++){
|
---|
195 | double* matrix=array[i];
|
---|
196 | xDelete<double>(matrix);
|
---|
197 | }
|
---|
198 | xDelete<int>(mdims_array);
|
---|
199 | xDelete<int>(ndims_array);
|
---|
200 | xDelete<double*>(array);
|
---|
201 | }
|
---|
202 | /*}}}*/
|
---|
203 | /*Free data: {{{*/
|
---|
204 | for(i=0;i<numresponsedescriptors;i++){
|
---|
205 | descriptor=responsedescriptors[i];
|
---|
206 | xDelete<char>(descriptor);
|
---|
207 | }
|
---|
208 | xDelete<char*>(responsedescriptors);
|
---|
209 |
|
---|
210 | for(i=0;i<numvariabledescriptors;i++){
|
---|
211 | descriptor=variabledescriptors[i];
|
---|
212 | xDelete<char>(descriptor);
|
---|
213 | }
|
---|
214 | xDelete<char*>(variabledescriptors);
|
---|
215 | xDelete<int>(part);
|
---|
216 | xDelete<double>(dpart);
|
---|
217 | xDelete<char>(qmuinname);
|
---|
218 | xDelete<char>(qmuerrname);
|
---|
219 | xDelete<char>(qmuoutname);
|
---|
220 | /*}}}*/
|
---|
221 | } //if(dakota_analysis)
|
---|
222 |
|
---|
223 | /*Free data*/
|
---|
224 | xDelete<char>(name);
|
---|
225 |
|
---|
226 | /*Assign output pointer: */
|
---|
227 | *pparameters=parameters;
|
---|
228 | }
|
---|