1 | /*!\file: CreateParametersControl.cpp
|
---|
2 | * \brief driver for creating parameters dataset, for control analysis.
|
---|
3 | */
|
---|
4 |
|
---|
5 | #undef __FUNCT__
|
---|
6 | #define __FUNCT__ "CreateParameters"
|
---|
7 |
|
---|
8 | #include "../../DataSet/DataSet.h"
|
---|
9 | #include "../../toolkits/toolkits.h"
|
---|
10 | #include "../../EnumDefinitions/EnumDefinitions.h"
|
---|
11 | #include "../../objects/objects.h"
|
---|
12 | #include "../../shared/shared.h"
|
---|
13 | #include "../IoModel.h"
|
---|
14 |
|
---|
15 | void CreateParametersControl(DataSet** pparameters,IoModel* iomodel,ConstDataHandle iomodel_handle){
|
---|
16 |
|
---|
17 | int i;
|
---|
18 |
|
---|
19 | DataSet* parameters=NULL;
|
---|
20 | Param* param = NULL;
|
---|
21 | int count;
|
---|
22 | int analysis_type;
|
---|
23 | int numberofdofspernode;
|
---|
24 |
|
---|
25 | double* fit=NULL;
|
---|
26 | double* optscal=NULL;
|
---|
27 | double* maxiter=NULL;
|
---|
28 | double* control_parameter=NULL;
|
---|
29 | double* param_g=NULL;
|
---|
30 |
|
---|
31 | double* vx_obs=NULL;
|
---|
32 | double* vy_obs=NULL;
|
---|
33 | double* u_g_obs=NULL;
|
---|
34 |
|
---|
35 | double* vx=NULL;
|
---|
36 | double* vy=NULL;
|
---|
37 | double* vz=NULL;
|
---|
38 | double* u_g=NULL;
|
---|
39 |
|
---|
40 | /*Get parameters: */
|
---|
41 | parameters=*pparameters;
|
---|
42 | count=parameters->Size();
|
---|
43 |
|
---|
44 | //control analysis?
|
---|
45 | count++;
|
---|
46 | param= new Param(count,"control_analysis",INTEGER);
|
---|
47 | param->SetInteger(iomodel->control_analysis);
|
---|
48 | parameters->AddObject(param);
|
---|
49 |
|
---|
50 | if(iomodel->control_analysis){
|
---|
51 | /*control_type: */
|
---|
52 | count++;
|
---|
53 | param= new Param(count,"control_type",STRING);
|
---|
54 | param->SetString(iomodel->control_type);
|
---|
55 | parameters->AddObject(param);
|
---|
56 |
|
---|
57 | /*extrude_param: */
|
---|
58 | count++;
|
---|
59 | param= new Param(count,"extrude_param",DOUBLE);
|
---|
60 | if (strcmp(iomodel->control_type,"drag")==0) param->SetDouble(0);
|
---|
61 | else if (strcmp(iomodel->control_type,"B")==0) param->SetDouble(1);
|
---|
62 | else throw ErrorException(__FUNCT__,exprintf("control_type %s not supported yet!",iomodel->control_type));
|
---|
63 | parameters->AddObject(param);
|
---|
64 |
|
---|
65 | /*nsteps: */
|
---|
66 | count++;
|
---|
67 | param= new Param(count,"nsteps",INTEGER);
|
---|
68 | param->SetInteger(iomodel->nsteps);
|
---|
69 | parameters->AddObject(param);
|
---|
70 |
|
---|
71 | /*tolx: */
|
---|
72 | count++;
|
---|
73 | param= new Param(count,"tolx",DOUBLE);
|
---|
74 | param->SetDouble(iomodel->tolx);
|
---|
75 | parameters->AddObject(param);
|
---|
76 |
|
---|
77 | /*mincontrolconstraint: */
|
---|
78 | count++;
|
---|
79 | param= new Param(count,"mincontrolconstraint",DOUBLE);
|
---|
80 | param->SetDouble(iomodel->mincontrolconstraint);
|
---|
81 | parameters->AddObject(param);
|
---|
82 |
|
---|
83 | /*maxcontrolconstraint: */
|
---|
84 | count++;
|
---|
85 | param= new Param(count,"maxcontrolconstraint",DOUBLE);
|
---|
86 | param->SetDouble(iomodel->maxcontrolconstraint);
|
---|
87 | parameters->AddObject(param);
|
---|
88 |
|
---|
89 | /*epsvel: */
|
---|
90 | count++;
|
---|
91 | param= new Param(count,"epsvel",DOUBLE);
|
---|
92 | param->SetDouble(iomodel->epsvel);
|
---|
93 | parameters->AddObject(param);
|
---|
94 |
|
---|
95 | /*meanvel: */
|
---|
96 | count++;
|
---|
97 | param= new Param(count,"meanvel",DOUBLE);
|
---|
98 | param->SetDouble(iomodel->meanvel);
|
---|
99 | parameters->AddObject(param);
|
---|
100 |
|
---|
101 | /*Now, recover fit, optscal and maxiter as vectors: */
|
---|
102 | IoModelFetchData((void**)&iomodel->fit,NULL,NULL,iomodel_handle,"fit","Matrix","Mat");
|
---|
103 | IoModelFetchData((void**)&iomodel->optscal,NULL,NULL,iomodel_handle,"optscal","Matrix","Mat");
|
---|
104 | IoModelFetchData((void**)&iomodel->maxiter,NULL,NULL,iomodel_handle,"maxiter","Matrix","Mat");
|
---|
105 |
|
---|
106 | count++;
|
---|
107 | param= new Param(count,"fit",DOUBLEVEC);
|
---|
108 | param->SetDoubleVec(iomodel->fit,iomodel->nsteps);
|
---|
109 | parameters->AddObject(param);
|
---|
110 |
|
---|
111 | count++;
|
---|
112 | param= new Param(count,"optscal",DOUBLEVEC);
|
---|
113 | param->SetDoubleVec(iomodel->optscal,iomodel->nsteps);
|
---|
114 | parameters->AddObject(param);
|
---|
115 |
|
---|
116 | count++;
|
---|
117 | param= new Param(count,"maxiter",DOUBLEVEC);
|
---|
118 | param->SetDoubleVec(iomodel->maxiter,iomodel->nsteps);
|
---|
119 | parameters->AddObject(param);
|
---|
120 |
|
---|
121 | xfree((void**)&iomodel->fit);
|
---|
122 | xfree((void**)&iomodel->optscal);
|
---|
123 | xfree((void**)&iomodel->maxiter);
|
---|
124 |
|
---|
125 | /*Get vx, vx_obs, vy, vy_obs, and the parameter value: */
|
---|
126 | IoModelFetchData((void**)&vx,NULL,NULL,iomodel_handle,"vx","Matrix","Mat");
|
---|
127 | IoModelFetchData((void**)&vy,NULL,NULL,iomodel_handle,"vy","Matrix","Mat");
|
---|
128 | IoModelFetchData((void**)&vz,NULL,NULL,iomodel_handle,"vz","Matrix","Mat");
|
---|
129 | IoModelFetchData((void**)&vx_obs,NULL,NULL,iomodel_handle,"vx_obs","Matrix","Mat");
|
---|
130 | IoModelFetchData((void**)&vy_obs,NULL,NULL,iomodel_handle,"vy_obs","Matrix","Mat");
|
---|
131 | IoModelFetchData((void**)&control_parameter,NULL,NULL,iomodel_handle,iomodel->control_type,"Matrix","Mat");
|
---|
132 |
|
---|
133 | u_g=(double*)xcalloc(iomodel->numberofnodes*3,sizeof(double));
|
---|
134 | if(vx)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+0]=vx[i]/iomodel->yts;
|
---|
135 | if(vy)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+1]=vy[i]/iomodel->yts;
|
---|
136 | if(vz)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+2]=vz[i]/iomodel->yts;
|
---|
137 |
|
---|
138 | count++;
|
---|
139 | param= new Param(count,"u_g",DOUBLEVEC);
|
---|
140 | param->SetDoubleVec(u_g,3*iomodel->numberofnodes,3);
|
---|
141 | parameters->AddObject(param);
|
---|
142 |
|
---|
143 | u_g_obs=(double*)xcalloc(iomodel->numberofnodes*2,sizeof(double));
|
---|
144 | if(vx_obs)for(i=0;i<iomodel->numberofnodes;i++)u_g_obs[2*i+0]=vx_obs[i]/iomodel->yts;
|
---|
145 | if(vy_obs)for(i=0;i<iomodel->numberofnodes;i++)u_g_obs[2*i+1]=vy_obs[i]/iomodel->yts;
|
---|
146 |
|
---|
147 | count++;
|
---|
148 | param= new Param(count,"u_g_obs",DOUBLEVEC);
|
---|
149 | param->SetDoubleVec(u_g_obs,2*iomodel->numberofnodes,2);
|
---|
150 | parameters->AddObject(param);
|
---|
151 |
|
---|
152 | param_g=(double*)xcalloc(iomodel->numberofnodes,sizeof(double));
|
---|
153 | for(i=0;i<iomodel->numberofnodes;i++)param_g[i]=control_parameter[i];
|
---|
154 |
|
---|
155 | count++;
|
---|
156 | param= new Param(count,"param_g",DOUBLEVEC);
|
---|
157 | param->SetDoubleVec(param_g,iomodel->numberofnodes,1);
|
---|
158 | parameters->AddObject(param);
|
---|
159 |
|
---|
160 | xfree((void**)&vx);
|
---|
161 | xfree((void**)&vy);
|
---|
162 | xfree((void**)&vz);
|
---|
163 | xfree((void**)&u_g);
|
---|
164 | xfree((void**)&vx_obs);
|
---|
165 | xfree((void**)&vy_obs);
|
---|
166 | xfree((void**)&u_g_obs);
|
---|
167 | xfree((void**)¶m_g);
|
---|
168 | xfree((void**)&control_parameter);
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*Assign output pointer: */
|
---|
172 | *pparameters=parameters;
|
---|
173 | }
|
---|