xref: /petsc/src/dm/dt/tests/ex11.c (revision 2ff79c18c26c94ed8cb599682f680f231dca6444)
1 #include <petscfv.h>
2 
3 static char help[] = "Test memory allocation of PetscFV arrays used in PetscFVComputeGradient";
4 
5 int main(int argc, char **argv)
6 {
7   PetscFV      fvm;
8   PetscInt     dim, numFaces;
9   PetscScalar *dx, *grad;
10 
11   PetscFunctionBeginUser;
12   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
13 
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));
25 
26   /* Issue here */
27   PetscCall(PetscFVComputeGradient(fvm, numFaces, dx, grad));
28 
29   PetscCall(PetscFVDestroy(&fvm));
30   PetscCall(PetscFree2(dx, grad));
31   PetscCall(PetscFinalize());
32   return 0;
33 }
34 
35 /*TEST
36 
37   test:
38     suffix: 1
39     output_file: output/empty.out
40 
41 TEST*/
42