[petsc-users] Custom matrix coloring for finite difference Jacobian

Barry Smith bsmith at petsc.dev
Wed Sep 17 14:10:21 CDT 2025


   Sorry, it looks like no one has gotten back to you yet.

   We don't have a mechanism for providing your own CreateColoring() for a DM at this time. The DMShellSetXXX() functionality appears to be the best way to provide the functionality. This would require adding a C DMShellSetCreateColoring() function and then mirroring the functionality over to petsc4py as is done for other DMShellSetXXX functions. 

  As a side note, the various DMShellSetXXX() functions currently have an error checker that restricts their use to a DMSHELL. I am not sure that is needed or desirable in the PETSc source, and I suggest we remove it since it is sometimes legitimate to overwrite the default DM operation, as in your situation.

  If this is something you would benefit from, consider making an MR that adds this functionality, or we can try to provide it.

  Barry


> On Sep 11, 2025, at 7:25 PM, Eirik Jaccheri Høydalsvik via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> Hi,
> 
> I have made a two-phase flow code which computes motion of two phases in one dimension, where the phases are allowed to intermix. This code relies on a finite difference Jacobian computed using the standard coloring I get from the DMDA object:
> 
>    da = PETSc.DMDA().create(
>         dim=(N_vertical,),
>         dof=3,
>         stencil_width=1,
>     )
> 
> I now want to add a variable for the interphase height L_z in addition to a velocity u_v, giving the velocity of the vapor flowing in to the interface. The interface will move throughout the grid, meaning that these two variables will not be coupled to a fixed set of grid cells, but will be coupled to different sets of three grid cells throughout the simulation.
> 
> Questions:
> 
> 1. Is it possible to create a custom coloring to efficiently compute the finite difference Jacobian including the interphase height and vapor velocity?
> 
> 2. How do I revert to computing the full finite difference Jacobian with the purpose of testing if the interphase model works?
> 
> Best regards,
> Eirik Jaccheri Høydalsvik
> Sintef ER and NTNU EPT

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250917/87fb09f4/attachment.html>


More information about the petsc-users mailing list