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 PetscFV fvm; 7 PetscInt dim, numFaces; 8 PetscScalar *dx, *grad; 9 10 PetscFunctionBeginUser; 11 PetscCall(PetscInitialize(&argc, &argv, PETSC_NULL, help)); 12 13 /* 14 Working with a 2D mesh, made of triangles, and using the 2nd neighborhood 15 to reconstruct the cell gradient with a least square method, we use numFaces = 9 16 The array dx is not initialised, but it doesn't matter here 17 */ 18 dim = 2; 19 numFaces = 9; 20 PetscCall(PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad)); 21 PetscCall(PetscFVCreate(PETSC_COMM_WORLD, &fvm)); 22 PetscCall(PetscFVSetType(fvm, PETSCFVLEASTSQUARES)); 23 PetscCall(PetscFVLeastSquaresSetMaxFaces(fvm, numFaces)); 24 25 /* Issue here */ 26 PetscCall(PetscFVComputeGradient(fvm, numFaces, dx, grad)); 27 28 PetscCall(PetscFVDestroy(&fvm)); 29 PetscCall(PetscFree2(dx, grad)); 30 PetscCall(PetscFinalize()); 31 return (0); 32 } 33 34 /*TEST 35 36 test: 37 suffix: 1 38 39 TEST*/ 40