source:
issm/oecreview/Archive/21724-22754/ISSM-22409-22410.diff@
22755
Last change on this file since 22755 was 22755, checked in by , 7 years ago | |
---|---|
File size: 5.3 KB |
-
../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp
181 181 /*Free ressources:*/ 182 182 for(j=0;j<numnodalvalues;j++){ 183 183 char* string=NULL; 184 IssmDouble* matrix = NULL;185 184 string = nodalvalue_name_s[j]; xDelete<char>(string); 186 185 } 187 186 xDelete<char*>(nodalvalue_name_s); … … 321 320 int numout; 322 321 char **ncf_name_s = NULL; 323 322 char **ncf_definitionstring_s = NULL; 323 char **cost_functions = NULL; 324 324 int cost_function ,domaintype; 325 325 int num_cost_functions; 326 char **cost_functions = NULL;327 int num_costfunc;328 char **cm_responses = NULL;329 326 330 327 /*Process cost functions and convert from string to enums*/ 331 328 iomodel->FindConstant(&num_cost_functions,"md.numberedcostfunction.num_cost_functions"); … … 336 333 cost_function_enums[i]=StringToEnumx(cost_functions[i]); 337 334 } 338 335 339 iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");336 //iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients"); 340 337 341 338 iomodel->FetchMultipleData(&ncf_name_s,&numout,"md.numberedcostfunction.name"); 342 339 iomodel->FetchMultipleData(&ncf_definitionstring_s,&numout,"md.numberedcostfunction.definitionstring"); … … 361 358 362 359 for(j=0;j<numout;j++){ 363 360 364 output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost func,cost_function_enums));361 output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums)); 365 362 366 363 } 367 364 368 parameters->AddObject(iomodel->CopyConstantObject("md.inversion.num_cost_functions",InversionNumCostFunctionsEnum));369 365 370 iomodel->FindConstant(&cm_responses,&num_costfunc,"md.inversion.cost_functions");371 //if(num_costfunc<1) error ("no cost functions found");372 int* costfunc_enums=xNew<int>(num_costfunc);373 for(int i=0;i<num_costfunc;i++){374 costfunc_enums[i]=StringToEnumx(cm_responses[i]);375 xDelete<char>(cm_responses[i]);376 }377 xDelete<char*>(cm_responses);378 379 parameters->AddObject(new IntVecParam(InversionCostFunctionsEnum,costfunc_enums,num_costfunc));380 xDelete<int>(costfunc_enums);381 382 366 /*Free data: */ 383 iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients"); 367 //iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients"); 368 iomodel->DeleteData(2,"md.numberedcostfunction.name","md.numberedcostfunction.definitionstring"); 384 369 xDelete<int>(cost_function_enums); 385 370 for(int i=0;i<num_cost_functions;i++) xDelete<char>(cost_functions[i]); 386 371 xDelete<char*>(cost_functions); 372 373 /*Free ressources:*/ 374 for(j=0;j<numout;j++){ 375 xDelete<char>(ncf_name_s[j]); 376 xDelete<char>(ncf_definitionstring_s[j]); 377 } 378 xDelete<char*>(ncf_name_s); 379 xDelete<char*>(ncf_definitionstring_s); 387 380 } 388 381 /*}}}*/ 389 382 else _error_("output definition enum " << EnumToStringx(output_definition_enums[i]) << " not supported yet!"); -
../trunk-jpl/src/c/classes/Numberedcostfunction.h
37 37 } 38 38 /*}}}*/ 39 39 Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/ 40 41 40 _assert_(number_cost_functions_in>0); 42 41 _assert_(cost_functions_list_in); 43 42 … … 107 106 /*}}}*/ 108 107 IssmDouble Response(FemModel* femmodel){/*{{{*/ 109 108 109 _assert_(number_cost_functions>0 && number_cost_functions<1e3); 110 110 /*output:*/ 111 111 IssmDouble value; 112 112 113 113 /*Intermediary*/ 114 int num_responses;115 int *responses = NULL;116 114 Results *cost_functions = NULL; 117 115 118 119 /*Recover parameters*/120 femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);121 femmodel->parameters->FindParam(&responses,NULL,InversionCostFunctionsEnum);122 123 116 /*Get the value of all cost functions*/ 124 femmodel->RequestedOutputsx(&cost_functions, responses,num_responses);117 femmodel->RequestedOutputsx(&cost_functions,cost_functions_list,number_cost_functions); 125 118 126 119 /*Get and add all contributions one by one*/ 127 IssmDouble J=0 ;128 IssmDouble* Jlist = xNew<IssmDouble>(num _responses);129 for(int i=0;i<num _responses;i++){120 IssmDouble J=0.; 121 IssmDouble* Jlist = xNew<IssmDouble>(number_cost_functions); 122 for(int i=0;i<number_cost_functions;i++){ 130 123 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i); 131 124 Jlist[i] = reCast<IssmDouble>(result->GetValue()); 132 125 J += Jlist[i]; 133 126 } 134 _assert_(cost_functions->Size()==num _responses);127 _assert_(cost_functions->Size()==number_cost_functions); 135 128 136 129 137 130 value = J; 138 131 _printf_("J: "<<J<<"\n"); 139 140 // _error_("STOP!");141 132 142 133 /*done:*/ 143 return value; 134 delete cost_functions; 135 xDelete<IssmDouble>(Jlist); 136 return value; 144 137 } 145 138 /*}}}*/ 146 139 };
Note:
See TracBrowser
for help on using the repository browser.