Changeset 5879


Ignore:
Timestamp:
09/17/10 17:42:12 (15 years ago)
Author:
Mathieu Morlighem
Message:

final clean

Location:
issm/trunk/src/c/objects/Elements
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Elements/Penta.cpp

    r5877 r5879  
    700700                case DiagnosticHorizAnalysisEnum: case AdjointHorizAnalysisEnum:
    701701                        Ke=CreateKMatrixDiagnosticHoriz();
    702                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    703                         delete Ke;
    704702                        break;
    705703                case DiagnosticHutterAnalysisEnum:
    706704                        Ke=CreateKMatrixDiagnosticHutter();
    707                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    708                         delete Ke;
    709705                        break;
    710706                case DiagnosticVertAnalysisEnum:
    711707                        Ke=CreateKMatrixDiagnosticVert();
    712                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    713                         delete Ke;
    714708                        break;
    715709                case BedSlopeXAnalysisEnum: case SurfaceSlopeXAnalysisEnum: case BedSlopeYAnalysisEnum: case SurfaceSlopeYAnalysisEnum:
    716710                        Ke=CreateKMatrixSlope();
    717                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    718                         delete Ke;
    719711                        break;
    720712                case PrognosticAnalysisEnum:
    721713                        Ke=CreateKMatrixPrognostic();
    722                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    723                         delete Ke;
    724714                        break;
    725715                case BalancedthicknessAnalysisEnum:
    726716                        Ke=CreateKMatrixBalancedthickness();
    727                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    728                         delete Ke;
    729717                        break;
    730718                case BalancedvelocitiesAnalysisEnum:
    731719                        Ke=CreateKMatrixBalancedvelocities();
    732                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    733                         delete Ke;
    734720                        break;
    735721                case ThermalAnalysisEnum:
    736                         CreateKMatrixThermal( Kgg);
     722                        Ke=CreateKMatrixThermal();
    737723                        break;
    738724                case MeltingAnalysisEnum:
    739725                        Ke=CreateKMatrixMelting();
    740                         if(Ke) Ke->AddToGlobal(Kgg,NULL,NULL);
    741                         delete Ke;
    742726                        break;
    743727                default:
    744728                        ISSMERROR("analysis %i (%s) not supported yet",analysis_type,EnumToString(analysis_type));
     729        }
     730
     731        /*Add to global matrix*/
     732        if(Ke){
     733                Ke->AddToGlobal(Kgg,Kff,Kfs);
     734                delete Ke;
    745735        }
    746736}
     
    28402830/*}}}*/
    28412831/*FUNCTION Penta::CreateKMatrixThermal {{{1*/
    2842 void  Penta::CreateKMatrixThermal(Mat Kgg){
    2843 
    2844         /* local declarations */
     2832ElementMatrix* Penta::CreateKMatrixThermal(void){
     2833
     2834        /*compute all stiffness matrices for this element*/
     2835        ElementMatrix* Ke1=CreateKMatrixThermalVolume();
     2836        ElementMatrix* Ke2=CreateKMatrixThermalShelf();
     2837        ElementMatrix* Ke =new ElementMatrix(Ke1,Ke2);
     2838        printf("-------------- file: Penta.cpp line: %i\n",__LINE__);
     2839        Ke->Echo();
     2840
     2841        /*clean-up and return*/
     2842        delete Ke1;
     2843        delete Ke2;
     2844        return Ke;
     2845}
     2846/*}}}*/
     2847/*FUNCTION Penta::CreateKMatrixThermalVolume {{{1*/
     2848ElementMatrix* Penta::CreateKMatrixThermalVolume(void){
     2849
    28452850        int i,j;
     2851        int     ig;
    28462852        int found=0;
    2847 
    2848         /* node data: */
    28492853        const int    numdof=NDOF1*NUMVERTICES;
    28502854        double       xyz_list[NUMVERTICES][3];
    28512855        int*         doflist=NULL;
    2852 
    2853         /* gaussian points: */
    2854         int     ig;
    28552856        GaussPenta *gauss=NULL;
    2856 
    28572857        double  K[2][2]={0.0};
    2858 
    28592858        double  u,v,w;
    2860 
    2861         /*matrices: */
    2862         double     K_terms[numdof][numdof]={0.0};
    28632859        double     Ke_gaussian_conduct[numdof][numdof];
    28642860        double     Ke_gaussian_advec[numdof][numdof];
     
    28812877        double     tBD_artdiff[3][numdof];
    28822878        double     tLD[numdof];
    2883 
    28842879        double     Jdet;
    2885 
    2886         /*Material properties: */
    28872880        double     gravity,rho_ice,rho_water;
    28882881        double     heatcapacity,thermalconductivity;
    28892882        double     mixed_layer_capacity,thermal_exchange_velocity;
    2890 
    2891         /*parameters: */
    28922883        double dt,epsvel;
    28932884        bool   artdiff;
    2894 
    2895         /*Collapsed formulation: */
    28962885        Tria*  tria=NULL;
    28972886
    2898         /*If on water, skip: */
    2899         if(IsOnWater())return;
    2900 
    2901         /* Get node coordinates and dof list: */
     2887        /*Initialize Element matrix and return if necessary*/
     2888        if(IsOnWater()) return NULL;
     2889        ElementMatrix* Ke=this->NewElementMatrix(NoneApproximationEnum);
     2890
     2891        /*Retrieve all inputs and parameters*/
    29022892        GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
    2903         GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
    2904 
    2905         // /*recovre material parameters: */
    29062893        rho_water=matpar->GetRhoWater();
    29072894        rho_ice=matpar->GetRhoIce();
     
    29092896        heatcapacity=matpar->GetHeatCapacity();
    29102897        thermalconductivity=matpar->GetThermalConductivity();
    2911 
    2912         /*retrieve some parameters: */
    29132898        this->parameters->FindParam(&dt,DtEnum);
    29142899        this->parameters->FindParam(&artdiff,ArtDiffEnum);
    29152900        this->parameters->FindParam(&epsvel,EpsVelEnum);
    2916 
    29172901        Input* vx_input=inputs->GetInput(VxEnum); ISSMASSERT(vx_input);
    29182902        Input* vy_input=inputs->GetInput(VyEnum); ISSMASSERT(vy_input);
     
    29292913                /*Conduction: */
    29302914
    2931                 /*Get B_conduct matrix: */
    29322915                GetBConduct(&B_conduct[0][0],&xyz_list[0][0],gauss);
    29332916
    2934                 /*Build D: */
    29352917                D_scalar=gauss->weight*Jdet*(thermalconductivity/(rho_ice*heatcapacity));
    2936 
    29372918                if(dt) D_scalar=D_scalar*dt;
    29382919
     
    29412922                D[2][0]=0; D[2][1]=0; D[2][2]=D_scalar;
    29422923
    2943                 /*  Do the triple product B'*D*B: */
    29442924                MatrixMultiply(&B_conduct[0][0],3,numdof,1,&D[0][0],3,3,0,&tBD_conduct[0][0],0);
    29452925                MatrixMultiply(&tBD_conduct[0][0],numdof,3,0,&B_conduct[0][0],3,numdof,0,&Ke_gaussian_conduct[0][0],0);
     
    29472927                /*Advection: */
    29482928
    2949                 /*Get B_advec and Bprime_advec matrices: */
    29502929                GetBAdvec(&B_advec[0][0],&xyz_list[0][0],gauss);
    29512930                GetBprimeAdvec(&Bprime_advec[0][0],&xyz_list[0][0],gauss);
    29522931
    2953                 //Build the D matrix
    29542932                vx_input->GetParameterValue(&u, gauss);
    29552933                vy_input->GetParameterValue(&v, gauss);
     
    29572935
    29582936                D_scalar=gauss->weight*Jdet;
    2959 
    29602937                if(dt) D_scalar=D_scalar*dt;
    29612938
     
    29642941                D[2][0]=0;         D[2][1]=0;         D[2][2]=D_scalar*w;
    29652942
    2966                 /*  Do the triple product B'*D*Bprime: */
    29672943                MatrixMultiply(&B_advec[0][0],3,numdof,1,&D[0][0],3,3,0,&tBD_advec[0][0],0);
    29682944                MatrixMultiply(&tBD_advec[0][0],numdof,3,0,&Bprime_advec[0][0],3,numdof,0,&Ke_gaussian_advec[0][0],0);
    29692945
    29702946                /*Transient: */
     2947
    29712948                if(dt){
    29722949                        GetNodalFunctionsP1(&L[0], gauss);
     
    29742951                        D_scalar=D_scalar;
    29752952
    2976                         /*  Do the triple product L'*D*L: */
    29772953                        MatrixMultiply(&L[0],numdof,1,0,&D_scalar,1,1,0,&tLD[0],0);
    29782954                        MatrixMultiply(&tLD[0],numdof,1,0,&L[0],1,numdof,0,&Ke_gaussian_transient[0][0],0);
     
    29832959
    29842960                /*Artifficial diffusivity*/
     2961
    29852962                if(artdiff){
    29862963                        /*Build K: */
     
    29902967                        K[1][0]=D_scalar*fabs(u)*fabs(v);K[1][1]=D_scalar*pow(v,2);
    29912968
    2992                         /*Get B_artdiff: */
    29932969                        GetBArtdiff(&B_artdiff[0][0],&xyz_list[0][0],gauss);
    29942970
    2995                         /*  Do the triple product B'*K*B: */
    29962971                        MatrixMultiply(&B_artdiff[0][0],2,numdof,1,&K[0][0],2,2,0,&tBD_artdiff[0][0],0);
    29972972                        MatrixMultiply(&tBD_artdiff[0][0],numdof,2,0,&B_artdiff[0][0],2,numdof,0,&Ke_gaussian_artdiff[0][0],0);
     
    30012976                }
    30022977
    3003                 /*Add Ke_gaussian to pKe: */
    3004                 for(i=0;i<numdof;i++) for(j=0;j<numdof;j++) K_terms[i][j]+=Ke_gaussian_conduct[i][j]+Ke_gaussian_advec[i][j]+Ke_gaussian_transient[i][j]+Ke_gaussian_artdiff[i][j];
    3005         }
    3006 
    3007         /*Add Ke_gg to global matrix Kgg: */
    3008         MatSetValues(Kgg,numdof,doflist,numdof,doflist,(const double*)K_terms,ADD_VALUES);
    3009 
    3010         //Ice/ocean heat exchange flux on ice shelf base
    3011         if(IsOnBed() && IsOnShelf()){
    3012 
    3013                 tria=(Tria*)SpawnTria(0,1,2); //grids 0, 1 and 2 make the new tria.
    3014                 tria->CreateKMatrixThermal(Kgg);
    3015                 delete tria->matice; delete tria;
    3016         }
    3017        
    3018         /*Free ressources:*/
     2978                for(i=0;i<numdof;i++) for(j=0;j<numdof;j++) Ke->values[i*numdof+j]+=Ke_gaussian_conduct[i][j]+Ke_gaussian_advec[i][j]+Ke_gaussian_transient[i][j]+Ke_gaussian_artdiff[i][j];
     2979        }
     2980
     2981        /*Clean up and return*/
    30192982        delete gauss;
    3020         xfree((void**)&doflist);
    3021 
     2983        return Ke;
     2984}
     2985/*}}}*/
     2986/*FUNCTION Penta::CreateKMatrixThermalShelf {{{1*/
     2987ElementMatrix* Penta::CreateKMatrixThermalShelf(void){
     2988
     2989        if (!IsOnBed() || !IsOnShelf() || IsOnWater()) return NULL;
     2990
     2991        /*Call Tria function*/
     2992        Tria* tria=(Tria*)SpawnTria(0,1,2);
     2993        ElementMatrix* Ke=tria->CreateKMatrixThermal();
     2994        delete tria->matice; delete tria;
     2995
     2996        return Ke;
    30222997}
    30232998/*}}}*/
  • issm/trunk/src/c/objects/Elements/Penta.h

    r5877 r5879  
    147147                ElementMatrix* CreateKMatrixPrognostic(void);
    148148                ElementMatrix* CreateKMatrixSlope(void);
    149                 void      CreateKMatrixThermal(Mat Kggg);
     149                ElementMatrix* CreateKMatrixThermal(void);
     150                ElementMatrix* CreateKMatrixThermalVolume(void);
     151                ElementMatrix* CreateKMatrixThermalShelf(void);
    150152                void      CreatePVectorBalancedthickness( Vec pg);
    151153                void      CreatePVectorBalancedvelocities( Vec pg);
  • issm/trunk/src/c/objects/Elements/Tria.cpp

    r5878 r5879  
    34083408/*}}}*/
    34093409/*FUNCTION Tria::CreateKMatrixThermal {{{1*/
    3410 void  Tria::CreateKMatrixThermal(Mat Kgg){
    3411 
     3410ElementMatrix* Tria::CreateKMatrixThermal(void){
     3411
     3412        const int    numdof=NDOF1*NUMVERTICES;
    34123413        int i,j;
    3413        
    3414         /* node data: */
    3415         const int    numdof=NDOF1*NUMVERTICES;
     3414        int     ig;
    34163415        double       xyz_list[NUMVERTICES][3];
    3417         int*         doflist=NULL;
    3418 
    34193416        double mixed_layer_capacity;
    34203417        double thermal_exchange_velocity;
     
    34223419        double rho_ice;
    34233420        double heatcapacity;
    3424 
    3425         int     ig;
    34263421        GaussTria *gauss=NULL;
    3427 
    3428         /*matrices: */
    34293422        double  Jdet;
    34303423        double  K_terms[numdof][numdof]={0.0};
     
    34333426        double     tl1l2l3D[3];
    34343427        double  D_scalar;
    3435 
    3436         /*parameters: */
    34373428        double dt;
    34383429
    3439         /*retrieve some parameters: */
     3430        /*Initialize Element matrix and return if necessary*/
     3431        if(IsOnWater() || !IsOnShelf()) return NULL;
     3432        ElementMatrix* Ke=this->NewElementMatrix(NoneApproximationEnum);
     3433
     3434        /*Retrieve all inputs and parameters*/
     3435        GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
    34403436        this->parameters->FindParam(&dt,DtEnum);
    3441 
    3442         /* Get node coordinates and dof list: */
    3443         GetVerticesCoordinates(&xyz_list[0][0], nodes, NUMVERTICES);
    3444         GetDofList(&doflist,NoneApproximationEnum,GsetEnum);
    3445 
    3446         //recover material parameters
    34473437        mixed_layer_capacity=matpar->GetMixedLayerCapacity();
    34483438        thermal_exchange_velocity=matpar->GetThermalExchangeVelocity();
     
    34573447                gauss->GaussPoint(ig);
    34583448               
    3459                 //Get the Jacobian determinant
    3460                 GetJacobianDeterminant3d(&Jdet, &xyz_list[0][0], gauss);
    3461                
    3462                 /*Get nodal functions values: */
    34633449                GetNodalFunctions(&l1l2l3[0], gauss);
    34643450                               
    3465                 /*Calculate DL on gauss point */
     3451                GetJacobianDeterminant3d(&Jdet, &xyz_list[0][0], gauss);
    34663452                D_scalar=gauss->weight*Jdet*rho_water*mixed_layer_capacity*thermal_exchange_velocity/(heatcapacity*rho_ice);
    3467                 if(dt){
    3468                         D_scalar=dt*D_scalar;
    3469                 }
    3470 
    3471                 /*  Do the triple product tL*D*L: */
     3453                if(dt) D_scalar=dt*D_scalar;
     3454
    34723455                MatrixMultiply(&l1l2l3[0],numdof,1,0,&D_scalar,1,1,0,&tl1l2l3D[0],0);
    34733456                MatrixMultiply(&tl1l2l3D[0],numdof,1,0,&l1l2l3[0],1,numdof,0,&Ke_gaussian[0][0],0);
    34743457
    3475                 for(i=0;i<3;i++){
    3476                         for(j=0;j<3;j++){
    3477                                 K_terms[i][j]+=Ke_gaussian[i][j];
    3478                         }
    3479                 }
     3458                for(i=0;i<numdof;i++) for(j=0;j<numdof;j++) Ke->values[i*numdof+j]+=Ke_gaussian[i][j];
    34803459        }
    34813460       
    3482         /*Add Ke_gg to global matrix Kgg: */
    3483         MatSetValues(Kgg,numdof,doflist,numdof,doflist,(const double*)K_terms,ADD_VALUES);
    3484 
    3485 
    34863461        /*Clean up and return*/
    34873462        delete gauss;
    3488         xfree((void**)&doflist);
     3463        return Ke;
    34893464}
    34903465/*}}}*/
  • issm/trunk/src/c/objects/Elements/Tria.h

    r5877 r5879  
    138138                ElementMatrix* CreateKMatrixPrognostic_DG(void);
    139139                ElementMatrix* CreateKMatrixSlope(void);
    140                 void      CreateKMatrixThermal(Mat Kgg);
     140                ElementMatrix* CreateKMatrixThermal(void);
    141141                void      CreatePVectorBalancedthickness_DG(Vec pg);
    142142                void      CreatePVectorBalancedthickness_CG(Vec pg);
Note: See TracChangeset for help on using the changeset viewer.