Changeset 23268


Ignore:
Timestamp:
09/12/18 13:34:23 (7 years ago)
Author:
Mathieu Morlighem
Message:

CHG: minor cosmetics

Location:
issm/trunk-jpl/src/c/cores
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp

    r23267 r23268  
    1717
    1818#if defined (_HAVE_M1QN3_) && defined(_HAVE_AD_)
    19 /*m1qn3 prototypes*/
     19/*m1qn3 prototypes {{{*/
    2020extern "C" void *ctonbe_; // DIS mode : Conversion
    2121extern "C" void *ctcabe_; // DIS mode : Conversion
     
    3636        int*         i;
    3737} m1qn3_struct;
     38/*}}}*/
    3839
    3940/*m1qm3 functions*/
     
    9192                tape_codi.reset();
    9293                //alloc_profiler.Tag(FinishInit, true);
     94                #else
     95                tape_codi.reset();
    9396                #endif
    9497
     
    181184
    182185        FemModel* femmodel = input_struct->femmodel;
    183         int num_responses,num_controls,numberofvertices,solution_type;
     186        int num_responses,num_controls,solution_type;
    184187        femmodel->parameters->FindParam(&solution_type,SolutionTypeEnum);
    185         int* N = NULL;
    186         int N_add = 0;
    187         int* control_enum = NULL;
    188188
    189189        /*In transient, we need to make sure we do not modify femmodel at each iteration, make a copy*/
     
    197197
    198198        /*Recover some parameters*/
    199         IssmDouble* scaling_factors = NULL;
     199        IssmDouble *scaling_factors = NULL;
     200        int        *N               = NULL;
     201        int        *control_enum    = NULL;
    200202        femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
    201203        femmodel->parameters->FindParam(&num_controls,InversionNumControlParametersEnum);
     
    203205        femmodel->parameters->FindParam(&N,NULL,ControlInputSizeNEnum);
    204206        femmodel->parameters->FindParam(&control_enum,NULL,InversionControlParametersEnum);
    205         numberofvertices=femmodel->vertices->NumberOfVertices();
     207        int numberofvertices=femmodel->vertices->NumberOfVertices();
    206208
    207209        /*Constrain input vector and update controls*/
     
    211213        GetPassiveVectorFromControlInputsx(&XU,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"upperbound");
    212214
    213         N_add = 0;
     215        int N_add = 0;
    214216        for (int c=0;c<num_controls;c++){
    215217                for(int i=0;i<numberofvertices*N[c];i++){
     
    304306        //if(my_rank==0) _printf_("\nTIME: "<<now<<"\n");
    305307
    306         /*diverse: */
    307         int  dummy;
    308         int  num_independents=0;
    309 
    310308        /*intermediary: */
     309        int          num_independents=intn;
    311310        IssmPDouble *aWeightVector=NULL;
    312311        IssmPDouble *weightVectorTimesJac=NULL;
    313 
    314         /*output: */
    315         IssmPDouble *totalgradient=NULL;
    316 
    317         /*retrieve parameters: */
    318         num_independents = intn;
     312        IssmPDouble *totalgradient=xNewZeroInit<IssmPDouble>(num_independents);
    319313
    320314        /*if no dependents, no point in running a driver: */
     
    341335        /* Ok, now we are going to call the fos_reverse in a loop on the index, from 0 to num_dependents, so
    342336         * as to generate num_dependents gradients: */
    343         totalgradient=xNewZeroInit<IssmPDouble>(num_independents_old);
    344 
    345337        for(int aDepIndex=0;aDepIndex<num_dependents_old;aDepIndex++){
    346338
     
    379371        /*Get gradient for CoDiPack{{{*/
    380372        if(VerboseAutodiff())_printf0_("   CoDiPack fos_reverse\n");
    381         int     aDepIndex=0; /*FIXME: do we really need this?*/
    382 
    383         /*retrieve direction index: */
    384         femmodel->parameters->FindParam(&aDepIndex,AutodiffFosReverseIndexEnum);
    385         if (my_rank==0) {
    386                 if (aDepIndex<0 || aDepIndex>=num_dependents || codi_global.output_indices.size() <= aDepIndex){
    387                         _error_("index value for AutodiffFosReverseIndexEnum should be in [0,num_dependents-1]");
    388                 }
    389                 tape_codi.setGradient(codi_global.output_indices[aDepIndex], 1.0);
    390         }
    391         tape_codi.evaluate();
    392 
    393         weightVectorTimesJac=xNew<double>(num_independents);
    394         /*call driver: */
    395         auto in_size = codi_global.input_indices.size();
    396         for(size_t i = 0; i < in_size; ++i) {
    397                 weightVectorTimesJac[i] = tape_codi.getGradient(codi_global.input_indices[i]);
    398         }
    399 
    400         /*Add to totalgradient: */
    401         totalgradient=xNewZeroInit<IssmPDouble>(num_independents_old);
    402         if(my_rank==0) for(int i=0;i<num_independents;i++) {
    403                 totalgradient[i]+=weightVectorTimesJac[i];
    404         }
    405 
    406         /*free resources :*/
    407         xDelete(weightVectorTimesJac);
     373
     374        /* call the fos_reverse in a loop on the index, from 0 to num_dependents, so
     375         * as to generate num_dependents gradients: */
     376        for(int aDepIndex=0;aDepIndex<num_dependents_old;aDepIndex++){
     377
     378                /*initialize direction index in the weights vector: */
     379                aWeightVector=xNewZeroInit<IssmPDouble>(num_dependents);
     380                if(my_rank==0)  tape_codi.setGradient(codi_global.output_indices[aDepIndex],1.0);
     381                tape_codi.evaluate();
     382
     383                /*Get gradient for this dependent */
     384                weightVectorTimesJac=xNew<IssmPDouble>(num_independents);
     385                auto in_size = codi_global.input_indices.size();
     386                for(size_t i = 0; i < in_size; ++i) {
     387                        weightVectorTimesJac[i] = tape_codi.getGradient(codi_global.input_indices[i]);
     388                }
     389                if(my_rank==0) for(int i=0;i<num_independents;i++) {
     390                        totalgradient[i]+=weightVectorTimesJac[i];
     391                }
     392                /*free resources :*/
     393                xDelete(weightVectorTimesJac);
     394                xDelete(aWeightVector);
     395        }
    408396        /*}}}*/
    409397        #else
     
    426414        Jlist[(*Jlisti)*JlistN+num_responses] = reCast<IssmPDouble>(J);
    427415
    428 /*
    429         IssmDouble* test = xNew<IssmDouble>(intn);
    430         femmodel->parameters->FindParam(&test,NULL,InversionXBestEnum);
    431         for(int i=0;i<10;i++)_printf_("X "<<test[i]<<"\n");
    432         xDelete<IssmDouble>(intn);
    433 */
    434416        if(*indic==0){
    435417                /*dry run, no gradient required*/
  • issm/trunk-jpl/src/c/cores/controlm1qn3_core.cpp

    r23252 r23268  
    1212
    1313#if defined (_HAVE_M1QN3_) && !defined(_HAVE_AD_)
    14 /*m1qn3 prototypes*/
     14/*m1qn3 prototypes {{{*/
    1515extern "C" void *ctonbe_; // DIS mode : Conversion
    1616extern "C" void *ctcabe_; // DIS mode : Conversion
     
    3434        int*        i;
    3535} m1qn3_struct;
    36 
    37 void controlm1qn3_core(FemModel* femmodel){
     36/*}}}*/
     37
     38void controlm1qn3_core(FemModel* femmodel){/*{{{*/
    3839
    3940        /*Intermediaries*/
     
    173174        xDelete<double>(mystruct.Jlist);
    174175        xDelete<int>(mystruct.i);
    175 }
    176 
    177 /*Cost function definition*/
    178 void simul(long* indic,long* n,double* X,double* pf,double* G,long izs[1],float rzs[1],void* dzs){
     176}/*}}}*/
     177void simul(long* indic,long* n,double* X,double* pf,double* G,long izs[1],float rzs[1],void* dzs){/*{{{*/
    179178
    180179        /*Recover Arguments*/
     
    278277        xDelete<IssmDouble>(XL);
    279278        xDelete<IssmDouble>(scaling_factors);
    280 }
     279}/*}}}*/
    281280
    282281#else
    283 void controlm1qn3_core(FemModel* femmodel){
    284         _error_("M1QN3 not installed");
    285 }
     282void controlm1qn3_core(FemModel* femmodel){_error_("M1QN3 not installed");}
    286283#endif //_HAVE_M1QN3_
Note: See TracChangeset for help on using the changeset viewer.