xref: /petsc/src/dm/dt/tests/ex11.c (revision 503c0ea9b45bcfbcebbb1ea5341243bbc69f0bea)
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, PETSC_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     PetscFunctionReturn(0);
33 }
34 
35 /*TEST
36   test:
37     suffix: 1
38 TEST*/
39