Changeset 758
- Timestamp:
- 06/04/09 10:18:31 (16 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/ProcessParamsx/ProcessParamsx.cpp
r713 r758 35 35 double* vy_obs=NULL; 36 36 double* control_parameter=NULL; 37 double* param_g=NULL; 37 38 38 39 double* u_g_obs=NULL; … … 124 125 125 126 u_g_obs=(double*)xcalloc(numberofnodes*2,sizeof(double)); 126 p _g=(double*)xcalloc(numberofnodes*2,sizeof(double));127 param_g=(double*)xcalloc(numberofnodes*2,sizeof(double)); 127 128 128 129 for(i=0;i<numberofnodes;i++){ 129 130 u_g_obs[(int)(2*partition[i]+0)]=vx_obs[i]; 130 131 u_g_obs[(int)(2*partition[i]+1)]=vy_obs[i]; 131 p _g[(int)(2*partition[i]+0)]=control_parameter[i];132 param_g[(int)(2*partition[i]+0)]=control_parameter[i]; 132 133 } 133 134 … … 139 140 140 141 count++; 141 param= new Param(count,"p _g",DOUBLEVEC);142 param->SetDoubleVec(p _g,2*numberofnodes);142 param= new Param(count,"param_g",DOUBLEVEC); 143 param->SetDoubleVec(param_g,2*numberofnodes); 143 144 parameters->AddObject(param); 144 145 … … 272 273 xfree((void**)&vx_obs); 273 274 xfree((void**)&vy_obs); 275 xfree((void**)¶m_g); 274 276 xfree((void**)&pressure); 275 277 xfree((void**)&control_parameter); -
issm/trunk/src/c/objects/OptArgs.h
r465 r758 15 15 mxArray* m; 16 16 mxArray* inputs; 17 mxArray* p _g;17 mxArray* param_g; 18 18 mxArray* u_g_obs; 19 19 mxArray* grad_g; … … 31 31 struct OptArgs{ 32 32 FemModel* femmodel; 33 double* p _g;33 double* param_g; 34 34 double* u_g_obs; 35 35 double* grad_g; -
issm/trunk/src/c/objects/Result.cpp
r643 r758 20 20 Result::Result(){ 21 21 return; 22 } 23 24 Result::Result(const Result& result){ 25 26 id=result.id; 27 time=result.time; 28 step=result.step; 29 size=result.size; 30 31 /*copy constructor: copy dynamically allocated fields: */ 32 if(result.fieldname){ 33 fieldname=(char*)xmalloc((strlen(result.fieldname)+1)*sizeof(char)); 34 strcpy(fieldname,result.fieldname); 35 } 36 if(result.field){ 37 VecDuplicatePatch(&field,result.field); 38 dfield=NULL; 39 } 40 if(result.dfield){ 41 dfield=(double*)xmalloc(result.size*sizeof(double)); 42 memcpy(dfield,result.dfield,result.size*sizeof(double)); 43 field=NULL; 44 } 22 45 } 23 46 … … 144 167 /*First write field name :*/ 145 168 length=(strlen(fieldname)+1)*sizeof(char); 146 147 169 fwrite(&length,sizeof(int),1,fid); 148 170 fwrite(fieldname,length,1,fid); … … 169 191 return new Result(*this); 170 192 } 193 194 -
issm/trunk/src/c/objects/Result.h
r643 r758 24 24 25 25 Result(); 26 Result(const Result& result); 26 27 Result(int result_id,double result_time,int result_step,char* result_fieldname,Vec result_field); 27 28 Result(int result_id,double result_time,int result_step,char* result_fieldname,double* result_field,int result_size); -
issm/trunk/src/c/parallel/OutputControl.cpp
r669 r758 16 16 #define __FUNCT__ "OutputControl" 17 17 18 void OutputControl(Vec u_g,double* p _g,double* J,int nsteps,FemModel* fem,char* outputfilename){18 void OutputControl(Vec u_g,double* param_g,double* J,int nsteps,FemModel* fem,char* outputfilename){ 19 19 20 20 /*intermediary: */ … … 26 26 fem->parameters->FindParam((void*)&numberofnodes,"numberofnodes"); 27 27 28 /*Initialize results*/ 28 29 results=new DataSet(ResultsEnum()); 29 30 … … 32 33 results->AddObject(result); 33 34 34 result=new Result(results->Size()+1,0,1,"param_g",p _g,numberofnodes);35 result=new Result(results->Size()+1,0,1,"param_g",param_g,numberofnodes); 35 36 results->AddObject(result); 36 37 … … 40 41 //process results 41 42 ProcessResults(&results,fem,ControlAnalysisEnum()); 42 43 43 44 //write results to disk: 44 45 OutputResults(results,outputfilename); … … 46 47 /*Free ressources:*/ 47 48 delete results; 48 49 49 } 50 -
issm/trunk/src/c/parallel/ProcessResults.cpp
r695 r758 45 45 /*fem prognostic models: */ 46 46 FemModel* fem_p=NULL; 47 48 /*fem control models: */ 49 FemModel* fem_c=NULL; 47 50 48 51 /*some parameters*/ … … 62 65 double* p_g_serial=NULL; 63 66 double* pressure=NULL; 64 double* parameter=NULL;65 67 double* partition=NULL; 66 68 double yts; 69 70 double* param_g=NULL; 71 double* parameter=NULL; 67 72 68 73 Vec h_g=NULL; … … 108 113 if(analysis_type==ThermalAnalysisEnum()){ 109 114 fem_t=fems+0; 115 } 116 117 if(analysis_type==ControlAnalysisEnum()){ 118 fem_dh=fems+0; //load u_g 119 fem_c=fems+0; //load param_g 110 120 } 111 121 … … 209 219 xfree((void**)&partition); 210 220 } 211 212 221 else if(strcmp(result->GetFieldName(),"p_g")==0){ 213 222 /*easy, p_g is of size numberofnodes, on 1 dof, just repartition: */ … … 244 253 xfree((void**)&partition); 245 254 } 246 247 255 else if(strcmp(result->GetFieldName(),"t_g")==0){ 248 256 /*easy, t_g is of size numberofnodes, on 1 dof, just repartition: */ … … 266 274 xfree((void**)&partition); 267 275 } 268 269 276 else if(strcmp(result->GetFieldName(),"m_g")==0){ 270 277 /*easy, m_g is of size numberofnodes, on 1 dof, just repartition: */ … … 289 296 xfree((void**)&partition); 290 297 } 291 292 298 else if(strcmp(result->GetFieldName(),"h_g")==0){ 293 299 /*easy, h_g is of size numberofnodes, on 1 dof, just repartition: */ … … 311 317 xfree((void**)&partition); 312 318 } 313 314 319 else if(strcmp(result->GetFieldName(),"param_g")==0){ 315 320 /*easy, param_g is of size numberofnodes, on 1 dof, just repartition: */ 316 result->GetField(&p_g); 317 VecToMPISerial(&p_g_serial,p_g); 318 fem_p->parameters->FindParam((void*)&numberofnodes,"numberofnodes"); 319 VecToMPISerial(&partition,fem_p->partition); 321 result->GetField(¶m_g); 322 fem_dh->parameters->FindParam((void*)&numberofnodes,"numberofnodes"); 323 VecToMPISerial(&partition,fem_dh->partition); 320 324 321 325 parameter=(double*)xmalloc(numberofnodes*sizeof(double)); 322 326 323 327 for(i=0;i<numberofnodes;i++){ 324 parameter[i]=p _g_serial[(int)partition[i]];328 parameter[i]=param_g[2*(int)partition[i]]; 325 329 } 326 330 … … 330 334 331 335 /*do some cleanup: */ 332 xfree((void**)&p_g_serial); 333 xfree((void**)&partition); 334 } 335 336 xfree((void**)&partition); 337 } 336 338 else{ 337 339 /*Just copy the result into the new results dataset: */ 338 newresults->AddObject(result );340 newresults->AddObject(result->copy()); 339 341 } 340 342 } -
issm/trunk/src/c/parallel/control.cpp
r667 r758 43 43 double* maxiter=NULL; 44 44 double tolx; 45 double* p _g=NULL;45 double* param_g=NULL; 46 46 Vec grad_g=NULL; 47 47 Vec new_grad_g=NULL; … … 90 90 femmodel.parameters->FindParam((void*)&mincontrolconstraint,"mincontrolconstraint"); 91 91 femmodel.parameters->FindParam((void*)&maxcontrolconstraint,"maxcontrolconstraint"); 92 femmodel.parameters->FindParam((void*)&p _g,"p_g");92 femmodel.parameters->FindParam((void*)¶m_g,"param_g"); 93 93 femmodel.parameters->FindParam((void*)&u_g_obs,"u_g_obs"); 94 94 femmodel.parameters->FindParam((void*)&analysis_type,"analysis_type"); … … 107 107 108 108 /*erase useless parameters: */ 109 param=(Param*)femmodel.parameters->FindParamObject("p _g");109 param=(Param*)femmodel.parameters->FindParamObject("param_g"); 110 110 femmodel.parameters->DeleteObject((Object*)param); 111 111 … … 121 121 122 122 _printf_("\n%s%i%s%i\n"," control method step ",n+1,"/",nsteps); 123 inputs->Add(control_type,p _g,2,numberofnodes);123 inputs->Add(control_type,param_g,2,numberofnodes); 124 124 inputs->Add("fit",fit[n]); 125 125 … … 139 139 140 140 _printf_("%s\n"," optimizing along gradient direction..."); 141 optargs.femmodel=&femmodel; optargs.p _g=p_g; optargs.u_g_obs=u_g_obs; optargs.grad_g=grad_g_double; optargs.inputs=inputs;optargs.n=n;141 optargs.femmodel=&femmodel; optargs.param_g=param_g; optargs.u_g_obs=u_g_obs; optargs.grad_g=grad_g_double; optargs.inputs=inputs;optargs.n=n; 142 142 optpars.xmin=0; optpars.xmax=1; optpars.tolerance=tolx; optpars.maxiter=(int)maxiter[n]; 143 143 BrentSearch(&search_scalar,J+n,&optpars,&objectivefunctionC,&optargs); … … 145 145 146 146 _printf_("%s\n"," updating parameter using optimized search scalar..."); 147 for(i=0;i<gsize;i++)p_g[i]=p_g[i]+search_scalar*optscal[n]*grad_g_double[i]; 147 PetscSynchronizedPrintf(MPI_COMM_WORLD,"gsize=%i\n",gsize); 148 PetscSynchronizedFlush(MPI_COMM_WORLD); 149 150 for(i=0;i<gsize;i++)param_g[i]=param_g[i]+search_scalar*optscal[n]*grad_g_double[i]; 148 151 _printf_("%s\n"," done."); 149 152 150 153 _printf_("%s\n"," constraining the new distribution..."); 151 ControlConstrainx( p _g,gsize,mincontrolconstraint,maxcontrolconstraint,control_type);154 ControlConstrainx( param_g,gsize,mincontrolconstraint,maxcontrolconstraint,control_type); 152 155 _printf_("%s\n"," done."); 153 156 … … 155 158 if (((n+1)%5)==0){ 156 159 _printf_("%s\n"," saving temporary results..."); 157 inputs->Add(control_type,p _g,2,numberofnodes);160 inputs->Add(control_type,param_g,2,numberofnodes); 158 161 inputs->Add("fit",fit[n]); 159 162 diagnostic_core_nonlinear(&u_g,NULL,NULL,&femmodel,inputs,analysis_type,sub_analysis_type); 160 OutputControl(u_g,p _g,J,nsteps,&femmodel,outputfilename);163 OutputControl(u_g,param_g,J,nsteps,&femmodel,outputfilename); 161 164 _printf_("%s\n"," done."); 162 165 } … … 170 173 /*Write results to disk: */ 171 174 _printf_("%s\n"," preparing final velocity solution..."); 172 inputs->Add(control_type,p _g,2,numberofnodes);175 inputs->Add(control_type,param_g,2,numberofnodes); 173 176 inputs->Add("fit",fit[n]); 174 177 … … 179 182 180 183 _printf_("%s\n"," saving final results..."); 181 OutputControl(u_g,p _g,J,nsteps,&femmodel,outputfilename);184 OutputControl(u_g,param_g,J,nsteps,&femmodel,outputfilename); 182 185 _printf_("%s\n"," done."); 183 186 -
issm/trunk/src/c/parallel/objectivefunctionC.cpp
r465 r758 24 24 /*parameters: */ 25 25 FemModel* femmodel=NULL; 26 double* p _g=NULL;26 double* param_g=NULL; 27 27 double* u_g_obs=NULL; 28 28 double* grad_g=NULL; … … 37 37 double maxcontrolconstraint; 38 38 char* control_type=NULL; 39 double* p _g_copy=NULL;39 double* param_g_copy=NULL; 40 40 int analysis_type; 41 41 int sub_analysis_type; … … 47 47 /*Recover parameters: */ 48 48 femmodel=optargs->femmodel; 49 p _g=optargs->p_g;49 param_g=optargs->param_g; 50 50 u_g_obs=optargs->u_g_obs; 51 51 grad_g=optargs->grad_g; … … 63 63 femmodel->parameters->FindParam((void*)&numberofnodes,"numberofnodes"); 64 64 65 /*First copy p _g so we don't modify it: */66 p _g_copy=(double*)xmalloc(gsize*sizeof(double));67 memcpy(p _g_copy,p_g,gsize*sizeof(double));65 /*First copy param_g so we don't modify it: */ 66 param_g_copy=(double*)xmalloc(gsize*sizeof(double)); 67 memcpy(param_g_copy,param_g,gsize*sizeof(double)); 68 68 69 /*First, update p _g using search_scalar: */70 for(i=0;i<gsize;i++)p _g_copy[i]=p_g_copy[i]+search_scalar*optscal[n]*grad_g[i];69 /*First, update param_g using search_scalar: */ 70 for(i=0;i<gsize;i++)param_g_copy[i]=param_g_copy[i]+search_scalar*optscal[n]*grad_g[i]; 71 71 72 72 /*Constrain:*/ 73 ControlConstrainx( p _g_copy,gsize,mincontrolconstraint,maxcontrolconstraint,control_type);73 ControlConstrainx( param_g_copy,gsize,mincontrolconstraint,maxcontrolconstraint,control_type); 74 74 75 75 /*Add new parameter to inputs: */ 76 inputs->Add(control_type,p _g_copy,2,numberofnodes);76 inputs->Add(control_type,param_g_copy,2,numberofnodes); 77 77 78 78 //Run diagnostic with updated parameters. … … 89 89 xfree((void**)&optscal); 90 90 xfree((void**)&control_type); 91 xfree((void**)&p _g_copy);91 xfree((void**)¶m_g_copy); 92 92 xfree((void**)&u_g_double); 93 93 -
issm/trunk/src/c/shared/Numerics/OptFunc.cpp
r465 r758 32 32 inputs[1]=optargs->m; 33 33 inputs[2]=optargs->inputs; 34 inputs[3]=optargs->p _g;34 inputs[3]=optargs->param_g; 35 35 inputs[4]=optargs->u_g_obs; 36 36 inputs[5]=optargs->grad_g;
Note:
See TracChangeset
for help on using the changeset viewer.