<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div>   Stefano will need to provide the full explanation with trust regions I will just try to provide some background based on looking at the code.<div><br></div><div>   Something that is not made clear in the manual page is that for <span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;">SNESSetFunctionDomainError() to work (in line search codes) properly, you must also set some Infinity or NaN into the computed vector.  I have attempted to make this clear in </span><a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/8603__;!!G_uCfscf7eWS!c2YPoljsHfCf3J1-tV6cQV7kuT9ezJmi1Kuv-pGMFz6-6ZuXvyEXCAbHOTEZ-AX9a_LlrYH2HTafcS-AU2WCXLw$">https://gitlab.com/petsc/petsc/-/merge_requests/8603</a></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><br></span></div><div>   In looking at SNESSolve_NEWTONTR() </div><div><br></div><div>   if the initial "guess" is not in the domain; that is you called <span style="font-family: arial, helvetica, sans-serif; font-size: 16px;">SNESSetFunctionDomainError() and set some vector entry to NaN or infinity) then it hits the lines</span></div><div><font face="arial, helvetica, sans-serif" size="3"><br></font></div><div><font face="arial, helvetica, sans-serif" size="3">   </font>if (!snes->vec_func_init_set) {<div>    PetscCall(SNESComputeFunction(snes, X, F)); /* F(X) */</div><div>  } else snes->vec_func_init_set = PETSC_FALSE;</div><div><br></div><div>  PetscCall(VecNorm(F, NORM_2, &fnorm)); /* fnorm <- || F || */</div><div>  SNESCheckFunctionNorm(snes, fnorm);</div><div><br></div><div>  and will return from SNESSolve() with SNES_DIVERGED_FUNCTION_DOMAIN (I think this is likely what we want to happen).</div><div><br></div><div>   Later in the algorithm, the nonlinear function gets called with</div><div><br></div><div>       /* Compute new objective function */</div><div>    PetscCall(SNESNewtonTRObjective(snes, has_objective, X, Y, W, G, &gnorm, &fkp1));</div><div>    if (PetscIsInfOrNanReal(fkp1)) rho = neP->eta1;</div><div><br></div><div>   So if part of the function vector has an Inf or NaN it sets rho to neP->eta1.</div><div>   But rho must be > neP->eta1 so the step is rejected and presumably</div><div>   the trust region will be shrunk or the algorithm will give up. Note that any value you gave for <span style="font-family: arial, helvetica, sans-serif; font-size: 16px;">SNESSetFunctionDomainError() is ignored.</span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;"><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;">   Barry</span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;"><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;"><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;">    </span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;"><br></span></div><div><span style="font-family: arial, helvetica, sans-serif; font-size: 16px;">   </span></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><blockquote type="cite"><div>On Jul 28, 2025, at 12:52 PM, Ali ALI AHMAD <ali.ali_ahmad@utt.fr> wrote:</div><br class="Apple-interchange-newline"><div><div><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"><div>Hi,</div><div><br data-mce-bogus="1"></div><div style="margin: 0px;">I am currently using the NEWTONTR method for compressible flow simulations. In some cases, I obtain non-physical solutions (for example, negative pressure). Can I use <code data-start="236" data-end="264">SNESSetFunctionDomainError</code> in this case? I tried, but I don’t fully understand how it works with NEWTONTR.</div><div style="margin: 0px;"><br data-mce-bogus="1"></div><div style="margin: 0px;">Thank you in advance</div><div><br data-mce-bogus="1"></div><div><div>best regrads,</div><div>Ali ALI AHMAD</div></div></div></div></div></blockquote></div><br></div></body></html>