source: issm/oecreview/Archive/11431-11450/ISSM-11447-11448.diff

Last change on this file was 11515, checked in by Eric.Larour, 13 years ago

Oecreview up to 11509

File size: 14.7 KB
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Elements/Tria.cpp

     
    335335        /*Just branch to the correct element stiffness matrix generator, according to the type of analysis we are carrying out: */
    336336        switch(analysis_type){
    337337                #ifdef _HAVE_DIAGNOSTIC_
    338                 case DiagnosticHorizAnalysisEnum: case AdjointHorizAnalysisEnum:
     338                case DiagnosticHorizAnalysisEnum:
    339339                        Ke=CreateKMatrixDiagnosticMacAyeal();
    340340                        break;
     341                case AdjointHorizAnalysisEnum:
     342                        Ke=CreateKMatrixAdjointMacAyeal();
     343                        break;
    341344                case DiagnosticHutterAnalysisEnum:
    342345                        Ke=CreateKMatrixDiagnosticHutter();
    343346                        break;
     
    30623065        return pe;
    30633066}
    30643067/*}}}*/
    3065 /*FUNCTION Tria::CreateJacobianDiagnosticPattyn{{{1*/
     3068/*FUNCTION Tria::CreateJacobianDiagnosticMacayeal{{{1*/
    30663069ElementMatrix* Tria::CreateJacobianDiagnosticMacayeal(void){
    30673070
    30683071        /*Constants*/
     
    38633866                rheologyb_input->GetInputDerivativeValue(&dp[0],&xyz_list[0][0],gauss);
    38643867
    38653868                /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
    3866                 //Jelem+=weight*1/2*(pow(dp[0],2.)+pow(dp[1],2.))*Jdet*gauss->weight;
     3869                Jelem+=weight*1/2*(pow(dp[0],2.)+pow(dp[1],2.))*Jdet*gauss->weight;
    38673870        }
    38683871
    38693872        /*Clean up and return*/
     
    47354738                drag_input->GetInputDerivativeValue(&dp[0],&xyz_list[0][0],gauss);
    47364739
    47374740                /*Tikhonov regularization: J = 1/2 ((dp/dx)^2 + (dp/dy)^2) */
    4738                 //Jelem+=weight*1/2*(pow(dp[0],2.)+pow(dp[1],2.))*Jdet*gauss->weight;
     4741                Jelem+=weight*1/2*(pow(dp[0],2.)+pow(dp[1],2.))*Jdet*gauss->weight;
    47394742        }
    47404743
    47414744        /*Clean up and return*/
     
    47654768        return Ke;
    47664769}
    47674770/*}}}*/
     4771/*FUNCTION Tria::CreateKMatrixAdjointMacAyeal{{{1*/
     4772ElementMatrix* Tria::CreateKMatrixAdjointMacAyeal(void){
     4773
     4774        /*Constants*/
     4775        const int    numdof=NDOF2*NUMVERTICES;
     4776
     4777        /*Intermediaries */
     4778        int        i,j,ig;
     4779        bool       incomplete_adjoint;
     4780        double     xyz_list[NUMVERTICES][3];
     4781        double     Jdet,thickness;
     4782        double     eps1dotdphii,eps1dotdphij;
     4783        double     eps2dotdphii,eps2dotdphij;
     4784        double     mu_prime;
     4785        double     epsilon[3];/* epsilon=[exx,eyy,exy];*/
     4786        double     eps1[2],eps2[2];
     4787        double     phi[NUMVERTICES];
     4788        double     dphi[2][NUMVERTICES];
     4789        GaussTria *gauss=NULL;
     4790
     4791        /*Initialize Jacobian with regular MacAyeal (first part of the Gateau derivative)*/
     4792        parameters->FindParam(&incomplete_adjoint,InversionIncompleteAdjointEnum);
     4793        ElementMatrix* Ke=CreateKMatrixDiagnosticMacAyeal();
     4794        if(incomplete_adjoint) return Ke;
     4795
     4796        /*Retrieve all inputs and parameters*/
     4797        GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
     4798        Input* vx_input=inputs->GetInput(VxEnum);       _assert_(vx_input);
     4799        Input* vy_input=inputs->GetInput(VyEnum);       _assert_(vy_input);
     4800        Input* thickness_input=inputs->GetInput(ThicknessEnum); _assert_(thickness_input);
     4801
     4802        /* Start  looping on the number of gaussian points: */
     4803        gauss=new GaussTria(2);
     4804        for (ig=gauss->begin();ig<gauss->end();ig++){
     4805
     4806                gauss->GaussPoint(ig);
     4807
     4808                GetJacobianDeterminant2d(&Jdet, &xyz_list[0][0],gauss);
     4809                GetNodalFunctionsDerivatives(&dphi[0][0],&xyz_list[0][0],gauss);
     4810
     4811                thickness_input->GetInputValue(&thickness, gauss);
     4812                this->GetStrainRate2d(&epsilon[0],&xyz_list[0][0],gauss,vx_input,vy_input);
     4813                matice->GetViscosity2dDerivativeEpsSquare(&mu_prime,&epsilon[0]);
     4814                eps1[0]=2*epsilon[0]+epsilon[1];   eps2[0]=epsilon[2];
     4815                eps1[1]=epsilon[2];                eps2[1]=epsilon[0]+2*epsilon[1];
     4816
     4817                for(i=0;i<3;i++){
     4818                        for(j=0;j<3;j++){
     4819                                eps1dotdphii=eps1[0]*dphi[0][i]+eps1[1]*dphi[1][i];
     4820                                eps1dotdphij=eps1[0]*dphi[0][j]+eps1[1]*dphi[1][j];
     4821                                eps2dotdphii=eps2[0]*dphi[0][i]+eps2[1]*dphi[1][i];
     4822                                eps2dotdphij=eps2[0]*dphi[0][j]+eps2[1]*dphi[1][j];
     4823
     4824                                Ke->values[6*(2*i+0)+2*j+0]+=gauss->weight*Jdet*2*mu_prime*thickness*eps1dotdphij*eps1dotdphii;
     4825                                Ke->values[6*(2*i+0)+2*j+1]+=gauss->weight*Jdet*2*mu_prime*thickness*eps2dotdphij*eps1dotdphii;
     4826                                Ke->values[6*(2*i+1)+2*j+0]+=gauss->weight*Jdet*2*mu_prime*thickness*eps1dotdphij*eps2dotdphii;
     4827                                Ke->values[6*(2*i+1)+2*j+1]+=gauss->weight*Jdet*2*mu_prime*thickness*eps2dotdphij*eps2dotdphii;
     4828                        }
     4829                }
     4830        }
     4831
     4832        /*Transform Coordinate System*/
     4833        TransformStiffnessMatrixCoord(Ke,nodes,NUMVERTICES,XYEnum);
     4834
     4835        /*Clean up and return*/
     4836        delete gauss;
     4837        //Ke->Transpose();
     4838        return Ke;
     4839}
     4840/*}}}*/
    47684841/*FUNCTION Tria::InputUpdateFromSolutionAdjointHoriz {{{1*/
    47694842void  Tria::InputUpdateFromSolutionAdjointHoriz(double* solution){
    47704843
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Elements/Tria.h

     
    216216
    217217                #ifdef _HAVE_CONTROL_
    218218                ElementMatrix* CreateKMatrixAdjointBalancethickness(void);
     219                ElementMatrix* CreateKMatrixAdjointMacAyeal(void);
    219220                ElementVector* CreatePVectorAdjointHoriz(void);
    220221                ElementVector* CreatePVectorAdjointStokes(void);
    221222                ElementVector* CreatePVectorAdjointBalancethickness(void);
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Elements/Penta.cpp

     
    584584        /*Just branch to the correct element stiffness matrix generator, according to the type of analysis we are carrying out: */
    585585        switch(analysis_type){
    586586                #ifdef _HAVE_DIAGNOSTIC_
    587                 case DiagnosticHorizAnalysisEnum: case AdjointHorizAnalysisEnum:
     587                case DiagnosticHorizAnalysisEnum:
    588588                        Ke=CreateKMatrixDiagnosticHoriz(); De=CreateDVectorDiagnosticHoriz();
    589589                        break;
     590                case AdjointHorizAnalysisEnum:
     591                        Ke=CreateKMatrixAdjointHoriz();
     592                        break;
    590593                case DiagnosticHutterAnalysisEnum:
    591594                        Ke=CreateKMatrixDiagnosticHutter();
    592595                        break;
     
    44424445        ((ControlInput*)input)->SetGradient(grad_input);
    44434446
    44444447}/*}}}*/
     4448/*FUNCTION Penta::CreateKMatrixAdjointHoriz{{{1*/
     4449ElementMatrix* Penta::CreateKMatrixAdjointHoriz(void){
     4450
     4451        int approximation;
     4452        inputs->GetInputValue(&approximation,ApproximationEnum);
     4453
     4454        switch(approximation){
     4455                case MacAyealApproximationEnum:
     4456                        return CreateKMatrixAdjointMacAyeal2d();
     4457                case PattynApproximationEnum:
     4458                        return CreateKMatrixAdjointPattyn();
     4459                case StokesApproximationEnum:
     4460                        return CreateKMatrixAdjointStokes();
     4461                case NoneApproximationEnum:
     4462                        return NULL;
     4463                default:
     4464                        _error_("Approximation %s not supported yet",EnumToStringx(approximation));
     4465        }
     4466}
     4467/*}}}*/
     4468/*FUNCTION Penta::CreateKMatrixAdjointMacAyeal2d{{{1*/
     4469ElementMatrix* Penta::CreateKMatrixAdjointMacAyeal2d(void){
     4470
     4471        /*Figure out if this penta is collapsed. If so, then bailout, except if it is at the
     4472          bedrock, in which case we spawn a tria element using the 3 first nodes, and use it to build
     4473          the stiffness matrix. */
     4474        if (!IsOnBed()) return NULL;
     4475
     4476        /*Depth Averaging B*/
     4477        this->InputDepthAverageAtBase(MaterialsRheologyBEnum,MaterialsRheologyBbarEnum,MaterialsEnum);
     4478
     4479        /*Call Tria function*/
     4480        Tria* tria=(Tria*)SpawnTria(0,1,2); //nodes 0, 1 and 2 make the new tria.
     4481        ElementMatrix* Ke=tria->CreateKMatrixAdjointMacAyeal();
     4482        delete tria->matice; delete tria;
     4483
     4484        /*Delete B averaged*/
     4485        this->matice->inputs->DeleteInput(MaterialsRheologyBbarEnum);
     4486
     4487        /*clean up and return*/
     4488        return Ke;
     4489}
     4490/*}}}*/
     4491/*FUNCTION Penta::CreateKMatrixAdjointPattyn{{{1*/
     4492ElementMatrix* Penta::CreateKMatrixAdjointPattyn(void){
     4493
     4494        /*Constants*/
     4495        const int    numdof=NDOF2*NUMVERTICES;
     4496
     4497        /*Intermediaries */
     4498        int        i,j,ig;
     4499        bool       incomplete_adjoint;
     4500        double     xyz_list[NUMVERTICES][3];
     4501        double     Jdet;
     4502        double     eps1dotdphii,eps1dotdphij;
     4503        double     eps2dotdphii,eps2dotdphij;
     4504        double     mu_prime;
     4505        double     epsilon[5]; /* epsilon=[exx,eyy,exy,exz,eyz];*/
     4506        double     eps1[3],eps2[3];
     4507        double     phi[NUMVERTICES];
     4508        double     dphi[3][NUMVERTICES];
     4509        GaussPenta *gauss=NULL;
     4510
     4511        /*Initialize Jacobian with regular Pattyn (first part of the Gateau derivative)*/
     4512        parameters->FindParam(&incomplete_adjoint,InversionIncompleteAdjointEnum);
     4513        ElementMatrix* Ke=CreateKMatrixDiagnosticPattyn();
     4514        if(incomplete_adjoint) return Ke;
     4515
     4516        /*Retrieve all inputs and parameters*/
     4517        GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
     4518        Input* vx_input=inputs->GetInput(VxEnum);       _assert_(vx_input);
     4519        Input* vy_input=inputs->GetInput(VyEnum);       _assert_(vy_input);
     4520
     4521        /* Start  looping on the number of gaussian points: */
     4522        gauss=new GaussPenta(5,5);
     4523        for (ig=gauss->begin();ig<gauss->end();ig++){
     4524
     4525                gauss->GaussPoint(ig);
     4526
     4527                GetJacobianDeterminant(&Jdet, &xyz_list[0][0],gauss);
     4528                GetNodalFunctionsP1Derivatives(&dphi[0][0],&xyz_list[0][0],gauss);
     4529
     4530                this->GetStrainRate3dPattyn(&epsilon[0],&xyz_list[0][0],gauss,vx_input,vy_input);
     4531                matice->GetViscosityDerivativeEpsSquare(&mu_prime,&epsilon[0]);
     4532                eps1[0]=2*epsilon[0]+epsilon[1];   eps2[0]=epsilon[2];
     4533                eps1[1]=epsilon[2];                eps2[1]=epsilon[0]+2*epsilon[1];
     4534                eps1[2]=epsilon[3];                eps2[2]=epsilon[4];
     4535
     4536                for(i=0;i<6;i++){
     4537                        for(j=0;j<6;j++){
     4538                                eps1dotdphii=eps1[0]*dphi[0][i]+eps1[1]*dphi[1][i]+eps1[2]*dphi[2][i];
     4539                                eps1dotdphij=eps1[0]*dphi[0][j]+eps1[1]*dphi[1][j]+eps1[2]*dphi[2][j];
     4540                                eps2dotdphii=eps2[0]*dphi[0][i]+eps2[1]*dphi[1][i]+eps2[2]*dphi[2][i];
     4541                                eps2dotdphij=eps2[0]*dphi[0][j]+eps2[1]*dphi[1][j]+eps2[2]*dphi[2][j];
     4542
     4543                                Ke->values[12*(2*i+0)+2*j+0]+=gauss->weight*Jdet*2*mu_prime*eps1dotdphij*eps1dotdphii;
     4544                                Ke->values[12*(2*i+0)+2*j+1]+=gauss->weight*Jdet*2*mu_prime*eps2dotdphij*eps1dotdphii;
     4545                                Ke->values[12*(2*i+1)+2*j+0]+=gauss->weight*Jdet*2*mu_prime*eps1dotdphij*eps2dotdphii;
     4546                                Ke->values[12*(2*i+1)+2*j+1]+=gauss->weight*Jdet*2*mu_prime*eps2dotdphij*eps2dotdphii;
     4547                        }
     4548                }
     4549        }
     4550
     4551        /*Transform Coordinate System*/
     4552        TransformStiffnessMatrixCoord(Ke,nodes,NUMVERTICES,XYEnum);
     4553
     4554        /*Clean up and return*/
     4555        delete gauss;
     4556        return Ke;
     4557}
     4558/*}}}*/
     4559/*FUNCTION Penta::CreateKMatrixAdjointStokes{{{1*/
     4560ElementMatrix* Penta::CreateKMatrixAdjointStokes(void){
     4561
     4562        /*Constants*/
     4563        const int    numdof=NDOF4*NUMVERTICES;
     4564
     4565        /*Intermediaries */
     4566        int        i,j,ig;
     4567        bool       incomplete_adjoint;
     4568        double     xyz_list[NUMVERTICES][3];
     4569        double     Jdet;
     4570        double     eps1dotdphii,eps1dotdphij;
     4571        double     eps2dotdphii,eps2dotdphij;
     4572        double     eps3dotdphii,eps3dotdphij;
     4573        double     mu_prime;
     4574        double     epsilon[5]; /* epsilon=[exx,eyy,exy,exz,eyz];*/
     4575        double     eps1[3],eps2[3],eps3[3];
     4576        double     phi[NUMVERTICES];
     4577        double     dphi[3][NUMVERTICES];
     4578        GaussPenta *gauss=NULL;
     4579
     4580        /*Initialize Jacobian with regular Stokes (first part of the Gateau derivative)*/
     4581        parameters->FindParam(&incomplete_adjoint,InversionIncompleteAdjointEnum);
     4582        ElementMatrix* Ke=CreateKMatrixDiagnosticStokes();
     4583        if(incomplete_adjoint) return Ke;
     4584
     4585        /*Retrieve all inputs and parameters*/
     4586        GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
     4587        Input* vx_input=inputs->GetInput(VxEnum);       _assert_(vx_input);
     4588        Input* vy_input=inputs->GetInput(VyEnum);       _assert_(vy_input);
     4589        Input* vz_input=inputs->GetInput(VzEnum);       _assert_(vz_input);
     4590
     4591        /* Start  looping on the number of gaussian points: */
     4592        gauss=new GaussPenta(5,5);
     4593        for (ig=gauss->begin();ig<gauss->end();ig++){
     4594
     4595                gauss->GaussPoint(ig);
     4596
     4597                GetJacobianDeterminant(&Jdet, &xyz_list[0][0],gauss);
     4598                GetNodalFunctionsP1Derivatives(&dphi[0][0],&xyz_list[0][0],gauss);
     4599
     4600                this->GetStrainRate3dPattyn(&epsilon[0],&xyz_list[0][0],gauss,vx_input,vy_input);
     4601                matice->GetViscosityDerivativeEpsSquare(&mu_prime,&epsilon[0]);
     4602                eps1[0]=epsilon[0];   eps2[0]=epsilon[2];   eps3[0]=epsilon[3];
     4603                eps1[1]=epsilon[2];   eps2[1]=epsilon[1];   eps3[1]=epsilon[4];
     4604                eps1[2]=epsilon[3];   eps2[2]=epsilon[4];   eps3[2]= -epsilon[0] -epsilon[1];
     4605
     4606                for(i=0;i<6;i++){
     4607                        for(j=0;j<6;j++){
     4608                                eps1dotdphii=eps1[0]*dphi[0][i]+eps1[1]*dphi[1][i]+eps1[2]*dphi[2][i];
     4609                                eps1dotdphij=eps1[0]*dphi[0][j]+eps1[1]*dphi[1][j]+eps1[2]*dphi[2][j];
     4610                                eps2dotdphii=eps2[0]*dphi[0][i]+eps2[1]*dphi[1][i]+eps2[2]*dphi[2][i];
     4611                                eps2dotdphij=eps2[0]*dphi[0][j]+eps2[1]*dphi[1][j]+eps2[2]*dphi[2][j];
     4612                                eps3dotdphii=eps3[0]*dphi[0][i]+eps3[1]*dphi[1][i]+eps3[2]*dphi[2][i];
     4613                                eps3dotdphij=eps3[0]*dphi[0][j]+eps3[1]*dphi[1][j]+eps3[2]*dphi[2][j];
     4614
     4615                                Ke->values[numdof*(4*i+0)+4*j+0]+=gauss->weight*Jdet*2*mu_prime*eps1dotdphij*eps1dotdphii;
     4616                                Ke->values[numdof*(4*i+0)+4*j+1]+=gauss->weight*Jdet*2*mu_prime*eps2dotdphij*eps1dotdphii;
     4617                                Ke->values[numdof*(4*i+0)+4*j+2]+=gauss->weight*Jdet*2*mu_prime*eps3dotdphij*eps1dotdphii;
     4618
     4619                                Ke->values[numdof*(4*i+1)+4*j+0]+=gauss->weight*Jdet*2*mu_prime*eps1dotdphij*eps2dotdphii;
     4620                                Ke->values[numdof*(4*i+1)+4*j+1]+=gauss->weight*Jdet*2*mu_prime*eps2dotdphij*eps2dotdphii;
     4621                                Ke->values[numdof*(4*i+1)+4*j+2]+=gauss->weight*Jdet*2*mu_prime*eps3dotdphij*eps2dotdphii;
     4622
     4623                                Ke->values[numdof*(4*i+2)+4*j+0]+=gauss->weight*Jdet*2*mu_prime*eps1dotdphij*eps3dotdphii;
     4624                                Ke->values[numdof*(4*i+2)+4*j+1]+=gauss->weight*Jdet*2*mu_prime*eps2dotdphij*eps3dotdphii;
     4625                                Ke->values[numdof*(4*i+2)+4*j+2]+=gauss->weight*Jdet*2*mu_prime*eps3dotdphij*eps3dotdphii;
     4626                        }
     4627                }
     4628        }
     4629
     4630        /*Transform Coordinate System*/
     4631        TransformStiffnessMatrixCoord(Ke,nodes,NUMVERTICES,XYZPEnum);
     4632
     4633        /*Clean up and return*/
     4634        delete gauss;
     4635        return Ke;
     4636}
     4637/*}}}*/
    44454638/*FUNCTION Penta::CreatePVectorAdjointHoriz{{{1*/
    44464639ElementVector* Penta::CreatePVectorAdjointHoriz(void){
    44474640
  • proj/ice/larour/issm-uci-clean/trunk-jpl/src/c/objects/Elements/Penta.h

     
    215215                ElementMatrix* CreateKMatrixCouplingMacAyealStokesFriction(void);
    216216                ElementMatrix* CreateKMatrixCouplingPattynStokes(void);
    217217                ElementMatrix* CreateKMatrixDiagnosticHoriz(void);
     218                ElementMatrix* CreateKMatrixAdjointHoriz(void);
    218219                ElementVector* CreateDVectorDiagnosticHoriz(void);
    219220                ElementVector* CreateDVectorDiagnosticStokes(void);
    220221                ElementMatrix* CreateKMatrixDiagnosticHutter(void);
     
    274275
    275276                #ifdef _HAVE_CONTROL_
    276277                ElementVector* CreatePVectorAdjointHoriz(void);
     278                ElementMatrix* CreateKMatrixAdjointMacAyeal2d(void);
     279                ElementMatrix* CreateKMatrixAdjointPattyn(void);
     280                ElementMatrix* CreateKMatrixAdjointStokes(void);
    277281                ElementVector* CreatePVectorAdjointMacAyeal(void);
    278282                ElementVector* CreatePVectorAdjointPattyn(void);
    279283                ElementVector* CreatePVectorAdjointStokes(void);
Note: See TracBrowser for help on using the repository browser.