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 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 CHKERRQ(PetscMalloc2(dim * numFaces, &dx, dim * numFaces, &grad)); 23 CHKERRQ(PetscFVCreate(PETSC_COMM_WORLD, &fvm)); 24 CHKERRQ(PetscFVSetType(fvm, PETSCFVLEASTSQUARES)); 25 CHKERRQ(PetscFVLeastSquaresSetMaxFaces(fvm, numFaces)); 26 27 /* Issue here */ 28 CHKERRQ(PetscFVComputeGradient(fvm, numFaces, dx, grad)); 29 30 CHKERRQ(PetscFVDestroy(&fvm)); 31 CHKERRQ(PetscFree2(dx, grad)); 32 CHKERRQ(PetscFinalize()); 33 PetscFunctionReturn(0); 34 } 35 36 /*TEST 37 test: 38 suffix: 1 39 TEST*/ 40