Changeset 18059


Ignore:
Timestamp:
05/25/14 18:24:32 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: still working on moving gradient to analysis

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

Legend:

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

    r18058 r18059  
    976976
    977977        /*return if floating*/
    978         if(element->IsFloating())return;
     978        if(element->IsFloating()) return;
    979979
    980980        /*Intermediaries*/
     
    10681068}/*}}}*/
    10691069void AdjointHorizAnalysis::GradientJBbarSSA(Element* element,Vector<IssmDouble>* gradient,int control_index){/*{{{*/
    1070         _error_("not implemented yet");
     1070
     1071        /*Intermediaries*/
     1072        int      domaintype,dim;
     1073        Element* basalelement;
     1074
     1075        /*Get basal element*/
     1076        element->FindParam(&domaintype,DomainTypeEnum);
     1077        switch(domaintype){
     1078                case Domain2DhorizontalEnum:
     1079                        basalelement = element;
     1080                        dim          = 2;
     1081                        break;
     1082                case Domain2DverticalEnum:
     1083                        if(!element->IsOnBase()) return;
     1084                        basalelement = element->SpawnBasalElement();
     1085                        dim          = 1;
     1086                        break;
     1087                case Domain3DEnum:
     1088                        if(!element->IsOnBase()) return;
     1089                        basalelement = element->SpawnBasalElement();
     1090                        dim          = 2;
     1091                        break;
     1092                default: _error_("mesh "<<EnumToStringx(domaintype)<<" not supported yet");
     1093        }
     1094
     1095        /*Intermediaries*/
     1096        IssmDouble Jdet,weight;
     1097        IssmDouble thickness,dmudB;
     1098        IssmDouble dvx[3],dvy[3],dadjx[3],dadjy[3];
     1099        IssmDouble *xyz_list= NULL;
     1100
     1101        /*Fetch number of vertices for this finite element*/
     1102        int numvertices = basalelement->GetNumberOfVertices();
     1103
     1104        /*Initialize some vectors*/
     1105        IssmDouble* basis         = xNew<IssmDouble>(numvertices);
     1106        IssmDouble* ge            = xNew<IssmDouble>(numvertices);
     1107        int*        vertexpidlist = xNew<int>(numvertices);
     1108
     1109        /*Retrieve all inputs we will be needing: */
     1110        basalelement->GetVerticesCoordinates(&xyz_list);
     1111        basalelement->GradientIndexing(&vertexpidlist[0],control_index);
     1112        Input* thickness_input = element->GetInput(ThicknessEnum);             _assert_(thickness_input);
     1113        Input* vx_input        = element->GetInput(VxEnum);                    _assert_(vx_input);
     1114        Input* vy_input        = element->GetInput(VyEnum);                    _assert_(vy_input);
     1115        Input* adjointx_input  = element->GetInput(AdjointxEnum);              _assert_(adjointx_input);
     1116        Input* adjointy_input  = element->GetInput(AdjointyEnum);              _assert_(adjointy_input);
     1117        Input* rheologyb_input = element->GetInput(MaterialsRheologyBbarEnum); _assert_(rheologyb_input);
     1118
     1119        /* Start  looping on the number of gaussian points: */
     1120        Gauss* gauss=basalelement->NewGauss(4);
     1121        for(int ig=gauss->begin();ig<gauss->end();ig++){
     1122                gauss->GaussPoint(ig);
     1123
     1124
     1125                thickness_input->GetInputValue(&thickness,gauss);
     1126                vx_input->GetInputDerivativeValue(&dvx[0],xyz_list,gauss);
     1127                vy_input->GetInputDerivativeValue(&dvy[0],xyz_list,gauss);
     1128                adjointx_input->GetInputDerivativeValue(&dadjx[0],xyz_list,gauss);
     1129                adjointy_input->GetInputDerivativeValue(&dadjy[0],xyz_list,gauss);
     1130
     1131                basalelement->dViscositydBSSA(&dmudB,dim,xyz_list,gauss,vx_input,vy_input);
     1132
     1133                basalelement->JacobianDeterminant(&Jdet,xyz_list,gauss);
     1134                basalelement->NodalFunctionsP1(basis,gauss);
     1135
     1136                /*Build gradient vector (actually -dJ/dB): */
     1137                for(int i=0;i<numvertices;i++){
     1138                        ge[i]+=-dmudB*thickness*(
     1139                                                (2*dvx[0]+dvy[1])*2*dadjx[0]+(dvx[1]+dvy[0])*(dadjx[1]+dadjy[0])+(2*dvy[1]+dvx[0])*2*dadjy[1]
     1140                                                )*Jdet*gauss->weight*basis[i];
     1141                        _assert_(!xIsNan<IssmDouble>(ge[i]));
     1142                }
     1143        }
     1144        gradient->SetValues(numvertices,vertexpidlist,ge,ADD_VAL);
     1145
     1146        /*Clean up and return*/
     1147        xDelete<IssmDouble>(xyz_list);
     1148        xDelete<IssmDouble>(basis);
     1149        xDelete<IssmDouble>(ge);
     1150        xDelete<int>(vertexpidlist);
     1151        delete gauss;
     1152        if(domaintype!=Domain2DhorizontalEnum){basalelement->DeleteMaterials(); delete basalelement;};
    10711153}/*}}}*/
    10721154void AdjointHorizAnalysis::GradientJBbarHO(Element* element,Vector<IssmDouble>* gradient,int control_index){/*{{{*/
  • issm/trunk-jpl/src/c/classes/Elements/Element.cpp

    r18058 r18059  
    213213        return divergence;
    214214}/*}}}*/
     215void       Element::dViscositydBSSA(IssmDouble* pdmudB,int dim,IssmDouble* xyz_list,Gauss* gauss,Input* vx_input,Input* vy_input){/*{{{*/
     216
     217        /*Intermediaries*/
     218        IssmDouble dmudB;
     219        IssmDouble epsilon2d[3];/* epsilon=[exx,eyy,exy];    */
     220        IssmDouble epsilon1d;   /* epsilon=[exx];    */
     221        IssmDouble eps_eff;
     222
     223         if(dim==2){
     224                 /* eps_eff^2 = exx^2 + eyy^2 + exy^2 + exx*eyy*/
     225                 this->StrainRateSSA(&epsilon2d[0],xyz_list,gauss,vx_input,vy_input);
     226                 eps_eff = sqrt(epsilon2d[0]*epsilon2d[0] + epsilon2d[1]*epsilon2d[1] + epsilon2d[2]*epsilon2d[2] + epsilon2d[0]*epsilon2d[1]);
     227         }
     228         else{
     229                 /* eps_eff^2 = 1/2 exx^2*/
     230                 this->StrainRateSSA1d(&epsilon1d,xyz_list,gauss,vx_input);
     231                 eps_eff = sqrt(epsilon1d*epsilon1d/2.);
     232         }
     233
     234        /*Get viscosity*/
     235        material->GetViscosity_B(&dmudB,eps_eff);
     236
     237        /*Assign output pointer*/
     238        *pdmudB=dmudB;
     239
     240}
     241/*}}}*/
    215242void       Element::ThermalToEnthalpy(IssmDouble* penthalpy,IssmDouble temperature,IssmDouble waterfraction,IssmDouble pressure){/*{{{*/
    216243        matpar->ThermalToEnthalpy(penthalpy,temperature,waterfraction,pressure);
  • issm/trunk-jpl/src/c/classes/Elements/Element.h

    r18058 r18059  
    6060                void       DeepEcho();
    6161                void       DeleteMaterials(void);
     62                void       dViscositydBSSA(IssmDouble* pdmudB,int dim,IssmDouble* xyz_list,Gauss* gauss,Input* vx_input,Input* vy_input);
    6263                IssmDouble Divergence(void);
    6364                void       ThermalToEnthalpy(IssmDouble* penthalpy,IssmDouble temperature,IssmDouble waterfraction,IssmDouble pressure);
  • issm/trunk-jpl/src/c/classes/Materials/Material.h

    r17926 r18059  
    2626                virtual void       Configure(Elements* elements)=0;
    2727                virtual void       GetViscosity(IssmDouble* pviscosity,IssmDouble epseff)=0;
     28                virtual void       GetViscosity_B(IssmDouble* pviscosity,IssmDouble epseff)=0;
    2829                virtual void       GetViscosityBar(IssmDouble* pviscosity,IssmDouble epseff)=0;
    2930                virtual void       GetViscosityComplement(IssmDouble* pviscosity_complement, IssmDouble* pepsilon)=0;
  • issm/trunk-jpl/src/c/classes/Materials/Matice.cpp

    r17926 r18059  
    284284}
    285285/*}}}*/
     286/*FUNCTION Matice::GetViscosity_B {{{*/
     287void  Matice::GetViscosity_B(IssmDouble* pviscosity,IssmDouble eps_eff){
     288        /*From a string tensor and a material object, return viscosity, using Glen's flow law.
     289          (1-D)
     290          viscosity= -----------------------
     291          2 eps_eff ^[(n-1)/n]
     292
     293          where viscosity is the viscotiy, B the flow law parameter , eps_eff is the effective strain rate
     294          and n the flow law exponent.
     295
     296          If eps_eff = 0 , it means this is the first time SystemMatrices is being run, and we
     297          return 10^14, initial viscosity.
     298          */
     299
     300        /*output: */
     301        IssmDouble viscosity;
     302
     303        /*Intermediary: */
     304        IssmDouble D=0.,n;
     305
     306        /*Get B and n*/
     307        n=GetN(); _assert_(n>0.);
     308        if(this->isdamaged){
     309                D=GetD();
     310                _assert_(D>=0. && D<1.);
     311        }
     312
     313        if (n==1.){
     314                /*Linear Viscous behavior (Newtonian fluid) viscosity=B/2: */
     315                viscosity=(1.-D)/2.;
     316        }
     317        else{
     318
     319                /*if no strain rate, return maximum viscosity*/
     320                if(eps_eff==0.){
     321                        viscosity = 1.e+14/2.;
     322                }
     323
     324                else{
     325                        viscosity=(1.-D)/(2.*pow(eps_eff,(n-1.)/n));
     326                }
     327        }
     328
     329        /*Checks in debugging mode*/
     330        if(viscosity<=0) _error_("Negative viscosity");
     331
     332        /*Return: */
     333        *pviscosity=viscosity;
     334}
     335/*}}}*/
    286336/*FUNCTION Matice::GetViscosityBar {{{*/
    287337void  Matice::GetViscosityBar(IssmDouble* pviscosity,IssmDouble eps_eff){
  • issm/trunk-jpl/src/c/classes/Materials/Matice.h

    r17926 r18059  
    5555                void       SetCurrentConfiguration(Elements* elements,Loads* loads,Nodes* nodes,Vertices* vertices,Materials* materials,Parameters* parameters);
    5656                void       GetViscosity(IssmDouble* pviscosity, IssmDouble eps_eff);
     57                void       GetViscosity_B(IssmDouble* pviscosity, IssmDouble eps_eff);
    5758                void       GetViscosityBar(IssmDouble* pviscosity, IssmDouble eps_eff);
    5859                void       GetViscosityComplement(IssmDouble* pviscosity_complement, IssmDouble* pepsilon);
  • issm/trunk-jpl/src/c/classes/Materials/Matpar.h

    r17926 r18059  
    7676                void       Configure(Elements* elements);
    7777                void       GetViscosity(IssmDouble* pviscosity,IssmDouble eps_eff){_error_("not supported");};
     78                void       GetViscosity_B(IssmDouble* pviscosity,IssmDouble eps_eff){_error_("not supported");};
    7879                void       GetViscosityBar(IssmDouble* pviscosity,IssmDouble eps_eff){_error_("not supported");};
    7980                void       GetViscosityComplement(IssmDouble* pviscosity_complement, IssmDouble* pepsilon){_error_("not supported");};
Note: See TracChangeset for help on using the changeset viewer.