Changeset 18347


Ignore:
Timestamp:
08/08/14 09:27:46 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: finished Zalesak, still one pb with umin and umax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/solutionsequences/solutionsequence_fct.cpp

    r18345 r18347  
    167167        IssmDouble* udot_serial = NULL;
    168168        IssmDouble* u_serial    = NULL;
    169         VecToMPISerial(&udot_serial,udot,IssmComm::GetComm());
    170         VecToMPISerial(&u_serial   ,u   ,IssmComm::GetComm());
    171 
     169        IssmDouble* ml_serial    = NULL;
     170        VecToMPISerial(&udot_serial,udot    ,IssmComm::GetComm());
     171        VecToMPISerial(&u_serial   ,u       ,IssmComm::GetComm());
     172        VecToMPISerial(&ml_serial  ,Ml_petsc,IssmComm::GetComm());
    172173
    173174        /*Anti diffusive fluxes*/
    174         Mat F    = NULL;
     175        Vec Ri_plus  = NULL;
     176        Vec Ri_minus = NULL;
     177        double uiLmax = 3.;
     178        double uiLmin = 2.;
     179        VecDuplicate(u,&Ri_plus);
     180        VecDuplicate(u,&Ri_minus);
     181        for(int row=rstart; row<rend; row++){
     182                double Pi_plus  = 0.;
     183                double Pi_minus = 0.;
     184                MatGetRow(Mc_petsc,row,&ncols, (const int**)&cols, (const double**)&vals);
     185                MatGetRow(D_petsc ,row,&ncols2,(const int**)&cols2,(const double**)&vals2);
     186                _assert_(ncols==ncols2);
     187                for(int j=0; j<ncols; j++) {
     188                        _assert_(cols[j]==cols2[j]);
     189                        d = vals[j]*(udot_serial[row] - udot_serial[cols[j]]) + vals2[j]*(u_serial[row] - u_serial[cols[j]]);
     190                        if(row!=cols[j]){
     191                                if(d>0.){
     192                                        Pi_plus  += d;
     193                                }
     194                                else{
     195                                        Pi_minus += d;
     196                                }
     197                        }
     198                }
     199
     200                /*Compute Qis and Ris*/
     201                double Qi_plus  = ml_serial[row]/deltat*(uiLmax - u_serial[row]);
     202                double Qi_minus = ml_serial[row]/deltat*(uiLmin - u_serial[row]);
     203                d = 1.;
     204                if(Pi_plus!=0.) d = min(1.,Qi_plus/Pi_plus);
     205                VecSetValue(Ri_plus,row,(const double)d,INSERT_VALUES);
     206                d = 1.;
     207                if(Pi_minus!=0.) d = min(1.,Qi_minus/Pi_minus);
     208                VecSetValue(Ri_minus,row,(const double)d,INSERT_VALUES);
     209
     210                MatRestoreRow(Mc_petsc, row,&ncols, (const int**)&cols, (const double**)&vals);
     211                MatRestoreRow(D_petsc,row,&ncols2,(const int**)&cols2,(const double**)&vals2);
     212        }
     213        VecAssemblyBegin(Ri_plus);
     214        VecAssemblyEnd(  Ri_plus);
     215        VecAssemblyBegin(Ri_minus);
     216        VecAssemblyEnd(  Ri_minus);
     217
     218        /*Serialize Ris*/
     219        IssmDouble* Ri_plus_serial  = NULL;
     220        IssmDouble* Ri_minus_serial = NULL;
     221        VecToMPISerial(&Ri_plus_serial,Ri_plus,IssmComm::GetComm());
     222        VecToMPISerial(&Ri_minus_serial,Ri_minus,IssmComm::GetComm());
     223        VecFree(&Ri_plus);
     224        VecFree(&Ri_minus);
     225
     226        /*Build fbar*/
    175227        Vec Fbar = NULL;
    176228        VecDuplicate(u,&Fbar);
    177         MatDuplicate(D_petsc,MAT_SHARE_NONZERO_PATTERN,&F);
    178229        for(int row=rstart; row<rend; row++){
    179230                MatGetRow(Mc_petsc,row,&ncols, (const int**)&cols, (const double**)&vals);
    180231                MatGetRow(D_petsc ,row,&ncols2,(const int**)&cols2,(const double**)&vals2);
    181232                _assert_(ncols==ncols2);
    182                 mi = 0.;
    183                 for(int j=0; j<ncols; j++) {
    184                         _assert_(cols[j]==cols2[j]);
    185                         d = vals[j]*(udot_serial[row] - udot_serial[cols[j]]) + vals2[j]*(u_serial[row] - u_serial[cols[j]]);
    186                         if(row!=cols[j]) mi += d;
    187                         MatSetValues(F,1,&row,1,&cols[j],(const double*)&d,INSERT_VALUES);
    188 
    189                 }
    190                 VecSetValue(Fbar,row,(const double)mi,INSERT_VALUES);
     233                d = 0.;
     234                for(int j=0; j<ncols; j++) {
     235                        _assert_(cols[j]==cols2[j]);
     236                        if(row==cols[j]) continue;
     237                        double f_ij = vals[j]*(udot_serial[row] - udot_serial[cols[j]]) + vals2[j]*(u_serial[row] - u_serial[cols[j]]);
     238                        if(f_ij>0){
     239                                d += min(Ri_plus_serial[row],Ri_minus_serial[cols[j]]) * f_ij;
     240                        }
     241                        else{
     242                                d += min(Ri_minus_serial[row],Ri_plus_serial[cols[j]]) * f_ij;
     243                        }
     244                }
     245                VecSetValue(Fbar,row,(const double)d,INSERT_VALUES);
    191246                MatRestoreRow(Mc_petsc, row,&ncols, (const int**)&cols, (const double**)&vals);
    192247                MatRestoreRow(D_petsc,row,&ncols2,(const int**)&cols2,(const double**)&vals2);
    193248        }
    194         MatAssemblyBegin(F,MAT_FINAL_ASSEMBLY);
    195         MatAssemblyEnd(  F,MAT_FINAL_ASSEMBLY);
    196249        VecAssemblyBegin(Fbar);
    197250        VecAssemblyEnd(  Fbar);
    198251
    199252        MatFree(&D_petsc);
    200         MatFree(&F);
    201253        delete Mc;
    202254        xDelete<IssmDouble>(udot_serial);
    203255        xDelete<IssmDouble>(u_serial);
     256        xDelete<IssmDouble>(ml_serial);
     257        xDelete<IssmDouble>(Ri_plus_serial);
     258        xDelete<IssmDouble>(Ri_minus_serial);
    204259
    205260        /*Compute solution u^n+1 = u_L + deltat Ml^-1 fbar*/
Note: See TracChangeset for help on using the changeset viewer.