Changeset 24730


Ignore:
Timestamp:
04/23/20 11:14:03 (5 years ago)
Author:
tsantos
Message:

CHG: inserting PVector in the FCT method

Location:
issm/trunk-jpl/src/c/analyses
Files:
2 edited

Legend:

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

    r24713 r24730  
    632632//              _error_("S");
    633633//      }
    634 
     634       
    635635        h=element->CharacteristicLength();
    636636       
     
    936936        /*Intermediaries */
    937937        IssmDouble Jdet,D_scalar;
    938         IssmDouble vx,vy;
     938        IssmDouble vx,vy,dvxdx,dvydy;
    939939        IssmDouble* xyz_list = NULL;
     940        IssmDouble dvx[2],dvy[2];
    940941
    941942        /*Fetch number of nodes and dof for this finite element*/
     
    964965                vxaverage_input->GetInputValue(&vx,gauss);
    965966                vyaverage_input->GetInputValue(&vy,gauss);
     967                vxaverage_input->GetInputDerivativeValue(&dvx[0],xyz_list,gauss);
     968                vyaverage_input->GetInputDerivativeValue(&dvy[0],xyz_list,gauss);
     969                dvxdx=dvx[0];
     970                dvydy=dvy[1];
    966971
    967972                D_scalar = gauss->weight*Jdet;
    968973                for(int i=0;i<numnodes;i++){
    969974                        for(int j=0;j<numnodes;j++){
     975                                /*\phi_i \phi_j \nabla\cdot v*/
     976                                Ke->values[i*numnodes+j] += -D_scalar*basis[i]*basis[j]*(dvxdx+dvydy);
     977                                /*\phi_i v\cdot\nabla\phi_j*/
    970978                                Ke->values[i*numnodes+j] += -D_scalar*(vx*dbasis[0*numnodes+j]*basis[i] + vy*dbasis[1*numnodes+j]*basis[i]);
    971979                        }
     
    10211029        return Me;
    10221030}/*}}}*/
     1031ElementVector* MasstransportAnalysis::CreateFctPVector(Element* element){/*{{{*/
     1032
     1033        /* Check if ice in element */
     1034        if(!element->IsIceInElement()) return NULL;
     1035
     1036        /*Intermediaries */
     1037        int                     stabilization,dim,domaintype;
     1038        int         melt_style,point1;
     1039        bool        mainlyfloating;
     1040        IssmDouble  fraction1,fraction2;
     1041        IssmDouble  Jdet;
     1042        IssmDouble  ms,mb,gmb,fmb;
     1043        IssmDouble  vx,vy,dvxdx,dvydy;
     1044        IssmDouble  dvx[2],dvy[2];
     1045        IssmDouble  gllevelset,phi=1.;
     1046        IssmDouble* xyz_list = NULL;
     1047        Gauss*      gauss     = NULL;
     1048
     1049        /*Get problem dimension*/
     1050        element->FindParam(&domaintype,DomainTypeEnum);
     1051        switch(domaintype){
     1052                case Domain2DverticalEnum:   dim = 1; break;
     1053                case Domain2DhorizontalEnum: dim = 2; break;
     1054                case Domain3DEnum:           dim = 2; break;
     1055                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
     1056        }
     1057         
     1058        /*Fetch number of nodes and dof for this finite element*/
     1059        int numnodes = element->GetNumberOfNodes();
     1060
     1061        /*Initialize Element vector and other vectors*/
     1062        ElementVector* pe    = element->NewElementVector();
     1063        IssmDouble*    basis = xNew<IssmDouble>(numnodes);
     1064        IssmDouble*    dbasis= xNew<IssmDouble>(dim*numnodes);
     1065
     1066        /*Retrieve all inputs and parameters*/
     1067        element->GetVerticesCoordinates(&xyz_list);
     1068        element->FindParam(&melt_style,GroundinglineMeltInterpolationEnum);
     1069        element->FindParam(&stabilization,MasstransportStabilizationEnum);
     1070        Input2* gmb_input        = element->GetInput2(BasalforcingsGroundediceMeltingRateEnum);  _assert_(gmb_input);
     1071        Input2* fmb_input        = element->GetInput2(BasalforcingsFloatingiceMeltingRateEnum);  _assert_(fmb_input);
     1072        Input2* gllevelset_input = element->GetInput2(MaskGroundediceLevelsetEnum);              _assert_(gllevelset_input);
     1073        Input2* ms_input         = element->GetInput2(SmbMassBalanceEnum);                       _assert_(ms_input);
     1074        Input2* vxaverage_input  = element->GetInput2(VxAverageEnum);                                                                           _assert_(vxaverage_input);
     1075        Input2* vyaverage_input  = element->GetInput2(VyAverageEnum);                                                                           _assert_(vyaverage_input);
     1076       
     1077        /*Recover portion of element that is grounded*/
     1078        phi=element->GetGroundedPortion(xyz_list);
     1079        if(melt_style==SubelementMelt2Enum){
     1080                element->GetGroundedPart(&point1,&fraction1,&fraction2,&mainlyfloating);
     1081           gauss = element->NewGauss(point1,fraction1,fraction2,3);
     1082        }
     1083        else{
     1084                gauss = element->NewGauss(3);
     1085        }
     1086
     1087        /* Start  looping on the number of gaussian points: */
     1088        for(int ig=gauss->begin();ig<gauss->end();ig++){
     1089                gauss->GaussPoint(ig);
     1090
     1091                element->JacobianDeterminant(&Jdet,xyz_list,gauss);
     1092                element->NodalFunctions(basis,gauss);
     1093
     1094                ms_input->GetInputValue(&ms,gauss);
     1095                gmb_input->GetInputValue(&gmb,gauss);
     1096                fmb_input->GetInputValue(&fmb,gauss);
     1097                gllevelset_input->GetInputValue(&gllevelset,gauss);
     1098
     1099                if(melt_style==SubelementMelt1Enum){
     1100                        if (phi>0.999999999) mb=gmb;
     1101                        else mb=(1-phi)*fmb+phi*gmb; // phi is the fraction of grounded ice so (1-phi) is floating
     1102                }
     1103                else if(melt_style==SubelementMelt2Enum){
     1104                        if(gllevelset>0.) mb=gmb;
     1105                        else mb=fmb;
     1106                }
     1107                else if(melt_style==NoMeltOnPartiallyFloatingEnum){
     1108                        if (phi<0.00000001) mb=fmb;
     1109                        else mb=gmb;
     1110                }
     1111                else if(melt_style==FullMeltOnPartiallyFloatingEnum){
     1112                        if (phi<0.99999999) mb=fmb;
     1113                        else mb=gmb;
     1114                }
     1115                else  _error_("melt interpolation "<<EnumToStringx(melt_style)<<" not implemented yet");
     1116
     1117                for(int i=0;i<numnodes;i++) pe->values[i]+=Jdet*gauss->weight*(ms-mb)*basis[i];
     1118       
     1119        }
     1120
     1121        /*Clean up and return*/
     1122        xDelete<IssmDouble>(xyz_list);
     1123        xDelete<IssmDouble>(basis);
     1124        xDelete<IssmDouble>(dbasis);
     1125        delete gauss;
     1126        return pe;
     1127}/*}}}*/
    10231128void           MasstransportAnalysis::FctKMatrix(Matrix<IssmDouble>** pKff,Matrix<IssmDouble>** pKfs,FemModel* femmodel){/*{{{*/
    10241129
     
    10491154        }
    10501155}/*}}}*/
     1156void           MasstransportAnalysis::FctPVector(Vector<IssmDouble>** ppf,FemModel* femmodel){/*{{{*/
     1157
     1158        /*Output*/
     1159        Vector<IssmDouble>* pf = NULL;
     1160
     1161        /*Initialize P vector*/
     1162        AllocateSystemMatricesx(NULL,NULL,NULL,&pf,femmodel);
     1163
     1164        /*Create and assemble matrix*/
     1165        for(int i=0;i<femmodel->elements->Size();i++){
     1166                Element*       element = xDynamicCast<Element*>(femmodel->elements->GetObjectByOffset(i));
     1167                ElementVector* pe      = this->CreateFctPVector(element);
     1168                if(pe) pe->AddToGlobal(pf);
     1169                delete pe;
     1170        }
     1171        pf->Assemble();
     1172
     1173        /*Assign output pointer*/
     1174        *ppf=pf;
     1175}/*}}}*/
    10511176void           MasstransportAnalysis::MassMatrix(Matrix<IssmDouble>** pMff,FemModel* femmodel){/*{{{*/
    10521177
  • issm/trunk-jpl/src/c/analyses/MasstransportAnalysis.h

    r24713 r24730  
    3838                ElementMatrix* CreateFctKMatrix(Element* element);
    3939                ElementMatrix* CreateMassMatrix(Element* element);
     40                ElementVector* CreateFctPVector(Element* element);
    4041                void           FctKMatrix(Matrix<IssmDouble>** pKff,Matrix<IssmDouble>** pKfs,FemModel* femmodel);
     42                void                            FctPVector(Vector<IssmDouble>** ppf,FemModel* femmodel);
    4143                void           MassMatrix(Matrix<IssmDouble>** pMff,FemModel* femmodel);
    4244};
Note: See TracChangeset for help on using the changeset viewer.