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

Last change on this file since 10937 was 10660, checked in by Eric.Larour, 13 years ago

Added new derived calss from DoubleMatParam, DoubleTransientMatParam, which
is needed for transient forcings in Dakota analyses.

File size: 7.0 KB
Line 
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 "../../../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
15void CreateParametersDakota(Parameters** pparameters,IoModel* iomodel,int solution_type,int analysis_type){
16
17 /*variable declarations: {{{1*/
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:{{{1*/
76 qmuinname=(char*)xmalloc((strlen(name)+strlen(".qmu.in")+1)*sizeof(char));
77 sprintf(qmuinname,"%s%s",name,".qmu.in");
78 parameters->AddObject(new StringParam(QmuInNameEnum,qmuinname));
79
80 qmuoutname=(char*)xmalloc((strlen(name)+strlen(".qmu.out")+1)*sizeof(char));
81 sprintf(qmuoutname,"%s%s",name,".qmu.out");
82 parameters->AddObject(new StringParam(QmuOutNameEnum,qmuoutname));
83
84 qmuerrname=(char*)xmalloc((strlen(name)+strlen(".qmu.err")+1)*sizeof(char));
85 sprintf(qmuerrname,"%s%s",name,".qmu.err");
86 parameters->AddObject(new StringParam(QmuErrNameEnum,qmuerrname));
87 /*}}}*/
88 /*Fetch variable descriptors: {{{1*/
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: {{{1*/
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: {{{1*/
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=(double*)xmalloc(numberofvertices*sizeof(double));
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: {{{1*/
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 xfree((void**)&dakota_parameter);
139 }
140 }
141 /*}}}*/
142 /*Deal with data needed to compute qmu responses: {{{1*/
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=(double*)xcalloc(5*m,sizeof(double));
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 xfree((void**)&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 xfree((void**)&matrix);
197 }
198 xfree((void**)&mdims_array);
199 xfree((void**)&ndims_array);
200 xfree((void**)&array);
201 }
202 /*}}}*/
203 /*Free data: {{{1*/
204 for(i=0;i<numresponsedescriptors;i++){
205 descriptor=responsedescriptors[i];
206 xfree((void**)&descriptor);
207 }
208 xfree((void**)&responsedescriptors);
209
210 for(i=0;i<numvariabledescriptors;i++){
211 descriptor=variabledescriptors[i];
212 xfree((void**)&descriptor);
213 }
214 xfree((void**)&variabledescriptors);
215 xfree((void**)&part);
216 xfree((void**)&dpart);
217 xfree((void**)&qmuinname);
218 xfree((void**)&qmuerrname);
219 xfree((void**)&qmuoutname);
220 /*}}}*/
221 } //if(dakota_analysis)
222
223 /*Free data*/
224 xfree((void**)&name);
225
226 /*Assign output pointer: */
227 *pparameters=parameters;
228}
Note: See TracBrowser for help on using the repository browser.