<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Dear PETSc community,</p>
    <p>We recently updated PETSc libraries and came across with a
      problem with FieldSplit preconditioning (our code is implemented
      in Fortran 90). </p>
    <p>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... </p>
    <p>With the new modification, that part of the code is the
      following:</p>
    <p>****Variable declarations</p>
    <p>      PetscInt              ::  n_splits_retrieved<br>
            IS                    ::  IS_field(max_field)<br>
            KSP, pointer :: subksp_array(:)<br>
            PC                    ::  subpc(max_field)<br>
            INTEGER(iwp)          ::  nfield, ifield<br>
    </p>
    <p>**** FieldSplit Part ****</p>
    <p>   !    Allocate Fortran array to hold the KSP contexts<br>
              ALLOCATE(subksp_array(n_splits_retrieved)) <br>
      <br>
         !    Second call to get the actual KSP contexts<br>
              CALL PCFieldSplitGetSubKSP(solver%pc, n_splits_retrieved,
      & <br>
                                         subksp_array, ierr) <br>
      <br>
              IF (n_splits_retrieved >= 2) THEN<br>
                DO ifield = 1, n_splits_retrieved<br>
      <br>
                ! Configure the KSP for the velocity block (field 0)<br>
                  CALL KSPGetPC(subksp_array(ifield), subpc(ifield),
      ierr)<br>
                  CALL KSPSetType(subksp_array(ifield), KSPGMRES, ierr) <br>
                  CALL PCSetType(subpc(ifield), PCJACOBI, ierr) <br>
                ! Allows runtime options for sub-KSP<br>
                  CALL KSPSetFromOptions(subksp_array(ifield), ierr)<br>
                ! Choose a viewer (stdout for example)<br>
      !           viewer = PETSC_VIEWER_STDOUT_WORLD<br>
      !           CALL PCView(subpc(ifield),viewer,ierr)<br>
                END DO<br>
              END IF                                                </p>
    <p>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?</p>
    <p>Thanks very much for your time,</p>
    <p class="ds-markdown-paragraph"><span>Sincerely,</span></p>
    <p class="ds-markdown-paragraph"><span>Lucía Barandiarán</span></p>
    <p class="ds-markdown-paragraph"><span>Scientific software
        developer  - Dracsys </span></p>
    <p class="ds-markdown-paragraph"><span>Collaborator at MECMAT group
        - Universitat Politècnica de Catalunya (UPC)</span></p>
  </body>
</html>