Actual source code: ex11.c
petsc-3.14.5 2021-03-03
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: {
8: PetscFV fvm;
9: PetscInt dim, numFaces;
10: PetscScalar *dx, *grad;
13: PetscInitialize(&argc, &argv, PETSC_NULL, help); if (ierr) return ierr;
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: PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad);
23: PetscFVCreate(PETSC_COMM_WORLD, &fvm);
24: PetscFVSetType(fvm, PETSCFVLEASTSQUARES);
25: PetscFVLeastSquaresSetMaxFaces(fvm, numFaces);
27: /* Issue here */
28: PetscFVComputeGradient(fvm, numFaces, dx, grad);
30: PetscFVDestroy(&fvm);
31: PetscFree2(dx, grad);
32: PetscFinalize();
33: return(0);
34: }
36: /*TEST
37: test:
38: suffix: 1
39: TEST*/