[petsc-users] SetVariableBounds vs ComputeVariableBounds
Ed Bueler
elbueler at alaska.edu
Wed Jun 22 14:42:12 CDT 2016
Justin --
Yeah, good point. SNESVISetVariableBounds() works fine, at least in ex9.c
(see attached patch). The reason for the other choice, which I found in my
5 year old email, was some bug in petsc3.2.
Ed
Date: Wed, 22 Jun 2016 08:42:33 +0100
> From: Justin Chang <jychang48 at gmail.com>
> To: petsc-users <petsc-users at mcs.anl.gov>
> Subject: [petsc-users] SetVariableBounds vs ComputeVariableBounds
>
> Hi all,
>
> I am looking at the SNES tutorials ex9.c and ex58.c and am wondering why
> SNESVISetComputeVariableBounds() is called instead of just
> SNESVISetVariableBounds(). When would it be appropriate to use only using
> the latter?
>
> Thanks,
> Justin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160622/54434ed1/attachment-0001.html>
-------------- next part --------------
diff --git a/src/snes/examples/tutorials/ex9.c b/src/snes/examples/tutorials/ex9.c
index 4e57917..acd5ca7 100644
--- a/src/snes/examples/tutorials/ex9.c
+++ b/src/snes/examples/tutorials/ex9.c
@@ -42,7 +42,6 @@ typedef struct {
} ObsCtx;
extern PetscErrorCode FormPsiAndExactSoln(DM);
-extern PetscErrorCode FormBounds(SNES,Vec,Vec);
extern PetscErrorCode FormFunctionLocal(DMDALocalInfo*,PetscScalar**,PetscScalar**,ObsCtx*);
extern PetscErrorCode FormJacobianLocal(DMDALocalInfo*,PetscScalar**,Mat,Mat,ObsCtx*);
@@ -54,7 +53,8 @@ int main(int argc,char **argv)
ObsCtx user;
SNES snes;
DM da;
- Vec u; /* solution */
+ Vec u, /* solution */
+ Xu; /* upper bound */
DMDALocalInfo info;
PetscReal error1,errorinf;
@@ -84,7 +84,12 @@ int main(int argc,char **argv)
ierr = SNESSetDM(snes,da);CHKERRQ(ierr);
ierr = SNESSetApplicationContext(snes,&user);CHKERRQ(ierr);
ierr = SNESSetType(snes,SNESVINEWTONRSLS);CHKERRQ(ierr);
- ierr = SNESVISetComputeVariableBounds(snes,&FormBounds);CHKERRQ(ierr);
+
+ /* set upper and lower bound constraints for VI */
+ ierr = VecDuplicate(u,&Xu);CHKERRQ(ierr);
+ ierr = VecSet(Xu,PETSC_INFINITY);CHKERRQ(ierr);
+ ierr = SNESVISetVariableBounds(snes,user.psi,Xu);CHKERRQ(ierr);
+ ierr = VecDestroy(&Xu);CHKERRQ(ierr);
ierr = DMDASNESSetFunctionLocal(da,INSERT_VALUES,(PetscErrorCode (*)(DMDALocalInfo*,void*,void*,void*))FormFunctionLocal,&user);CHKERRQ(ierr);
ierr = DMDASNESSetJacobianLocal(da,(PetscErrorCode (*)(DMDALocalInfo*,void*,Mat,Mat,void*))FormJacobianLocal,&user);CHKERRQ(ierr);
@@ -158,22 +163,6 @@ PetscErrorCode FormPsiAndExactSoln(DM da) {
#undef __FUNCT__
-#define __FUNCT__ "FormBounds"
-/* FormBounds() for call-back: tell SNESVI (variational inequality)
- that we want u >= psi */
-PetscErrorCode FormBounds(SNES snes, Vec Xl, Vec Xu) {
- PetscErrorCode ierr;
- ObsCtx *user;
-
- PetscFunctionBeginUser;
- ierr = SNESGetApplicationContext(snes,&user);CHKERRQ(ierr);
- ierr = VecCopy(user->psi,Xl);CHKERRQ(ierr); /* u >= psi */
- ierr = VecSet(Xu,PETSC_INFINITY);CHKERRQ(ierr);
- PetscFunctionReturn(0);
-}
-
-
-#undef __FUNCT__
#define __FUNCT__ "FormFunctionLocal"
/* FormFunctionLocal - Evaluates nonlinear function, F(x) on local process patch */
PetscErrorCode FormFunctionLocal(DMDALocalInfo *info,PetscScalar **x,PetscScalar **f,ObsCtx *user) {
diff --git a/src/snes/examples/tutorials/output/ex9_5.out b/src/snes/examples/tutorials/output/ex9_5.out
index d465a07..8b81a5b 100644
--- a/src/snes/examples/tutorials/output/ex9_5.out
+++ b/src/snes/examples/tutorials/output/ex9_5.out
@@ -1,6 +1,6 @@
setup done: grid Mx,My = 11,11 with spacing dx,dy = 0.4000,0.4000
0 SNES Function norm 3.8949
1 SNES Function norm 0.595977
- 2 SNES Function norm 1.33042e-06
+ 2 SNES Function norm 1.33052e-06
3 SNES Function norm < 1.e-11
errors: av |u-uexact| = 7.156e-03 |u-uexact|_inf = 2.550e-02
diff --git a/src/snes/examples/tutorials/output/ex9_6.out b/src/snes/examples/tutorials/output/ex9_6.out
index bbcd4d9..7f04d68 100644
--- a/src/snes/examples/tutorials/output/ex9_6.out
+++ b/src/snes/examples/tutorials/output/ex9_6.out
@@ -1,53 +1,53 @@
setup done: grid Mx,My = 81,81 with spacing dx,dy = 0.0500,0.0500
0 SNES Function norm 8.91139
- 0 KSP Residual norm 7.66854
- 1 KSP Residual norm 0.0817114
- 2 KSP Residual norm 0.0014303
- 3 KSP Residual norm 4.09214e-05
+ 0 KSP Residual norm 7.66838
+ 1 KSP Residual norm 0.0855604
+ 2 KSP Residual norm 0.00147261
+ 3 KSP Residual norm 4.02632e-05
1 SNES Function norm 1.79664
- 0 KSP Residual norm 3.66508
- 1 KSP Residual norm 0.0254715
- 2 KSP Residual norm 0.000698771
- 3 KSP Residual norm 1.52442e-05
+ 0 KSP Residual norm 3.66486
+ 1 KSP Residual norm 0.0256337
+ 2 KSP Residual norm 0.000698574
+ 3 KSP Residual norm 1.50355e-05
2 SNES Function norm 0.965357
- 0 KSP Residual norm 2.0992
- 1 KSP Residual norm 0.0107506
- 2 KSP Residual norm 0.000332135
- 3 KSP Residual norm 7.30506e-06
+ 0 KSP Residual norm 2.09921
+ 1 KSP Residual norm 0.010811
+ 2 KSP Residual norm 0.000336569
+ 3 KSP Residual norm 7.32146e-06
3 SNES Function norm 0.602599
- 0 KSP Residual norm 1.33076
- 1 KSP Residual norm 0.00851554
- 2 KSP Residual norm 0.000224731
- 3 KSP Residual norm 4.94949e-06
+ 0 KSP Residual norm 1.33072
+ 1 KSP Residual norm 0.0085465
+ 2 KSP Residual norm 0.000224369
+ 3 KSP Residual norm 4.90542e-06
4 SNES Function norm 0.37491
- 0 KSP Residual norm 0.826408
- 1 KSP Residual norm 0.00409587
- 2 KSP Residual norm 0.000122243
- 3 KSP Residual norm 2.85825e-06
+ 0 KSP Residual norm 0.826413
+ 1 KSP Residual norm 0.00411738
+ 2 KSP Residual norm 0.000124072
+ 3 KSP Residual norm 2.84879e-06
5 SNES Function norm 0.215489
- 0 KSP Residual norm 0.419143
- 1 KSP Residual norm 0.00291159
- 2 KSP Residual norm 8.03321e-05
- 3 KSP Residual norm 1.69582e-06
+ 0 KSP Residual norm 0.41911
+ 1 KSP Residual norm 0.00292809
+ 2 KSP Residual norm 8.03589e-05
+ 3 KSP Residual norm 1.69054e-06
6 SNES Function norm 0.110008
- 0 KSP Residual norm 0.145017
- 1 KSP Residual norm 0.00102091
- 2 KSP Residual norm 2.75348e-05
- 3 KSP Residual norm 5.21408e-07
+ 0 KSP Residual norm 0.144991
+ 1 KSP Residual norm 0.00101012
+ 2 KSP Residual norm 2.76287e-05
+ 3 KSP Residual norm 5.30273e-07
7 SNES Function norm 0.0509393
- 0 KSP Residual norm 0.06307
- 1 KSP Residual norm 0.000503537
- 2 KSP Residual norm 1.32709e-05
- 3 KSP Residual norm 3.31102e-07
+ 0 KSP Residual norm 0.0630681
+ 1 KSP Residual norm 0.00050114
+ 2 KSP Residual norm 1.32608e-05
+ 3 KSP Residual norm 3.33183e-07
8 SNES Function norm 0.00699757
- 0 KSP Residual norm 0.00485744
- 1 KSP Residual norm 3.93063e-05
- 2 KSP Residual norm 1.07492e-06
- 3 KSP Residual norm 2.17717e-08
- 9 SNES Function norm 9.21939e-08
- 0 KSP Residual norm 2.17718e-08
- 1 KSP Residual norm 8.694e-10
- 2 KSP Residual norm 2.238e-11
+ 0 KSP Residual norm 0.00485817
+ 1 KSP Residual norm 3.88895e-05
+ 2 KSP Residual norm 1.07055e-06
+ 3 KSP Residual norm 2.16788e-08
+ 9 SNES Function norm 9.18511e-08
+ 0 KSP Residual norm 2.16788e-08
+ 1 KSP Residual norm 8.553e-10
+ 2 KSP Residual norm 2.212e-11
3 KSP Residual norm < 1.e-11
4 KSP Residual norm < 1.e-11
10 SNES Function norm < 1.e-11
diff --git a/src/snes/examples/tutorials/output/ex9_7.out b/src/snes/examples/tutorials/output/ex9_7.out
index e4b2c9c..27ca8d8 100644
--- a/src/snes/examples/tutorials/output/ex9_7.out
+++ b/src/snes/examples/tutorials/output/ex9_7.out
@@ -1,18 +1,18 @@
setup done: grid Mx,My = 21,21 with spacing dx,dy = 0.2000,0.2000
0 SNES Function norm 4.16496
- 0 SNES VI Function norm 5.529305066445e+00 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.
- 1 SNES VI Function norm 6.955134607642e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
- 0 SNES VI Function norm 6.955134607642e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
- 1 SNES VI Function norm 2.094553435635e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
+ 0 SNES VI Function norm 5.52931 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.156463
+ 1 SNES VI Function norm 0.695513 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
+ 0 SNES VI Function norm 0.695513 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
+ 1 SNES VI Function norm 0.209455 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
1 SNES Function norm 0.209455
- 0 SNES VI Function norm 2.094553435635e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
- 1 SNES VI Function norm 8.520955028454e-02 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 0 SNES VI Function norm 8.520955028454e-02 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 1.306727995906e-02 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.209455 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
+ 1 SNES VI Function norm 0.0852096 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 0 SNES VI Function norm 0.0852096 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 0.0130673 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
2 SNES Function norm 0.0130673
- 0 SNES VI Function norm 1.306727995906e-02 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 5.700004299565e-08 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 0 SNES VI Function norm 5.700004299565e-08 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 4.214574191759e-13 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.0130673 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 5.7e-08 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 0 SNES VI Function norm 5.7e-08 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 4.21547e-13 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
3 SNES Function norm < 1.e-11
errors: av |u-uexact| = 1.287e-03 |u-uexact|_inf = 7.882e-03
diff --git a/src/snes/examples/tutorials/output/ex9_8.out b/src/snes/examples/tutorials/output/ex9_8.out
index 24cc9a2..10f06d0 100644
--- a/src/snes/examples/tutorials/output/ex9_8.out
+++ b/src/snes/examples/tutorials/output/ex9_8.out
@@ -1,18 +1,18 @@
setup done: grid Mx,My = 21,21 with spacing dx,dy = 0.2000,0.2000
0 SNES Function norm 4.16496
- 0 SNES VI Function norm 5.529305066445e+00 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.
- 1 SNES VI Function norm 6.955134607642e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
+ 0 SNES VI Function norm 5.52931 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.156463
+ 1 SNES VI Function norm 0.695513 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
1 SNES Function norm 0.695513
- 0 SNES VI Function norm 6.955134607642e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
- 1 SNES VI Function norm 2.242112530318e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
+ 0 SNES VI Function norm 0.695513 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
+ 1 SNES VI Function norm 0.224211 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
2 SNES Function norm 0.224211
- 0 SNES VI Function norm 2.242112530318e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
- 1 SNES VI Function norm 8.520960015422e-02 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.224211 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
+ 1 SNES VI Function norm 0.0852096 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
3 SNES Function norm 0.0852096
- 0 SNES VI Function norm 8.520960015422e-02 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 3.719497543884e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.0852096 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 3.7195e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
4 SNES Function norm 3.7195e-07
- 0 SNES VI Function norm 3.719497543884e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 2.762524667649e-12 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 3.7195e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 2.76257e-12 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
5 SNES Function norm < 1.e-11
errors: av |u-uexact| = 1.287e-03 |u-uexact|_inf = 7.882e-03
diff --git a/src/snes/examples/tutorials/output/ex9_9.out b/src/snes/examples/tutorials/output/ex9_9.out
index ef6570a..77ab4ee 100644
--- a/src/snes/examples/tutorials/output/ex9_9.out
+++ b/src/snes/examples/tutorials/output/ex9_9.out
@@ -1,21 +1,21 @@
setup done: grid Mx,My = 21,21 with spacing dx,dy = 0.2000,0.2000
0 SNES Function norm 4.16496
- 0 SNES VI Function norm 5.529305066445e+00 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.
- 1 SNES VI Function norm 6.955134607642e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
+ 0 SNES VI Function norm 5.52931 Active lower constraints 69/79 upper constraints 0/0 Percent of total 0.156463 Percent of bounded 0.156463
+ 1 SNES VI Function norm 0.695513 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
1 SNES Function norm 0.708647
- 0 SNES VI Function norm 6.520805467410e-01 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.
- 1 SNES VI Function norm 2.242111559824e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
+ 0 SNES VI Function norm 0.652081 Active lower constraints 57/69 upper constraints 0/0 Percent of total 0.129252 Percent of bounded 0.129252
+ 1 SNES VI Function norm 0.224211 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
2 SNES Function norm 0.759478
- 0 SNES VI Function norm 2.242111559824e-01 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.
- 1 SNES VI Function norm 8.520960016210e-02 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.224211 Active lower constraints 49/57 upper constraints 0/0 Percent of total 0.111111 Percent of bounded 0.111111
+ 1 SNES VI Function norm 0.0852096 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
3 SNES Function norm 0.134526
- 0 SNES VI Function norm 1.345259947681e-01 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 2.347080344381e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.134526 Active lower constraints 45/49 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 2.34708e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
4 SNES Function norm 0.00191518
- 0 SNES VI Function norm 1.915180573496e-03 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 3.337090244033e-09 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 0.00191518 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 3.33709e-09 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
5 SNES Function norm 3.82153e-07
- 0 SNES VI Function norm 3.821526562597e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
- 1 SNES VI Function norm 7.033950685756e-13 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.
+ 0 SNES VI Function norm 3.82153e-07 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
+ 1 SNES VI Function norm 7.03211e-13 Active lower constraints 45/45 upper constraints 0/0 Percent of total 0.102041 Percent of bounded 0.102041
6 SNES Function norm < 1.e-11
errors: av |u-uexact| = 1.287e-03 |u-uexact|_inf = 7.882e-03
More information about the petsc-users
mailing list