On Sun, May 19, 2024 at 11:25 PM Barry Smith <bsm...@petsc.dev> wrote:

> Certainly missing Jacobian entries can dramatically change the Newton
> direction and hence the convergence. Even if the optimal (in time) setup
> skips some Jacobian entries it is always good to have runs with all the
> entries to see the "best
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>
> ZjQcmQRYFpfptBannerEnd
>
>   Certainly missing Jacobian entries can dramatically change the Newton
> direction and hence the convergence. Even if the optimal (in time) setup
> skips some Jacobian entries it is always good to have runs with all the
> entries to see the "best possible" convergence.
>

Let me expand on this. If you are missing Jacobian entries, one option is
to use the -snes_mf_operator mode for the solve. In this mode, you provide
an approximate Jacobian that is used to generate the preconditioner, but
the action of the Jacobian is calculated by finite differences using the
residual function. Thus, the Jaccbian "matrix" should be consistent with
the residual, but the preconditioner is approximate.

  Thanks,

      Matt


>   Barry
>
>
> On May 19, 2024, at 10:44 PM, Adrian Croucher <a.crouc...@auckland.ac.nz>
> wrote:
>
> Great, it sounds like this might be easier than I expected. Thanks very
> much.
>
> Did you have any thoughts on my diagnosis of the problem (the poor
> nonlinear solver convergence being caused by missing Jacobian elements
> representing interaction between the sources)?
>
> - Adrian
> On 20/05/24 12:41 pm, Matthew Knepley wrote:
>
> On Sun, May 19, 2024 at 8:25 PM Barry Smith <bsm...@petsc.dev> wrote:
>
>> You can call MatSetOption(mat,MAT_NEW_NONZERO_LOCATION_ERR) then insert
>> the new values. If it is just a handful of new insertions the extra time
>> should be small. Making a copy of the matrix won't give you a new matrix
>> that is any faster to
>> ZjQcmQRYFpfptBannerStart
>> This Message Is From an External Sender
>> This message came from outside your organization.
>>
>> ZjQcmQRYFpfptBannerEnd
>>
>>    You can call MatSetOption(mat,MAT_NEW_NONZERO_LOCATION_ERR) then
>> insert the new values. If it is just a handful of new insertions the extra
>> time should be small.
>>
>>     Making a copy of the matrix won't give you a new matrix that is any
>> faster to insert into so best to just use the same matrix.
>>
>
> Let me add to Barry's answer. The preallocation infrastructure is now not
> strictly necessary. It is possible to just add all your nonzeros in and
> assembly,  and the performance will be pretty good (uses hashing etc). So
> if just adding a few nonzeros does not work, we can go this route.
>
>   Thanks,
>
>      Matt
>
>
>>   Barry
>>
>>
>> On May 19, 2024, at 7:44 PM, Adrian Croucher <a.crouc...@auckland.ac.nz>
>> wrote:
>>
>> This Message Is From an External Sender
>> This message came from outside your organization.
>>
>> hi,
>>
>> I have a Jacobian matrix created using DMCreateMatrix(). What would be
>> the best way to add extra nonzero entries into it?
>>
>> I'm guessing that DMCreateMatrix() allocates the storage so the nonzero
>> structure can't really be easily modified. Would it be a case of
>> creating a new matrix, copying the nonzero entries from the original one
>> and then adding the extra ones, before calling MatSetUp() or similar? If
>> so, how exactly would you copy the nonzero structure from the original
>> matrix?
>>
>> Background: the flow problem I'm solving (on a DMPlex with finite volume
>> method) has complex source terms that depend on the solution (e.g.
>> pressure), and can also depend on other source terms. A simple example
>> is when fluid is extracted from one location, with a pressure-dependent
>> flow rate, and some of it is then reinjected in another location. This
>> can result in poor nonlinear solver convergence. I think the reason is
>> that there are effectively missing Jacobian entries in the row for the
>> reinjection cell, which should have an additional dependence on the
>> solution in the cell where fluid is extracted.
>>
>> - Adrian
>>
>>
> --
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> Waipapa Taumata Rau / University of Auckland, New Zealand
> email: a.crouc...@auckland.ac.nz
> tel: +64 (0)9 923 4611
>
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eoJE8Eq9V_WNo4aDVL3rN9-rq3xKlASAxI-BbyITAUnKZ2Se208TWSxPRfxptNTBq0ZDwJ7rPdCyNyy2-i4i$
  
<https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eoJE8Eq9V_WNo4aDVL3rN9-rq3xKlASAxI-BbyITAUnKZ2Se208TWSxPRfxptNTBq0ZDwJ7rPdCyN0s5AfvC$
 >

Reply via email to