static char help[] = "Tests the DMShellCreate() and PetscSectionCreate() for fieldsplit initialization."; #include "petscsys.h" #include "petscvec.h" #include "petscmat.h" #include "petscdm.h" #include "petscdmshell.h" #include "petscksp.h" int main(int argc, char **argv) { int i, indsfield[8]; PetscInt numeq = 8, start = 1, NF, NE, numFields = 2, inds[8]; PetscErrorCode ierr; DM FSDM; PetscSection FSSection; Mat Kmat; Vec rhs, sol; KSP kspsol; const PetscScalar K[] = {4,2,0,0,2,1,0,0,2,8,2,0,1,4,0,0,0,2,8,2,0,0,3,2,0,0,2,4,0,0,2,1,0,0,0,0,1,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,1}; const PetscScalar r[] = {3,3,3,3,3,3,3,3}; indsfield[0] = 0; indsfield[1] = 0; indsfield[2] = 0; indsfield[3] = 0; indsfield[4] = 1; indsfield[5] = 1; indsfield[6] = 1; indsfield[7] = 1; for(i=0; i<8; i++) { inds[i] = i; } // We would like to use a DMShell to represent this data structure. // To do so we start by creating a section with 10points having one dof each. ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); ierr = PetscSectionCreate(PETSC_COMM_WORLD, &FSSection);CHKERRQ(ierr); ierr = PetscSectionSetNumFields(FSSection, numFields);CHKERRQ(ierr); // <---- We create the two fields ierr = PetscSectionSetChart(FSSection, start, numeq+1);CHKERRQ(ierr); // <---- We set the chart for the section /!\ This needs to be done after the creation of the fields ierr = PetscSectionGetChart(FSSection, &NF, &NE);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD, "start=%i, End=%i.\n",NF,NE);CHKERRQ(ierr); for(i=0; i