Changeset 24579


Ignore:
Timestamp:
02/25/20 14:07:05 (5 years ago)
Author:
Mathieu Morlighem
Message:

CHG: making PDD inputs a dataset instead, as we know its size is 12

Location:
issm/trunk-jpl
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/analyses/SmbAnalysis.cpp

    r24385 r24579  
    9696                        iomodel->FindConstant(&isfirnwarming,"md.smb.isfirnwarming");
    9797                        iomodel->FetchDataToInput(inputs2,elements,"md.smb.smb_corr",SmbSmbCorrEnum);
    98                         iomodel->FetchDataToInput(inputs2,elements,"md.smb.precipitation",SmbPrecipitationEnum);
    99                         iomodel->FetchDataToInput(inputs2,elements,"md.smb.monthlytemperatures",SmbMonthlytemperaturesEnum);
    10098                        iomodel->FetchDataToInput(inputs2,elements,"md.smb.precipitation_anomaly",SmbPrecipitationsAnomalyEnum);
    10199                        iomodel->FetchDataToInput(inputs2,elements,"md.smb.temperature_anomaly",SmbTemperaturesAnomalyEnum);
     100                        iomodel->FetchDataToDatasetInput(inputs2,elements,"md.smb.monthlytemperatures",SmbMonthlytemperaturesEnum);
     101                        iomodel->FetchDataToDatasetInput(inputs2,elements,"md.smb.precipitation",SmbPrecipitationEnum);
    102102                        break;
    103103                case SMBd18opddEnum:
  • issm/trunk-jpl/src/c/classes/Elements/Element.cpp

    r24561 r24579  
    30303030        IssmDouble mu           = MU_0*(1000.0*86400.0)*(rho_ice/rho_water);   // (d*deg C)/(mm WE) --> (s*deg C)/(m IE)
    30313031
     3032        /*Get inputs*/
     3033        DatasetInput2* dinput =this->GetDatasetInput2(SmbMonthlytemperaturesEnum); _assert_(dinput);
     3034        DatasetInput2* dinput2=this->GetDatasetInput2(SmbPrecipitationEnum);       _assert_(dinput2);
    30323035
    30333036        /*loop over vertices: */
     
    30353038        for(int month=0;month<12;month++){
    30363039
    3037                 /*Recover monthly temperatures and precipitation*/
    3038                 Input2* dinput =this->GetInput2(SmbMonthlytemperaturesEnum,reCast<IssmDouble>(month+1)/12.*yts); _assert_(dinput);
    3039                 Input2* dinput2=this->GetInput2(SmbPrecipitationEnum,reCast<IssmDouble>(month+1)/12.*yts);       _assert_(dinput2);
    3040 
    30413040                for(int iv=0;iv<NUM_VERTICES;iv++){
    30423041                        gauss->GaussVertex(iv);
    3043                         dinput->GetInputValue(&monthlytemperatures[iv*12+month],gauss);
     3042                        dinput->GetInputValue(&monthlytemperatures[iv*12+month],gauss,month);
    30443043                        monthlytemperatures[iv*12+month]=monthlytemperatures[iv*12+month]-273.15; // conversion from Kelvin to celcius for PDD module
    3045                         dinput2->GetInputValue(&monthlyprec[iv*12+month],gauss);
     3044                        dinput2->GetInputValue(&monthlyprec[iv*12+month],gauss,month);
    30463045                        monthlyprec[iv*12+month]=monthlyprec[iv*12+month]*yts;
    30473046                }
  • issm/trunk-jpl/src/c/classes/Elements/Tria.cpp

    r24578 r24579  
    233233
    234234        /*Intermediaries*/
     235        int        vertexsids[NUMVERTICES];
     236        int        vertexlids[NUMVERTICES];
    235237        IssmDouble nodeinputs[NUMVERTICES];
    236         int        vertexlids[NUMVERTICES];
    237238
    238239        /*Some sanity checks*/
     
    244245        _assert_(iomodel->elements);
    245246        for(int i=0;i<NUMVERTICES;i++){
    246                 int vertexid =reCast<int>(iomodel->elements[NUMVERTICES*this->Sid()+i]); //ids for vertices are in the elements array from Matlab
    247 
    248                 vertexlids[i]=iomodel->my_vertices_lids[vertexid-1];
    249                 nodeinputs[i]=array[vertexid*N+i];
     247                vertexsids[i] = reCast<int>(iomodel->elements[NUMVERTICES*this->Sid()+i])-1;
     248                vertexlids[i] = iomodel->my_vertices_lids[vertexsids[i]];
    250249        }
    251250
    252251        /*Create inputs and add to DataSetInput*/
    253252        for(int i=0;i<num_inputs;i++){
    254                 this->inputs2->SetTriaDatasetInput(input_enum,individual_enums[i],P1Enum,NUMVERTICES,vertexlids,nodeinputs); break;
     253                for(int j=0;j<NUMVERTICES;j++) nodeinputs[j]=array[vertexsids[j]*N+i];
     254                inputs2->SetTriaDatasetInput(input_enum,individual_enums[i],P1Enum,NUMVERTICES,vertexlids,nodeinputs);
    255255        }
    256256}
  • issm/trunk-jpl/src/c/classes/Inputs2/DatasetInput2.cpp

    r24335 r24579  
    207207        if(index == -1){
    208208                this->Echo();
    209                 _error_("Could not find input "<<id<<" ("<<EnumToStringx(id)<<") in DatasetInput");
     209                _error_("Could not find input "<<id<<" ("<<EnumToStringx(id)<<"?) in DatasetInput");
    210210        }
    211211
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r24335 r24579  
    16631663        int         integer;
    16641664        IssmDouble  scalar;
    1665         char       *string           = NULL;
    16661665        IssmDouble *doublearray = NULL;
    16671666        int         M,N;
     
    17231722        /*Free ressources*/
    17241723        xDelete<IssmDouble>(doublearray);
    1725         xDelete<char>(string);
     1724}
     1725/*}}}*/
     1726void  IoModel::FetchDataToDatasetInput(Inputs2* inputs2,Elements* elements,const char* vector_name,int input_enum){/*{{{*/
     1727
     1728        /*First, look whether it is not already loaded in this->data*/
     1729        vector<IoData*>::iterator iter;
     1730        for(iter=data.begin();iter<data.end();iter++){
     1731                IoData* iodata=*iter;
     1732                if(strcmp(iodata->name,vector_name)==0){
     1733                        for(int i=0;i<elements->Size();i++){
     1734                                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     1735                                _error_("to be implemented...");
     1736                                //element->InputCreate(iodata->data,inputs2,this,iodata->M,iodata->N,iodata->layout,input_enum,iodata->code);//we need i to index into elements.
     1737                        }
     1738                        return;
     1739                }
     1740        }
     1741
     1742        /*intermediary: */
     1743        int         code,vector_layout;
     1744        IssmDouble *doublearray = NULL;
     1745        int         M,N;
     1746
     1747        /*First of, find the record for the name, and get code  of data type: */
     1748        this->SetFilePointerToData(&code,&vector_layout,vector_name);
     1749
     1750        switch(code){
     1751                case 1: //boolean constant
     1752                        _error_("not implemented yet");
     1753                        break;
     1754                case 2: //integer constant
     1755                        _error_("not implemented yet");
     1756                        break;
     1757                case 3: //IssmDouble constant
     1758                        _error_("not implemented yet");
     1759                        break;
     1760                case 5: //boolean vector
     1761                        _error_("not implemented yet");
     1762                        break;
     1763                case 6: //int vector
     1764                        _error_("not implemented yet");
     1765                        break;
     1766                case 7: //IssmDouble vector
     1767                          {
     1768                        this->FetchData(&doublearray,&M,&N,vector_name);
     1769                        if(!doublearray) _error_("\""<<vector_name<<"\" not found in binary file");
     1770
     1771                        int* ids = xNew<int>(N);
     1772                        for(int i=0;i<N;i++) ids[i] = i;
     1773
     1774                        for(int i=0;i<elements->Size();i++){
     1775                                Element* element=xDynamicCast<Element*>(elements->GetObjectByOffset(i));
     1776                                element->DatasetInputCreate(doublearray,M,N,ids,N,inputs2,this,input_enum);
     1777                        }
     1778                        xDelete<int>(ids);
     1779                          }
     1780                        break;
     1781                default:
     1782                        _error_("data code " << code << " not supported yet (detected while processing \""<<vector_name<<"\")");
     1783                        break;
     1784        }
     1785        /*Free ressources*/
     1786        xDelete<IssmDouble>(doublearray);
    17261787}
    17271788/*}}}*/
  • issm/trunk-jpl/src/c/classes/IoModel.h

    r24459 r24579  
    141141                void        FetchDataToInput(Inputs2* inputs2,Elements* elements,const char* vector_name,int input_enum);
    142142                void        FetchDataToInput(Inputs2* inputs2,Elements* elements,const char* vector_name,int input_enum,IssmDouble default_value);
     143                void        FetchDataToDatasetInput(Inputs2* inputs2,Elements* elements,const char* vector_name,int input_enum);
    143144                void        FetchIndependent(const char* dependent_name);
    144145                void        FetchMultipleData(char***   pstringarray,int* pnumstrings,const char* data_name);
  • issm/trunk-jpl/test/NightlyRun/test245.m

    r23317 r24579  
    1818for imonth=0:11
    1919    md.smb.monthlytemperatures(1:md.mesh.numberofvertices,imonth+1)=md.materials.meltingpoint+temp_ma_present+(temp_mj_present-temp_ma_present)*sin(double(imonth+1-4)*pi/6.0);
    20     md.smb.monthlytemperatures(md.mesh.numberofvertices+1,imonth+1)=((imonth+1)/12);
    2120    md.smb.precipitation(1:md.mesh.numberofvertices,imonth+1)=precipitation;
    22     md.smb.precipitation(md.mesh.numberofvertices+1,imonth+1)=((imonth+1)/12);
    2321end
    2422
  • issm/trunk-jpl/test/NightlyRun/test245.py

    r24261 r24579  
    3030for imonth in range(12):
    3131    md.smb.monthlytemperatures[0:md.mesh.numberofvertices, imonth] = md.materials.meltingpoint + temp_ma_present + (temp_mj_present - temp_ma_present) * np.sin((imonth + 1. - 4.) * np.pi / 6.0)
    32     md.smb.monthlytemperatures[md.mesh.numberofvertices, imonth] = ((imonth + 1) / 12.)
    3332    md.smb.precipitation[0:md.mesh.numberofvertices, imonth] = precipitation
    34     md.smb.precipitation[md.mesh.numberofvertices, imonth] = ((imonth + 1) / 12.)
    3533
    3634# time steps and resolution
Note: See TracChangeset for help on using the changeset viewer.