Changeset 27728


Ignore:
Timestamp:
05/04/23 17:45:09 (23 months ago)
Author:
Mathieu Morlighem
Message:

NEW: moving J to cost function itself instead of being weirdly handled

Location:
issm/trunk-jpl/src/c
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.cpp

    r27685 r27728  
    2929        this->definitionenum = -1;
    3030        this->name = NULL;
     31        this->J = 0.;
    3132}
    3233/*}}}*/
     
    3738        this->name              = xNew<char>(strlen(in_name)+1);
    3839        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     40
     41        this->J = 0.;
     42}
     43/*}}}*/
     44Cfdragcoeffabsgrad::Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, IssmDouble in_J){/*{{{*/
     45
     46        this->definitionenum=in_definitionenum;
     47
     48        this->name              = xNew<char>(strlen(in_name)+1);
     49        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     50
     51        this->J = in_J;
    3952}
    4053/*}}}*/
     
    4558/*Object virtual function resolutoin: */
    4659Object* Cfdragcoeffabsgrad::copy() {/*{{{*/
    47         Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum);
     60        Cfdragcoeffabsgrad* mf = new Cfdragcoeffabsgrad(this->name,this->definitionenum, this->J);
    4861        return (Object*) mf;
    4962}
     
    6982        marshallhandle->call(this->definitionenum);
    7083        marshallhandle->call(this->name);
     84        marshallhandle->call(this->J);
    7185}
    7286/*}}}*/
     
    90104
    91105        /*recover parameters: */
    92         IssmDouble J=0.;
     106        IssmDouble J_part=0.;
    93107        IssmDouble J_sum=0.;
    94108
    95109        for(Object* & object : femmodel->elements->objects){
    96110                Element* element=xDynamicCast<Element*>(object);
    97                 J+=this->Cfdragcoeffabsgrad_Calculation(element);
     111                J_part+=this->Cfdragcoeffabsgrad_Calculation(element);
    98112        }
    99113
    100         ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     114        ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    101115        ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    102         J=J_sum;
     116        this->J=J_sum;
    103117
    104118        return J;
  • issm/trunk-jpl/src/c/classes/Cfdragcoeffabsgrad.h

    r27681 r27728  
    1616        public:
    1717
    18                 int   definitionenum;
    19                 char *name;
     18                int         definitionenum;
     19                char       *name;
     20                IssmDouble  J;
    2021
    2122                /*Cfdragcoeffabsgrad constructors, destructors :*/
    2223                Cfdragcoeffabsgrad();
    2324                Cfdragcoeffabsgrad(char* in_name, int in_definitionenum);
     25                Cfdragcoeffabsgrad(char* in_name, int in_definitionenum, IssmDouble in_J);
    2426                ~Cfdragcoeffabsgrad();
    2527
  • issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.cpp

    r27681 r27728  
    3232        this->datatime=0.;
    3333        this->timepassedflag = false;
    34 }
    35 /*}}}*/
    36 Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
     34        this->J = 0.;
     35}
     36/*}}}*/
     37Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime){/*{{{*/
     38
     39        this->definitionenum=in_definitionenum;
     40
     41        this->name              = xNew<char>(strlen(in_name)+1);
     42        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     43
     44        this->model_enum=in_model_enum;
     45        this->datatime=in_datatime;
     46        this->timepassedflag=false;
     47        this->J = 0.;
     48}
     49/*}}}*/
     50Cflevelsetmisfit::Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
    3751
    3852        this->definitionenum=in_definitionenum;
     
    4458        this->datatime=in_datatime;
    4559        this->timepassedflag=in_timepassedflag;
     60        this->J = in_J;
    4661}
    4762/*}}}*/
     
    5267/*Object virtual function resolutoin: */
    5368Object* Cflevelsetmisfit::copy() {/*{{{*/
    54         Cflevelsetmisfit* mf = new Cflevelsetmisfit(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag);
     69        Cflevelsetmisfit* mf = new Cflevelsetmisfit(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag, this->J);
    5570        return (Object*) mf;
    5671}
     
    8297        marshallhandle->call(this->datatime);
    8398        marshallhandle->call(this->timepassedflag);
     99        marshallhandle->call(this->J);
    84100}
    85101/*}}}*/
     
    106122         /*recover time parameters: */
    107123         femmodel->parameters->FindParam(&time,TimeEnum);
    108 
    109          IssmDouble J=0.;
    110          IssmDouble J_sum=0.;
    111 
    112124         if(datatime<=time && !timepassedflag){
     125
     126                 IssmDouble J_part = 0.;
     127                 IssmDouble J_sum  = 0.;
     128
    113129                 for(Object* & object : femmodel->elements->objects){
    114130                         Element* element=xDynamicCast<Element*>(object);
    115                          J+=this->Cflevelsetmisfit_Calculation(element,model_enum);
     131                         J_part+=this->Cflevelsetmisfit_Calculation(element,model_enum);
    116132                 }
    117133
    118                  ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     134                 ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    119135                 ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    120                  J=J_sum;
    121136
    122137                 this->timepassedflag = true;
    123                  return J;
     138                 this->J = J_sum;
    124139         }
    125          else return J;
    126  }
    127         /*}}}*/
     140
     141         return this->J;
     142 }/*}}}*/
    128143IssmDouble Cflevelsetmisfit::Cflevelsetmisfit_Calculation(Element* element, int model_enum){/*{{{*/
    129144
  • issm/trunk-jpl/src/c/classes/Cflevelsetmisfit.h

    r27681 r27728  
    2121                IssmDouble  datatime;
    2222                bool        timepassedflag;
     23                IssmDouble  J;
    2324
    2425                /*Cflevelsetmisfit constructors, destructors :*/
    2526                Cflevelsetmisfit();
    26                 Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag);
     27                Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime);
     28                Cflevelsetmisfit(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
    2729                ~Cflevelsetmisfit();
    2830
  • issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.cpp

    r27686 r27728  
    3030        this->name = NULL;
    3131        this->weights_enum = UNDEF;
    32         this->misfit=0;
    3332        this->timepassedflag = false;
     33        this->J = 0.;
    3434}
    3535/*}}}*/
    36 Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, bool in_timepassedflag){/*{{{*/
     36Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum){/*{{{*/
     37
     38        this->definitionenum=in_definitionenum;
     39
     40        this->name              = xNew<char>(strlen(in_name)+1);
     41        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     42
     43        this->weights_enum=in_weights_enum;
     44        this->timepassedflag=false;
     45
     46        this->J=0;
     47}
     48/*}}}*/
     49Cfrheologybbarabsgrad::Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
    3750
    3851        this->definitionenum=in_definitionenum;
     
    4457        this->timepassedflag=in_timepassedflag;
    4558
    46         this->misfit=0;
     59        this->J=in_J;
    4760}
    4861/*}}}*/
    4962Cfrheologybbarabsgrad::~Cfrheologybbarabsgrad(){/*{{{*/
    5063        if(this->name)xDelete(this->name);
    51         this->misfit=0;
    5264}
    5365/*}}}*/
    5466/*Object virtual function resolutoin: */
    5567Object* Cfrheologybbarabsgrad::copy() {/*{{{*/
    56         Cfrheologybbarabsgrad* mf = new Cfrheologybbarabsgrad(this->name,this->definitionenum, this->weights_enum,this->timepassedflag);
    57         mf->misfit=this->misfit;
     68        Cfrheologybbarabsgrad* mf = new Cfrheologybbarabsgrad(this->name,this->definitionenum, this->weights_enum,this->timepassedflag,this->J);
    5869        return (Object*) mf;
    5970}
     
    8394        marshallhandle->call(this->weights_enum);
    8495        marshallhandle->call(this->timepassedflag);
    85         marshallhandle->call(this->misfit);
     96        marshallhandle->call(this->J);
    8697}
    8798/*}}}*/
     
    105116
    106117        /*recover parameters: */
    107         IssmDouble J=0.;
     118        IssmDouble J_part=0.;
    108119        IssmDouble J_sum=0.;
    109120
    110121        for(Object* & object : femmodel->elements->objects){
    111122                Element* element=xDynamicCast<Element*>(object);
    112                 J+=this->Cfrheologybbarabsgrad_Calculation(element,weights_enum);
     123                J_part+=this->Cfrheologybbarabsgrad_Calculation(element,weights_enum);
    113124        }
    114125
    115         ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     126        ISSM_MPI_Allreduce( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    116127        ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    117         J=J_sum;
    118128
    119         timepassedflag = true;
    120         return J;
     129        this->timepassedflag = true;
     130        this->J = J_sum;
     131        return this->J;
    121132}/*}}}*/
    122133IssmDouble Cfrheologybbarabsgrad::Cfrheologybbarabsgrad_Calculation(Element* element, int weights_enum){/*{{{*/
     
    124135        int        domaintype,numcomponents;
    125136        IssmDouble Jelem=0.;
    126         IssmDouble misfit,Jdet;
     137        IssmDouble Jdet;
    127138        IssmDouble dp[2],weight;
    128139        IssmDouble* xyz_list = NULL;
  • issm/trunk-jpl/src/c/classes/Cfrheologybbarabsgrad.h

    r27686 r27728  
    2121                int         weights_enum;
    2222                bool                    timepassedflag;
    23 
    24                 IssmDouble  misfit; //value carried over in time.
     23                IssmDouble  J;
    2524
    2625                /*Cfrheologybbarabsgrad constructors, destructors :*/
    2726                Cfrheologybbarabsgrad();
    28                 Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum,  bool timepassedflag);
     27                Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum);
     28                Cfrheologybbarabsgrad(char* in_name, int in_definitionenum, int in_weights_enum,  bool in_timepassedflag, IssmDouble in_J);
    2929                ~Cfrheologybbarabsgrad();
    3030
  • issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.cpp

    r26888 r27728  
    3131        this->datatime=0.;
    3232        this->timepassedflag = false;
    33 
    34 }
    35 /*}}}*/
    36 Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
     33        this->J = 0.;
     34
     35}
     36/*}}}*/
     37Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime){/*{{{*/
    3738
    3839        this->definitionenum=in_definitionenum;
     
    4243
    4344        this->datatime=in_datatime;
     45
     46        this->timepassedflag=false;
     47        this->J=0.;
     48
     49}
     50/*}}}*/
     51Cfsurfacelogvel::Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool in_timepassedflag,IssmDouble in_J){/*{{{*/
     52
     53        this->definitionenum=in_definitionenum;
     54
     55        this->name              = xNew<char>(strlen(in_name)+1);
     56        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     57
     58        this->datatime=in_datatime;
    4459        this->timepassedflag=in_timepassedflag;
     60        this->J=in_J;
    4561
    4662}
     
    5268/*Object virtual function resolutoin: */
    5369Object* Cfsurfacelogvel::copy() {/*{{{*/
    54         Cfsurfacelogvel* mf = new Cfsurfacelogvel(this->name,this->definitionenum,this->datatime,this->timepassedflag);
     70        Cfsurfacelogvel* mf = new Cfsurfacelogvel(this->name,this->definitionenum,this->datatime,this->timepassedflag, this->J);
    5571        return (Object*) mf;
    5672}
     
    6480        _printf_("    datatime: " << datatime << "\n");
    6581        _printf_("        timepassedflag: "<<timepassedflag<<"\n");
     82        _printf_("        J: "<<J<<"\n");
    6683}
    6784/*}}}*/
     
    7895        marshallhandle->call(this->datatime);
    7996        marshallhandle->call(this->timepassedflag);
     97        marshallhandle->call(this->J);
    8098}
    8199/*}}}*/
     
    104122        if(this->datatime<=time && !this->timepassedflag){
    105123
    106                 IssmDouble J=0.;
     124                IssmDouble J_part=0.;
    107125                IssmDouble J_sum=0.;
    108126
    109127                for(Object* & object : femmodel->elements->objects){
    110128                        Element* element=xDynamicCast<Element*>(object);
    111                         J+=this->Cfsurfacelogvel_Calculation(element,definitionenum);
    112                 }
    113 
    114                 ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     129                        J_part+=this->Cfsurfacelogvel_Calculation(element,definitionenum);
     130                }
     131
     132                ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    115133                ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    116                 J=J_sum;
    117134
    118135                this->timepassedflag = true;
    119                 return J_sum;
    120         }
    121         else{
    122                 return 0.;
    123         }
     136                this->J = J_sum;
     137        }
     138
     139        return this->J;
    124140}/*}}}*/
    125141IssmDouble Cfsurfacelogvel::Cfsurfacelogvel_Calculation(Element* element, int definitionenum){/*{{{*/
  • issm/trunk-jpl/src/c/classes/Cfsurfacelogvel.h

    r27681 r27728  
    2020                IssmDouble      datatime;
    2121                bool                    timepassedflag;
     22                IssmDouble  J;
    2223
    2324                /*Cfsurfacelogvel constructors, destructors :*/
    2425                Cfsurfacelogvel();
    25                 Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool timepassedflag);
     26                Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime);
     27                Cfsurfacelogvel(char* in_name, int in_definitionenum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
    2628                ~Cfsurfacelogvel();
    2729
  • issm/trunk-jpl/src/c/classes/Cfsurfacesquare.cpp

    r27681 r27728  
    3232        this->datatime         = 0.;
    3333        this->timepassedflag   = false;
    34 }
    35 /*}}}*/
    36 Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag){/*{{{*/
     34        this->J                = 0.;
     35}
     36/*}}}*/
     37Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime){/*{{{*/
     38
     39        this->definitionenum=in_definitionenum;
     40
     41        this->name              = xNew<char>(strlen(in_name)+1);
     42        xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
     43
     44        this->model_enum=in_model_enum;
     45        this->datatime=in_datatime;
     46        this->timepassedflag=false;
     47        this->J=0.;
     48}
     49/*}}}*/
     50Cfsurfacesquare::Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool in_timepassedflag, IssmDouble in_J){/*{{{*/
    3751
    3852        this->definitionenum=in_definitionenum;
     
    4458        this->datatime=in_datatime;
    4559        this->timepassedflag=in_timepassedflag;
     60        this->J=in_J;
    4661}
    4762/*}}}*/
     
    5368/*Object virtual function resolutoin: */
    5469Object* Cfsurfacesquare::copy() {/*{{{*/
    55         Cfsurfacesquare* mf = new Cfsurfacesquare(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag);
     70        Cfsurfacesquare* mf = new Cfsurfacesquare(this->name,this->definitionenum, this->model_enum,this->datatime,this->timepassedflag,this->J);
    5671        return (Object*) mf;
    5772}
     
    6681        _printf_("    datatime: " << datatime << "\n");
    6782        _printf_("        timepassedflag: "<<timepassedflag<<"\n");
     83        _printf_("        J: "<<J<<"\n");
    6884}
    6985/*}}}*/
     
    8298        marshallhandle->call(this->datatime);
    8399        marshallhandle->call(this->timepassedflag);
     100        marshallhandle->call(this->J);
    84101}
    85102/*}}}*/
     
    110127        if(this->datatime<=time && !this->timepassedflag){
    111128
    112                 IssmDouble J=0.;
     129                IssmDouble J_part=0.;
    113130                IssmDouble J_sum=0.;
    114131
    115132                for(Object* & object : femmodel->elements->objects){
    116133                        Element* element=xDynamicCast<Element*>(object);
    117                         J+=this->Cfsurfacesquare_Calculation(element,model_enum);
     134                        J_part+=this->Cfsurfacesquare_Calculation(element,model_enum);
    118135                }
    119136
    120                 ISSM_MPI_Allreduce ( (void*)&J,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     137                ISSM_MPI_Allreduce ( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    121138                ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    122139
    123140                this->timepassedflag = true;
    124                 return J_sum;
     141                this->J = J_sum;
    125142        }
    126         else{
    127                 return 0.;
    128         }
     143
     144        return this->J;
    129145}
    130146/*}}}*/
  • issm/trunk-jpl/src/c/classes/Cfsurfacesquare.h

    r27681 r27728  
    2121                IssmDouble  datatime;
    2222                bool        timepassedflag;
     23                IssmDouble  J;
    2324
    2425                /*Cfsurfacesquare constructors, destructors :*/
    2526                Cfsurfacesquare();
    26                 Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag);
     27                Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime);
     28                Cfsurfacesquare(char* in_name, int in_definitionenum, int in_model_enum, IssmDouble in_datatime, bool timepassedflag, IssmDouble in_J);
    2729                ~Cfsurfacesquare();
    2830
  • issm/trunk-jpl/src/c/classes/Cfsurfacesquaretransient.cpp

    r27721 r27728  
    159159        /*Check that we have not yet calculated this cost function*/
    160160        if(this->passedflags[pos]){
    161                 return 0.;
    162                 //return this->J; //FIXME
     161                return this->J;
    163162        }
    164163
     
    172171        /*Sum across partition*/
    173172        IssmDouble J_sum;
    174         ISSM_MPI_Allreduce( (void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
     173        ISSM_MPI_Allreduce((void*)&J_part,(void*)&J_sum,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
    175174        ISSM_MPI_Bcast(&J_sum,1,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
    176175
     
    180179
    181180        /*Return full cost function this far*/
    182         //return this->J; //FIXME
    183         return J_sum;
     181        return this->J;
    184182}/*}}}*/
    185183IssmDouble Cfsurfacesquaretransient::Cfsurfacesquaretransient_Calculation(Element* element, int model_enum){/*{{{*/
  • issm/trunk-jpl/src/c/classes/DependentObject.cpp

    r27725 r27728  
    7070
    7171/*DependentObject methods: */
    72 void  DependentObject::Responsex(IssmDouble* poutput_value,FemModel* femmodel){/*{{{*/
     72void  DependentObject::RecordResponsex(FemModel* femmodel){/*{{{*/
    7373
    7474        /*Is this some special type of response for which we need to go in the output definitions? :*/
    7575        if (StringToEnumx(this->name,false)==-1){
    76                 *poutput_value=OutputDefinitionsResponsex(femmodel,this->name);
     76                this->response_value = OutputDefinitionsResponsex(femmodel,this->name);
    7777        }
    78         else femmodel->Responsex(poutput_value,this->name);
     78        else{
     79                femmodel->Responsex(&this->response_value, this->name);
     80        }
    7981}
    8082/*}}}*/
     
    8385}
    8486/*}}}*/
    85 void DependentObject::AddValue(IssmDouble in_value){/*{{{*/
    86         this->response_value+=in_value;
    87 }
    88 /*}}}*/
    8987void DependentObject::ResetResponseValue(){/*{{{*/
    9088        this->response_value=0.;
  • issm/trunk-jpl/src/c/classes/DependentObject.h

    r27725 r27728  
    3535
    3636                /*DependentObject methods: */
    37                 void       Responsex(IssmDouble *poutput_value,FemModel*femmodel);
     37                void       RecordResponsex(FemModel*femmodel);
    3838                IssmDouble GetValue(void);
    39                 void       AddValue(IssmDouble in_value);
    4039                void       ResetResponseValue(void);
    4140
  • issm/trunk-jpl/src/c/classes/FemModel.cpp

    r27491 r27728  
    23352335void FemModel::RequestedDependentsx(void){/*{{{*/
    23362336
    2337         bool        isautodiff      = false;
    2338         IssmDouble  output_value;
    2339 
    2340         int         num_dependents;
    2341         IssmPDouble *dependents;
    2342         DataSet*    dependent_objects=NULL;
    2343         int my_rank=IssmComm::GetRank();
    2344 
    23452337        /*AD mode on?: */
     2338        bool isautodiff;
    23462339        parameters->FindParam(&isautodiff,AutodiffIsautodiffEnum);
    23472340
    23482341        if(isautodiff){
    23492342                #ifdef _HAVE_AD_
     2343                int      num_dependents;
     2344                DataSet* dependent_objects=NULL;
    23502345                parameters->FindParam(&num_dependents,AutodiffNumDependentsEnum);
    23512346                parameters->FindParam(&dependent_objects,AutodiffDependentObjectsEnum);
    23522347                if(num_dependents){
    2353                         dependents=xNew<IssmPDouble>(num_dependents);
     2348                        IssmPDouble* dependents=xNew<IssmPDouble>(num_dependents);
    23542349
    23552350                        #if defined(_HAVE_CODIPACK_)
     
    23642359
    23652360                        /*Go through our dependent variables, and compute the response:*/
     2361                        int my_rank=IssmComm::GetRank();
    23662362                        int i = 0;
    23672363                        for(Object* & object : dependent_objects->objects){
    23682364                                DependentObject* dep=(DependentObject*)object;
    2369                                 dep->Responsex(&output_value,this);
     2365                                dep->RecordResponsex(this);
     2366                                IssmDouble output_value = dep->GetValue();
    23702367                                if (my_rank==0) {
    23712368                                        #if defined(_HAVE_CODIPACK_)
     
    23852382                                i++;
    23862383                        }
     2384                        xDelete<IssmPDouble>(dependents);
    23872385                }
    23882386                delete dependent_objects;
    2389                 if(num_dependents)xDelete<IssmPDouble>(dependents);
    23902387                #else
    23912388                _error_("Should not be requesting dependents when an AD library is not available!");
     
    46084605void FemModel::DakotaResponsesx(double* d_responses,char** responses_descriptors,int numresponsedescriptors,int d_numresponses){/*{{{*/
    46094606
    4610         int        i,j;
    4611         int        my_rank;
    4612 
    46134607        /*intermediary: */
     4608        int    i,j;
    46144609        char   root[50];
    46154610        int    index;
     
    46314626
    46324627        /*retrieve my_rank: */
    4633         my_rank=IssmComm::GetRank();
     4628        int my_rank=IssmComm::GetRank();
    46344629
    46354630        /*save the d_responses pointer: */
  • issm/trunk-jpl/src/c/cores/controladm1qn3_core.cpp

    r27724 r27728  
    329329                        i++;
    330330                        DependentObject* dep=xDynamicCast<DependentObject*>(object);
    331                         if(solution_type==TransientSolutionEnum) output_value = dep->GetValue();
    332                         if(solution_type!=TransientSolutionEnum) dep->Responsex(&output_value,femmodel);
     331
     332                        /*Get cost function for this dependent*/
     333                        dep->RecordResponsex(femmodel);
     334                        IssmDouble output_value = dep->GetValue();
    333335
    334336                        #if defined(_HAVE_CODIPACK_)
     
    349351                        _error_("not suppoted");
    350352                        #endif
     353
    351354                        J+=output_value;
    352355                }
  • issm/trunk-jpl/src/c/cores/controlvalidation_core.cpp

    r26556 r27728  
    243243
    244244        /*Get Dependents*/
    245         IssmDouble  output_value;
    246245        int         num_dependents;
    247246        IssmPDouble *dependents;
     
    257256                DependentObject* dep=xDynamicCast<DependentObject*>(object);
    258257                i++;
    259                 if(solution_type==TransientSolutionEnum){
    260                         output_value = dep->GetValue();
    261                 }
    262                 else{
    263                         dep->Responsex(&output_value,femmodel);
    264                 }
     258                dep->RecordResponsex(femmodel);
     259                IssmDouble output_value = dep->GetValue();
     260
    265261                _printf0_("=== output ="<<output_value<<" \n");
    266262                if(my_rank==0) {
     
    339335                for(Object* & object:dependent_objects->objects){
    340336                        DependentObject* dep=xDynamicCast<DependentObject*>(object);
    341                         if(solution_type==TransientSolutionEnum){
    342                                 output_value = dep->GetValue();
    343                         }
    344                         else{
    345                                 dep->Responsex(&output_value,femmodel);
    346                         }
     337                        dep->RecordResponsex(femmodel);
     338                        IssmDouble output_value = dep->GetValue();
    347339                        j+=output_value;
    348340                }
  • issm/trunk-jpl/src/c/cores/transient_core.cpp

    r27724 r27728  
    118118                        for(Object* & object:dependent_objects->objects){
    119119                                DependentObject* dep=(DependentObject*)object;
    120                                 IssmDouble  output_value;
    121                                 dep->Responsex(&output_value,femmodel);
    122                                 dep->AddValue(output_value);
     120                                dep->RecordResponsex(femmodel);
    123121                        }
    124122                }
     
    269267
    270268        /*parameters: */
    271         IssmDouble output_value;
    272269        IssmDouble finaltime,dt,yts,time;
    273270        bool       isoceancoupling;
     
    342339                for(Object* & object:dependent_objects->objects){
    343340                        DependentObject* dep=(DependentObject*)object;
    344                         dep->Responsex(&output_value,femmodel);
    345                         dep->AddValue(output_value);
     341                        dep->RecordResponsex(femmodel);
    346342                }
    347343
     
    401397                IssmDouble       output_value = dep->GetValue();
    402398
    403 
    404399                J += output_value;
    405400
    406401                tape_codi.registerOutput(J);
    407 #if _CODIPACK_MAJOR_==2
     402                #if _CODIPACK_MAJOR_==2
    408403                codi_global.output_indices.push_back(J.getIdentifier());
    409 #elif _CODIPACK_MAJOR_==1
     404                #elif _CODIPACK_MAJOR_==1
    410405                codi_global.output_indices.push_back(J.getGradientData());
    411 #else
    412 #error "_CODIPACK_MAJOR_ not supported"
    413 #endif
     406                #else
     407                #error "_CODIPACK_MAJOR_ not supported"
     408                #endif
    414409
    415410                /*Keep track of output for printing*/
     
    477472                        for(Object* & object:dependent_objects->objects){
    478473                                DependentObject* dep=(DependentObject*)object;
    479                                 dep->Responsex(&output_value,femmodel);
    480                                 dep->AddValue(output_value);
     474                                dep->RecordResponsex(femmodel);
    481475                        }
    482476
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/Autodiff/CreateParametersAutodiff.cpp

    r27725 r27728  
    151151                if(num_dependent_objects){
    152152                        iomodel->FindConstant(&names,&dummy,"md.autodiff.dependent_object_names");
    153                         iomodel->FetchData(&indices,&dummy,&dummy,"md.autodiff.dependent_object_indices");
    154153
    155154                        for(i=0;i<num_dependent_objects;i++){
    156                                 DependentObject* dep=new DependentObject(names[i],indices[i]);
     155                                DependentObject* dep=new DependentObject(names[i]);
    157156                                dependent_objects->AddObject(dep);
    158157                                num_dep++;
     
    164163                        }
    165164                        xDelete<char*>(names);
    166                         xDelete<int>(indices);
    167165                }
    168166                parameters->AddObject(new DataSetParam(AutodiffDependentObjectsEnum,dependent_objects));
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp

    r27717 r27728  
    205205
    206206                                        /*First create a cfsurfacesquare object for that specific string (cfsurfacesquare_model_string_s[j]):*/
    207                                         output_definitions->AddObject(new Cfsurfacesquare(cfsurfacesquare_name_s[j],StringToEnumx(cfsurfacesquare_definitionstring_s[j]),StringToEnumx(cfsurfacesquare_model_string_s[j]),cfsurfacesquare_datatime_s[j],false));
     207                                        output_definitions->AddObject(new Cfsurfacesquare(cfsurfacesquare_name_s[j],StringToEnumx(cfsurfacesquare_definitionstring_s[j]),StringToEnumx(cfsurfacesquare_model_string_s[j]),cfsurfacesquare_datatime_s[j]));
    208208
    209209                                        /*Now, for this particular cfsurfacesquare object, make sure we plug into the elements: the observation, and the weights.*/
     
    413413
    414414                                        /*First create a cfrheologybbarabsgrad object for that specific string (cfrheologybbarabsgrad_model_string_s[j]):*/
    415                                         output_definitions->AddObject(new Cfrheologybbarabsgrad(cfrheologybbarabsgrad_name_s[j],StringToEnumx(cfrheologybbarabsgrad_definitionstring_s[j]),StringToEnumx(cfrheologybbarabsgrad_weights_string_s[j]),false));
     415                                        output_definitions->AddObject(new Cfrheologybbarabsgrad(cfrheologybbarabsgrad_name_s[j],StringToEnumx(cfrheologybbarabsgrad_definitionstring_s[j]),StringToEnumx(cfrheologybbarabsgrad_weights_string_s[j])));
    416416
    417417                                        /*Now, for this particular cfrheologybbarabsgrad object, make sure we plug into the elements: the observation, and the weights.*/
     
    496496
    497497                                        /*First create a cfsurfacelogvel object for that specific string (cfsurfacelogvel_modeltring[j]):*/
    498                                         output_definitions->AddObject(new Cfsurfacelogvel(cfsurfacelogvel_name[j],StringToEnumx(cfsurfacelogvel_definitionstring[j]),cfsurfacelogvel_datatime[j],false));
     498                                        output_definitions->AddObject(new Cfsurfacelogvel(cfsurfacelogvel_name[j],StringToEnumx(cfsurfacelogvel_definitionstring[j]),cfsurfacelogvel_datatime[j]));
    499499
    500500                                        /*Now, for this particular cfsurfacelogvel object, make sure we plug into the elements: the observation, and the weights.*/
     
    590590
    591591                                        /*First create a cflevelsetmisfit object for that specific string (cflevelsetmisfit_model_string_s[j]):*/
    592                                         output_definitions->AddObject(new Cflevelsetmisfit(cflevelsetmisfit_name_s[j],StringToEnumx(cflevelsetmisfit_definitionstring_s[j]),StringToEnumx(cflevelsetmisfit_model_string_s[j]),cflevelsetmisfit_datatime_s[j],false));
     592                                        output_definitions->AddObject(new Cflevelsetmisfit(cflevelsetmisfit_name_s[j],StringToEnumx(cflevelsetmisfit_definitionstring_s[j]),StringToEnumx(cflevelsetmisfit_model_string_s[j]),cflevelsetmisfit_datatime_s[j]));
    593593
    594594                                        /*Now, for this particular cflevelsetmisfit object, make sure we plug into the elements: the observation, and the weights.*/
Note: See TracChangeset for help on using the changeset viewer.