Re: [petsc-users] SNES function domain error

2015-12-03 Thread Adrian Croucher

hi

On 03/12/15 18:43, Barry Smith wrote:

I absolutely do NOT recommend doing variable switching with SNES. Our 
Newton solvers are not designed with variable switching in mind so you get 
these absurd limitations like needing SNESLINESEARCHBASIC

It would be great if someone who understood variable switching would either 
1) contribute a Newton that supports variable switching to PETSc or 2) enhance 
the current SNESSolve_NewtonLS to support variable switching (I don't know 
which is easier).


I had resigned myself to not being able to use a line search, partly 
because the nonlinear solver in the TOUGH2 simulator (which we've used 
for many years to solve geothermal flow problems with phase changes and 
variable switching) doesn't use one either, and it generally works fine 
without one. Without the line search, SNES is doing much the same thing 
and doesn't seem to be upset by the variable switching either. It's only 
the error handling that's causing trouble.


But also I couldn't really see how a line search could be made to work 
with variable switching. When you switch variables, you're effectively 
doing a discontinuous leap into another part of the solution space. How 
can searching along a line between the old phase conditions and the new 
ones be made to make sense? Are there literature examples where people 
have done it?


Cheers, Adrian

--
Dr Adrian Croucher
Senior Research Fellow
Department of Engineering Science
University of Auckland, New Zealand
email: a.crouc...@auckland.ac.nz
tel: +64 (0)9 923 84611



Re: [petsc-users] SNES function domain error

2015-12-03 Thread Barry Smith

