Changeset 16208


Ignore:
Timestamp:
09/20/13 11:09:57 (12 years ago)
Author:
Mathieu Morlighem
Message:

CHG: simplifying InputCreate

Location:
issm/trunk-jpl/src/c/classes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Element.h

    r16188 r16208  
    6767                virtual void   InputToResult(int enum_type,int step,IssmDouble time)=0;
    6868                virtual void   InputDuplicate(int original_enum,int new_enum)=0;
    69                 virtual void   InputCreate(IssmDouble* vector, int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code)=0;
     69                virtual void   InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code)=0;
    7070                virtual void   RequestedOutput(int output_enum,int step,IssmDouble time)=0;
    7171
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Penta.cpp

    r16200 r16208  
    18741874}
    18751875/*}}}*/
    1876 /*FUNCTION Penta::InputCreate(IssmDouble* vector,int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){{{*/
    1877 void Penta::InputCreate(IssmDouble* vector, int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){//index into elements
     1876/*FUNCTION Penta::InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){{{*/
     1877void Penta::InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){
    18781878
    18791879        /*Intermediaries*/
     
    18911891                for(i=0;i<6;i++){
    18921892                        _assert_(iomodel->elements);
    1893                         penta_vertex_ids[i]=iomodel->elements[6*index+i]; //ids for vertices are in the elements array from Matlab
     1893                        penta_vertex_ids[i]=iomodel->elements[6*this->sid+i]; //ids for vertices are in the elements array from Matlab
    18941894                }
    18951895
     
    19301930
    19311931                        if (code==5){ //boolean
    1932                                 this->inputs->AddInput(new BoolInput(vector_enum,reCast<bool,IssmDouble>(vector[index])));
     1932                                this->inputs->AddInput(new BoolInput(vector_enum,reCast<bool,IssmDouble>(vector[this->sid])));
    19331933                        }
    19341934                        else if (code==6){ //integer
    1935                                 this->inputs->AddInput(new IntInput(vector_enum,reCast<int,IssmDouble>(vector[index])));
     1935                                this->inputs->AddInput(new IntInput(vector_enum,reCast<int,IssmDouble>(vector[this->sid])));
    19361936                        }
    19371937                        else if (code==7){ //IssmDouble
    1938                                 this->inputs->AddInput(new DoubleInput(vector_enum,vector[index]));
     1938                                this->inputs->AddInput(new DoubleInput(vector_enum,vector[this->sid]));
    19391939                        }
    19401940                        else _error_("could not recognize nature of vector from code " << code);
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Penta.h

    r16188 r16208  
    9494                int    Sid();
    9595                void   InputArtificialNoise(int enum_type,IssmDouble min, IssmDouble max);
    96                 void   InputCreate(IssmDouble* vector, int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code);
     96                void   InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code);
    9797                void   InputDepthAverageAtBase(int enum_type,int average_enum_type,int object_enum=MeshElementsEnum);
    9898                void   InputDuplicate(int original_enum,int new_enum);
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Tria.cpp

    r16188 r16208  
    2424/*FUNCTION Tria::Tria(){{{*/
    2525Tria::Tria(){
    26         this->nodes    = NULL;
    27         this->vertices = NULL;
    28         this->material = NULL;
    29         this->matpar   = NULL;
     26        this->nodes      = NULL;
     27        this->vertices   = NULL;
     28        this->material   = NULL;
     29        this->matpar     = NULL;
    3030        this->inputs     = NULL;
    3131        this->parameters = NULL;
     
    3636/*FUNCTION Tria::Tria(int id, int sid,int index, IoModel* iomodel,int nummodels){{{*/
    3737Tria::Tria(int tria_id, int tria_sid, int index, IoModel* iomodel,int nummodels)
    38         :TriaRef(nummodels)
    39         ,ElementHook(nummodels,index+1,3,iomodel){
     38        :TriaRef(nummodels),ElementHook(nummodels,index+1,3,iomodel){
    4039
    4140                /*id: */
    42                 this->id=tria_id;
    43                 this->sid=tria_sid;
     41                this->id  = tria_id;
     42                this->sid = tria_sid;
    4443
    4544                //this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
    46                 this->parameters=NULL;
     45                this->parameters = NULL;
    4746
    4847                /*intialize inputs and results: */
     
    8180        tria->hnodes=new Hook*[tria->numanalyses];
    8281        for(i=0;i<tria->numanalyses;i++)tria->hnodes[i]=(Hook*)this->hnodes[i]->copy();
    83         tria->hvertices=(Hook*)this->hvertices->copy();
    84         tria->hmaterial=(Hook*)this->hmaterial->copy();
    85         tria->hmatpar=(Hook*)this->hmatpar->copy();
     82        tria->hvertices = (Hook*)this->hvertices->copy();
     83        tria->hmaterial = (Hook*)this->hmaterial->copy();
     84        tria->hmatpar   = (Hook*)this->hmatpar->copy();
    8685
    8786        /*deal with Tria fields: */
    88         tria->id=this->id;
    89         tria->sid=this->sid;
     87        tria->id  = this->id;
     88        tria->sid = this->sid;
    9089        if(this->inputs){
    9190                tria->inputs=(Inputs*)this->inputs->Copy();
     
    104103
    105104        /*recover objects: */
    106         tria->nodes=xNew<Node*>(3); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
     105        tria->nodes = xNew<Node*>(3); //we cannot rely on an analysis_counter to tell us which analysis_type we are running, so we just copy the nodes.
    107106        for(i=0;i<3;i++)tria->nodes[i]=this->nodes[i];
    108         tria->vertices=(Vertex**)tria->hvertices->deliverp();
    109         tria->material=(Material*)tria->hmaterial->delivers();
    110         tria->matpar=(Matpar*)tria->hmatpar->delivers();
     107
     108        tria->vertices = (Vertex**)tria->hvertices->deliverp();
     109        tria->material = (Material*)tria->hmaterial->delivers();
     110        tria->matpar   = (Matpar*)tria->hmatpar->delivers();
    111111
    112112        return tria;
     
    18671867}
    18681868/*}}}*/
    1869 /*FUNCTION Tria::InputCreate(IssmDouble* vector,int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){{{*/
    1870 void Tria::InputCreate(IssmDouble* vector, int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){//index into elements
     1869/*FUNCTION Tria::InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){{{*/
     1870void Tria::InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code){
    18711871
    18721872        /*Intermediaries*/
     
    18841884                for(i=0;i<3;i++){
    18851885                        _assert_(iomodel->elements);
    1886                         tria_vertex_ids[i]=reCast<int>(iomodel->elements[3*index+i]); //ids for vertices are in the elements array from Matlab
     1886                        tria_vertex_ids[i]=reCast<int>(iomodel->elements[3*this->sid+i]); //ids for vertices are in the elements array from Matlab
    18871887                }
    18881888
     
    19231923
    19241924                        if (code==5){ //boolean
    1925                                 this->inputs->AddInput(new BoolInput(vector_enum,reCast<bool>(vector[index])));
     1925                                this->inputs->AddInput(new BoolInput(vector_enum,reCast<bool>(vector[this->sid])));
    19261926                        }
    19271927                        else if (code==6){ //integer
    1928                                 this->inputs->AddInput(new IntInput(vector_enum,reCast<int>(vector[index])));
     1928                                this->inputs->AddInput(new IntInput(vector_enum,reCast<int>(vector[this->sid])));
    19291929                        }
    19301930                        else if (code==7){ //IssmDouble
    1931                                 this->inputs->AddInput(new DoubleInput(vector_enum,vector[index]));
     1931                                this->inputs->AddInput(new DoubleInput(vector_enum,vector[this->sid]));
    19321932                        }
    19331933                        else _error_("could not recognize nature of vector from code " << code);
  • TabularUnified issm/trunk-jpl/src/c/classes/Elements/Tria.h

    r16188 r16208  
    9191                void        GetVectorFromResults(Vector<IssmDouble>* vector,int offset,int enum_in,int interp);
    9292                void        InputArtificialNoise(int enum_type,IssmDouble min, IssmDouble max);
    93                 void        InputCreate(IssmDouble* vector, int index,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code);
     93                void        InputCreate(IssmDouble* vector,IoModel* iomodel,int M,int N,int vector_type,int vector_enum,int code);
    9494                void        InputDepthAverageAtBase(int enum_type,int average_enum_type,int object_enum=MeshElementsEnum);
    9595                void        InputDuplicate(int original_enum,int new_enum);
  • TabularUnified issm/trunk-jpl/src/c/classes/IoModel.cpp

    r16186 r16208  
    531531}
    532532/*}}}*/
    533 /*FUNCTION IoModel::FetchData(bool*     pbool,int data_enum){{{*/
     533/*FUNCTION IoModel::FetchData(bool*         pbool,int data_enum){{{*/
    534534void  IoModel::FetchData(bool* pboolean,int data_enum){
    535535
     
    560560}
    561561/*}}}*/
    562 /*FUNCTION IoModel::FetchData(int*      pinteger,int data_enum){{{*/
     562/*FUNCTION IoModel::FetchData(int*          pinteger,int data_enum){{{*/
    563563void  IoModel::FetchData(int* pinteger,int data_enum){
    564564
     
    616616}
    617617/*}}}*/
    618 /*FUNCTION IoModel::FetchData(char**    pstring,int data_enum){{{*/
     618/*FUNCTION IoModel::FetchData(char**        pstring,int data_enum){{{*/
    619619void  IoModel::FetchData(char** pstring,int data_enum){
    620620
     
    663663}
    664664/*}}}*/
    665 /*FUNCTION IoModel::FetchData(int**     pintegerematrix,int* pM,int* pN,int data_enum){{{*/
     665/*FUNCTION IoModel::FetchData(int**         pintegerematrix,int* pM,int* pN,int data_enum){{{*/
    666666void  IoModel::FetchData(int** pmatrix,int* pM,int* pN,int data_enum){
    667667
     
    792792}
    793793/*}}}*/
    794 /*FUNCTION IoModel::FetchData(char***   pstrings,int* pnumstrings,int data_enum){{{*/
     794/*FUNCTION IoModel::FetchData(char***       pstrings,int* pnumstrings,int data_enum){{{*/
    795795void  IoModel::FetchData(char*** pstrings,int* pnumstrings,int data_enum){
    796796
     
    10331033/*}}}*/
    10341034/*FUNCTION IoModel::FetchDataToInput{{{*/
    1035 void IoModel::FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum,IssmDouble default_value){
     1035void IoModel::FetchDataToInput(Elements* elements,int vector_enum,IssmDouble default_value){
    10361036
    10371037        /*intermediary: */
    10381038        int     i;
    1039         bool    defaulting    = false;
    1040         int     code          = 0;
    1041         int     vector_layout = 0;
    1042         int     counter;
    1043         int     numberofelements;
     1039        int     code,vector_layout;
    10441040
    10451041        /*variables being fetched: */
     
    10511047        int         M,N;
    10521048
    1053         /*Fetch parameters: */
    1054         this->constants->FindParam(&numberofelements,MeshNumberofelementsEnum);
    1055 
    10561049        /*First of, find the record for the enum, and get code  of data type: */
    10571050        this->SetFilePointerToData(&code, &vector_layout,vector_enum);
    10581051
    10591052        switch(code){
    1060                 case 1: //boolean constant.  {{{
     1053                case 1: //boolean constant
    10611054                        this->FetchData(&boolean,vector_enum);
    10621055                        for(i=0;i<elements->Size();i++){
     
    10641057                                element->InputUpdateFromConstant(boolean,vector_enum);
    10651058                        }
    1066                         break; /*}}}*/
    1067                 case 2: //integer constant.  {{{
     1059                        break;
     1060                case 2: //integer constant
    10681061                        this->FetchData(&integer,vector_enum);
    10691062                        for(i=0;i<elements->Size();i++){
     
    10711064                                element->InputUpdateFromConstant(integer,vector_enum);
    10721065                        }
    1073                         break; /*}}}*/
    1074                 case 3: //IssmDouble constant.  {{{
     1066                        break;
     1067                case 3: //IssmDouble constant
    10751068                        this->FetchData(&scalar,vector_enum);
    10761069                        for(i=0;i<elements->Size();i++){
     
    10781071                                element->InputUpdateFromConstant(scalar,vector_enum);
    10791072                        }
    1080                         break; /*}}}*/
    1081                 case 5: //boolean vector.  {{{
    1082 
    1083                         /*Fetch vector:*/
     1073                        break;
     1074                case 5: //boolean vector
    10841075                        this->FetchData(&doublearray,&M,&N,vector_enum); //we still have a doublearray, because it might include times in transient mode
    1085                         /*Check we got something, otherwise fetch default: */
    1086                         if(doublearray){
    1087                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1088                         }
    1089                         else{
    1090                                 /*do we have a default enum to go fetch? */
    1091                                 if(default_vector_enum!=NoneEnum){
    1092                                         /*yes. fetch it: */
    1093                                         this->FetchData(&doublearray,&M,&N,default_vector_enum);
    1094                                         if(doublearray){
    1095                                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1096                                         }
    1097                                         else{
    1098                                                 /*even the default vector is non existent. we are defaulting to the default value: */
    1099                                                 defaulting=true;
    1100                                         }
    1101                                 }
    1102                                 else{
    1103                                         /*we are left with the default value: */
    1104                                         defaulting=true;
    1105                                 }
    1106                         }
    1107 
    1108                         /*Create inputs:*/
    1109                         counter=0;
    1110                         for (i=0;i<numberofelements;i++){
    1111                                 if(this->my_elements[i]){
    1112                                         Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(counter));
    1113                                         if(defaulting) element->InputUpdateFromConstant(reCast<bool>(default_value),vector_enum);
    1114                                         else           element->InputCreate(doublearray,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    1115                                         counter++;
    1116                                 }
    1117                         }
    1118                         break; /*}}}*/
    1119                 case 6: //int vector{{{
    1120 
    1121                         /*Fetch vector:*/
     1076                        for(i=0;i<elements->Size();i++){
     1077                                Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
     1078                                if(!doublearray) element->InputUpdateFromConstant(reCast<bool>(default_value),vector_enum);
     1079                                else             element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1080                                element->InputUpdateFromConstant(boolean,vector_enum);
     1081                        }
     1082                        break;
     1083                case 6: //int vector
    11221084                        this->FetchData(&doublearray,&M,&N,vector_enum); //we still have a doublearray, because it might include times in transient mode
    1123                         /*Check we got something, otherwise fetch default: */
    1124                         if(doublearray){
    1125                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1126                         }
    1127                         else{
    1128                                 /*do we have a default enum to go fetch? */
    1129                                 if(default_vector_enum!=NoneEnum){
    1130                                         /*yes. fetch it: */
    1131                                         this->FetchData(&doublearray,&M,&N,default_vector_enum);
    1132                                         if(doublearray){
    1133                                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1134                                         }
    1135                                         else{
    1136                                                 /*even the default vector is non existent. we are defaulting to the default value: */
    1137                                                 defaulting=true;
    1138                                         }
    1139                                 }
    1140                                 else{
    1141                                         /*we are left with the default value: */
    1142                                         defaulting=true;
    1143                                 }
    1144                         }
    1145 
    1146                         /*Create inputs:*/
    1147                         counter=0;
    1148                         for (i=0;i<numberofelements;i++){
    1149                                 if(this->my_elements[i]){
    1150                                         Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(counter));
    1151                                         if(defaulting) element->InputUpdateFromConstant(reCast<int>(default_value),vector_enum);
    1152                                         else           element->InputCreate(doublearray,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    1153                                         counter++;
    1154                                 }
    1155                         }
    1156                         break; /*}}}*/
    1157                 case 7: //IssmDouble vector{{{
    1158 
    1159                         /*Fetch vector:*/
     1085                        for(i=0;i<elements->Size();i++){
     1086                                Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
     1087                                if(!doublearray) element->InputUpdateFromConstant(reCast<int>(default_value),vector_enum);
     1088                                else             element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1089                                element->InputUpdateFromConstant(boolean,vector_enum);
     1090                        }
     1091                        break;
     1092                case 7: //IssmDouble vector
    11601093                        this->FetchData(&doublearray,&M,&N,vector_enum);
    1161                         /*Check we got something, otherwise fetch default: */
    1162                         if(doublearray){
    1163                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1164                         }
    1165                         else{
    1166                                 /*do we have a default enum to go fetch? */
    1167                                 if(default_vector_enum!=NoneEnum){
    1168                                         /*yes. fetch it: */
    1169                                         this->FetchData(&doublearray,&M,&N,default_vector_enum);
    1170                                         if(doublearray){
    1171                                                 defaulting=false;  //we are not defaulting, because  we do have a vector
    1172                                         }
    1173                                         else{
    1174                                                 /*even the default vector is non existent. we are defaulting to the default value: */
    1175                                                 defaulting=true;
    1176                                         }
    1177                                 }
    1178                                 else{
    1179                                         /*we are left with the default value: */
    1180                                         defaulting=true;
    1181                                 }
    1182                         }
    1183 
    1184                         /*Create inputs:*/
    1185                         counter=0;
    1186                         for (i=0;i<numberofelements;i++){
    1187                                 if(this->my_elements[i]){
    1188                                         Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(counter));
    1189                                         if(defaulting) element->InputUpdateFromConstant(default_value,vector_enum);
    1190                                         else           element->InputCreate(doublearray,i,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
    1191                                         counter++;
    1192                                 }
    1193                         }
    1194 
    1195                         break; /*}}}*/
    1196                 default: /*{{{*/
     1094                        for(i=0;i<elements->Size();i++){
     1095                                Element* element=dynamic_cast<Element*>(elements->GetObjectByOffset(i));
     1096                                if(!doublearray) element->InputUpdateFromConstant(default_value,vector_enum);
     1097                                else             element->InputCreate(doublearray,this,M,N,vector_layout,vector_enum,code);//we need i to index into elements.
     1098                                element->InputUpdateFromConstant(boolean,vector_enum);
     1099                        }
     1100                        break;
     1101                default:
    11971102                        _error_("data code " << code << " not supported yet!");
    11981103                        break;
    1199                         /*}}}*/
    12001104        }
    12011105        /*Free ressources. Pay attention to not freeing an AD mode independent variable though!:*/
    1202         if (!this->independents[vector_enum] && !this->independents[default_vector_enum]) xDelete<IssmDouble>(doublearray);
     1106        if (!this->independents[vector_enum]) xDelete<IssmDouble>(doublearray);
    12031107        xDelete<char>(string);
    12041108}
  • TabularUnified issm/trunk-jpl/src/c/classes/IoModel.h

    r15611 r16208  
    7878                void        FetchData(Option **poption,int data_enum);
    7979                void        FetchData(int num,...);
    80                 void        FetchDataToInput(Elements* elements,int vector_enum,int default_vector_enum=NoneEnum,IssmDouble default_value=0.);
     80                void        FetchDataToInput(Elements* elements,int vector_enum,IssmDouble default_value=0.);
    8181                void        LastIndex(int *pindex);
    8282                FILE*       SetFilePointerToData(int* pcode,int* pvector_type, int data_enum);
Note: See TracChangeset for help on using the changeset viewer.