Changeset 25024


Ignore:
Timestamp:
06/12/20 08:22:16 (5 years ago)
Author:
bdef
Message:

CHG:moving averaging on inputs and modification on 905 test

Location:
issm/trunk-jpl
Files:
14 edited

Legend:

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

    r24933 r25024  
    299299        /*Intermediaries */
    300300        int        smb_model;
     301        int        smb_averaging;
     302        int        smbsubstepping;
     303        int        hydrologysubstepping;
    301304        IssmDouble dt,scalar,water_head;
    302305        IssmDouble water_load,transfer,runoff_value;
     
    307310        IssmDouble *xyz_list             = NULL;
    308311        Input2     *old_wh_input         = NULL;
     312        Input2     *dummy_input          = NULL;
    309313        Input2     *surface_runoff_input = NULL;
    310314
     
    321325        basalelement->FindParam(&dt,TimesteppingTimeStepEnum);
    322326        basalelement ->FindParam(&smb_model,SmbEnum);
     327        basalelement->FindParam(&smb_averaging,SmbAveragingEnum);
    323328
    324329        Input2* epl_thick_input  = basalelement->GetInput2(HydrologydcEplThicknessSubstepEnum); _assert_(epl_thick_input);
     
    329334        Input2* base_input       = basalelement->GetInput2(BaseEnum); _assert_(base_input);
    330335
     336        IssmDouble time;
     337        basalelement->FindParam(&time,TimeEnum);
     338
    331339        if(dt!= 0.){
    332340                old_wh_input = basalelement->GetInput2(EplHeadOldEnum);            _assert_(old_wh_input);
    333341        }
    334342        if(smb_model==SMBgradientscomponentsEnum){
    335                 surface_runoff_input = basalelement->GetInput2(SmbRunoffEnum); _assert_(surface_runoff_input);
     343                basalelement->FindParam(&smbsubstepping,SmbStepsPerStepEnum);
     344                basalelement->FindParam(&hydrologysubstepping,HydrologyStepsPerStepEnum);
     345
     346                if(smbsubstepping==1){
     347                        //no substeping for the smb we take the result from there
     348                        dummy_input = basalelement->GetInput2(SmbRunoffEnum); _assert_(dummy_input);
     349                }
     350                else if(smbsubstepping>1 && smbsubstepping<=hydrologysubstepping){
     351                        //finer hydro stepping, we take the value at the needed time
     352                        dummy_input = basalelement->GetInput2(SmbRunoffTransientEnum, time); _assert_(dummy_input);
     353                }
     354                else{
     355                        //finer stepping in smb, we average the runoff from transient input
     356                        dummy_input = basalelement->GetInput2(SmbRunoffTransientEnum,time-dt,time,smb_averaging); _assert_(dummy_input);
     357                }
     358                surface_runoff_input=xDynamicCast<Input2*>(dummy_input); _assert_(surface_runoff_input);
    336359        }
    337360
  • issm/trunk-jpl/src/c/analyses/HydrologyDCInefficientAnalysis.cpp

    r24933 r25024  
    375375        basalelement->FindParam(&time,TimeEnum);
    376376
    377 
    378377        if(dt!= 0.){
    379378                old_wh_input = basalelement->GetInput2(SedimentHeadOldEnum); _assert_(old_wh_input);
     
    384383
    385384                if(smbsubstepping==1){
     385                        //no substeping for the smb we take the result from there
    386386                        dummy_input = basalelement->GetInput2(SmbRunoffEnum); _assert_(dummy_input);
    387387                }
    388388                else if(smbsubstepping>1 && smbsubstepping<=hydrologysubstepping){
     389                        //finer hydro stepping, we take the value at the needed time
    389390                        dummy_input = basalelement->GetInput2(SmbRunoffTransientEnum, time); _assert_(dummy_input);
    390391                }
    391392                else{
     393                        //finer stepping in smb, we average the runoff from transient input
    392394                        dummy_input = basalelement->GetInput2(SmbRunoffTransientEnum,time-dt,time,smb_averaging); _assert_(dummy_input);
    393395                }
  • issm/trunk-jpl/src/c/classes/Elements/Penta.cpp

    r24933 r25024  
    10091009/*}}}*/
    10101010void       Penta::CreateInputTimeAverage(int transientinput_enum,int averagedinput_enum,IssmDouble start_time,IssmDouble end_time,int averaging_method){/*{{{*/
    1011 
    10121011        _assert_(end_time>start_time);
    10131012
    1014         /*Intermediaries*/
    1015         IssmDouble averaged_values[NUMVERTICES];
    1016         IssmDouble current_values[NUMVERTICES];
    1017         IssmDouble dt;
    1018         int        found,start_offset,end_offset;
    1019 
    10201013        /*Get transient input time steps*/
    1021         int         numtimesteps;
    1022         IssmDouble *timesteps    = NULL;
    10231014        TransientInput2* transient_input  = this->inputs2->GetTransientInput(transientinput_enum);
    1024         transient_input->GetAllTimes(&timesteps,&numtimesteps);
    1025 
    1026         /*go through the timesteps, and grab offset for start and end*/
    1027         found=binary_search(&start_offset,start_time,timesteps,numtimesteps);
    1028         if(!found) _error_("Input not found (is TransientInput sorted ?)");
    1029         found=binary_search(&end_offset,end_time,timesteps,numtimesteps);
    1030         if(!found) _error_("Input not found (is TransientInput sorted ?)");
    1031 
    1032         Gauss* gauss=this->NewGauss();
    1033 
    1034         /*stack the input for each timestep in the slice*/
    1035         int offset = start_offset;
    1036         while(offset < end_offset ){
    1037 
    1038 
    1039                 if(offset==-1){
    1040                         /*get values for the first time: */
    1041                         _assert_(start_time<timesteps[0]);
    1042                         PentaInput2* input = transient_input->GetPentaInput(0);
    1043 
    1044                         int interpolation = input->GetInterpolation();
    1045                         _assert_(interpolation==P1Enum);
    1046                         /*Intermediaries*/
    1047                         int numindices;
    1048                         int indices[NUMVERTICES];
    1049                         numindices = NUMVERTICES;
    1050                         for(int i=0;i<NUMVERTICES;i++) indices[i] = vertices[i]->lid;
    1051                         input->Serve(numindices,&indices[0]);
    1052 
    1053                         for(int iv=0;iv<NUMVERTICES;iv++){
    1054                                 gauss->GaussVertex(iv);
    1055                                 input->GetInputValue(&current_values[iv],gauss);
    1056                         }
    1057                         dt = timesteps[0] - start_time; _assert_(dt>0.);
    1058                 }
    1059                 else{
    1060                         PentaInput2* input = transient_input->GetPentaInput(offset+1);
    1061                         int interpolation = input->GetInterpolation();
    1062                         _assert_(interpolation==P1Enum);
    1063                         /*Intermediaries*/
    1064                         int numindices;
    1065                         int indices[NUMVERTICES];
    1066                         numindices = NUMVERTICES;
    1067                         for(int i=0;i<NUMVERTICES;i++) indices[i] = vertices[i]->lid;
    1068                         input->Serve(numindices,&indices[0]);
    1069 
    1070                         for(int iv=0;iv<NUMVERTICES;iv++){
    1071                                 gauss->GaussVertex(iv);
    1072                                 input->GetInputValue(&current_values[iv],gauss);
    1073                         }
    1074                         if(offset == numtimesteps-1){
    1075                                 dt = end_time - timesteps[offset]; _assert_(dt>0.);
    1076                         }
    1077                         else{
    1078                                 dt = timesteps[offset+1] - timesteps[offset]; _assert_(dt>0.);
    1079                         }
    1080                 }
    1081 
    1082                 switch(averaging_method){
    1083                         case 0: /*Arithmetic mean*/
    1084                                 if(offset==start_offset){
    1085                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv]  = dt*current_values[iv];
    1086                                 }
    1087                                 else{
    1088                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] += dt*current_values[iv];
    1089                                 }
    1090                                 break;
    1091                         case 1: /*Geometric mean*/
    1092                                 if(offset==start_offset){
    1093                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv]  = dt*current_values[iv];
    1094                                 }
    1095                                 else{
    1096                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] *= dt*current_values[iv];
    1097                                 }
    1098                                 break;
    1099                         case 2: /*Harmonic mean*/
    1100                                 if(offset==start_offset){
    1101                                         for(int iv=0;iv<NUMVERTICES;iv++){
    1102                                                 _assert_(current_values[iv]>1.e-50);
    1103                                                 averaged_values[iv]  = dt*1./current_values[iv];
    1104                                         }
    1105                                 }
    1106                                 else{
    1107                                         for(int iv=0;iv<NUMVERTICES;iv++){
    1108                                                 _assert_(current_values[iv]>1.e-50);
    1109                                                 averaged_values[iv]  += dt*1./current_values[iv];
    1110                                         }
    1111                                 }
    1112                                 break;
    1113                         default:
    1114                                 _error_("averaging method is not recognised");
    1115                 }
    1116 
    1117                 offset+=1;
    1118         }
    1119 
    1120         /*Integration done, now normalize*/
    1121         switch(averaging_method){
    1122                 case 0: //Arithmetic mean
    1123                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] =  averaged_values[iv]/(end_time - start_time);
    1124                         break;
    1125                 case 1: /*Geometric mean*/
    1126                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = pow(averaged_values[iv], 1./(end_time - start_time));
    1127                         break;
    1128                 case 2: /*Harmonic mean*/
    1129                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = 1./(averaged_values[iv]/(end_time - start_time));
    1130                         break;
    1131                 default:
    1132                         _error_("averaging method is not recognised");
    1133         }
    1134 
    1135         this->AddInput2(averagedinput_enum,&averaged_values[0],P1Enum);
    1136 
    1137         /*Cleanup*/
    1138         delete gauss;
    1139         xDelete<IssmDouble>(timesteps);
     1015        PentaInput2* averaged_input = transient_input->GetPentaInput(start_time,end_time,averaging_method);
     1016        Input2* averaged_copy = averaged_input->copy();
     1017
     1018        averaged_input->ChangeEnum(averagedinput_enum);
     1019        this->inputs2->AddInput(averaged_copy);
    11401020}
    11411021/*}}}*/
  • issm/trunk-jpl/src/c/classes/Elements/Tria.cpp

    r24980 r25024  
    914914}
    915915/*}}}*/
    916 void                        Tria::ComputeEsaStrainAndVorticity(){ /*{{{*/
     916void         Tria::ComputeEsaStrainAndVorticity(){ /*{{{*/
    917917
    918918        IssmDouble  xyz_list[NUMVERTICES][3];
     
    19181918        /*Get Input from dataset*/
    19191919        if(this->iscollapsed){
    1920                 _error_("Get Average input not implemented in Penta yet");
     1920                PentaInput2* input = this->inputs2->GetPentaInput(inputenum,start_time,end_time,averaging_method);
     1921                if(!input) return input;
     1922
     1923                this->InputServe(input);
     1924                return input;
    19211925        }
    19221926        else{
     
    21142118        _assert_(end_time>start_time);
    21152119
    2116         /*Intermediaries*/
    2117         IssmDouble averaged_values[NUMVERTICES];
    2118         IssmDouble current_values[NUMVERTICES];
    2119         IssmDouble dt;
    2120         int        found,start_offset,end_offset;
    2121 
    21222120        /*Get transient input time steps*/
    2123         int         numtimesteps;
    2124         IssmDouble *timesteps    = NULL;
    21252121        TransientInput2* transient_input  = this->inputs2->GetTransientInput(transientinput_enum);
    2126         transient_input->GetAllTimes(&timesteps,&numtimesteps);
    2127 
    2128         /*go through the timesteps, and grab offset for start and end*/
    2129         found=binary_search(&start_offset,start_time,timesteps,numtimesteps);
    2130         if(!found) _error_("Input not found (is TransientInput sorted ?)");
    2131         found=binary_search(&end_offset,end_time,timesteps,numtimesteps);
    2132         if(!found) _error_("Input not found (is TransientInput sorted ?)");
    2133 
    2134         Gauss* gauss=this->NewGauss();
    2135 
    2136         /*stack the input for each timestep in the slice*/
    2137         int offset = start_offset;
    2138         while(offset < end_offset ){
    2139                 if(offset==-1){
    2140                         /*get values for the first time: */
    2141                         _assert_(start_time<timesteps[0]);
    2142                         TriaInput2* input = transient_input->GetTriaInput(0);
    2143                         _assert_(input->GetInterpolation()==P1Enum);
    2144                         this->InputServe(input);
    2145                         for(int iv=0;iv<NUMVERTICES;iv++){
    2146                                 gauss->GaussVertex(iv);
    2147                                 input->GetInputValue(&current_values[iv],gauss);
    2148                         }
    2149                         dt = timesteps[0] - start_time; _assert_(dt>0.);
    2150                 }
    2151                 else{
    2152                         TriaInput2* input = transient_input->GetTriaInput(offset+1);
    2153                         _assert_(input->GetInterpolation()==P1Enum);
    2154                         this->InputServe(input);
    2155                         for(int iv=0;iv<NUMVERTICES;iv++){
    2156                                 gauss->GaussVertex(iv);
    2157                                 input->GetInputValue(&current_values[iv],gauss);
    2158                         }
    2159                         if(offset == numtimesteps-1){
    2160                                 dt = end_time - timesteps[offset]; _assert_(dt>0.);
    2161                         }
    2162                         else{
    2163                                 dt = timesteps[offset+1] - timesteps[offset]; _assert_(dt>0.);
    2164                         }
    2165                 }
    2166 
    2167                 switch(averaging_method){
    2168                         case 0: /*Arithmetic mean*/
    2169                                 if(offset==start_offset){
    2170                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv]  = dt*current_values[iv];
    2171                                 }
    2172                                 else{
    2173                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] += dt*current_values[iv];
    2174                                 }
    2175                                 break;
    2176                         case 1: /*Geometric mean*/
    2177                                 if(offset==start_offset){
    2178                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv]  = dt*current_values[iv];
    2179                                 }
    2180                                 else{
    2181                                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] *= dt*current_values[iv];
    2182                                 }
    2183                                 break;
    2184                         case 2: /*Harmonic mean*/
    2185                                 if(offset==start_offset){
    2186                                         for(int iv=0;iv<NUMVERTICES;iv++){
    2187                                                 _assert_(current_values[iv]>1.e-50);
    2188                                                 averaged_values[iv]  = dt*1./current_values[iv];
    2189                                         }
    2190                                 }
    2191                                 else{
    2192                                         for(int iv=0;iv<NUMVERTICES;iv++){
    2193                                                 _assert_(current_values[iv]>1.e-50);
    2194                                                 averaged_values[iv]  += dt*1./current_values[iv];
    2195                                         }
    2196                                 }
    2197                                 break;
    2198                         default:
    2199                                 _error_("averaging method is not recognised");
    2200                 }
    2201 
    2202                 offset+=1;
    2203         }
    2204 
    2205         /*Integration done, now normalize*/
    2206         switch(averaging_method){
    2207                 case 0: //Arithmetic mean
    2208                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] =  averaged_values[iv]/(end_time - start_time);
    2209                         break;
    2210                 case 1: /*Geometric mean*/
    2211                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = pow(averaged_values[iv], 1./(end_time - start_time));
    2212                         break;
    2213                 case 2: /*Harmonic mean*/
    2214                         for(int iv=0;iv<NUMVERTICES;iv++) averaged_values[iv] = (end_time - start_time)/averaged_values[iv];
    2215                         break;
    2216                 default:
    2217                         _error_("averaging method is not recognised");
    2218         }
    2219 
    2220         this->AddInput2(averagedinput_enum,&averaged_values[0],P1Enum);
    2221 
    2222         /*Cleanup*/
    2223         delete gauss;
    2224         xDelete<IssmDouble>(timesteps);
     2122        TriaInput2* averaged_input = transient_input->GetTriaInput(start_time,end_time,averaging_method);
     2123        Input2* averaged_copy = averaged_input->copy();
     2124
     2125        averaged_copy->ChangeEnum(averagedinput_enum);
     2126        this->inputs2->AddInput(averaged_copy);
    22252127}
    22262128/*}}}*/
     
    53295231        rho_ice=FindParam(MaterialsRhoIceEnum);
    53305232        rho_earth=FindParam(MaterialsEarthDensityEnum);
    5331        
     5233
    53325234        /*recover earth area: */
    53335235        this->parameters->FindParam(&planetarea,SealevelPlanetAreaEnum);
     
    53565258        }
    53575259
    5358         // correction at the north pole: given longitude of the North pole a definition 
     5260        // correction at the north pole: given longitude of the North pole a definition
    53595261        // closer to the other two vertices.
    53605262        if(llr_list[0][0]==0)llr_list[0][1]=(llr_list[1][1]+llr_list[2][1])/2.0;
     
    53625264        if(llr_list[2][0]==0)llr_list[2][1]=(llr_list[0][1]+llr_list[1][1])/2.0;
    53635265
    5364         // correction at the north pole: given longitude of the North pole a definition 
     5266        // correction at the north pole: given longitude of the North pole a definition
    53655267        // closer to the other two vertices.
    53665268        if(llr_list[0][0]==180)llr_list[0][1]=(llr_list[1][1]+llr_list[2][1])/2.0;
     
    55695471        masks->isiceonly[this->lid]=this->IsIceOnlyInElement();
    55705472        masks->isoceanin[this->lid]=this->IsOceanInElement();
    5571        
     5473
    55725474        /*are we fully floating:*/
    55735475        Input2* gr_input=this->GetInput2(MaskOceanLevelsetEnum); _assert_(gr_input);
     
    55955497        IssmDouble x_element,y_element,z_element,x,y,z,dx,dy,dz,N_azim,E_azim;
    55965498
    5597         #ifdef _HAVE_RESTRICT_ 
     5499        #ifdef _HAVE_RESTRICT_
    55985500        IssmDouble* __restrict__ G=NULL;
    55995501        IssmDouble* __restrict__ GU=NULL;
     
    56165518        IssmDouble* indices=NULL;
    56175519        #endif
    5618  
     5520
    56195521        /*elastic green function:*/
    56205522        int index;
     
    56565558                GE=xNewZeroInit<IssmDouble>(gsize);
    56575559        }
    5658        
     5560
    56595561        /*compute area:*/
    56605562        area=GetAreaSpherical();
     
    56765578
    56775579        constant=3/rho_earth*area/planetarea;
    5678        
     5580
    56795581        for(int i=0;i<gsize;i++){
    56805582                IssmDouble alpha;
     
    56875589                indices[i]=alpha/PI*reCast<IssmDouble,int>(M-1);
    56885590                index=reCast<int,IssmDouble>(indices[i]);
    5689                
     5591
    56905592                /*Rigid earth gravitational perturbation: */
    56915593                if(computerigid){
     
    56955597                        G[i]+=G_elastic_precomputed[index];
    56965598                }
    5697                 G[i]=G[i]*constant; 
     5599                G[i]=G[i]*constant;
    56985600
    56995601                /*Elastic components:*/
     
    57285630
    57295631        /*Free allocations:*/
    5730         #ifdef _HAVE_RESTRICT_ 
    5731         delete indices; 
    5732         delete G; 
    5733         delete GU; 
     5632        #ifdef _HAVE_RESTRICT_
     5633        delete indices;
     5634        delete G;
     5635        delete GU;
    57345636        if(horiz){
    5735                 delete GN; 
     5637                delete GN;
    57365638                delete GE;
    57375639        }
     
    57525654
    57535655        int bp_compute_fingerprints= 0;
    5754                
     5656
    57555657        /*Compute bottom pressure contribution from ocean if requested:*/
    57565658        this->parameters->FindParam(&bp_compute_fingerprints,DslComputeFingerprintsEnum);
     
    57955697        /*early return if we are fully floating:*/
    57965698        if (masks->isfullyfloating[this->lid]){
    5797                 constant=0; 
     5699                constant=0;
    57985700                #ifdef _ISSM_DEBUG_
    57995701                this->AddInput2(SealevelEustaticMaskEnum,&constant,P0Enum);
    5800                 #endif 
     5702                #endif
    58015703                *peustatic=0; //do not forget to assign this pointer, otherwise, global eustatic will be garbage!
    58025704                return;
     
    58055707        /*If we are here, we are on ice that is fully grounded or half-way to floating:*/
    58065708        if (masks->notfullygrounded[this->lid]) notfullygrounded=true; //used later on.
    5807    
     5709
    58085710        /*Inform mask: */
    5809         constant=1; 
     5711        constant=1;
    58105712        #ifdef _ISSM_DEBUG_
    58115713        this->AddInput2(SealevelEustaticMaskEnum,&constant,P0Enum);
     
    58205722
    58215723        /*retrieve precomputed G:*/
    5822         this->inputs2->GetArrayPtr(SealevelriseGEnum,this->lid,&G,&gsize); 
     5724        this->inputs2->GetArrayPtr(SealevelriseGEnum,this->lid,&G,&gsize);
    58235725
    58245726        /*Get area of element: precomputed in the sealevelrise_core_geometry:*/
     
    58265728
    58275729        /*Compute fraction of the element that is grounded: */
    5828         if(notfullygrounded){ 
     5730        if(notfullygrounded){
    58295731                IssmDouble xyz_list[NUMVERTICES][3];
    58305732                ::GetVerticesCoordinates(&xyz_list[0][0],vertices,NUMVERTICES);
    58315733
    58325734                phi=this->GetGroundedPortion(&xyz_list[0][0]); //watch out, this only works because of the Thales theorem! We are in 3D, but this routine is inherently for 2D trias
    5833         } 
     5735        }
    58345736        else phi=1.0;
    58355737
     
    58925794        /*elastic green function:*/
    58935795        IssmDouble* G=NULL;
    5894        
     5796
    58955797        /*water properties: */
    58965798        IssmDouble rho_water;
     
    59085810
    59095811        /*retrieve precomputed G:*/
    5910         this->inputs2->GetArrayPtr(SealevelriseGEnum,this->lid,&G,&gsize); 
     5812        this->inputs2->GetArrayPtr(SealevelriseGEnum,this->lid,&G,&gsize);
    59115813
    59125814        /*Get area of element: precomputed in the sealevelrise_core_geometry:*/
     
    59435845        /*early return if we are not on the ocean:*/
    59445846        if (!masks->isoceanin[this->lid]){
    5945                 constant=0; 
    5946                 #ifdef _ISSM_DEBUG_ 
     5847                constant=0;
     5848                #ifdef _ISSM_DEBUG_
    59475849                this->AddInput2(SealevelEustaticOceanMaskEnum,&constant,P0Enum);
    59485850                #endif
    59495851                return;
    59505852        }
    5951         constant=1; 
    5952         #ifdef _ISSM_DEBUG_ 
     5853        constant=1;
     5854        #ifdef _ISSM_DEBUG_
    59535855        this->AddInput2(SealevelEustaticOceanMaskEnum,&constant,P0Enum);
    59545856        #endif
     
    59565858        /*how many dofs are we working with here? */
    59575859        this->parameters->FindParam(&gsize,MeshNumberofverticesEnum);
    5958        
     5860
    59595861        /*retrieve precomputed G:*/
    59605862        this->inputs2->GetArrayPtr(SealevelriseGEnum,this->lid,&G,&dummy); _assert_(dummy==gsize);
     
    60045906
    60055907        /*recover elastic Green's functions for displacement:*/
    6006         this->inputs2->GetArrayPtr(SealevelriseGUEnum,this->lid,&GU,&gsize); 
     5908        this->inputs2->GetArrayPtr(SealevelriseGUEnum,this->lid,&GU,&gsize);
    60075909        if(horiz){
    6008                 this->inputs2->GetArrayPtr(SealevelriseGEEnum,this->lid,&GE,&gsize); 
    6009                 this->inputs2->GetArrayPtr(SealevelriseGNEnum,this->lid,&GN,&gsize); 
     5910                this->inputs2->GetArrayPtr(SealevelriseGEEnum,this->lid,&GE,&gsize);
     5911                this->inputs2->GetArrayPtr(SealevelriseGNEnum,this->lid,&GN,&gsize);
    60105912        }
    60115913
  • issm/trunk-jpl/src/c/classes/Inputs2/Inputs2.cpp

    r24935 r25024  
    388388        }
    389389}/*}}}*/
     390PentaInput2* Inputs2::GetPentaInput(int enum_in,IssmDouble start_time,IssmDouble end_time,int averaging_method){/*{{{*/
     391
     392        /*Get input id*/
     393        int id = EnumToIndex(enum_in);
     394
     395        /*Check that it has the right format*/
     396        Input2* input = this->inputs[id];
     397        if(!input) return NULL;
     398
     399        if(input->ObjectEnum()==TransientInput2Enum){
     400                return xDynamicCast<TransientInput2*>(input)->GetPentaInput(start_time,end_time,averaging_method);
     401        }
     402        else{
     403                _error_("Input "<<EnumToStringx(enum_in)<<" is not an TransientInput2");
     404        }
     405}/*}}}*/
    390406TransientInput2* Inputs2::GetTransientInput(int enum_in){/*{{{*/
    391407
  • issm/trunk-jpl/src/c/classes/Inputs2/Inputs2.h

    r24935 r25024  
    5858                PentaInput2*     GetPentaInput(int enum_type);
    5959                PentaInput2*     GetPentaInput(int enum_type,IssmDouble time);
     60                PentaInput2*     GetPentaInput(int enum_in,IssmDouble start_time,IssmDouble end_time,int averaging_method);
    6061                TransientInput2* GetTransientInput(int enum_type);
    6162                ElementInput2*   GetControlInput2Data(int enum_type,const char* data);
  • issm/trunk-jpl/src/c/classes/Inputs2/TransientInput2.cpp

    r24791 r25024  
    355355}
    356356/*}}}*/
     357PentaInput2* TransientInput2::GetPentaInput(IssmDouble start_time, IssmDouble end_time, int averaging_method){/*{{{*/
     358
     359        /*Set current time input*/
     360        this->SetAverageAsCurrentTimeInput(start_time,end_time,averaging_method);
     361        _assert_(this->current_input);
     362
     363        /*Cast and return*/
     364        if(this->current_input->ObjectEnum()!=PentaInput2Enum){
     365                _error_("Cannot return a PentaInput2");
     366        }
     367        return xDynamicCast<PentaInput2*>(this->current_input);
     368
     369}
     370/*}}}*/
     371
    357372void TransientInput2::SetCurrentTimeInput(IssmDouble time){/*{{{*/
    358373
     
    404419
    405420                /*If already processed return*/
    406                 if(this->current_step>this_step-1.e-5 && this->current_step<this_step+1.e-5) return;
     421                if(abs(this->current_step-this_step)<1.e-5) return;
     422                //              if(this->current_step>this_step-1.e-5 && this->current_step<this_step+1.e-5) return;
    407423
    408424                /*Prepare input*/
     
    424440
    425441        IssmDouble  dt,durinv;
    426         IssmPDouble eps=1.0e-6;
    427442        IssmDouble  dtsum=0;
    428         int         found,start_offset,end_offset;
     443        IssmDouble  timespan,mid_step;
     444        int         found,start_offset,end_offset,input_offset;
    429445
    430446        /*go through the timesteps, and grab offset for start and end*/
    431         IssmDouble temp = start_time-eps;
    432         found=binary_search(&start_offset,temp,this->timesteps,this->numtimesteps);
     447        found=binary_search(&start_offset,start_time,this->timesteps,this->numtimesteps);
    433448        if(!found) _error_("Input not found (is TransientInput sorted ?)");
    434         temp = end_time+eps;
    435         found=binary_search(&end_offset,temp,this->timesteps,this->numtimesteps);
     449        found=binary_search(&end_offset,end_time,this->timesteps,this->numtimesteps);
    436450        if(!found) _error_("Input not found (is TransientInput sorted ?)");
    437451
     452        if(start_offset==-1){
     453                timespan=this->timesteps[end_offset]-start_time;
     454        }
     455        else{
     456                timespan=this->timesteps[end_offset]-this->timesteps[start_offset];
     457        }
     458        mid_step=reCast<IssmDouble>(start_offset)+0.5*timespan;
     459
     460        /*If already processed return, we set step in the middle of the interval*/
     461        if(abs(this->current_step-mid_step)<1.e-5) return;
     462        /*If not processed set current_step*/
     463        if(this->current_input) delete this->current_input;
     464        this->current_step = mid_step;
     465
    438466        int offset=start_offset;
    439         if(this->current_input) delete this->current_input;
    440467        while(offset < end_offset){
    441                 if (offset==-1){
    442                         dt=this->timesteps[0]-start_time;
    443                         _assert_(start_time<this->timesteps[0]);
    444                 }
    445                 else if(offset==this->numtimesteps-1)dt=end_time-this->timesteps[offset];
    446                 else if(offset==start_offset && this->timesteps[offset]<start_time) dt=this->timesteps[offset+1]-start_time;
    447                 else if(offset==end_offset && this->timesteps[offset]>end_time) dt=end_time-this->timesteps[offset];
    448                 else dt=this->timesteps[offset+1]-this->timesteps[offset];
    449                 _assert_(dt>0.);
    450 
     468                if(offset==start_offset){
     469                        dt=this->timesteps[offset+1]-start_time;
     470                        _assert_(dt>0.);
     471                        if(offset==end_offset-1){
     472                                dt=end_time-start_time;
     473                                _assert_(dt>0.);
     474                        }
     475                }
     476                else if(offset==end_offset-1){
     477                        dt=end_time-this->timesteps[offset];
     478                        _assert_(dt>0.);
     479                }
     480                else{
     481                        dt=this->timesteps[offset+1]-this->timesteps[offset];
     482                        _assert_(dt>0.);
     483                }
    451484                Input2* stepinput=this->inputs[offset+1];
    452485
     
    454487                        case 0: /*Arithmetic mean*/
    455488                                if(offset==start_offset){
    456                                         this->current_input = stepinput->copy();
     489                                        this->current_input=stepinput->copy();
    457490                                        this->current_input->Scale(dt);
    458491                                }
  • issm/trunk-jpl/src/c/classes/Inputs2/TransientInput2.h

    r24790 r25024  
    5555                PentaInput2* GetPentaInput(IssmDouble time);
    5656                PentaInput2* GetPentaInput(int offset);
     57                PentaInput2* GetPentaInput(IssmDouble start_time,IssmDouble end_time,int averaging_method);
    5758                Input2*      GetTimeInput(IssmDouble time){_error_("This should not happen!");};
    5859                IssmDouble   GetTimeByOffset(int offset);
  • issm/trunk-jpl/src/c/cores/hydrology_core.cpp

    r24816 r25024  
    7676                                substep=0;
    7777                                femmodel->parameters->SetParam(subdt,TimesteppingTimeStepEnum);
     78                                femmodel->parameters->SetParam(subtime,TimeEnum);
    7879
    7980                                /*intermiedaries to deal with averaging*/
     
    119120                                /*averaging the stack*/
    120121                                femmodel->AverageTransientInputx(&transientinput[0],&averagedinput[0],global_time-dt,subtime,numaveragedinput,hydro_averaging);
    121 
    122122                                /*And reseting to global time*/
    123123                                femmodel->parameters->SetParam(dt,TimesteppingTimeStepEnum);
  • issm/trunk-jpl/src/c/modules/InputUpdateFromSolutionx/InputUpdateFromSolutionx.cpp

    r23636 r25024  
    99void InputUpdateFromSolutionx(FemModel* femmodel,Vector<IssmDouble>* solution){
    1010
    11         /*Display message*/
    12         if(VerboseModule()) _printf0_("   Updating inputs from solution\n");
    13 
    1411        /*GetAnalysis*/
    1512        int analysisenum;
    1613        femmodel->parameters->FindParam(&analysisenum,AnalysisTypeEnum);
    1714        Analysis* analysis = EnumToAnalysis(analysisenum);
     15
     16        /*Display message*/
     17        if(VerboseModule()) _printf0_("   Updating inputs from solution for " << EnumToStringx(analysisenum) << "\n");
    1818
    1919        /*Get local vector with both masters and slaves:*/
  • issm/trunk-jpl/src/m/classes/hydrologydc.m

    r24803 r25024  
     1
    12%Hydrologydc class definition
    23%
  • issm/trunk-jpl/test/NightlyRun/test905.m

    r24575 r25024  
    3333
    3434md.hydrology.steps_per_step=5;
    35 md.smb.steps_per_step=7.;
    36 md.timestepping.time_step=2.;
     35md.smb.steps_per_step=10;
     36md.timestepping.time_step=1.;
    3737md.timestepping.final_time=20.0;
    3838
     
    5959             'SedimentWaterHead5','EplWaterHead5','SedimentHeadResidual5',...
    6060             'SedimentWaterHead9','EplWaterHead9','SedimentHeadResidual9',...
    61              'EplWaterHead10','EplWaterHeadSubstep10','SedimentWaterHead10',...
    62              'SedimentWaterHeadSubstep10'}
     61             'EplWaterHead20','EplWaterHeadSubstep20','SedimentWaterHead20',...
     62             'SedimentWaterHeadSubstep20'}
    6363field_tolerances={1e-13,1e-13,1e-13,...
    6464                  1e-13,1e-13,1e-13,...
  • issm/trunk-jpl/test/NightlyRun/test905.py

    r24575 r25024  
    4242md.initialization.epl_thickness = np.ones((md.mesh.numberofvertices))
    4343
     44#try to keep the different steps as common multipliers of eachother
     45#for the sake of precision the values of the model used as input should be on a shorter time-step-
     46#you can plot the results of this test and check how the time stepping is doing (see bellow)
    4447md.hydrology.steps_per_step = 5
    45 md.smb.steps_per_step = 7  #md.hydrology.steps_per_step
    46 md.timestepping.time_step = 2.
     48md.smb.steps_per_step = 10  #md.hydrology.steps_per_step
     49md.timestepping.time_step = 1.
    4750md.timestepping.final_time = 20.0
    4851
    4952smb_step = md.timestepping.time_step / md.smb.steps_per_step
     53hydro_step = md.timestepping.time_step / md.hydrology.steps_per_step
    5054duration = np.arange(md.timestepping.start_time, md.timestepping.final_time + smb_step, smb_step)
    5155
     
    5559md.smb.accugrad = 0.0
    5660
     61#md.smb.runoffref = 9. * ddf * np.ones(np.shape(duration))  #constant input for testing
    5762md.smb.runoffref = 0.9 * duration * ddf
    5863md.smb.runoffref = np.vstack((md.smb.runoffref, duration))
     
    6469
    6570md = solve(md, 'Transient')
    66 
    6771field_names = ['SedimentWaterHead1', 'EplWaterHead1', 'SedimentHeadResidual1',
    6872               'SedimentWaterHead4', 'EplWaterHead4', 'SedimentHeadResidual4',
    6973               'SedimentWaterHead5', 'EplWaterHead5', 'SedimentHeadResidual5',
    7074               'SedimentWaterHead9', 'EplWaterHead9', 'SedimentHeadResidual9',
    71                'EplWaterHead10', 'EplWaterHeadSubstep10', 'SedimentWaterHead10',
    72                'SedimentWaterHeadSubstep10']
     75               'EplWaterHead20', 'EplWaterHeadSubstep20', 'SedimentWaterHead20',
     76               'SedimentWaterHeadSubstep20']
    7377field_tolerances = [1e-13, 1e-13, 1e-13,
    7478                    1e-13, 1e-13, 1e-13,
     
    9397                md.results.TransientSolution[-1].SedimentHead,
    9498                md.results.TransientSolution[-1].SedimentHeadSubstep]
     99
     100
     101#===Stepping and plotting reference
     102# import matplotlib as mpl
     103# import matplotlib.pyplot as plt
     104
     105# agregatedInput = np.zeros(len(md.results.TransientSolution))
     106# agregatedInputSub = np.zeros(len(md.results.TransientSolution))
     107# RefInput = np.zeros(len(md.results.TransientSolution))
     108# RefInputSub = np.zeros(len(md.results.TransientSolution))
     109# Input = np.zeros(len(md.results.TransientSolution))
     110# InputSub = np.zeros(len(md.results.TransientSolution))
     111# SedVol = np.zeros(len(md.results.TransientSolution))
     112# SedVolSub = np.zeros(len(md.results.TransientSolution))
     113# EplVol = np.zeros(len(md.results.TransientSolution))
     114# EplVolSub = np.zeros(len(md.results.TransientSolution))
     115# SmbTimer = np.zeros(len(md.results.TransientSolution))
     116# HydroTimer = np.zeros(len(md.results.TransientSolution))
     117# TimerSub = np.zeros(len(md.results.TransientSolution))
     118# HeadEVol = np.zeros(len(md.results.TransientSolution))
     119# sedstore = md.materials.rho_freshwater * md.constants.g * md.hydrology.sediment_porosity * md.hydrology.sediment_thickness * ((md.hydrology.sediment_compressibility / md.hydrology.sediment_porosity) + md.hydrology.water_compressibility)
     120# eplstore = md.materials.rho_freshwater * md.constants.g * md.hydrology.sediment_porosity * ((md.hydrology.sediment_compressibility / md.hydrology.sediment_porosity) + md.hydrology.water_compressibility)
     121
     122# for i, res in enumerate(md.results.TransientSolution):
     123
     124#     TimerSub[i] = res.time
     125#     RefInputSub[i] = max(0, res.time * 0.9 * ddf + (-6.5e-3 * 1000 * ddf))
     126#     try:
     127#         InputSub[i] = np.nanmean(res.SmbRunoffSubstep)
     128#         SedVolSub[i] = np.nanmean(res.SedimentHeadSubstep) * sedstore
     129#         EplVolSub[i] = np.nanmean(res.EplHeadSubstep) * eplstore * np.nanmean(res.HydrologydcEplThicknessSubstep)
     130#         substep = True
     131#         if i > 0:
     132#             agregatedInputSub[i:] += 0.5 * ((1 + smb_step) * np.nanmean(res.SmbRunoffSubstep) + (1 - smb_step) * np.nanmean(md.results.TransientSolution[i - 1].SmbRunoffSubstep)) * (TimerSub[i] - TimerSub[i - 1])
     133#         else:
     134#             agregatedInputSub[i:] += np.nanmean(res.SmbRunoffSubstep) * TimerSub[i]
     135
     136#     except AttributeError:
     137#         substep = False
     138#     SmbTimer[i] = res.time - (0.5 * md.timestepping.time_step * (1 - smb_step))
     139#     HydroTimer[i] = res.time - (0.5 * md.timestepping.time_step * (1 - hydro_step))
     140
     141#     RefInput[i] = max(0, (SmbTimer[i] * 0.9 * ddf + (-6.5e-3 * 1000 * ddf)))
     142#     Input[i] = np.nanmean(res.SmbRunoff)
     143#     SedVol[i] = np.nanmean(res.SedimentHead) * sedstore
     144#     EplVol[i] = np.nanmean(res.EplHead) * eplstore * np.nanmean(res.HydrologydcEplThickness)
     145#     if i > 0:
     146#         agregatedInput[i:] += 0.5 * ((1 + hydro_step) * np.nanmean(res.SmbRunoff) + (1 - hydro_step) * np.nanmean(md.results.TransientSolution[i - 1].SmbRunoff)) * (SmbTimer[i] - SmbTimer[i - 1])
     147#     else:
     148#         agregatedInput[i:] += np.nanmean(res.SmbRunoff) * SmbTimer[i]
     149
     150
     151# layout, ax = plt.subplots(2, 2, sharex=True, sharey=False, figsize=(10, 10))
     152
     153# DiffTimer = (TimerSub[:-1] + 0.5 * (smb_step + hydro_step))
     154# Indiff = (DiffTimer) * 0.9 * ddf + (-6.5e-3 * 1000 * ddf)
     155# Indiff[np.where(Indiff < 0)] = 0
     156
     157# ax[0, 0].plot(SmbTimer, RefInput - Input, 'g+')
     158# ax[0, 0].plot(DiffTimer, (Indiff - np.diff((SedVol+EplVol)) / md.timestepping.time_step), 'kx')
     159
     160# ax[0, 1].plot(SmbTimer, RefInput, 'm+')
     161# ax[0, 1].plot(SmbTimer, Input, 'g+')
     162# ax[0, 1].plot(DiffTimer, np.diff(SedVol+EplVol) / md.timestepping.time_step, 'r')
     163
     164# ax[1, 0].plot(HydroTimer, (agregatedInput - SedVol - EplVol), 'b+')
     165
     166# ax[1, 1].plot(HydroTimer, SedVol + EplVol, 'r+')
     167# ax[1, 1].plot(SmbTimer, agregatedInput, 'b+')
     168
     169# if substep:
     170#     SubDiffTimer = (SmbTimer[1:])
     171#     SubIndiff = (SubDiffTimer) * 0.9 * ddf + (-6.5e-3 * 1000 * ddf)
     172#     SubIndiff[np.where(SubIndiff < 0)] = 0
     173
     174#     ax[0, 0].plot(TimerSub, RefInputSub - InputSub, 'm')
     175#     ax[0, 0].plot(SubDiffTimer, (SubIndiff - np.diff(SedVolSub + EplVolSub) / md.timestepping.time_step), 'y')
     176
     177#     ax[0, 1].plot(TimerSub, RefInputSub, 'm')
     178#     ax[0, 1].plot(TimerSub, InputSub, 'g')
     179
     180#     ax[1, 0].plot(TimerSub, (agregatedInputSub - SedVolSub - EplVolSub), 'r')
     181
     182#     ax[1, 1].plot(TimerSub, SedVolSub + EplVolSub, 'r')
     183#     ax[1, 1].plot(TimerSub, SedVolSub, 'r', alpha=0.5)
     184#     ax[1, 1].plot(TimerSub, EplVolSub, 'r', alpha=0.5)
     185#     ax[1, 1].plot(TimerSub, agregatedInputSub, 'b')
Note: See TracChangeset for help on using the changeset viewer.