source: issm/trunk/src/c/ModelProcessorx/Control/CreateParametersControl.cpp@ 1837

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

Brachning back from issm.controlstatic, by hand

File size: 5.1 KB
Line 
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
15void 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_type: */
45 count++;
46 param= new Param(count,"control_type",STRING);
47 param->SetString(iomodel->control_type);
48 parameters->AddObject(param);
49
50 /*extrude_param: */
51 count++;
52 param= new Param(count,"extrude_param",DOUBLE);
53 if (strcmp(iomodel->control_type,"drag")==0) param->SetDouble(0);
54 else if (strcmp(iomodel->control_type,"B")==0) param->SetDouble(1);
55 else throw ErrorException(__FUNCT__,exprintf("control_type %s not supported yet!",iomodel->control_type));
56 parameters->AddObject(param);
57
58 /*nsteps: */
59 count++;
60 param= new Param(count,"nsteps",INTEGER);
61 param->SetInteger(iomodel->nsteps);
62 parameters->AddObject(param);
63
64 /*tolx: */
65 count++;
66 param= new Param(count,"tolx",DOUBLE);
67 param->SetDouble(iomodel->tolx);
68 parameters->AddObject(param);
69
70 /*mincontrolconstraint: */
71 count++;
72 param= new Param(count,"mincontrolconstraint",DOUBLE);
73 param->SetDouble(iomodel->mincontrolconstraint);
74 parameters->AddObject(param);
75
76 /*maxcontrolconstraint: */
77 count++;
78 param= new Param(count,"maxcontrolconstraint",DOUBLE);
79 param->SetDouble(iomodel->maxcontrolconstraint);
80 parameters->AddObject(param);
81
82 /*epsvel: */
83 count++;
84 param= new Param(count,"epsvel",DOUBLE);
85 param->SetDouble(iomodel->epsvel);
86 parameters->AddObject(param);
87
88 /*meanvel: */
89 count++;
90 param= new Param(count,"meanvel",DOUBLE);
91 param->SetDouble(iomodel->meanvel);
92 parameters->AddObject(param);
93
94 /*Now, recover fit, optscal and maxiter as vectors: */
95 IoModelFetchData((void**)&iomodel->fit,NULL,NULL,iomodel_handle,"fit","Matrix","Mat");
96 IoModelFetchData((void**)&iomodel->optscal,NULL,NULL,iomodel_handle,"optscal","Matrix","Mat");
97 IoModelFetchData((void**)&iomodel->maxiter,NULL,NULL,iomodel_handle,"maxiter","Matrix","Mat");
98
99 count++;
100 param= new Param(count,"fit",DOUBLEVEC);
101 param->SetDoubleVec(iomodel->fit,iomodel->nsteps);
102 parameters->AddObject(param);
103
104 count++;
105 param= new Param(count,"optscal",DOUBLEVEC);
106 param->SetDoubleVec(iomodel->optscal,iomodel->nsteps);
107 parameters->AddObject(param);
108
109 count++;
110 param= new Param(count,"maxiter",DOUBLEVEC);
111 param->SetDoubleVec(iomodel->maxiter,iomodel->nsteps);
112 parameters->AddObject(param);
113
114 xfree((void**)&iomodel->fit);
115 xfree((void**)&iomodel->optscal);
116 xfree((void**)&iomodel->maxiter);
117
118 /*Get vx, vx_obs, vy, vy_obs, and the parameter value: */
119 IoModelFetchData((void**)&vx,NULL,NULL,iomodel_handle,"vx","Matrix","Mat");
120 IoModelFetchData((void**)&vy,NULL,NULL,iomodel_handle,"vy","Matrix","Mat");
121 IoModelFetchData((void**)&vz,NULL,NULL,iomodel_handle,"vz","Matrix","Mat");
122 IoModelFetchData((void**)&vx_obs,NULL,NULL,iomodel_handle,"vx_obs","Matrix","Mat");
123 IoModelFetchData((void**)&vy_obs,NULL,NULL,iomodel_handle,"vy_obs","Matrix","Mat");
124 IoModelFetchData((void**)&control_parameter,NULL,NULL,iomodel_handle,iomodel->control_type,"Matrix","Mat");
125
126 u_g=(double*)xcalloc(iomodel->numberofnodes*3,sizeof(double));
127 if(vx)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+0]=vx[i]/iomodel->yts;
128 if(vy)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+1]=vy[i]/iomodel->yts;
129 if(vz)for(i=0;i<iomodel->numberofnodes;i++)u_g[3*i+2]=vz[i]/iomodel->yts;
130
131 count++;
132 param= new Param(count,"u_g",DOUBLEVEC);
133 param->SetDoubleVec(u_g,3*iomodel->numberofnodes,3);
134 parameters->AddObject(param);
135
136 u_g_obs=(double*)xcalloc(iomodel->numberofnodes*2,sizeof(double));
137 if(vx_obs)for(i=0;i<iomodel->numberofnodes;i++)u_g_obs[2*i+0]=vx_obs[i]/iomodel->yts;
138 if(vy_obs)for(i=0;i<iomodel->numberofnodes;i++)u_g_obs[2*i+1]=vy_obs[i]/iomodel->yts;
139
140 count++;
141 param= new Param(count,"u_g_obs",DOUBLEVEC);
142 param->SetDoubleVec(u_g_obs,2*iomodel->numberofnodes,2);
143 parameters->AddObject(param);
144
145 param_g=(double*)xcalloc(iomodel->numberofnodes,sizeof(double));
146 for(i=0;i<iomodel->numberofnodes;i++)param_g[i]=control_parameter[i];
147
148 count++;
149 param= new Param(count,"param_g",DOUBLEVEC);
150 param->SetDoubleVec(param_g,iomodel->numberofnodes,1);
151 parameters->AddObject(param);
152
153 xfree((void**)&vx);
154 xfree((void**)&vy);
155 xfree((void**)&vz);
156 xfree((void**)&u_g);
157 xfree((void**)&vx_obs);
158 xfree((void**)&vy_obs);
159 xfree((void**)&u_g_obs);
160 xfree((void**)&param_g);
161 xfree((void**)&control_parameter);
162
163 /*Assign output pointer: */
164 *pparameters=parameters;
165}
Note: See TracBrowser for help on using the repository browser.