Changeset 18871


Ignore:
Timestamp:
11/28/14 09:37:39 (10 years ago)
Author:
Eric.Larour
Message:

CHG: new logic here. If supplied with an X vector of independent variables, use them instead of what is being
read from disk. Useful for updating from control inputs during an ad control run.

File:
1 edited

Legend:

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

    r18064 r18871  
    7070
    7171/*IndependentObject methods: */
    72 void IndependentObject::FetchIndependent(IoModel* iomodel){/*{{{*/
     72void IndependentObject::FetchIndependent(IoModel* iomodel,int* pXcount,IssmPDouble* X){ /*{{{*/
    7373
    7474        int my_rank;
    7575        FILE* fid=NULL;
     76        int Xcount;
    7677
    7778        /*recover my_rank:*/
    7879        my_rank=IssmComm::GetRank();
     80
     81        /*recover Xcount if X is not NULL:*/
     82        if(X)Xcount=*pXcount;
    7983
    8084        #ifdef _HAVE_ADOLC_ //cannot come here unless you are running AD mode, from DeclaredIndependents:
     
    98102                        if(fread(&pscalar,sizeof(IssmPDouble),1,fid)!=1)_error_("could not read scalar ");
    99103
    100                         /*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!: */
    101                         scalar<<=pscalar;
     104                        /*Now, before we even broadcast this to other nodes, declare the scalar  as an independent variable!. If we
     105                         *have been supplied an X vector, use it instead of what we just read: */
     106                        if(X){
     107                                scalar<<=X[Xcount];
     108                        }
     109                        else{
     110                                scalar<<=pscalar;
     111                        }
    102112                }
    103113
     
    113123                iomodel->independents[name]=true;
    114124
     125                /*increment offset into X vector, now that we have read 1 value:*/
     126                Xcount++; *pXcount=Xcount;
     127
    115128                //finally, record the number of independents:
    116129                this->numberofindependents=1;
     
    150163                                if(fread(buffer,M*N*sizeof(IssmPDouble),1,fid)!=1) _error_("could not read matrix ");
    151164
    152                                 /*Now, before we even broadcast this to other nodes, declare the whole matrix as a independent variable!: */
    153                                 for (int i=0;i<M*N;++i) matrix[i]<<=buffer[i];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
     165                                /*Now, before we even broadcast this to other nodes, declare the whole matrix as a independent variable!
     166                                 If we have been supplied an X vector, use it instead of what we just read: */
     167                                if(X){
     168                                        for (int i=0;i<M*N;++i) matrix[i]<<=X[Xcount+i];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
     169                                }
     170                                else{
     171                                        for (int i=0;i<M*N;++i) matrix[i]<<=buffer[i];  /*we use the <<= ADOLC overloaded operator to declare the independency*/
     172                                }
    154173                        }
    155174                        ISSM_MPI_Bcast(matrix,M*N,ISSM_MPI_DOUBLE,0,IssmComm::GetComm());
     
    165184                iomodel->independents[name]=true;
    166185
     186                       
     187                /*increment offset into X vector, now that we have read M*N values:*/
     188                Xcount+=M*N; *pXcount=Xcount;
     189               
    167190                //Finally, record the number of independents created:
    168191                this->numberofindependents=M*N;
Note: See TracChangeset for help on using the changeset viewer.