Changeset 18207


Ignore:
Timestamp:
07/01/14 10:37:09 (11 years ago)
Author:
seroussi
Message:

BUG: fixing Uzawa pressure

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

Legend:

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

    r18182 r18207  
    9292        int          dim;
    9393        IssmDouble   Jdet,r,divu;
    94         IssmDouble   dvx[3],dvy[3],dvz[3];
    9594        IssmDouble   *xyz_list = NULL;
    9695        int numnodes = element->GetNumberOfNodes();
    97 
    98         /*Initialize Element matrix and vectors*/
    99         ElementVector* pe   = element->NewElementVector();
    100         IssmDouble*    basis = xNew<IssmDouble>(numnodes);
    10196
    10297        /*Retrieve all inputs and parameters*/
     
    105100        element->GetVerticesCoordinates(&xyz_list);
    106101
     102        /*Initialize Element matrix and vectors*/
     103        ElementVector* pe    = element->NewElementVector();
     104        IssmDouble*    basis = xNew<IssmDouble>(numnodes);
     105        IssmDouble*    dvx   = xNew<IssmDouble>(dim);
     106        IssmDouble*    dvy   = xNew<IssmDouble>(dim);
     107        IssmDouble*    dvz   = xNew<IssmDouble>(dim);
     108
    107109        Input* vx_input=element->GetInput(VxEnum);     _assert_(vx_input);
    108110        Input* vy_input=element->GetInput(VyEnum);     _assert_(vy_input);
    109         Input* vz_input;
     111        Input* vz_input = NULL;
    110112        if(dim==3){vz_input=element->GetInput(VzEnum); _assert_(vz_input);}
    111113
     
    122124                }
    123125
     126                divu=dvx[0]+dvy[1];
     127                if (dim==3) divu=divu+dvz[2];
     128
    124129                for(int i=0;i<numnodes;i++){
    125                         divu=dvx[0]+dvy[1];
    126                         if (dim==3) divu=divu+dvz[2];
    127                         pe->values[i]+=divu*r*Jdet*gauss->weight*basis[i];
     130                        pe->values[i] += - r * divu * Jdet * gauss->weight * basis[i];
    128131                }
    129132        }
     
    133136        xDelete<IssmDouble>(xyz_list);
    134137        xDelete<IssmDouble>(basis);
     138        xDelete<IssmDouble>(dvx);
     139        xDelete<IssmDouble>(dvy);
     140        xDelete<IssmDouble>(dvz);
    135141        return pe;
    136142}/*}}}*/
  • issm/trunk-jpl/src/c/solutionsequences/solutionsequence_la.cpp

    r18186 r18207  
    1313        Matrix<IssmDouble>*  Kff     = NULL;
    1414        Matrix<IssmDouble>*  Kfs     = NULL;
    15         Vector<IssmDouble>*  ug_old  = NULL;
    1615        Vector<IssmDouble>*  ug      = NULL;
    1716        Vector<IssmDouble>*  uf      = NULL;
     
    2322        IssmDouble           eps_rel,r,theta; // 0<theta<.5   -> .15<theta<.45
    2423        int                  configuration_type,max_nonlinear_iterations;
     24        bool                 vel_converged      = false;
     25        bool                 pressure_converged = false;
    2526
    2627        /*Create analysis*/
     
    4041        /*Convergence criterion*/
    4142        int  count = 0;
    42         GetSolutionFromInputsx(&ug,femmodel);
    43         Vector<IssmDouble>* vx    = NULL;
    44         Vector<IssmDouble>* vx_old = NULL;
    45         GetVectorFromInputsx(&vx,femmodel,VxEnum,VertexEnum);
     43        Vector<IssmDouble>* vel     = NULL;
     44        Vector<IssmDouble>* vel_old = NULL;
     45        GetVectorFromInputsx(&vel,femmodel,VxEnum,VertexEnum);
     46        GetVectorFromInputsx(&pug,femmodel,PressureEnum,VertexEnum);
    4647
    4748        while(true){
     
    4950
    5051                /*save pointer to old velocity*/
    51                 delete ug_old;ug_old=ug;
    52                 delete vx_old;vx_old=vx;
    53                 delete pug_old;pug_old=pug;
     52                delete vel_old;vel_old=vel;
     53                delete pug_old;pug_old=pug;
     54                pressure_converged=false; vel_converged=false;
    5455
    5556                /*Solve KU=F*/
    5657                femmodel->SetCurrentConfiguration(StressbalanceAnalysisEnum);
     58                femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
    5759                SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
    5860                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
     
    6365
    6466                /*Update solution*/
    65                 InputUpdateFromSolutionx(femmodel,ug);
    66                 GetVectorFromInputsx(&vx,femmodel,VxEnum,VertexEnum);
     67                InputUpdateFromSolutionx(femmodel,ug); delete ug;
     68                GetVectorFromInputsx(&vel,femmodel,VxEnum,VertexEnum);
    6769
    6870                femmodel->SetCurrentConfiguration(UzawaPressureAnalysisEnum);
     71                femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
    6972                SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
    7073                CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
     
    7275                Solverx(&uf, Kff, pf, NULL, df, femmodel->parameters);
    7376                delete Kff; delete pf; delete df;
    74                 Mergesolutionfromftogx(&pug, uf,ys,femmodel->nodes,femmodel->parameters);delete uf; delete ys;
     77                Mergesolutionfromftogx(&pug, uf,ys,femmodel->nodes,femmodel->parameters); delete uf; delete ys;
    7578
    7679                /*Update solution*/
    77                 InputUpdateFromSolutionx(femmodel,pug);
     80                InputUpdateFromSolutionx(femmodel,pug); delete pug;
     81                GetVectorFromInputsx(&pug,femmodel,PressureEnum,VertexEnum);
    7882
    7983                /*Check for convergence*/
    80                 //Vector<IssmDouble>* dug=ug_old->Duplicate(); ug_old->Copy(dug); dug->AYPX(ug,-1.0);
    81                 //IssmDouble ndu=dug->Norm(NORM_TWO);   delete dug;
    82                 //IssmDouble nu =ug_old->Norm(NORM_TWO);
    83                 Vector<IssmDouble>* dvx=vx_old->Duplicate(); vx_old->Copy(dvx); dvx->AYPX(vx,-1.0);
    84                 IssmDouble ndu=dvx->Norm(NORM_TWO);   delete dvx;
    85                 IssmDouble nu =vx_old->Norm(NORM_TWO);
     84                Vector<IssmDouble>* dvel=vel_old->Duplicate(); vel_old->Copy(dvel); dvel->AYPX(vel,-1.0);
     85                IssmDouble ndu=dvel->Norm(NORM_TWO);   delete dvel;
     86                IssmDouble nu =vel_old->Norm(NORM_TWO);
    8687                if (xIsNan<IssmDouble>(ndu) || xIsNan<IssmDouble>(nu)) _error_("convergence criterion is NaN!");
    8788                if((ndu/nu)<eps_rel){
    8889                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " < " << eps_rel*100 << " %\n");
    89                         break;
     90                        vel_converged=true;
    9091                }
    9192                else{
    9293                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " > " << eps_rel*100 << " %\n");
     94                        vel_converged=false;
     95                }
     96                Vector<IssmDouble>* dup=pug_old->Duplicate(); pug_old->Copy(dup); dup->AYPX(pug,-1.0);
     97                IssmDouble ndp=dup->Norm(NORM_TWO);   delete dup;
     98                IssmDouble np =pug_old->Norm(NORM_TWO);
     99                if (xIsNan<IssmDouble>(ndp) || xIsNan<IssmDouble>(np)) _error_("convergence criterion is NaN!");
     100                if((ndp/np)<eps_rel){
     101                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   Convergence criterion: norm(dp)/norm(p)" << ndp/np*100 << " < " << eps_rel*100 << " %\n");
     102                        pressure_converged=true;
     103                }
     104                else{
     105                        if(VerboseConvergence()) _printf0_(setw(50) << left << "   Convergence criterion: norm(dp/)/norm(p)" << ndp/np*100 << " > " << eps_rel*100 << " %\n");
     106                        pressure_converged=false;
    93107                }
    94108
     109                if(pressure_converged && vel_converged) break;
    95110                if(count>=max_nonlinear_iterations){
    96111                        _printf0_("   maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
     
    101116        if(VerboseConvergence()) _printf0_("\n   total number of iterations: " << count-1 << "\n");
    102117
    103         delete ug; 
    104         delete ug_old; 
    105118        delete pug; 
    106119        delete pug_old; 
    107         delete vx
    108         delete vx_old; 
     120        delete vel
     121        delete vel_old; 
    109122        delete stressanalysis;
    110123        delete pressureanalysis;
Note: See TracChangeset for help on using the changeset viewer.