1. petsc
  2. PETSc
  3. petsc

Commits

Jed Brown  committed 468ee44

KSP ex49: restrict near-null space for elasticity example with sym BC

This example enforces boundary conditions in a non-symmetric way and has
an option to "lift" the contributions to the right hand side. Formerly,
the near-null space was not transfered to the constrained operator,
causing smoothed aggregation methods to perform poorly. This commit
restricts the near-null vectors and attaches them to the reduced-space
operator.

Reported-by: Garth N. Wells <gnw20@cam.ac.uk>

  • Participants
  • Parent commits 7a03a9f
  • Branches master

Comments (0)

Files changed (3)

File src/ksp/ksp/examples/tutorials/ex49.c

View file
  • Ignore whitespace
   ierr = VecScatterCreate(f,is,*ff,NULL,&scat);CHKERRQ(ierr);
   ierr = VecScatterBegin(scat,f,*ff,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
   ierr = VecScatterEnd(scat,f,*ff,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
+
+  {                             /* Constrain near-null space */
+    PetscInt nvecs;
+    const Vec *vecs;
+    Vec *uvecs;
+    PetscBool has_const;
+    MatNullSpace mnull,unull;
+    ierr = MatGetNearNullSpace(A,&mnull);CHKERRQ(ierr);
+    ierr = MatNullSpaceGetVecs(mnull,&has_const,&nvecs,&vecs);CHKERRQ(ierr);
+    ierr = VecDuplicateVecs(*ff,nvecs,&uvecs);CHKERRQ(ierr);
+    for (i=0; i<nvecs; i++) {
+      ierr = VecScatterBegin(scat,vecs[i],uvecs[i],INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
+      ierr = VecScatterEnd(scat,vecs[i],uvecs[i],INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
+    }
+    ierr = MatNullSpaceCreate(PetscObjectComm((PetscObject)A),has_const,nvecs,uvecs,&unull);CHKERRQ(ierr);
+    ierr = MatSetNearNullSpace(*AA,unull);CHKERRQ(ierr);
+    ierr = MatNullSpaceDestroy(&unull);CHKERRQ(ierr);
+    for (i=0; i<nvecs; i++) {
+      ierr = VecDestroy(&uvecs[i]);CHKERRQ(ierr);
+    }
+    ierr = PetscFree(uvecs);CHKERRQ(ierr);
+  }
+
   ierr = VecScatterDestroy(&scat);CHKERRQ(ierr);
 
   *dofs = is;

File src/ksp/ksp/examples/tutorials/makefile

View file
  • Ignore whitespace
 	   ${DIFF} output/ex49_4.out ex49_4.tmp || echo ${PWD} "\nPossible problem with with ex49_4, diffs above \n========================================="; \
 	   ${RM} -f ex49_4.tmp
 
+runex49_5:
+	-@${MPIEXEC} -n 3 ./ex49 -elas_ksp_monitor_short -elas_ksp_converged_reason -elas_ksp_type cg -elas_ksp_norm_type natural -mx 22 -my 22 -c_str 2 -brick_E 1,1e-6,1e-2 -brick_nu .3,.2,.4 -brick_span 8 -elas_pc_type gamg -elas_mg_levels_ksp_type chebyshev -elas_mg_levels_ksp_max_it 1 -elas_mg_levels_ksp_chebyshev_estimate_eigenvalues 0.2,1.1 -elas_mg_levels_pc_type jacobi > ex49_5.tmp 2>&1; \
+	   ${DIFF} output/ex49_5.out ex49_5.tmp || printf "${PWD}\nPossible problem with with ex49_5, diffs above \n=========================================\n"; \
+	   ${RM} -f ex49_5.tmp
+
 runex50:
 	-@${MPIEXEC} -n 1 ./ex50 -pc_type mg -pc_mg_type full -ksp_type fgmres -ksp_monitor_short -da_refine 1 -mg_levels_pc_factor_shift_type nonzero -mg_coarse_pc_factor_shift_type nonzero -ksp_view  > ex50.tmp 2>&1;         \
         ${DIFF} output/ex50.out ex50.tmp || echo ${PWD} "\nPossible problem with with ex50, diffs above \n========================================="; \
                                  ex31.PETSc ex31.rm ex32.PETSc runex32 ex32.rm ex34.PETSc runex34 ex34.rm ex38.PETSc runex38 ex38.rm \
                                  ex43.PETSc runex43 runex43_2 runex43_3 runex43_bjacobi runex43_bjacobi_baij ex43.rm \
                                  ex45.PETSc runex45 runex45_2 ex45.rm \
-                                 ex49.PETSc runex49 runex49_2 runex49_3 ex49.rm ex53.PETSc runex53 ex53.rm ex55.PETSc runex55_SA runex55_Classical ex55.rm\
+                                 ex49.PETSc runex49 runex49_2 runex49_3 runex49_5 ex49.rm ex53.PETSc runex53 ex53.rm ex55.PETSc runex55_SA runex55_Classical ex55.rm\
                                  ex58.PETSc runex58 runex58_baij runex58_sbaij ex58.rm
 TESTEXAMPLES_C_X	       = ex2.PETSc runex2_5 ex2.rm ex5.PETSc runex5_5 ex5.rm ex8.PETSc ex8.rm ex28.PETSc runex28 ex28.rm
 TESTEXAMPLES_FORTRAN	       = ex1f.PETSc runex1f ex1f.rm ex2f.PETSc runex2f ex2f.rm ex6f.PETSc ex6f.rm \

File src/ksp/ksp/examples/tutorials/output/ex49_5.out

View file
  • Ignore whitespace
+  Residual norms for elas_ solve.
+  0 KSP Residual norm 4.58045 
+  1 KSP Residual norm 0.271904 
+  2 KSP Residual norm 0.0610548 
+  3 KSP Residual norm 0.0160577 
+  4 KSP Residual norm 0.00777575 
+  5 KSP Residual norm 0.00260232 
+  6 KSP Residual norm 0.000885077 
+  7 KSP Residual norm 0.000427332 
+  8 KSP Residual norm 0.000217801 
+  9 KSP Residual norm 8.08386e-05 
+ 10 KSP Residual norm 2.28434e-05 
+Linear solve converged due to CONVERGED_RTOL iterations 10