[petsc-users] Problem with KSPGetPC within FieldSplit context
Matthew Knepley
knepley at gmail.com
Mon May 18 08:42:38 CDT 2026
On Tue, Mar 24, 2026 at 2:31 PM Lucia Barandiaran via petsc-users <
petsc-users at mcs.anl.gov> wrote:
> Dear PETSc community,
>
> We recently updated PETSc libraries and came across with a problem with
> FieldSplit preconditioning (our code is implemented in Fortran 90).
>
Hi Lucia,
It looks like no one has answered, so I will try.
I found this example doing what you want:
https://urldefense.us/v3/__https://petsc.org/main/src/ksp/ksp/tutorials/ex7f.F90.html__;!!G_uCfscf7eWS!ffhItiXPRGqL12Cm8zfgA3cJ-lq0wTR-Ps_Yfj0WcTtLylJ7w1bKSGfj7gfbUC-DkI-SOf_Sn1OyZD0ylKex$
It seems that you need to initialize the pointer to null, and also the
array starts at 1.
Can you run the example?
Thanks,
Matt
> In the older version, when calling PCFieldSplitGetSubKSP we declared the
> subksp array as KSP and it worked perfectly. However, now we must declare
> it as a Fortran pointer and allocate it before
> calling PCFieldSplitGetSubKSP otherwise the code won't compile...
>
> With the new modification, that part of the code is the following:
>
> ****Variable declarations
>
> PetscInt :: n_splits_retrieved
> IS :: IS_field(max_field)
> KSP, pointer :: subksp_array(:)
> PC :: subpc(max_field)
> INTEGER(iwp) :: nfield, ifield
>
> **** FieldSplit Part ****
>
> ! Allocate Fortran array to hold the KSP contexts
> ALLOCATE(subksp_array(n_splits_retrieved))
>
> ! Second call to get the actual KSP contexts
> CALL PCFieldSplitGetSubKSP(solver%pc, n_splits_retrieved, &
> subksp_array, ierr)
>
> IF (n_splits_retrieved >= 2) THEN
> DO ifield = 1, n_splits_retrieved
>
> ! Configure the KSP for the velocity block (field 0)
> CALL KSPGetPC(subksp_array(ifield), subpc(ifield), ierr)
> CALL KSPSetType(subksp_array(ifield), KSPGMRES, ierr)
> CALL PCSetType(subpc(ifield), PCJACOBI, ierr)
> ! Allows runtime options for sub-KSP
> CALL KSPSetFromOptions(subksp_array(ifield), ierr)
> ! Choose a viewer (stdout for example)
> ! viewer = PETSC_VIEWER_STDOUT_WORLD
> ! CALL PCView(subpc(ifield),viewer,ierr)
> END DO
> END IF
>
> When debugging the fortran code we observed that it stops with an error
> when calling KSPGetPC and we can't figure out what are we doing wrong...
> Maybe we need an interface when calling that function?
>
> Thanks very much for your time,
>
> Sincerely,
>
> Lucía Barandiarán
>
> Scientific software developer - Dracsys
>
> Collaborator at MECMAT group - Universitat Politècnica de Catalunya (UPC)
>
--
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!ffhItiXPRGqL12Cm8zfgA3cJ-lq0wTR-Ps_Yfj0WcTtLylJ7w1bKSGfj7gfbUC-DkI-SOf_Sn1OyZJC2yvOw$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ffhItiXPRGqL12Cm8zfgA3cJ-lq0wTR-Ps_Yfj0WcTtLylJ7w1bKSGfj7gfbUC-DkI-SOf_Sn1OyZLTzok7e$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20260518/c71607d5/attachment.html>
More information about the petsc-users
mailing list