1 #include <petscfv.h>
2 
3 static char help[] = "Test memory allocation of PetscFV arrays used in PetscFVComputeGradient";
4 
main(int argc,char ** argv)5 int main(int argc, char **argv)
6 {
7     PetscErrorCode ierr;
8     PetscFV        fvm;
9     PetscInt       dim, numFaces;
10     PetscScalar    *dx, *grad;
11 
12     PetscFunctionBeginUser;
13     ierr = PetscInitialize(&argc, &argv, PETSC_NULL, help); if (ierr) return ierr;
14 
15     /*
16       Working with a 2D mesh, made of triangles, and using the 2nd neighborhood
17       to reconstruct the cell gradient with a least square method, we use numFaces = 9
18       The array dx is not initialised, but it doesn't matter here
19       */
20     dim = 2;
21     numFaces = 9;
22     ierr = PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad);CHKERRQ(ierr);
23     ierr = PetscFVCreate(PETSC_COMM_WORLD, &fvm);CHKERRQ(ierr);
24     ierr = PetscFVSetType(fvm, PETSCFVLEASTSQUARES);CHKERRQ(ierr);
25     ierr = PetscFVLeastSquaresSetMaxFaces(fvm, numFaces);CHKERRQ(ierr);
26 
27     /* Issue here */
28     ierr = PetscFVComputeGradient(fvm, numFaces, dx, grad);CHKERRQ(ierr);
29 
30     ierr = PetscFVDestroy(&fvm);CHKERRQ(ierr);
31     ierr = PetscFree2(dx, grad);CHKERRQ(ierr);
32     ierr = PetscFinalize();CHKERRQ(ierr);
33     PetscFunctionReturn(0);
34 }
35 
36 /*TEST
37   test:
38     suffix: 1
39 TEST*/
40