source: issm/oecreview/Archive/21724-22754/ISSM-22409-22410.diff@ 22755

Last change on this file since 22755 was 22755, checked in by Mathieu Morlighem, 7 years ago

CHG: added 21724-22754

File size: 5.3 KB
  • ../trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp

     
    181181                                /*Free ressources:*/
    182182                                for(j=0;j<numnodalvalues;j++){
    183183                                        char* string=NULL;
    184                                         IssmDouble* matrix = NULL;
    185184                                        string = nodalvalue_name_s[j];    xDelete<char>(string);
    186185                                }
    187186                                xDelete<char*>(nodalvalue_name_s);
     
    321320                                int    numout;
    322321                                char **ncf_name_s             = NULL;
    323322                                char **ncf_definitionstring_s = NULL;
     323                                char **cost_functions         = NULL;
    324324                                int    cost_function ,domaintype;
    325325                                int    num_cost_functions;
    326                                 char **cost_functions         = NULL;
    327                                 int    num_costfunc;
    328                                 char **cm_responses           = NULL;
    329326
    330327                                /*Process cost functions and convert from string to enums*/
    331328                                iomodel->FindConstant(&num_cost_functions,"md.numberedcostfunction.num_cost_functions");
     
    336333                                        cost_function_enums[i]=StringToEnumx(cost_functions[i]);
    337334                                }
    338335
    339                                 iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
     336                                //iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
    340337
    341338                                iomodel->FetchMultipleData(&ncf_name_s,&numout,"md.numberedcostfunction.name");
    342339                                iomodel->FetchMultipleData(&ncf_definitionstring_s,&numout,"md.numberedcostfunction.definitionstring");
     
    361358
    362359                                for(j=0;j<numout;j++){
    363360
    364                                         output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_costfunc,cost_function_enums));
     361                                        output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums));
    365362
    366363                                }
    367364
    368                                 parameters->AddObject(iomodel->CopyConstantObject("md.inversion.num_cost_functions",InversionNumCostFunctionsEnum));
    369365                               
    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 
    382366                                /*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");
    384369                                xDelete<int>(cost_function_enums);
    385370                                for(int i=0;i<num_cost_functions;i++) xDelete<char>(cost_functions[i]);
    386371                                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);
    387380                        }
    388381                        /*}}}*/
    389382                else _error_("output definition enum " << EnumToStringx(output_definition_enums[i]) << " not supported yet!");
  • ../trunk-jpl/src/c/classes/Numberedcostfunction.h

     
    3737                }
    3838                /*}}}*/
    3939                Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/
    40 
    4140                        _assert_(number_cost_functions_in>0);
    4241                        _assert_(cost_functions_list_in);
    4342
     
    107106                /*}}}*/
    108107                 IssmDouble Response(FemModel* femmodel){/*{{{*/
    109108                       
     109                         _assert_(number_cost_functions>0 && number_cost_functions<1e3);
    110110                         /*output:*/
    111111                         IssmDouble value;
    112112
    113113                         /*Intermediary*/
    114                          int      num_responses;
    115                          int     *responses      = NULL;
    116114                         Results *cost_functions = NULL;
    117115
    118 
    119                          /*Recover parameters*/
    120                          femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
    121                          femmodel->parameters->FindParam(&responses,NULL,InversionCostFunctionsEnum);
    122 
    123116                         /*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);
    125118
    126119                         /*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++){
    130123                                 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i);
    131124                                 Jlist[i] = reCast<IssmDouble>(result->GetValue());
    132125                                 J       += Jlist[i];
    133126                         }
    134                          _assert_(cost_functions->Size()==num_responses);
     127                         _assert_(cost_functions->Size()==number_cost_functions);
    135128                         
    136129                         
    137130                        value = J;             
    138131                        _printf_("J: "<<J<<"\n");
    139                          
    140                         // _error_("STOP!");
    141132
    142133                         /*done:*/
    143                          return value;
     134                        delete  cost_functions;
     135                        xDelete<IssmDouble>(Jlist);
     136                        return value;
    144137                 }
    145138                 /*}}}*/
    146139};
Note: See TracBrowser for help on using the repository browser.