Changeset 23204
- Timestamp:
- 08/30/18 11:14:27 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/solutionsequences/solutionsequence_schurcg.cpp
r23197 r23204 22 22 Vec tmpu, tmpp, rhsu,rhsp; /* temp. vectors, arbitrary RHS in vel. / pressure space */ 23 23 Vec gold,gnew,wold,wnew,chi,thetaold,thetanew,eta; /* CG intermediaries */ 24 Vec f ,BTAinvf;/* RHS of the global system */24 Vec f1,f2; /* RHS of the global system */ 25 25 double rho,gamma,tmpScalar; /* Step sizes, arbitrary double */ 26 26 KSP kspu,kspp; /* KSP contexts for vel. / pressure systems*/ … … 33 33 34 34 /*STOP tolerance for the rel. residual*/ 35 TOL = 0. 1;35 TOL = 0.4; 36 36 37 37 /*Initialize output*/ … … 73 73 74 74 /* Set up intermediaries */ 75 VecDuplicate(uold,&f);VecSet(f,0.0); 76 VecAssemblyBegin(f);VecAssemblyEnd(f); 77 78 VecDuplicate(p,&BTAinvf);VecSet(BTAinvf,0.0); 79 VecAssemblyBegin(BTAinvf);VecAssemblyEnd(BTAinvf); 80 75 VecDuplicate(uold,&f1);VecSet(f1,0.0); 76 VecDuplicate(p,&f2);VecSet(f2,0.0); 81 77 VecDuplicate(uold,&tmpu);VecSet(tmpu,0.0); 82 VecAssemblyBegin(tmpu);VecAssemblyEnd(tmpu);83 84 78 VecDuplicate(p,&tmpp);VecSet(tmpp,0.0); 85 VecAssemblyBegin(tmpp);VecAssemblyEnd(tmpp);86 87 79 VecDuplicate(p,&rhsp);VecSet(rhsp,0.0); 88 VecAssemblyBegin(rhsp);VecAssemblyEnd(rhsp);89 90 80 VecDuplicate(uold,&rhsu);VecSet(rhsu,0.0); 91 VecAssemblyBegin(rhsu);VecAssemblyEnd(rhsu);92 93 81 VecDuplicate(p,&gold);VecSet(gold,0.0); 94 VecAssemblyBegin(gold);VecAssemblyEnd(gold); 95 96 VecDuplicate(gold,&wnew);VecSet(wnew,0.0); 97 VecAssemblyBegin(wnew);VecAssemblyEnd(wnew); 98 82 VecDuplicate(p,&wnew);VecSet(wnew,0.0); 99 83 VecDuplicate(uold,&chi);VecSet(chi,0.0); 100 VecAssemblyBegin(chi);VecAssemblyEnd(chi);101 102 84 VecDuplicate(p,&thetanew);VecSet(thetanew,0.0); 103 VecAssemblyBegin(thetanew);VecAssemblyEnd(thetanew);104 105 85 VecDuplicate(p,&thetaold);VecSet(thetaold,0.0); 106 VecAssemblyBegin(thetaold);VecAssemblyEnd(thetaold);107 108 86 VecDuplicate(p,&eta);VecSet(eta,0.0); 109 VecAssemblyBegin(eta);VecAssemblyEnd(eta); 110 111 /* Get global RHS (restricted to the velocity space */ 112 VecGetSubVector(pf,isv,&f); 113 87 88 /* Get global RHS (for each block sub-problem respectively)*/ 89 VecGetSubVector(pf,isv,&f1); 90 VecGetSubVector(pf,isp,&f2); 114 91 115 92 /* ------------------------------------------------------------ */ 116 93 117 94 /* Generate initial value for the velocity from the pressure */ 118 /* a(u0,v) = f (v)-b(p0,v) i.e. Au0 = F-Bp0 */95 /* a(u0,v) = f1(v)-b(p0,v) i.e. Au0 = F1-Bp0 */ 119 96 /* u0 = u_DIR on \Gamma_DIR */ 120 97 … … 124 101 KSPSetType(kspu,KSPCG); 125 102 KSPSetInitialGuessNonzero(kspu,PETSC_TRUE); 103 //KSPSetTolerances(kspu,1e-12,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT); 104 //KSPMonitorSet(kspu,KSPMonitorDefault,NULL,NULL); 126 105 KSPGetPC(kspu,&pcu); 127 PCSetType(pcu,PC JACOBI);106 PCSetType(pcu,PCSOR); 128 107 KSPSetUp(kspu); 129 108 130 109 131 110 /* Create RHS */ 132 /* RHS = F -B * pold */133 VecScale(p,-1.);MatMultAdd(B,p,f ,rhsu);VecScale(p,-1.);134 135 /* Go solve Au0 = F -Bp0*/111 /* RHS = F1-B * pold */ 112 VecScale(p,-1.);MatMultAdd(B,p,f1,rhsu);VecScale(p,-1.); 113 114 /* Go solve Au0 = F1-Bp0*/ 136 115 KSPSolve(kspu,rhsu,uold); 137 116 138 /* Calculate B^T * A^{-1} * F for future reference */139 KSPSolve(kspu,f,tmpu);MatMult(BT,tmpu,BTAinvf);140 141 117 142 118 /* Set up u_new */ … … 149 125 150 126 /*Get initial residual*/ 151 /*(1/mu(x) * g0, q) = b(q,u0) i.e. IP * g0 = BT * u0*/127 /*(1/mu(x) * g0, q) = b(q,u0) - (f2,q) i.e. IP * g0 = BT * u0 - F2*/ 152 128 153 129 /* Create KSP context */ … … 156 132 157 133 /* Create RHS */ 158 /* RHS = BT * uold */159 MatMult(BT,uold,rhsp);134 /* RHS = BT * uold - F2 */ 135 VecScale(f2,-1.);MatMultAdd(BT,uold,f2,rhsp);VecScale(f2,-1.); 160 136 161 137 /* Set KSP & PC options */ … … 187 163 188 164 /*Realizing the step size part 1: thetam */ 189 /*IP * theta = BT * uold */190 MatMult(BT,uold,rhsp);165 /*IP * theta = BT * uold - F2*/ 166 VecScale(f2,-1.);MatMultAdd(BT,uold,f2,rhsp);VecScale(f2,-1.); 191 167 KSPSolve(kspp,rhsp,thetaold); 192 168 … … 212 188 213 189 /*Set step size*/ 214 /*rhom = [(wm)^T * IP^-1 * BT * um]/[(wm)^T * IP^-1 * BT * chim]*/190 /*rhom = [(wm)^T * IP^-1 * (BT * um - F2)]/[(wm)^T * IP^-1 * BT * chim]*/ 215 191 VecDot(wold,thetaold,&rho); 216 192 VecDot(wold,eta,&tmpScalar); … … 234 210 235 211 /*Theta update*/ 236 /*IP * theta = BT * uold */237 MatMult(BT,unew,rhsp);212 /*IP * theta = BT * uold - F2*/ 213 VecScale(f2,-1.);MatMultAdd(BT,unew,f2,rhsp);VecScale(f2,-1.); 238 214 KSPSolve(kspp,rhsp,thetanew); 239 215 … … 250 226 /*BREAK if norm(g(m+0),2) < TOL or pressure space has been full searched*/ 251 227 VecNorm(gnew,NORM_INFINITY,&rnorm); 252 if(rnorm < TOL*initRnorm) break; 228 if(rnorm < TOL*initRnorm) 229 break; 230 else if(rnorm > 100*initRnorm) 231 _error_("Solver diverged. This shouldn't happen\n"); 232 else 233 PetscPrintf(PETSC_COMM_WORLD,"rel. residual at step %d: %g, at TOL = %g\n",count,rnorm/initRnorm,TOL); 234 253 235 if(count > np-1) break; 254 236 255 237 256 238 /* ---------------------------------------------------------- */ … … 272 254 } 273 255 256 274 257 /* Restore pressure and velocity sol. vectors to its global form */ 275 258 VecRestoreSubVector(out_uf->pvector->vector,isv,&unew); … … 287 270 VecDestroy(&p);VecDestroy(&uold);VecDestroy(&unew);VecDestroy(&rhsu);VecDestroy(&rhsp); 288 271 VecDestroy(&gold);VecDestroy(&gnew);VecDestroy(&wold);VecDestroy(&wnew);VecDestroy(&chi); 289 VecDestroy(&tmpp);VecDestroy(&tmpu);VecDestroy(&f );VecDestroy(&BTAinvf);VecDestroy(&eta);272 VecDestroy(&tmpp);VecDestroy(&tmpu);VecDestroy(&f1);VecDestroy(&f2);VecDestroy(&eta); 290 273 VecDestroy(&thetanew);VecDestroy(&thetaold); 291 274 … … 342 325 /*Create mass matrix*/ 343 326 int fsize; Kff->GetSize(&fsize,&fsize); 344 Iff=new Matrix<IssmDouble>(fsize,fsize, 200,4);327 Iff=new Matrix<IssmDouble>(fsize,fsize,300,4); 345 328 StressbalanceAnalysis* analysis = new StressbalanceAnalysis(); 346 329 /*Get complete stiffness matrix without penalties*/ … … 367 350 femmodel->profiler->Stop(SOLVER); 368 351 delete Iff; 369 370 352 371 353 /*Merge solution from f set to g set*/ 372 354 Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
Note:
See TracChangeset
for help on using the changeset viewer.