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;

 11:   PetscFunctionBeginUser;
 12:   PetscCall(PetscInitialize(&argc, &argv, 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:   PetscCall(PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad));
 22:   PetscCall(PetscFVCreate(PETSC_COMM_WORLD, &fvm));
 23:   PetscCall(PetscFVSetType(fvm, PETSCFVLEASTSQUARES));
 24:   PetscCall(PetscFVLeastSquaresSetMaxFaces(fvm, numFaces));

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

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

 35: /*TEST

 37:   test:
 38:     suffix: 1

 40: TEST*/