<div dir="ltr">Hi again Barry,<div><br></div><div>I sorted out the jacobian issue, and made a comparison between the two definitions of the active set.</div><div>The active set with strict inequality takes the same or fewer Newton steps than the current petsc code. With a larger search space, I expect this to happen. snes_vi_monitor logs comparing the two are shown below.</div><div><br></div><div>I could submit a pull request with the change, but we should probably consider:</div><div>1) Whether this active set definition is consistent with newtonssls</div><div>2) The linear systems to solve becomes larger, so for some cases the overall performance might not improve so much.</div><div>3) For more flexibility, we could add an option to decide whether to use a strict inequality or not. This would sort out 1) and 2).</div><div><br></div><div>I don't have much experience with the petsc codebase though, so adding options might take me some time.</div><div><br></div><div><br></div><div>Ozzy</div><div><br></div><div><br></div><div>__ log using my patch __</div><div><div> 0 SNES VI Function norm 7.796491981333e+02 Active lower constraints 0/18 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 1 SNES VI Function norm 2.405400030748e+02 Active lower constraints 0/16 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 2 SNES VI Function norm 2.145739795389e+02 Active lower constraints 0/17 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 3 SNES VI Function norm 1.942498283668e+02 Active lower constraints 0/13 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 4 SNES VI Function norm 1.834306037299e+01 Active lower constraints 0/11 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 5 SNES VI Function norm 1.724597091463e+01 Active lower constraints 0/11 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 6 SNES VI Function norm 4.210027533399e-02 Active lower constraints 0/10 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div> 7 SNES VI Function norm 3.014124871281e-07 Active lower constraints 0/10 upper constraints 0/0 Percent of total 0 Percent of bounded 0</div><div>SNES Object:(firedrake_snes_0_) 1 MPI processes</div><div> type: vinewtonrsls</div><div> maximum iterations=20, maximum function evaluations=10000</div><div> tolerances: relative=0, absolute=1e-06, solution=0</div><div> total number of linear solver iterations=7</div><div> total number of function evaluations=22</div><div> norm schedule ALWAYS</div><div> SNESLineSearch Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: l2</div><div> maxstep=1.000000e+08, minlambda=1.000000e-12</div><div> tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08</div><div> maximum iterations=1</div><div> KSP Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: preonly</div><div> maximum iterations=10000, initial guess is zero</div><div> tolerances: relative=1e-05, absolute=1e-50, divergence=10000</div><div> left preconditioning</div><div> using NONE norm type for convergence test</div><div> PC Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: lu</div><div> LU: out-of-place factorization</div><div> tolerance for zero pivot 2.22045e-14</div><div> matrix ordering: nd</div><div> factor fill ratio given 5, needed 1.54545</div><div> Factored matrix follows:</div><div> Mat Object: 1 MPI processes</div><div> type: seqaij</div><div> rows=36, cols=36</div><div> package used to perform factorization: petsc</div><div> total: nonzeros=816, allocated nonzeros=816</div><div> total number of mallocs used during MatSetValues calls =0</div><div> using I-node routines: found 15 nodes, limit used is 5</div><div> linear system matrix = precond matrix:</div><div> Mat Object: 1 MPI processes</div><div> type: seqaij</div><div> rows=36, cols=36</div><div> total: nonzeros=528, allocated nonzeros=528</div><div> total number of mallocs used during MatSetValues calls =0</div><div> not using I-node routines</div></div><div>--------------------------------------------------</div><div><br></div><div>__ log using the original petsc code __</div><div><div> 0 SNES VI Function norm 7.796491981333e+02 Active lower constraints 12/18 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 1 SNES VI Function norm 2.630718602212e+02 Active lower constraints 12/16 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 2 SNES VI Function norm 2.363417090057e+02 Active lower constraints 12/17 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 3 SNES VI Function norm 1.902271040685e+01 Active lower constraints 12/14 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 4 SNES VI Function norm 1.866193366410e+01 Active lower constraints 12/12 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 5 SNES VI Function norm 1.865568900723e+01 Active lower constraints 12/12 upper constraints 0/0 Percent of total 0.333333 Percent of bounded 0.333333</div><div> 6 SNES VI Function norm 2.182461654877e+02 Active lower constraints 10/12 upper constraints 0/0 Percent of total 0.277778 Percent of bounded 0.277778</div><div> 7 SNES VI Function norm 2.575010971279e-01 Active lower constraints 10/11 upper constraints 0/0 Percent of total 0.277778 Percent of bounded 0.277778</div><div> 8 SNES VI Function norm 1.056372578821e-05 Active lower constraints 10/10 upper constraints 0/0 Percent of total 0.277778 Percent of bounded 0.277778</div><div> 9 SNES VI Function norm 4.368019257866e-11 Active lower constraints 10/10 upper constraints 0/0 Percent of total 0.277778 Percent of bounded 0.277778</div><div>SNES Object:(firedrake_snes_0_) 1 MPI processes</div><div> type: vinewtonrsls</div><div> maximum iterations=20, maximum function evaluations=10000</div><div> tolerances: relative=0, absolute=1e-06, solution=0</div><div> total number of linear solver iterations=9</div><div> total number of function evaluations=28</div><div> norm schedule ALWAYS</div><div> SNESLineSearch Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: l2</div><div> maxstep=1.000000e+08, minlambda=1.000000e-12</div><div> tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08</div><div> maximum iterations=1</div><div> KSP Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: preonly</div><div> maximum iterations=10000, initial guess is zero</div><div> tolerances: relative=1e-05, absolute=1e-50, divergence=10000</div><div> left preconditioning</div><div> using NONE norm type for convergence test</div><div> PC Object: (firedrake_snes_0_) 1 MPI processes</div><div> type: lu</div><div> LU: out-of-place factorization</div><div> tolerance for zero pivot 2.22045e-14</div><div> matrix ordering: nd</div><div> factor fill ratio given 5, needed 1.57895</div><div> Factored matrix follows:</div><div> Mat Object: 1 MPI processes</div><div> type: seqaij</div><div> rows=26, cols=26</div><div> package used to perform factorization: petsc</div><div> total: nonzeros=420, allocated nonzeros=420</div><div> total number of mallocs used during MatSetValues calls =0</div><div> using I-node routines: found 11 nodes, limit used is 5</div><div> linear system matrix = precond matrix:</div><div> Mat Object: 1 MPI processes</div><div> type: seqaij</div><div> rows=26, cols=26</div><div> total: nonzeros=266, allocated nonzeros=266</div><div> total number of mallocs used during MatSetValues calls =0</div><div> not using I-node routines</div></div><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Sat, 30 May 2015 at 01:07 Asbjørn Nilsen Riseth <<a href="mailto:riseth@maths.ox.ac.uk" target="_blank">riseth@maths.ox.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Barry,<div><br></div><div>thanks for the offer to have a look at the code. I ran SNESTEST today: user-defined failed, 1.0 and -1.0 seemed to work fine. My first step will have to be to find out what's wrong with my jacobian. If I've still got issues after that, I'll try to set up an easy-to-experiment code</div><div><br></div><div>The code is a DG0 FVM formulation set up in Firedrake (a "fork" of FEniCS). I was assuming UFL would sort the Jacobian for me.</div><div>Lesson learnt: always do a SNESTEST.</div><div><br></div><div><br></div><div>Ozzy</div></div><div dir="ltr"><div><br><div class="gmail_quote"><div dir="ltr">On Fri, 29 May 2015 at 19:21 Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On May 29, 2015, at 4:19 AM, Asbjørn Nilsen Riseth <<a href="mailto:riseth@maths.ox.ac.uk" target="_blank">riseth@maths.ox.ac.uk</a>> wrote:<br>
><br>
> Barry,<br>
><br>
> I changed the code, but it only makes a difference at the order of 1e-10 - so that's not the cause. I've attached (if that's appropriate?) the patch in case anyone is interested.<br>
><br>
> Investigating the function values, I see that the first Newton step goes towards the expected solution for my function values. Then it shoots back close to the initial conditions.<br>
<br>
When does it "shoot back close to the initial conditions"? At the second Newton step? If so is the residual norm still smaller at the second step?<br>
<br>
> At the time the solver hits tolerance for the inactive set; the function value is 100-1000 at some of the active set indices.<br>
> Reducing the timestep by an order of magnitude shows the same behavior for the first two timesteps.<br>
><br>
> Maybe VI is not the right approach. The company I work with seem to just be projecting negative values.<br>
<br>
The VI solver is essentially just a "more sophisticated" version of "projecting negative values" so should not work worse then an ad hoc method and should generally work better (sometimes much better).<br>
<br>
Is your code something simple you could email me to play with or is it a big application that would be hard for me to experiment with?<br>
<br>
<br>
<br>
Barry<br>
<br>
><br>
> I'll investigate further.<br>
><br>
> Ozzy<br>
><br>
><br>
> On Thu, 28 May 2015 at 20:26 Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> Ozzy,<br>
><br>
> I cannot say why it is implemented as >= (could be in error). Just try changing the PETSc code (just run make gnumake in the PETSc directory after you change the source to update the library) and see how it affects your code run.<br>
><br>
> Barry<br>
><br>
> > On May 28, 2015, at 3:15 AM, Asbjørn Nilsen Riseth <<a href="mailto:riseth@maths.ox.ac.uk" target="_blank">riseth@maths.ox.ac.uk</a>> wrote:<br>
> ><br>
> > Dear PETSc developers,<br>
> ><br>
> > Is the active set in NewtonRSLS defined differently from the reference* you give in the documentation on purpose?<br>
> > The reference defines the active set as:<br>
> > x_i = 0 and F_i > 0,<br>
> > whilst the PETSc code defines it as x_i = 0 and F_i >= 0 (vi.c: 356) :<br>
> > !((PetscRealPart(x[i]) > PetscRealPart(xl[i]) + 1.e-8 || (PetscRealPart(f[i]) < 0.0)<br>
> > So PETSc freezes the variables if f[i] == 0.<br>
> ><br>
> > I've been using the Newton RSLS method to ensure positivity in a subsurface flow problem I'm working on. My solution stays almost constant for two timesteps (seemingly independent of the size of the timestep), before it goes towards the expected solution.<br>
> > From my initial conditions, certain variables are frozen because x_i = 0 and f[i] = 0, and I was wondering if that could be the cause of my issue.<br>
> ><br>
> ><br>
> > *:<br>
> > - T. S. Munson, and S. Benson. Flexible Complementarity Solvers for Large-Scale Applications, Optimization Methods and Software, 21 (2006).<br>
> ><br>
> ><br>
> > Regards,<br>
> > Ozzy<br>
><br>
> <0001-Define-active-and-inactive-sets-correctly.patch><br>
<br>
</blockquote></div></div></div></blockquote></div></div>