Actual source code: ex11.c

  1: #include <petscfv.h>

  3: static char help[] = "Test memory allocation of PetscFV arrays used in PetscFVComputeGradient";

  5: int main(int argc, char **argv)
  6: {
  7:     PetscFV        fvm;
  8:     PetscInt       dim, numFaces;
  9:     PetscScalar    *dx, *grad;

 12:     PetscInitialize(&argc, &argv, PETSC_NULL, help);

 14:     /*
 15:       Working with a 2D mesh, made of triangles, and using the 2nd neighborhood
 16:       to reconstruct the cell gradient with a least square method, we use numFaces = 9
 17:       The array dx is not initialised, but it doesn't matter here
 18:       */
 19:     dim = 2;
 20:     numFaces = 9;
 21:     PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad);
 22:     PetscFVCreate(PETSC_COMM_WORLD, &fvm);
 23:     PetscFVSetType(fvm, PETSCFVLEASTSQUARES);
 24:     PetscFVLeastSquaresSetMaxFaces(fvm, numFaces);

 26:     /* Issue here */
 27:     PetscFVComputeGradient(fvm, numFaces, dx, grad);

 29:     PetscFVDestroy(&fvm);
 30:     PetscFree2(dx, grad);
 31:     PetscFinalize();
 32:     return 0;
 33: }

 35: /*TEST
 36:   test:
 37:     suffix: 1
 38: TEST*/