xref: /petsc/src/ksp/ksp/impls/rich/richscale.c (revision cbb748920e211f6b92d982894ce7f87ce159189c)
1 #include <../src/ksp/ksp/impls/rich/richardsonimpl.h> /*I "petscksp.h" I*/
2 
3 /*@
4   KSPRichardsonSetScale - Set the damping factor; if this routine is not called, the factor defaults to 1.0.
5 
6   Logically Collective
7 
8   Input Parameters:
9 + ksp   - the iterative context
10 - scale - the damping factor
11 
12   Options Database Key:
13 . -ksp_richardson_scale <scale> - Set the scale factor
14 
15   Level: intermediate
16 
17 .seealso: [](ch_ksp), `KSPRICHARDSON`, `KSPRichardsonSetSelfScale()`
18 @*/
KSPRichardsonSetScale(KSP ksp,PetscReal scale)19 PetscErrorCode KSPRichardsonSetScale(KSP ksp, PetscReal scale)
20 {
21   PetscFunctionBegin;
22   PetscValidHeaderSpecific(ksp, KSP_CLASSID, 1);
23   PetscValidLogicalCollectiveReal(ksp, scale, 2);
24   PetscTryMethod(ksp, "KSPRichardsonSetScale_C", (KSP, PetscReal), (ksp, scale));
25   PetscFunctionReturn(PETSC_SUCCESS);
26 }
27 
28 /*@
29   KSPRichardsonSetSelfScale - Sets Richardson to automatically determine optimal scaling at each iteration to minimize the 2-norm of the
30   preconditioned residual
31 
32   Logically Collective
33 
34   Input Parameters:
35 + ksp   - the iterative context
36 - scale - `PETSC_TRUE` or the default of `PETSC_FALSE`
37 
38   Options Database Key:
39 . -ksp_richardson_self_scale - Use self-scaling
40 
41   Level: intermediate
42 
43   Note:
44   Requires two extra work vectors. Uses an extra `VecAXPY()` and `VecDotNorm2()` per iteration.
45 
46   Developer Note:
47   Could also minimize the 2-norm of the true residual with one less work vector
48 
49 .seealso: [](ch_ksp), `KSPRICHARDSON`, `KSPRichardsonSetScale()`
50 @*/
KSPRichardsonSetSelfScale(KSP ksp,PetscBool scale)51 PetscErrorCode KSPRichardsonSetSelfScale(KSP ksp, PetscBool scale)
52 {
53   PetscFunctionBegin;
54   PetscValidHeaderSpecific(ksp, KSP_CLASSID, 1);
55   PetscValidLogicalCollectiveBool(ksp, scale, 2);
56   PetscTryMethod(ksp, "KSPRichardsonSetSelfScale_C", (KSP, PetscBool), (ksp, scale));
57   PetscFunctionReturn(PETSC_SUCCESS);
58 }
59