> On Dec 3, 2015, at 6:22 PM, Adrian Croucher  wrote:
> 
> hi
> 
> On 03/12/15 18:43, Barry Smith wrote:
>>I absolutely do NOT recommend doing variable switching with SNES. Our 
>> Newton solvers are not designed with variable switching in mind so you get 
>> these absurd limitations like needing SNESLINESEARCHBASIC
>> 
>>It would be great if someone who understood variable switching would 
>> either 1) contribute a Newton that supports variable switching to PETSc or 
>> 2) enhance the current SNESSolve_NewtonLS to support variable switching (I 
>> don't know which is easier).
> 
> I had resigned myself to not being able to use a line search, partly because 
> the nonlinear solver in the TOUGH2 simulator (which we've used for many years 
> to solve geothermal flow problems with phase changes and variable switching) 
> doesn't use one either, and it generally works fine without one. Without the 
> line search, SNES is doing much the same thing and doesn't seem to be upset 
> by the variable switching either. It's only the error handling that's causing 
> trouble.
> 
> But also I couldn't really see how a line search could be made to work with 
> variable switching. When you switch variables, you're effectively doing a 
> discontinuous leap into another part of the solution space. How can searching 
> along a line between the old phase conditions and the new ones be made to 
> make sense? Are there literature examples where people have done it?

   These are hard questions (at least to me) which is why I've never been able 
to implement a full featured Newton with variable switching. 

   Switching variables between function evaluations in a line search is 
completely nuts which is why I envision a "full featured" Newton with variable 
switching to be somewhat (or a lot) like active set (also called reduced space) 
Newton methods. Basically freeze the variables (not allow switching them) and 
build the Newton correction  including a full line search in a subspace that 
wouldn't violate any "bounds" on the variables. Then after this Newton step you 
decide if certain variables should be switched, and then you do the next full 
featured Newton step. So instead of freely switching variables at each function 
evaluation you only switch them at each "Jacobian" evaluation.

   There is some PETSc code SNESSolve_VINEWTONRSLS that solves nonlinear 
equations with bounds on some or all variables; but in this case there are not 
all the complications of variable switching, basically when variables are on 
the bound you just "turned off" the related equation. So it is possible that it 
is a very special case of what is needed for variable switching.

  Actually if you could provide a simple case of where variable switching is 
using I'd like to try to develop some algorithms, so far when I ask people they 
give me a big messy things with many variables that I could never understand.

   Barry



> 
> Cheers, Adrian
> 
> -- 
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> University of Auckland, New Zealand
> email: a.crouc...@auckland.ac.nz
> tel: +64 (0)9 923 84611
> 



[petsc-users] SNES function domain error

2015-12-02 Thread Adrian Croucher

hi

I am trying to use SNESSetFunctionDomainError() to make SNES abort when 
my solution vector goes out of the function domain. However, it's not 
always working.


Specifically, I check the solution in a function called after the 
linesearch (set using SNESLineSearchSetPostCheck()). If it has gone out 
of the function domain I call SNESSetFunctionDomainError(). (I also 
check for phase changes at this point and do variable switching if 
necessary, which seems to work fine as long as I only use 
SNESLINESEARCHBASIC.)


This causes the linesearch reason to return SNES_LINESEARCH_FAILED_DOMAIN.

In SNESSolve_NEWTONLS() (ls.c:251) it checks the linesearch reason, but 
then also checks if (snes->stol*xnorm > ynorm). If that is true then it 
resets the snes->reason to SNES_CONVERGED_SNORM_RELATIVE and returns, 
i.e. it overrides the function domain error. So it thinks everything is 
fine, even though the 'converged' solution is out of the function domain.


Is this how it's meant to work? If so, what can I do to ensure the SNES 
always aborts if the solution goes out of the function domain? At 
present it's only working if (snes->stol*xnorm <= ynorm) as well.


Cheers, Adrian

--
Dr Adrian Croucher
Senior Research Fellow
Department of Engineering Science
University of Auckland, New Zealand
email: a.crouc...@auckland.ac.nz
tel: +64 (0)9 923 84611



Re: [petsc-users] SNES function domain error

2015-12-02 Thread Barry Smith

  Set the -snes_stol to be so small that it doesn't trigger this reason?

  We are working on improving the "failure" modes of KSP/SNES so hopefully 
we'll have a better handle this type of thing in a few months.

 

> On Dec 2, 2015, at 10:09 PM, Adrian Croucher  
> wrote:
> 
> hi
> 
> I am trying to use SNESSetFunctionDomainError() to make SNES abort when my 
> solution vector goes out of the function domain. However, it's not always 
> working.
> 
> Specifically, I check the solution in a function called after the linesearch 
> (set using SNESLineSearchSetPostCheck()). If it has gone out of the function 
> domain I call SNESSetFunctionDomainError(). (I also check for phase changes 
> at this point and do variable switching if necessary, which seems to work 
> fine as long as I only use SNESLINESEARCHBASIC.)

   I absolutely do NOT recommend doing variable switching with SNES. Our Newton 
solvers are not designed with variable switching in mind so you get these 
absurd limitations like needing SNESLINESEARCHBASIC

   It would be great if someone who understood variable switching would either 
1) contribute a Newton that supports variable switching to PETSc or 2) enhance 
the current SNESSolve_NewtonLS to support variable switching (I don't know 
which is easier).

  Barry

> 
> This causes the linesearch reason to return SNES_LINESEARCH_FAILED_DOMAIN.
> 
> In SNESSolve_NEWTONLS() (ls.c:251) it checks the linesearch reason, but then 
> also checks if (snes->stol*xnorm > ynorm). If that is true then it resets the 
> snes->reason to SNES_CONVERGED_SNORM_RELATIVE and returns, i.e. it overrides 
> the function domain error. So it thinks everything is fine, even though the 
> 'converged' solution is out of the function domain.
> 
> Is this how it's meant to work? If so, what can I do to ensure the SNES 
> always aborts if the solution goes out of the function domain? At present 
> it's only working if (snes->stol*xnorm <= ynorm) as well.
> 
> Cheers, Adrian
> 
> -- 
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> University of Auckland, New Zealand
> email: a.crouc...@auckland.ac.nz
> tel: +64 (0)9 923 84611
>